• Advertisement
Sign in to follow this  

Blending RGBA8

This topic is 1910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello there. I'm currently working on my light prepass render pipeline, that is, writing normal and depth buffer (1), then creating light accumulation buffer (2) and finally render geometry again (3) using the information from the light accumulation buffer.

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

Share this post


Link to post
Share on other sites
Advertisement
The simplest solution is to use alpha-test (or [font=courier new,courier,monospace]discard[/font]) decals instead of alpha-blend decals, but that's changing the problem wink.png

There's a solution in this presentation, which I think requires your decals to have a constant spec-power over their surface, which it looks like you're already doing.
http://www.slideshar...marine-14699854 Edited by Hodgman

Share this post


Link to post
Share on other sites

Hm, they use alpha testing for the normals only.
They say that they were originally using alpha testing, but then switched to blending with the blend mode of:
result.rgb = src.rgb * src.a + dst.rgb * (1-src.a)
result.a = src.a * factor + dst.a * (1-src.a)

where [font=courier new,courier,monospace]factor[/font] is set to the material's spec power. Obviously this doesn't work if you want the spec-power to vary across the decal though.
N.B. this relies on EXT_blend_func_separate.
I wonder how they did it here (that's what I'm looking for): http://blog.wolfire....tor-part-three/
This one doesn't mention deferred lighting, so it doesn't deal with your spec-power blending issue. In his level editor, he's pre-generating a world-space normal map per decal instance (which is a mixture of the underlying geometric normals, and the decals tangent-space normals), and saving those texture alongside the level. Edited by Hodgman

Share this post


Link to post
Share on other sites
This still seems to be incorrect. Shouldn't "factor" be multiplied with src.a?

Share this post


Link to post
Share on other sites
Sorry, I typed it up wrong. Edited my post.

The code would be something like:
BlendColor( 0, 0, 0, specPow );//N.B. 0-1 range
BlendFuncSeparate( SRC_ALPHA, ONE_MINUS_SRC_ALPHA, CONSTANT_ALPHA, ONE_MINUS_SRC_ALPHA );
BlendEquationSeparate( FUNC_ADD, FUNC_ADD );
Edited by Hodgman

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement