Archived

This topic is now archived and is closed to further replies.

Multitextured Terrain

This topic is 5624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there. I want to create a terrainrenderer but I have one problem. I don''t want to use just one big texture. My idea is to create the world out of different textures like grass, stone, snow etc. These texture are drawn on the specified vertexes. But how can I create a smooth drawing from one texture to another like grass to snow. I saw this technique in many demos and games (project igi, giants...) but I don''t know how this can be created. I''m using DirectX 8.1 for rendering.

Share this post


Link to post
Share on other sites
you can generate one texure inside the game or app or whatever which will be blended amazingly from other textures.
you have your snow, grass, paper textures and you look on the values of your height map or anything. according to some values you specify you say:
"hmm!! on this pixel i should have 20% grass, 60% paper and another 20% snow!"
"hmm!! on this pixel i should have 99% snow, 1% grass!"
and then you blend them amazingly, and they''ll look sexy and kewl coz it''s according to the height map and the height map is beautiful.
this is a basic idea you can do more amazing stuff i guess... and there are probably more amazing and useful ideas but my d3d brain is small so i can''t tell.

May The Gzoo Be With You!
~Lord Gzoo

Share this post


Link to post
Share on other sites
you do that vertex by vertex right, not pixel by pixel? is there something in the D3DFVF_XYZ|blah blah, another one of those that lets you specify the multitexturing percentage. then it blends by vertexes, not pixels (i think)

Share this post


Link to post
Share on other sites
RTFM for info on multi-texturing, however it seems to be a complete mess in DX 8.1 as different 3D cards have all sorts of limitations on render/blending states.
But you can just draw different textures on different polys, then do another render pass with alpha blended polys between different textures to smooth between them.
Ignore Gzoo unless you only want to support high-end cards with pixel shaders.

Share this post


Link to post
Share on other sites
quote:
Original post by billybob
you do that vertex by vertex right, not pixel by pixel? is there something in the D3DFVF_XYZ|blah blah, another one of those that lets you specify the multitexturing percentage. then it blends by vertexes, not pixels (i think)


Nope, you use the alpha values of the texture i think. That gives you per-texel accuracy (not really per-pixel, but close enough)

Steve
DirectX Programmer
Soon to be the new Bill Gates

Share this post


Link to post
Share on other sites
quote:
Original post by Evil Bill
[quote]Original post by billybob
you do that vertex by vertex right, not pixel by pixel? is there something in the D3DFVF_XYZ|blah blah, another one of those that lets you specify the multitexturing percentage. then it blends by vertexes, not pixels (i think)


Nope, you use the alpha values of the texture i think. That gives you per-texel accuracy (not really per-pixel, but close enough)

Steve
DirectX Programmer
Soon to be the new Bill Gates

so thats how you do it. i will be needing this very same thing for a game, with heightmapped terrain. the problem is it isn''t one texture across the whole terrain, the heightmap loader makes triangles with a variable that sets how many squares of the terrain a texture covers before it is tiled. so your method would mean that i can''t set the blending level across the whole terrain, just the texture. what i thought i would have to do, is make a blend map the same size as the heightmap. then set each vertex''s ''texture percentage'' somehow, so this vertex is 20% grass, 80% rock. and the one next to it is 80% grass, 20% rock. it would then interpolate across the terrain triangle. how do i do this?

Share this post


Link to post
Share on other sites
Doing all this, why not just set each vertex to one texture e.g grass, then each triangle blend the three textures together from each vertex?
Only problem with these ideas is that for with triangles you need 3-texture multitexture, which means at least 2 passes (except radeon8500 with 3 texture units and GF4 with 4), plus if you''re using a lightmap too that''s 4, then detail textures...
Could be doing 3 passes on "old" cards like TNT2,GF256,GF2



Read about my game, project #1



John 3:16

Share this post


Link to post
Share on other sites
quote:
Original post by d000hg
Doing all this, why not just set each vertex to one texture e.g grass, then each triangle blend the three textures together from each vertex?
Only problem with these ideas is that for with triangles you need 3-texture multitexture, which means at least 2 passes (except radeon8500 with 3 texture units and GF4 with 4), plus if you''re using a lightmap too that''s 4, then detail textures...
Could be doing 3 passes on "old" cards like TNT2,GF256,GF2



Read about my game, project #1



John 3:16


that is exactly what i''m trying to do, how do i do it? i don''t need blending of the whole square, i just need smooth transitions between the changes in textures. is that what you are talking about?

Share this post


Link to post
Share on other sites
Well I''m going to assume you mean my idea about setting each vertex with a texture.

So lets have 3 vertices V1,V2 & V3. Each has the corresponding texture T1,T2,T3.

Now at V1, we have 100% T1 & 0% T2 & T3. Similarly for V2 & V3.

