0
votes

I have raycasting with this kind of color blending in for cycle in PS

 actual = <some color loaded from texture>;
 actual.a *= 0.05; //reduce the alpha to have a more transparent result 

 //Front to back blending  
 actual.rgb *= actual.a;
 last = (1.0 - last.a) * actual + last;   

Can this equation be rewritten to use OpenGL 3 blending functions ? The goal is to remove cycle from PS by rendering more qauds over themselves

So far I am using this: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), but result looks different

EDIT:

last = cumulated color (aka. final color)    
actual = current color from texture
2
Could you please clarify what last and and actual are? Is actual the current source color and last is the destination color, is last the current value in the framebuffer? - thokra
@thokra I have edited the question - Martin Perry

2 Answers

0
votes

The main problem is that you still have to premultiply the source color with the alpha value in your shader (actual.rgb *= actual.a).

I think for blending you have to use this function:

glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
glBlendEquation(GL_FUNC_ADD):
0
votes

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) - by using this, you have formula like:

last.rgb = actual.a * actual.rgb + ( 1.0 - actual.a ) * last.rgb;

It's completely different from yours shader formula:

actual.rgb *= actual.a;

last = (1.0 - last.a) * actual + last;

So, you have different result.