Multipass blending wireframe artifact

I have two draw functions that both use glsl shaders, one renders a texture and the other a lightmap. When I draw the texture first than modulate the lightmap onto it everything is fine but when I draw the lightmap first there is a weird wireframe-like affect that appears.

fine:



// draw texture

glEnable( GL_BLEND );
glBlendFunc( GL_ZERO, GL_SRC_COLOR ); // not sure how this works (from my understanding it should be black cause of the GL_ZERO)

// draw lightmap

glDisable( GL_BLEND );


has weird wireframe:



// draw lightmap

glEnable( GL_BLEND );
glBlendFunc( GL_ZERO, GL_SRC_COLOR );

// draw texture

glDisable( GL_BLEND );


I’ve tried changing some setting such as glShadeModel(/* GL_FLAT and GL_SMOOTH */), glDepthFunc() and glDepthMask() with no change.

I also want to add a third pass that will use “texture” alpha as a mask, I’m not sure how glBlendFunc works entirely so I’m not sure what I should be setting to achieve this effect. I’ve read it in detail but I still don’t understand how it works. Thanks for any help.

GL_SMOOTH_POLYGON was the culprit for the artifacts.

I still need help with the blending:



// draw lightmap

glEnable( GL_BLEND );

glBlendFuncSeparate( GL_ZERO, GL_SRC_COLOR, GL_ONE, GL_ZERO ); // only keep the texture alpha

// draw texture

// the alpha seems to be either completely white or black here
// but I am able to use this blend in the draw above (with *SRC* instead) and have the correct parts transparent
glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA ); 

// draw glow


I am not an expert on blends but I do use them

glBlendFunc( GL_ZERO, GL_SRC_COLOR ); // not sure how this works (from my understanding it should be black cause of the GL_ZERO)

this looks strange. As I understand it it blends a source of zero (not the texture) with a destination of texture (rather than the destination buffer).
This effectively is a non-blend draw of the texture unless the texture has an alpha value.

glBlendFuncSeparate( GL_ZERO, GL_SRC_COLOR, GL_ONE, GL_ZERO ); // only keep the texture alpha

this should result in a black screen, I think, because the source is black (zero) and the destintion has an aplha value of 0 meaning transparent.

to draw just the alpha of the source I think the blend fundtion should be

glBlendFuncSeparate[GL_SRC_ALPHA,GL_ZERO,GL_ONE,GL_ZERO]

don’t forget to have a look at glBlendEquation

This effectively is a non-blend draw of the texture unless the texture has an alpha value.

No, it is multiplying the source color with the destination color. The GL_ZERO is there because the function is additive: srcfactor + dstfactor. To get multiplicative blending, one of the adding terms needs to be zero.

to draw just the alpha of the source I think the blend fundtion should be

No, that’s nonsense. It multiplies the source color by the source alpha. That simply reduces the source color by some percentage based on the alpha. It doesn’t draw “just the alpha”.

Thanks Alfonse,
this is starting to make more sense to me know. I have only used basic blending like alpha translucency. So you can’t really
just render the alpha using blend functions unless your rgb happened to be 1,1,1? You need to use a fragment shader instead.

Do you know of examples where these various combinations are actually useful?

You shouldn’t be trying to copy-and-paste blend settings. You should be trying to understand how the blend functions work, then develop equations and try to provide those equations as blend functions.

I think you are right; so far I have just used examples very similar to what I need and I think I am missing out in getting the most out of blending. I will have to find some time to write a program using a range of blends and see what I get out.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.