PDA

View Full Version : Merging Textures



Swiftless
05-29-2005, 04:08 AM
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

Ehsan Kamrani
05-29-2005, 04:28 AM
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. :(

powerpad
05-29-2005, 04:38 AM
you could create a texture that "simuates" this blend from one area to the other.

Swiftless
05-29-2005, 10:30 PM
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.

powerpad
05-30-2005, 12:26 AM
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)

Ehsan Kamrani
05-30-2005, 02:36 AM
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-

carl_lewis
05-30-2005, 07:36 AM
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)

Swiftless
05-30-2005, 07:10 PM
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.

powerpad
05-31-2005, 12:07 AM
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.

PickleWorld
05-31-2005, 06:26 AM
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)

plasmonster
05-31-2005, 05:13 PM
Try a search for "Texture Splatting."

You guys are closing in on the basic idea, which is to composite an alpha texture with a diffuse texture and alpha blend each layer, or "splat", one after the other. This can be done with OpenGL's combiners, or in a fragment program.

This approach requires no modifications to the underlying geometry. The tricky bit, if there is one, is figuring out how to best chunk your splats so that your batching is optimal.

05-31-2005, 07:47 PM
From what I gather, I need the 3 textures. They are each different colours and of different patterns.

Unless, are you saying, to use one texture, that covers the things in the other 3, and maps the certain parts of that texture to where they belong. So instead of a texture at the top of the Mountain, it will map the top part of a texture to the top of the Mountain, the middle of the texture to the middle of the mountain, and the bottom of the texture to the bottom of the Mountain?

plasmonster
05-31-2005, 09:02 PM
Suppose you have 3 different materials in your world: rock, dirt, and grass. For each of these textures you would have a separate alpha texture representing the amount of that material at each texel over a given area of the terrain. For example, the rock's alpha texture would have 1's where there's rock only, and a gradual fade to 0 where there's no rock at all; likewise for the dirt and grass. When these 3 material-alpha pairs are alpha-blended together with the scene you'll have a smooth transistion from one material to another across the terrain.

You're limited only by your imagination in the ways you might populate these alpha textures. You could base the alpha on height, slope, temperature, smell, whatever grabs you. The important thing is that the alpha sums to 1 at each sample when taken together. This may require a re-normalization step during creation time; otherwise, visible seams may appear as a result of the blending.

If you can run this in a fragment program/shader, you can most likely pull this off in one pass. You can also eliminate alpha textures by packing 4 channels of alpha into a single RGBA, for instance. This will get you 5 splats per alpha texture, if you can render the first opaquely.

This can be done in the fixed-function pipeline too, but may require more passes.

There's some more information here: http://www.vterrain.org/Textures/detail.html