# Texture splatting with lighting

## Recommended Posts

m4ch0dude    122
I'm working on a terrain engine which blends several textures based on vertex color to achieve smooth transitions. The problem occurs when I enable lighting and the color values after light is applied changes the textures on the terrain. I have a GLSL render path which is not affected by this problem, but I'm wondering is it possible to prevent lighting from affecting the texture splatting without using shaders? Here's my code:
colors=new float[numVertices][4];

/*
before rendering, set up color for each vertex based on the color of a corresponding texture lookup (r,g,b):
*/
for each vertex{
color=r/(1.0f-b);
alpha=1.0f-b;
colors[currentVert][0]=color;
colors[currentVert][1]=color;
colors[currentVert][2]=color;
colors[currentVert][3]=alpha;
}

...

// in the render function:

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_textures[redtex]->texID);

// interpolate between T0 and T1 based on color saturation (r,g,b are the same):
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_textures[greentex]->texID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR);

// interpolate previous value with T2 based on alpha
glActiveTextureARB(GL_TEXTURE2_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_textures[bluetex]->texID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);



##### Share on other sites
strtok    191
Unfortunately, I don't think this is possible. I'm interpolating based on alpha only for this very reason. This can be achieved with a shader, but short of that, you're probably going to have to do lighting in a second pass. Of course, I could be wrong, so maybe someone else will post after me with a better solution.