Jump to content

  • Log In with Google      Sign In   
  • Create Account


Blending RGBA8


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 mk1x86   Members   -  Reputation: 442

Like
0Likes
Like

Posted 31 October 2012 - 02:23 AM

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

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 27614

Like
1Likes
Like

Posted 31 October 2012 - 02:53 AM

The simplest solution is to use alpha-test (or discard) decals instead of alpha-blend decals, but that's changing the problem Posted Image

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, 31 October 2012 - 02:57 AM.


#3 mk1x86   Members   -  Reputation: 442

Like
0Likes
Like

Posted 31 October 2012 - 04:24 AM

Hm, they use alpha testing for the normals only. This might actually work in most cases.
Constant specular is only in the code provided. There're other shaders that support specular power mapping. I wonder how they did it here (that's what I'm looking for):
http://blog.wolfire.com/2009/06/decals-editor-part-three/

#4 Hodgman   Moderators   -  Reputation: 27614

Like
1Likes
Like

Posted 31 October 2012 - 05:28 AM

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 factor 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, 31 October 2012 - 06:36 AM.


#5 mk1x86   Members   -  Reputation: 442

Like
0Likes
Like

Posted 31 October 2012 - 05:44 AM

This still seems to be incorrect. Shouldn't "factor" be multiplied with src.a?

#6 Hodgman   Moderators   -  Reputation: 27614

Like
0Likes
Like

Posted 31 October 2012 - 06:30 AM

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, 31 October 2012 - 06:40 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS