Page 1 of 1

Rendering something in UV space.

Posted: Sat Aug 06, 2016 7:29 pm
by christianclavet
Hi,

I'm creating terrains textures in IRB and they are done in real time from shaders. Is there a way to "bake" the shader rendering using the terrain UV, so I could use the terrain mesh and generated texture in other applications? The rendering of the shader will be done in UV space...

Is there a code example somewhere? The only thing I was thinking and could probably do myself is take a RTT from a camera from a top angle (since a terrain come from a flat plane). I'm pretty sure the texture will get more and more stretched when there are mountain and would only look good on "mostly flat" areas. So I was wondering if a RTT could be done from UV space of the model instead of a camera view.

Re: Rendering something in UV space.

Posted: Sun Aug 07, 2016 1:17 am
by mongoose7
In the vertex shader you could try setting x = u, y = v, z = far/2.

Re: Rendering something in UV space.

Posted: Sun Aug 07, 2016 2:03 am
by christianclavet
This would give me a picture of the UV Map with the texture rendered? I would need to "bake" the texture of the terrain that is done with the shader.

Re: Rendering something in UV space.

Posted: Sun Aug 07, 2016 10:25 am
by mongoose7
The pixel shader does the "baking". The vertex shader just flattens the scene, proportionately to the UV coordinates. In any case, the picture of the UV map is what you asked for!

Re: Rendering something in UV space.

Posted: Sun Aug 07, 2016 12:16 pm
by Mel
In the vertex shader you could try setting x = u, y = v, z = far/2.
That way you'd flatten the terrain. What if the shader is needs some height information? Instead, Pick the terrain bounding box, build an orthographic projection around it (it is surprisingly easy :)), and set the camera with the z axis being the height. That way you can render the terrain from the top into a perspective less view. Picking the terrain bounding box as the reference for the orthographic projection makes it so the render fills the whole texture space, and you should be pretty much done. And unless you're doing something with the perspective in your shader, (perhaps some mipmapping or stuff like that to avoid atlas border glitches) you don't need to change it.

Re: Rendering something in UV space.

Posted: Fri Aug 12, 2016 8:42 pm
by Vectrotek
You could have a look at the Blender Python scripts that deal with baking Procedural
Textures onto an image using the existing UV Map assigned to the given material..
(I know there is one somewhere)
I think I understand your question and Googled it, but Google don't
seem to have much on the subject.. (or we are using the wrong terminology)
Python is very like C++ so there should be some clues there.
Perhaps Max scripts could also offer some clues.
Interesting thing though..
Like to hear what you find out!

Re: Rendering something in UV space.

Posted: Fri Aug 12, 2016 8:56 pm
by Vectrotek
You can't really get anything back from your shaders, so you might have to "re-code" those
procedures from your shaders into a C++ function which would then plot those
pixels onto an image using a Specific Formula (which I can't find) that uses your UV Map Coords
and probably all your Vertex 3D positions as well.
Looks like a extremely complex problem..
Definitely the kind of thing that would be used to program 3D Apps that
can "Bake" procedural textures onto an image.

This looks interesting
http://libnoise.sourceforge.net/example ... index.html

Google "baking procedural textures programmatically"..

Re: Rendering something in UV space.

Posted: Tue Aug 16, 2016 12:50 am
by Mel
That reminds me of a program called "Genetica" which was capable of generating seamless textures :)