Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Merging Textures

  1. #1
    Junior Member Regular Contributor Swiftless's Avatar
    Join Date
    Apr 2005
    Location
    Australia
    Posts
    118

    Merging Textures

    In my heightfield, I have a different texture depending on the height of my 'mountains'. This looks dodgy as the textures from one face to another do not merge into one another, how can I have 1 texture, merge with the one above, or fade into the one above, so I get a clean, smooth looking mountain.

    Thanks

  2. #2
    Advanced Member Frequent Contributor Ehsan Kamrani's Avatar
    Join Date
    May 2005
    Location
    Iran
    Posts
    547

    Re: Merging Textures

    I believe that you should use from the glTexGen() function:

    Regarding the specification of this function:

    ...If the texture generation function is GL_OBJECT_LINEAR, the function
    g = p1x0+p2y0+p3z0+p4w0
    is used, where g is the value computed for the coordinate named in coord; p (1) , p (2) , p (3) , and p (4) are the four values supplied in params; and x (o) , y (o) , z (o) , and w (o) are the object coordinates of the vertex. This function can be used to texture-map terrain using sea level as a reference plane (defined by p (1) , p (2) , p (3) , and p (4) ). The altitude of a terrain vertex is computed by the GL_OBJECT_LINEAR coordinate generation function as its distance from sea level; that altitude is used to index the texture image to map white snow onto peaks and green grass onto foothills, for example.

    But i never have used from this function to simulate the mountain.
    <span style="color: #006600">-Ehsan-</span>

  3. #3
    Junior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Dresden, Sachsen, Germany
    Posts
    205

    Re: Merging Textures

    you could create a texture that "simuates" this blend from one area to the other.

  4. #4
    Junior Member Regular Contributor Swiftless's Avatar
    Join Date
    Apr 2005
    Location
    Australia
    Posts
    118

    Re: Merging Textures

    I have tried what you said Ehsan, but It does not change anything. Maybe I am inserting the code incorrectly.

    Anyway, from what you have said, I am getting the idea that the code you want me to use will map the texture to the face.

    I already have them mapped, but I want it to blend the textures together where they meet, so that it doesnt go from Green, straight to brown, then straight to white. I want it to fade inbetween the textures so that it is seamless.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Dresden, Sachsen, Germany
    Posts
    205

    Re: Merging Textures

    I don't know if this works but you could use another texture map that represents alpha values that can be used to blend the two textures together. (makes the one texture fade out and the other fade in)

  6. #6
    Advanced Member Frequent Contributor Ehsan Kamrani's Avatar
    Join Date
    May 2005
    Location
    Iran
    Posts
    547

    Re: Merging Textures

    Another technique is to use from two textures: a grayscale texture and a texture for your model.You create your mountain based on the grayscale texture.Then you can use from the mutitexturing and blend the grayscale image with that texture.So the peaks are whiter than foothills.
    The result is like the function glShadeModel(GL_SMOOTH).
    Make sense?
    -Ehsan-
    <span style="color: #006600">-Ehsan-</span>

  7. #7
    Intern Newbie
    Join Date
    Feb 2005
    Location
    burton-on-trent [england]
    Posts
    35

    Re: Merging Textures

    swiftless, what graphics card are you using?

    this sounds like a task for the shading language if you have access to a fairly recent board...
    (needs to be geForce3 or newer - geForce FX is probably the best fit for your app)

  8. #8
    Junior Member Regular Contributor Swiftless's Avatar
    Join Date
    Apr 2005
    Location
    Australia
    Posts
    118

    Re: Merging Textures

    Carl, I am using an FX5900XT 128mb. Geforce 3 is recent?

    Ehsan, I know what you are on about but the terrain is generated randomly on startup. I will soon be implementing loading and saving of the terrain. But for now, I cannot use your idea.

    PowerPad, that sounds like it might just work, how would I do that? I would have to create another face inbetween the current ones for the new texture (the fad in and out). How would I achieve the fading effect? And how would I create the new face inbetween the current ones? I am using a triangle strip.

  9. #9
    Junior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Dresden, Sachsen, Germany
    Posts
    205

    Re: Merging Textures

    I don't know whether this (and how it really) works but my idea would be

    A)
    for those special triangles run a first pass rendering texture one.

    and use some sort of alpha channel that blends in a second pass the second texture with the first texture and thus blend it from texture one to texture 2

    B)
    if you know about those special triangles neigboring each other e.g.

    a line in your height map looks like this

    1 2 3 1

    where each number refers to a special triangle
    and 2 and 3 are your special triangles.
    You could create a texture for the case that
    2 and 3 are neighbors.

  10. #10
    Junior Member Regular Contributor
    Join Date
    Apr 2005
    Location
    Toronto
    Posts
    122

    Re: Merging Textures

    Question: Do you need to use 3 textures?

    Why not create a single texture that blends from high to low and then do a lookup into that texture using your height to modulate the texture coordinates?

    (note: this would also solve your binding problem as you would only need to bind to a single texture at the start of your draw pass)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •