Jump to content
  • Advertisement
Sign in to follow this  
Mawww

fading detail textures with distance

This topic is 5012 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

got a problem with my terrain engine, currently it is running with frustum culling and texture splatting but i got a base texture and i want to use splatting only for near terrain and keep base texture for far one. i just have no idea on how to achieve it, perhaps projecting an alpha texture or something like that, but i already use alpha for splatting... any idea ?

Share this post


Link to post
Share on other sites
Advertisement
Here's how I do it.

Now I'm using Geomipmapping for my terrain with indexed patches, so I don't know if this is how you do yours or not.

But basically, I get the position of the player (camera), and figure out where inside the terrain it is, meaning which vertex on the terrain is the player closest too. Then I create an indexed array of all vertices within a certain radius.

So lets say I want to draw the detail texture 16 vertices out from the player in all directions. This is how I create the index array.

int mapX = playerPos.x / terrain.worldWidth;
int mapY = playerPos.z / terrain.worldLength;
int *indices = new int[32*32*6];
int index=0;
for(int i=mapX - 16; i < mapX+16; i++)
{
if(i < 0 || i >= terrain.Cols) continue;
for(int j=mapY-16; j < mapY+16; j++)
{
if(j < 0 || j >= terrain.Rows) continue;

// first triangle
indices[index++] = j*terrain.Cols+i;
indices[index++] = (j+1)*terrain.Cols+i;
indices[index++] = j*terrain.Cols+i+1;
// second triangle
indices[index++] = (j+1)*terrain.Cols+i;
indices[index++] = j*terrain.Cols+i+1;
indices[index++] = (j+1)*terrain.Cols+i+1;
}
}


So basically that's how you could setup all the indices to render for the detail texture or splat if you're doing texture splats. This will draw individual triangles though, so if you want triangle strips you'll have to modify it.

If you want a fade out effect, you could then just create an array of actual vertices, then copy the terrain vertex data into the new vertex array and also set alpha values for each vertex based on the distance from mapX and mapY.

Share this post


Link to post
Share on other sites
Assuming I'm interpreting the question correctly (it's late so I'm probably not); Once you have the "only splat near the viewer" sorted:

- use an ADDSIGNED blend to apply the detail texture on top of the base map

- mip map your detail texture

- when creating the mip map levels for the detail texture, fade each level progressively towards RGB=0,0,0 as you go down in size. So when rendered, as polygons get further away from the camera, the detail map fades away, and then any polygons past that point don't need to use the detail map.

Share this post


Link to post
Share on other sites
Quote:
Original post by S1CA
fade each level progressively towards RGB=0,0,0 as you go down in size.

Shouldn't you fade towards RGB = ( 127, 127, 127 ) since you are using 'signed' texture so it actualy represents zero?

Share this post


Link to post
Share on other sites
Quote:
Original post by _DarkWIng_
Quote:
Original post by S1CA
fade each level progressively towards RGB=0,0,0 as you go down in size.

Shouldn't you fade towards RGB = ( 127, 127, 127 ) since you are using 'signed' texture so it actualy represents zero?


That's what I meant by 0,0,0 - i.e. from -x or +x towards 0. I tend to think of pixel colours as float values and as signed float values with operations like addsigned.



Quote:
Original post by oconnellseanm
Don't use signed values.


Any particular reason? - IMO addsigned style blends and signed textures make much more sense for plain detail texturing because your high frequency detail usually adds both highlight AND shadow.

Share this post


Link to post
Share on other sites
I recommend the fading mip-map technique as well. Some tips :

1) Use trilinear filtering to fade it smoother than point sampling the mip-levels

2) for addsigned or modulate2x, the fade color is 0x80808080

3) for modulate, the fade color is 0xffffffff

4) for add, addsmooth, the fade color is 0x00000000

5) You can use the nvidia photoshop plugin to create the mip-levels with the fade color you specify

6) This general technique works the same way in multi-texture or multi-pass

Share this post


Link to post
Share on other sites
If you're willing to get a little more advanced, you could also use a vertex (or pixel if you don't mind the cost) shader to fade the alpha out over distance using a similar equation to distance based fog. To make this more efficient you could then cull away chunks that are beyond your 0 alpha distance. I don't have time to go into detailsn ow but could provide sample shader code if it helps?

Cheers,

Steve

Share this post


Link to post
Share on other sites
That's a good point Mephs.

Of course, it won't clamp properly - no vertex-level operation can do a per-pixel clamp.

That's what makes textures so useful for this sort of thing.

One way you can sort of get clamping is if you move the 0..1 blending weight into a range like .25-.75, and then expand it per-pixel.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!