PDA

View Full Version : Texture Blending



Winegums
03-18-2006, 10:58 PM
Hi, I will start by appologising for this thread. I am aware that this topic has been covered a million times, but I just cant grasp what everyones saying and to be honest i think i need my hand held through this :p

I've trawled various forums and websites looking for help and so many of them are in different languages and/or using different methods (render in 1 pass etc) that im confused. so im just going to write what i think i know to be fact and then hope some kind soul will fill in the blanks..

I have a heightmap composed of 4 point quads with a heightmap. As it stands there are 3 textures: Grass, Rock and Snow. At the point of rendering each quad i check the height of a point and bind a texture reletive to the smallest height. This works but obviously looks hideous, and i wanted to apply blending to smoothe the transition between textures.

Texture Blending:- A Method Thereof

glDisable(GL_BLEND); //Disable Blending
RenderTerrainWithBaseTexture(); //First pass...render whole terrain with green fields :)

glEnable(GL_BLEND); //Enable blending
glEnable(GL_BLEND); //Enable blending
glBlendFunc(); //There should be a blend function here but I'm not sure of the parameters...one of the threads i read on this forum suggested GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA

RenderTerrainWithOtherTextures
{
...
BindAppropriateTexture();
// Set The Color Value Of The Current Vertex
glTexCoord2f(1,0);
glColor4f(0.0f, 0.0f, 0.0f, FindVertexAlpha());
glVertex3f(x, y, z);// Send This Vertex To OpenGL To Be Rendered
...
}

glBindTexture(GL_TEXTURE_2D, NULL);// Clear the bound texture

Komat
03-19-2006, 02:09 AM
The blend function depends on what you send in as vertex alpha. If you send 1.0 where the other texture (rock, snow) should be at full strength then the blending mode should be GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA.
If you are using GL_MODULATE texture environment which is the default, you have to specify nonblack vertex color or result will be black so you probably wish to use glColor4f(1.0f, 1.0f, 1.0f, FindVertexAlpha());