Multiple light in unity 2.6 with custom shader

Hello,

In Unity 2.6, I think I am the only one to have a problem to display 2 light at the same time:)

I written a custom shader, which basically just apply a dot(N,L) lighting per pixel with following declaration
SubShader {

Pass {
Name “PPL”
Blend off
Tags { “LightMode” = “Pixel” }
(…)
// Main function
float4 frag (v2f i) : COLOR
{
(…)
return float4(saturate(dot(normal, lightDir)) * _LightColor0.xyz, 1);
}

My custom shader work well on one object when there is only one light which affect it.

When I add a second light, I will expect to have the two light added with additive blending per pixel,
but in fact, I get only one of the two.
If I disable one, I am able to get the other, but not the two at the same time.
I have no Vertex lit declaration in my shader cause I want only per pixel lighting.
I force light mode to be “Force Pixel” and set light count in quality settings to 10 for all configuration and Game/Editor/Web without success.
My lights are simple point light, no shadow, no attenuation.

Any advice would be appreciated.

Thanks you

you have to write your shader to use more than one light, otherwise it won’t.

you can get up to 4 lights in the shader (thats the max you can have per object under 2.x)

Thanks for you very quick answer!

In fact you right, it work.
Another way I just notice after my post is that I do Blend off in my shader, thinking about the translucent part,
but in fact, this is use to additive blending too. So just set Blend on worked.
And yours solution worked two.

I am wondering if Unity is able to count the number of light before doing another pass. i.e if I manage 4 light in a shader
and have a scene with 8 light. Are Unity doing two pass of 4 light ?

thank you

no, it will not work with more than 4 lights affecting an object at all.

No, Unity 2.6 can have as many pixel lights affecting an object as you put in the quality settings. Not sure if it depends on the graphics card, but I got over 100 spotlights affecting a plane with no problems; not sure what the actual max is, if there is one. It just keeps adding draw calls for each light. The max number of vertex lights you can have per object is 8, but it’s just one draw call.

–Eric

hu, really? was under the impression that it was mentioned somehwere that it is 4 … especially when the lights are meant to do moer than just light, ie also cast shadows

Indeed…you can try it yourself (also no problems with shadows), and that’s probably why the pixel light count is a text entry box instead of enum dropdown, which is what it would logically be if the max really was 4. Otherwise why have a textfield and allow people to enter more than 4…

–Eric

I think the text field vs enum logic does not indicate anything, otherwise unity would not offer many other things as well which will not work when really used in “freeform style”. the anisotrophy for example is fucked up the vice versa way as its values you can set through the sliders are bullocks. it offers aniso levels not present at all and does not offer the maximum thats actually present on hw at all

The aniso slider isn’t ideal, but it does convey the correct idea that there are a limited number of choices, which a textfield doesn’t do. So yes, the text field vs enum logic does indicate something, especially since it’s true.

–Eric

(to the original post: ) I found that I had to make sure I used LIGHT_ATTENUATION(i) in the RGB calculation or I would not get anything but 1 DirectionLight.

Yes, but in my case, it is a custom shader, and I do my own attenuation, so don’t wory about directional light. Anyway, thanks for the help provided.