Now I'm working on adding decals to the system. Since decals are placed on top of solid geometry I disable depth writing and then render the decals using alpha blending. Here is where the problem starts:
During (3) I can smoothly alpha blend my decals on top of the solid geometry using ogl's blend function (ONE_MINUS_SRC_ALPHA, SRC_ALPHA). Decals blend in very well, BUT it uses the normals of the underlying surface. While this may be desired in some cases like graffiti on walls, it should sometimes use its own normals for lighting calculation. A simple example would be foot step marks on the ground.
What I'd like to do is to use alpha blending during (1), i.e. alpha blend solid geometry normals with my decal normals. The normal buffer layout is
ARGB8 with normal xyz in RGB and object's specular roughness in A. That means I need to blend all 4 channels. Since the alpha blend function uses the alpha channel for blending I can't blend normals and roughness at the same time. Actually I need some additional fragment value on which I can base the alpha blending.
Here's the code
#extension GL_ARB_draw_buffers : enable
varying vec3 normal;
varying vec4 position;
uniform sampler2D texAlpha;
void main()\n \
{\n \
// normal\n \
gl_FragData[0].rgb = normal * 0.5 + 0.5;
//roughness
gl_FragData[0].a = gl_FrontMaterial.shininess/128.;
// the blend factor that I actually need for blending
float blendFactor = texture2D(texAlpha, gl_TexCoord[0].st);
gl_FragDepth = position.z/position.w;
}
So basicall I'd like to use the blending function with the blend factor I defined in the code. Like ONE_MINUS_BLENDFACTOR_ALPHA. I know this doesn't exist but you get the idea. Is there any way to make this possible or workaround the problem?
Thanks for your help