# fading detail textures with distance

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

## 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 on other sites
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 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 on other sites
Quote:
 Original post by S1CAfade 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 on other sites
Don't use signed values.

##### Share on other sites
Quote:
Original post by _DarkWIng_
Quote:
 Original post by S1CAfade 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 oconnellseanmDon'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 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

3) for modulate, the fade color is 0xffffffff

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 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 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.

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009417
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!