Sign in to follow this  
angelmu88

Multipass lighting problems

Recommended Posts

Hi everybody!
I'm having some trouble programming a mutlipass lighting technique.
I want to [color=#000000][font=arial, sans-serif]enlighten a house with 2 differents lights, a directional light and a spot light. In addition the spotlight casts shadows so I'm using two passes, a simple pass for the directional light and one extra pass with shadow mapping for the spotligh. I know I can achieve the same result with a single pass but I preffer two passes because of scalability.[/font][/color]
[color=#000000][font=arial, sans-serif]I'm writing the shader in HLSL, and my technique looks like this:[/font][/color]
[font="arial, sans-serif"][color="#000000"][CODE]
technique drawShadowTech
{
pass P0
{
CullMode = CW;
vertexShader = compile vs_3_0 LightShadowVS();
pixelShader = compile ps_3_0 LightShadowPS();
}
pass P1
{
CullMode = CW;
VertexShader = compile vs_3_0 v();
PixelShader = compile ps_3_0 f2();
}
}[/color][/font]
[font="arial, sans-serif"][color="#000000"][/CODE][/color][/font]
[color=#000000][font=arial, sans-serif]The first pass draws the spotlight with shadow mapping and the second one draws the directional light contribution.[/font][/color]
[color=#000000][font=arial, sans-serif]The problem is that the above technique doesn't add up both passes colors, I mean the result is not pass0color + pass1 color, instead it is only pass1color, i.e the last pass color. If I implement the passes the other way round, I mean pass1 first, and pass0 after it, the result is pass0 color (again the last pass color).[/font][/color]
[color=#000000][font=arial, sans-serif]Is there a way to add up both passes contribution?[/font][/color]

Share this post


Link to post
Share on other sites
It sounds like you need to set up you blending mode. The default is probably 'replace' whereas you probably want 'additive'. Google for something like 'Direct3D blend modes'.

Share this post


Link to post
Share on other sites
[quote name='PolyVox' timestamp='1329479793' post='4913873']
It sounds like you need to set up you blending mode. The default is probably 'replace' whereas you probably want 'additive'. Google for something like 'Direct3D blend modes'.
[/quote]
I was thinking of doing something similar. I've applied alpha blending before, but alpha blending blends the pixel color taking into account all the scene pixels (at least all the objectes previously drawn), and I only want to add the second pass's pixel color to the previous pass's color. Does anyone know if I can do this, and how?

Share this post


Link to post
Share on other sites
Don't use alpha-based blend factors.

EDIT:
Remember, alpha blending is ( srcAlpha * srcColor ) + ( ( 1 - srcAlpha ) * dstColor ); just set both blend factors to 1 and it cancels out to srcColor + dstColor, which is what you want.

Share this post


Link to post
Share on other sites
[quote name='InvalidPointer' timestamp='1329492437' post='4913935']
Don't use alpha-based blend factors.

EDIT:
Remember, alpha blending is ( srcAlpha * srcColor ) + ( ( 1 - srcAlpha ) * dstColor ); just set both blend factors to 1 and it cancels out to srcColor + dstColor, which is what you want.
[/quote]

Tank you! I'm going to to do that

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this