PDA

View Full Version : Additive blending problem with ppl



Gorg
02-04-2003, 07:42 PM
I am trying to add the contributions of two lights. What happens though is that nothing gets blend and I only see the result of one or the other. I actually get depth fighting, which really weird since and always use the same calls and matrices to do the transform.

I render all my scene to the depth buffer first, then disable depth write and use GL_EQUAL for depth test and go on with rendering the lighted objects.

I do diffuse by rendering N dot L in the alpha buffer and simply blending with the diffuse color.

This is the setup for a light shining on an object




glColorMask( false, false ,false, true );
{
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);

glBindTexture( GL_TEXTURE_CUBE_MAP, cubemaptexture) ;

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}

{
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);


glBindTexture( GL_TEXTURE_2D, bumpMap );

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGBA_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

}

Draw();
{
glDisable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_CUBE_MAP);
}


//do the color pass

glEnable(GL_BLEND);
glBlendFunc(GL_DST_ALPHA,GL_ONE);

glColorMask( true, true , true, false );
{
glEnable(GL_TEXTURE_2D);


glBindTexture( GL_TEXTURE_2D, diffuse ) ;

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}

Draw();

glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);


Blending does work properly when I am rendering differently.

If somebody could point something wrong or hint on something to look for, I would be quite happy.

[This message has been edited by Gorg (edited 02-04-2003).]

[This message has been edited by Gorg (edited 02-04-2003).]

zed
02-04-2003, 08:05 PM
instead of using destination alpha

why cant u just enable blending with ONE ONE for each extra light (turn off zwrites as well for a performance boost)

Gorg
02-05-2003, 05:16 AM
I am using a normalisation cube map, and I am restricted to 2 tex units. So I need at least 2 passes, I don't think I can set that up with ONE, ONE ?

zed
02-05-2003, 09:29 AM
i like to do all the lights first (which could be many using ONE ONE) + then last of all draw the decal texture with blending DST_COLOR ZERO

Gorg
02-05-2003, 10:30 AM
I see. That could be problematic has the architecture is working per light/object. Though I will still try to try it http://www.opengl.org/discussion_boards/ubb/wink.gif to see if I can at least get the blending to work properly.

Though I still assume my code should work. I guess you could not point anything obvious from the source?