I'm trying to render a texture with alpha to a frame buffer with alpha. I need the texture's transparency to be controlled by a combination of its own alpha, and the alpha already rendered to the frame buffer.
ie:
Normal transparency:
(src_colour * src_alpha) + (dst_colour * 1-src_alpha)
Required transparency:
(src_colou开发者_开发百科r * src_alpha * dst_alphe) + (dst_colour * 1-(src_alpha * dst_alpha))
Can anyone figure out how to do this?
I've been working on it for 9 hours now :-)
I'm using OpenGL 1.0 with GL11ExtensionPack on Android, so I have access to glBlendFunc and glBlendFuncSeparate. I would prefer not to go the GLES20 route with shaders as that would require a lot of code to be rewritten.
Thanks, Andrew
This is the solution I've used:
- enable colour and alpha writes
- glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA)
- render foreground objects
- disabe alpha writes
- render shadows
- render objects that are casting shadows
- glBlendFunc(GL10.GL_ONE_MINUS_DST_ALPHA, GL10.GL_DST_ALPHA)
- render background objects
This produces the desired effect of shadows appearing only on foreground objects. Effectively the alpha buffer becomes a stencil buffer with variable opacity.
It's fortunate that my background objects don't have transparency, as if they did I don't think there would be any way to achieve this effect without using shaders.
精彩评论