Procedural Texture Generation for Height Mapped Terrain - By Perspective

This is a discussion on Procedural Texture Generation for Height Mapped Terrain - By Perspective within the Article Discussions forums, part of the Community Boards category; For our next article - Procedural Texture Generation for Height Mapped Terrain - By Perspective http://cprogramming.com/discussionar...eneration.html...

  1. #1
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595

    Procedural Texture Generation for Height Mapped Terrain - By Perspective

    For our next article - Procedural Texture Generation for Height Mapped Terrain - By Perspective


    http://cprogramming.com/discussionar...eneration.html
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Bubba
    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.
    indeed Bubba, this is a cool way to increase the range of colours (blending) in the texture. The only thing to watch out for when doing this is the percentage calculation. Calculating overlaped ranges the way i described in the article can result in percentages that add up to more than 100! which means texture values overflowing. With some modifications this can be accounted for though.

    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 Originally Posted by Bubba
    Good article.
    Thanks,

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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.

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >>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.
    • The advantage to clamping is that there will be no visible repeating in the texture.
    • The disadvantage is that you will lose detail in your texture (assuming the texture is larger than the height map)

    An alternative to clamping is repeating. Here, instead of normalizing, you wrap the texture indices to make the texture repeat.

    • The advantage to repeating is that you get the maximum possible detail from the texture at any given spot on the terrain... there is no "stretched out" effect.
    • The disadvantage to repeating is that areas on the boundries of the texture dimensions can have noticable edges where the texture repeats. Also, different areas of the heightmap can have the same area of a texture on them (which is only a problem if your texture has very distinctive fearures)

    "Tile-able" textures can solve the noticable edge problem when repeating.

    Which to use highly depends on the particular situation your in.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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);
    This will cause the texture to be mirrored on both the vertical component (v) and the horizontal component (u). This is very useful for texturing large areas with the same texture w/o all the hassle of creating seamless textures. Any coordinate below 0.0f or above 1.0f is correctly mirrored. So if you set mirror and specify tex coords of

    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.
    Last edited by VirtualAce; 02-25-2005 at 04:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. d3d9 c++ texture wrapper... again...
    By yaya in forum Game Programming
    Replies: 0
    Last Post: 04-01-2009, 02:08 PM
  2. D3d Texture Wrapper == ARRRGGGGHHH
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 03-25-2009, 07:41 PM
  3. Replies: 4
    Last Post: 02-27-2008, 03:10 PM
  4. My terrain Generation function's fubar.
    By indigo0086 in forum Game Programming
    Replies: 12
    Last Post: 06-22-2007, 10:57 AM
  5. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21