PDA

View Full Version : Texture combiners



red_gfx
04-24-2009, 10:10 AM
I'm trying to modelate snow falling on ground. My terrain is textured using one 2D grayscale texture for details and another 1D texture to apply color per height. When snowfalls get on terrain I want the terrain to slowly blend to white (geometry color).



// bind the detail texture to the first unit
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_grassTexture);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);//GL_REPLACE


// bind the height texture to the second unit
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_1D, m_heightTexture);
glEnable(GL_TEXTURE_1D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);


glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_CONSTANT);

glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);

float mycolor[4];
mycolor[0]=mycolor[1]=mycolor[2]=0.9; // blend factor is set by color
//mycolor[3]=0.8;
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, mycolor);


But it seams that GL_PREVIOUS refers to Unit1 texture , not to the result of Unit1 + Unit2. How can I get the result Unit1+Unit2 and blend it with the geometry color ?

scratt
04-24-2009, 12:17 PM
Modulate texture unit 0.

Then do this with texture unit 1.
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glTexEnvf (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
glTexEnvf (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);

You may need to do some stuff with the ALPHA channel also.
But that should get you going..

red_gfx
04-24-2009, 01:55 PM
Sorry scratt, but I have written it wrong. I wanted to say Unit1 and Unit2, not Unit1 + Unit2(the effect obtained by modulating the 2 texture to blend it to white). Here is a scheme(now I'm trying to achieve the image from step 2).

http://www.kamino-prod.com/sketch.jpg