Hello Guest

"Darken only" Blending

  • 4 Replies
  • 7104 Views
"Darken only" Blending
« on: May 17, 2011, 11:47:48 »
I can get the beginnings of an interesting blending function by using the following parameters:

Code: [Select]
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.

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: "Darken only" Blending
« Reply #1 on: May 17, 2011, 13:59:11 »
Pre-multiplied alpha? Or just do it in the fragment shader, like:

Code: [Select]
gl_FragColor = vec4(color.rgb * color.a, color.a);
Where color == whatever you'd normally output from the shader.

Re: "Darken only" Blending
« Reply #2 on: May 17, 2011, 16:25:05 »
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.

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: "Darken only" Blending
« Reply #3 on: May 17, 2011, 16:56:39 »
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.

Re: "Darken only" Blending
« Reply #4 on: May 17, 2011, 17:07:24 »
Thank you. :D