"Darken only" Blending

Started by CodeBunny, May 17, 2011, 11:47:48

Previous topic - Next topic

CodeBunny

I can get the beginnings of an interesting blending function by using the following parameters:

GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA);


The result is that render results are bounded by the color they're being rendered to. This has some potentially useful effects in terms of shadows and other details.

However, the problem is that the above blending function doesn't allow the source image to effectively use transparency. It only works if I'm using full alpha.

Is there any way I can multiply the source pixels by both GL_DST_COLOR and GL_SRC_ALPHA? That would completely fix this effect and get it to where I'd like.

spasi

Pre-multiplied alpha? Or just do it in the fragment shader, like:

gl_FragColor = vec4(color.rgb * color.a, color.a);


Where color == whatever you'd normally output from the shader.

CodeBunny

I was hoping to do it without shaders. Is there another way to do that?

Yeah, I've realized that premultiplied alpha will fix this, but I wanted to see if it could work with "normal" alpha images.

spasi

I haven't used the fixed-function texture environment shading in many years, but I think you should be able to do this with ARB_texture_env_combine (or OpenGL 1.3+). ATI_fragment_shader and NV_register_combiners are two other, vendor-specific, options.

CodeBunny