What to do:
1)Draw the triangle V1,V2,V3 with T1, not using transparencyat all.
2)Now draw the triangle again with T2, but this time set the alpha component of the color in the vertices to 0 for v2 & 1 for the other 2 vertices, so at V2 you only see T2.
3)Lastly, repeat step 2 with T3; this time have it transparent for V1 & V2, opaque for V3.
This should give you a triangle with T1 at V1, T2 at V2 & T3 at V3, all smoothly blended together.
You''ll have to set the renderstates to get aplha colour data from vertices and color data from the textures.
I think that''s fairly clear, if not email me. Wait & see if anyone says it''s rubbish first though!

I have a question on this, too. When you add LOD to remove polygons, a typical approach is to only look at every second vertex, or every 4th or so on. But with this method when you remove a vertex you lose texture information. Is this likely to be a huge problem and if so how would you avoid it?



Read about my game, project #1



John 3:16

Share this post


Link to post
Share on other sites
about how to do loding of the terrain meshes, i think this would work for my terrain vertex buffer, the way i have it set up is there is a variable that says how many squares a texture covers before its texel coordinates start again. as long as you don''t lod out the edges of a texture, you wouldn''t lose texture information. i guess you would have to make sure that the textures covered a 2^x amount of squares in order to lod well. but then, the max squares is like 8 before you get too low of texture detail. but as long as you don''t eliminate the edge veriecs of a texture, you should be fine iwth the texture information.

Share this post


Link to post
Share on other sites
I am also very interested in finding out how to do this.

d000hg: Ignoring LOD for a moment, does this mean that you would have to rebuild the data in your vertex buffer each time? So that you can update the diffuse and texture coordinates? Could you use multiple stream sources for this. The first stream containing the vertex information (x,y,z) and the second stream containing the diffuse/texture information? Then (in a brute force method) all you would need to do is create 4 vertex buffers (one for positional information and the other 3 for the texture information) and during the render phase just change stream 1 to each of the texture streams for each rendering pass?

Share this post


Link to post
Share on other sites
TooTer:
I think you would rebuild VBs each frame yes, but gor a heightmapped terrain that''s better because think how much space you can save with a heightmap than a big bulky VB. For instance I store heights as shorts, which are then multiplied by a scaling factor to get the height in floats.

Your idea for 4 VBs sounds good, but I''m not up to scratch on how to do that. With single-pass multitexturing, can you make each texture stage get its vertex data from different streams? Otherwise you HAVE to do it in single passes I think, because the alpha components of the vertices are different for each texture. Ideally you''d want to do this in a single pass, not sure how though - if you understand the streams and multitexturing stuff well can you email me and explain please? Also if you want to ask about the theory side - think I got that down ok





Read about my game, project #1



John 3:16

Share this post


Link to post
Share on other sites
Rebuilding vertex buffers every frame is a big performance hit in my tests though, so if the camera is not moving a lot you''ve really got to check if its neccesary...

Share this post


Link to post
Share on other sites
quote:

Hi there. I want to create a terrainrenderer but I have one problem. I don't want to use just one big texture. My idea is to create the world out of different textures like grass, stone, snow etc. These texture are drawn on the specified vertexes. But how can I create a smooth drawing from one texture to another like grass to snow. I saw this technique in many demos and games (project igi, giants...) but I don't know how this can be created. I'm using DirectX 8.1 for rendering.



One nice way to do this is to allow each vertex to have two texture stages. You can put your grass texture in one, then the sand on in the other. Then you can use the vertex alpha to control how much of each is shown (this is easiest to do using pixel shaders). So if you imagine a vertex alpha on 1.0f is fully texture 1, 0.0f is texture 0, and 0.5f is half-and half, then you can apply smooth and arbitrary blends across terrain.

I would highly recommend reading the Multitexturing part of the following link to see what I mean: http://www.gamasutra.com/features/20020626/hargreaves_02.htm.

You need to be a member of gamasutra to read this but its free to sign up.

(EDIT)

Erm, well, actually I thought Shawn had written about the texture blending using the vertex alpha in that article, but it turns out he didn't, but its still worth a read. Still, that is the way that the texture blending is done.

Rory.


[edited by - protopornopants on July 25, 2002 11:05:33 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by AndyM
Rebuilding vertex buffers every frame is a big performance hit in my tests though, so if the camera is not moving a lot you''ve really got to check if its neccesary...


Yeah it can be a speed hit, but if you can''t get a decent framerate anyway on your p3/4 with GF2/3/4 doing something that''s been around since pre 3D accelerator days, you are rubbish! Check you''re using a dynamic VB, using the D3DLOCK_DISCARD flag gave me a big increase - I got from 20fps to 40 just doing those 2 things.

You could see if all the stuff you need to draw is in your VB from last frame, but I don''t think it''s necessary.



Read about my game, project #1



John 3:16

Share this post


Link to post
Share on other sites