# Multipass lighting problems

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

## 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=#000000][font=arial, sans-serif]I'm writing the shader in HLSL, and my technique looks like this:[/font]
[font="arial, sans-serif"][color="#000000"] 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(); } }[/font] [font="arial, sans-serif"][color="#000000"][/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=#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=#000000][font=arial, sans-serif]Is there a way to add up both passes contribution?[/font]

##### 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 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'.

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 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 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.

Tank you! I'm going to to do that

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 14
• 30
• 9
• 16
• 22