Multiple lighting passes in a shader

Started by
10 comments, last by simotix 15 years, 10 months ago
I am trying to multiple lights through multipassing in a shader. I know my lighting is fine because when I do the first technique (OneLight) everything runs smoothly. For the second pass I thought all I had to do was enable blending and change the blending modes. Is this true? I also made sure my values in the second light was correct by sending in the index of on my first pass for the light. Here is what I do for my technique. Is this all that I need? (Well, I hope not because it just looks wrong with the blending).

technique OneLight
{
	pass pass0
	{
		VertexShader = compile vs_2_0 VS(0);
		PixelShader = compile ps_2_0 PS(0);
	}
}

technique TwoLight
{
	pass pass0
	{
		VertexShader = compile vs_2_0 VS(0);
		PixelShader = compile ps_2_0 PS(0);
	}
    
  	pass pass1
	{
        	AlphaBlendEnable = true;
		SrcBlend=srcalpha;
		DestBlend=invsrcColor;

		VertexShader = compile vs_2_0 VS(1);
		PixelShader = compile ps_2_0 PS(1);
	}
}

Advertisement
You want additive blending, not alpha-based blending. Also, do you update your second pass's lighting parameters with the second light's data?
I do set the second lights parameters correctly. How do I do additive blending? I do not see a render state to set. I have checked all the msdn hlsl docs
Additive is SrcBlend,DestBlend= ONE with BlendOp = ADD
I have tried doing what you said and I still get undesired results. I have tried it with AlphaBlendEnable = true and with it not on. Is this what you expect the code to be?

technique TwoLight{	pass pass0	{		VertexShader = compile vs_2_0 VS(0);		PixelShader = compile ps_2_0 PS(0);	}      	pass pass1	{        	//AlphaBlendEnable = true;		SrcBlend=ONE;		DestBlend=ONE;		BlendOp = ADD;		VertexShader = compile vs_2_0 VS(1);		PixelShader = compile ps_2_0 PS(1);	}}
Well, posting a screen shot of what 1 light looks like as well as what 2 lights look like would help out, because right now "it doesn't look right" doesn't really ring a bell in anyone's head [grin]
For some reason the light pass doesn't render the effect on the last plane. I render everything in this order.
- Set Technique For TwoLight
for(number of quads)
{
Set Matrix, ect information
for(number of passes)
{
BeginPass
Render
EndPass
}
}

That is how it is suppose to be right?

First Light:
http://www.4freeimagehost.com/show.php?i=6c427c1835da.jpg

Second Light:
http://www.4freeimagehost.com/show.php?i=af14fd6b470e.jpg

With The TwoLight Shader
http://www.4freeimagehost.com/show.php?i=9b68af08b84d.jpg

technique TwoLight{	pass pass0	{		VertexShader = compile vs_2_0 VS(0);		PixelShader = compile ps_2_0 PS(0);	}      	pass pass1	{        	AlphaBlendEnable = true;		SrcBlend= ONE;		DestBlend=ONE;		BlendOp = ADD;		VertexShader = compile vs_2_0 VS(1);		PixelShader = compile ps_2_0 PS(1);	}}
I still have no idea how to do this, does anyone know how?
Have you done anything weird with the ZFUNC? It should be LESSEQUAL on the first pass, and EQUAL on subsequent passes. I doubt a problem there would lead to those bizarre screenshots, tho.
Well the first two screen shots are fine, it is when I mix them that I have a problem.

I did not do anything with ZFUNC and I did not know I had to change anything for blending on the first pass? Do I have to?

This topic is closed to new replies.

Advertisement