Rendering something in UV space.

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Rendering something in UV space.

Post 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.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Rendering something in UV space.

Post by mongoose7 »

In the vertex shader you could try setting x = u, y = v, z = far/2.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Rendering something in UV space.

Post 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.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Rendering something in UV space.

Post 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!
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Rendering something in UV space.

Post 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.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Rendering something in UV space.

Post 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!
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Rendering something in UV space.

Post 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"..
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Rendering something in UV space.

Post by Mel »

That reminds me of a program called "Genetica" which was capable of generating seamless textures :)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply