Archived

This topic is now archived and is closed to further replies.

"Fading" from texture to texture (Blending, Maybe?)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Thanks for reading this =)! Well, anyhow, my current project will use height maps, and I would like to know something. I have seen many games with terrain (hills, etc.) that kind of "fade" from one texture to another. For example, a grass texture smoothly "fades" (blends?) into a dirt or snow texture. I would like to know how this is done. I have glBlendFunc(), but if it is correct I don''t know the correct parameters. This is what I am doing just to figure it out:
// Grass Texture
glBindTexture(GL_TEXTURE_2D, idGrass);
// 64x64 Quad (Size of Texture)
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(.64f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(.64f, .64f);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, .64f);
glEnd();

// Dirt Texture
glBindTexture(GL_TEXTURE_2D, idDirt);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f( 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(-.64f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(-.64f, .64f);
glTexCoord2f(0.0f, 1.0f); glVertex2f( 0.0f, .64f);
glEnd();
 
I don''t know if that is the correct way to do it. Please help if at all possible =)! Thanks, Matt U. If thispost = 0 Then GoBack() Else Read() End If

Share this post


Link to post
Share on other sites
I had this cool idea todo terrains with 3d textures, Like its a cube, the top is snow and there is grass then dirt... and going horizontally across the cube is the texture for each layer... Make sence?

Thatway you can give the terrain real XYZ coordinates, If you have linear filtering it should blend in between each height, eg merge from grass into hills.

I just thought about this a while ago, I never actually come around to doing it, does anyone know if it works very well?

Share this post


Link to post
Share on other sites
quote:
Original post by Thorin_nz
I had this cool idea todo terrains with 3d textures, Like its a cube, the top is snow and there is grass then dirt... and going horizontally across the cube is the texture for each layer... Make sence?

That way you can give the terrain real XYZ coordinates, If you have linear filtering it should blend in between each height, eg merge from grass into hills.

I just thought about this a while ago, I never actually come around to doing it, does anyone know if it works very well?
Not until computers get quite a bit faster. I'm not sure about the theory behind your method, but I do know that one 3D texture, 256x256x256 takes up 32MB of video memory. Imagine the framerates on today's machines [shudders]...



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]


[edited by - iNsAn1tY on March 24, 2003 2:23:51 PM]

Share this post


Link to post
Share on other sites
I think what you''re trying to say is change from a grass tile to a dirt one, i belive you can''t use glBlend to achieve this effect, you''ll have to use transition tiles wich you than lay over the terrain you want.

If you have tiles like this:

1 1 1 0
1 1 1 0

and would like to change to a tile like:

2 2
2 2

you lay the second 1''s tile over the 2''s tile getting

1 2
1 2

chanan!

Hehe! hope that helped!

cya

Share this post


Link to post
Share on other sites
Shaders are probably the way to go. Simply use the height of the vertex to get a ''blend factor'' that you then use on each texture. I''d recommend adding some noise to it, because otherwise you''re going to get all these lovely straight lines all over your landscape.

As for 3D textures, they would be nicest, but they''re way out of reach for the time being.

If you can''t do shaders, then it''s more difficult.

Firstly, I''d recommend using the ARB Multitexture extensions.

Then, see if you can''t use the alpha values at the vertices to fade one texture from opaque to transparent and the second from transparent to opaque. As long as all the alpha values at any given vertex add up to 1.0f, you should be OK. I don''t know the multitexture extensions very well, but I think this is possible - if not, you''ll have to do it in multiple passes, but the principle is the same.

Anfernius suggested ''crossover tiles,'' and I think you''ll find you may want them too. Unless your terrain textures are very generic/noisy, simply fading from one to the other in a linear fashion would look at tad... weird.

Hope I helped.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.

Share this post


Link to post
Share on other sites
one thing about using the alpha values (though vertex shaders should cause the same problem)... i was using this until now, when i realized that this method is NOT working well with lod. the reason is simple: if you insert more vertices the alpha/height values will be interpolated differently and the whole look of your blended textures will change. that way every change of lod will be extremely obvious, even though the difference in geometry would be invisible the sudden texture change looks awful.

if you dont need lod anyway you can use the vertex color and alpha to blend up to three textures.

Share this post


Link to post
Share on other sites