[Closed] export bitmap bake of HLSL material
Hello together,
I need to implement a feature that let’s me export bitmaps of HLSL shaded surfaces. I don’t need any cage or fancy stuff, just the plain material as it appears on the surface with the current configuration of parameters.
I know I’m not the first one asking to render out a shader but I haven’t found an answer yet. I’d write a material plugin that does the same, but that’d be quite ineffiecient wouldn’t it.
Any ideas? I’m curious.
cheers,
Gunnar
…welcome to reverso world
You could render the model to a texture in a shader (off screen render target).
That will only work if your model is nicely UV unwrapped.
Then you have the texture, but I’m not to sure how you save the texture to disk, since you only have it on the graphics card at that point.
I’m guessing you probably could get the pixel values and create a bitmap from it, but I don’t know for sure since I never tried.
Doing it through a software renderer like max’s render to texture will fail obviously since it will not render HLSL shaders.
Second thought.
If you did have nice UVs, maybe you could ‘flatten’ the object in max’s viewport by using the UVs to flatten the object to a flat mesh.
Then render that flat object into a bitmap.
(Essentially just grabbing a viewport screenshot should do the trick if you set the ratio of the viewport to a square)
rockin! Cheers kees!
I’ll have a look into offscreen render targets. That does indeed sound promising. The UVs are not my concern yet. a planar mapping does the job for now.
Right, so were you talking about the IDirect3DDevice9::CreateOffscreenPlainSurface method? or is there some smooth way max does faciliate this?
I looked into mental ray yesterday as I remebered it supporting real time shaders as well. My reference was unfortumately just mentioning Cg in a rather old-fashoined style with a struct syntax… Still a way of doing it probably. Then you’d have to get max to compile Cg code on the fly to get the real-time feedback of the tool… Don’t know if that’s possible. Do you know about some DirectX online compiler for Cg?
thanks again for your answer kees!
Gunnar
I was talking about the one a few items below it:
http://msdn2.microsoft.com/en-us/library/bb174361.aspx
“Render Target”
But maybe yours works too, I never used a ‘OffscreenPlainSurface’ so I’m not sure what it does.
-Kees
Hi Kees,
Sorry, there were like usual more concerns regarding the whole project…
However, it worked finest. After checking through the various Interfaces Max kindly offers it was eventually a case of invoking a self standing Direct3D scene to fulfill the needs. Viewport grabs through gw->GetDib() would have brought multiple draw backs with them, like light disabling and object hides, since i needed a clean square render of the shader.
But yes, like mentioned, simple Direct3D scene, mesh conversion, shader initialisation and after a render to texture a SafeSurfaceAsFile() does the job.
Cheers for the hint again,
Gunnar