Multipass lighting problems

Started by
3 comments, last by angelmu88 12 years, 2 months ago
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]
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/
Advertisement
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'.

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?
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/
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.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

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
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/

This topic is closed to new replies.

Advertisement