![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Lead Moderator Join Date: Aug 1998
Posts: 2,568
| Procedural Texture Generation for Height Mapped Terrain - By Perspective http://cprogramming.com/discussionar...eneration.html |
| kermi3 is offline | |
| | #2 |
| Super Moderator Join Date: Aug 2001
Posts: 7,472
| Very good article and the procedure works very well with pre-designed textures. You can have some issues where the texel color does not match the height very well, but with carefully designed textures this technique can yield some very nice results. Also an addition to it would be to have the height ranges overlap so that when you are in the overlap area you perform a linear interpolation or do an additive blend between the two. This makes for some very nice transitions between terrain types. Good article.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #3 | ||
| Crazy Fool Join Date: Jan 2003 Location: Canada
Posts: 2,588
| Quote:
Another thing id like to point out is the convention used for texture selection. I kept the article simple but another (more realistic) approach is to use slope in selecting a texture. You'll notice that the examples i posted have grass (in the grass range) on the side of a steep mountain. This would more likely be rock in a realistic situation because the slope is so steep. I'll leave slope calculations for texture selection as an excersize for the reader ![]() Quote:
__________________ jeff.bagu.org - Terrain rendering and other random stuff | ||
| Perspective is offline | |
| | #4 |
| Super Moderator Join Date: Aug 2001
Posts: 7,472
| No problem. To fix the overflow problem you would just normalize all coordinates so that they always fall between 0.0f and 1.0f. This would then work with any size texture and with any type of color addition, multiplication, etc. With addition you would have to clamp, but that shouldn't be too much of an issue.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #5 |
| Crazy Fool Join Date: Jan 2003 Location: Canada
Posts: 2,588
| >>This would then work with any size texture ah yes, you raise a good point. The article assumes you pull indices from the textures which directly map to the height map. ie. the height map and the textures have to have the same dimensions. If your textures arent the same size as your height map you have a couple of choices. Clamping, as Bubba mentioned, is one option to essentially stretch your smaller texture (or shrink your larger texter, though the latter is more often the case) to cover the height map.
Which to use highly depends on the particular situation your in.
__________________ jeff.bagu.org - Terrain rendering and other random stuff |
| Perspective is offline | |
| | #6 |
| Super Moderator Join Date: Aug 2001
Posts: 7,472
| And another technique that can minimize those nasty texture 'borders' is the concept of mirroring textures. In Direct3D this is done using a simple API function. Code: Device->SetSamplerState(<texture_sampler_stage>,D3DSAMP_ADDRESSU,D3DTADDRESS_MIRROR); Device->SetSamplerState(<texture_sampler_stage>,D3DSAMP_ADDRESSV,D3DTADDRESS_MIRROR); 0.0f,0.0f 4.0f,0.0f 0.0f,4.0f 4.0f,4.0f You will see 4 mirror images of your texture. Note that because of the nature of the mirror operation you will probably need an even number of repeats in order for the last texture to correctly mirror with the first. This is only necessary if you are wrapping the texture across an object where the left side of the texture meets the right side - as in the case of texture mapping a sphere or a cylinder. I have experienced problems on my video card with the mirror function. It seems to be 1 pixel off in both directions so you get this nasty grid which kills the idea of trying to hide the underlying grid in the first place. Perhaps there is a driver patch that addresses this issue. The other address mode that Perspective described above is D3DTADDRESS_CLAMP.
__________________ If you aim at everything you will hit something but you won't know what it is. Last edited by Bubba; 02-25-2005 at 04:51 PM. |
| Bubba is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| d3d9 c++ texture wrapper... again... | yaya | Game Programming | 0 | 04-01-2009 01:08 PM |
| D3d Texture Wrapper == ARRRGGGGHHH | yaya | Game Programming | 1 | 03-25-2009 06:41 PM |
| Why doesn't glbindtexture recognize the texture id I pass it? | Shamino | Game Programming | 4 | 02-27-2008 03:10 PM |
| My terrain Generation function's fubar. | indigo0086 | Game Programming | 12 | 06-22-2007 09:57 AM |
| Pong is completed!!! | Shamino | Game Programming | 11 | 05-26-2005 10:50 AM |