PDA

View Full Version : OpenGL, 3D Textures and Cg shaders



DaMangz
10-30-2002, 08:44 PM
Hi,
This is a multi-variable list of questions, any help will be appreciated.

I am building a terain engine. What I want to do is generate the textures procedurally while the program is running.

I have been looking at the Cg terrain demo, and it uses a 3D texture. It looks like it just copies the textures onto each other somehow from a 3D texture. I really haven't figured it out yet.

How do 3D textures work?

Is there a way to just make Cg do the textures, not the vertices? I need to calculate the verts for my game. The cg demo seems to calc the verts in the shader. I don't want this. I need the verts for collisions and stuff.

I know this is alot of Cg questions for the OpenGL board, so how do you do this stuff in OpenGL without Cg? I see these extensions but I don't have any documents to explain to a beginner how to use them at all.

How do you use register combiners, vertex programmers and shader in OGL without Cg? I will probably use Cg because it looks cool and easy to use, but I'd also like to understand how Cg works in the graphcis layer.

Thanks

vladk
10-30-2002, 10:30 PM
The fastest way, that worked for me ok, was to use textures only as colour layer to the terrain. The terrain itself I made with a height map.

Consider your terrain to be XZ coplanar. Thus, each vertex should have their -Y values set according to the height of that point. For example, take a plasma fractal for a height map. 255 is highest, 0 is lowest. Set, for example, height of 20 as sea level.

Now decide the scaling. You have to interpolate 255 values in your lowest-to-highest point. Say you are using units as meters, meaning Y value of -10 represents 10 meters FROM THE LOWEST POINT.

Now you should make a predrawing routine that scans the height map (a simple grayscale BMP, or RAW) and interpolates each pixel value as height of the vertex.

This means you should have exactly the same amount of vertices as you have pixels in the heightmap.

Maps of 128x128 or 256x256 are suitable. Of course, in this case, your height map DOES NOT to be proportioned as exponent of 2. It will not be used as TEXTURE.

A triangle strip in a list should speed the things to the top!

Hope this helps.