Add Point Light Support to Shader ?
Hello,
I wrote a custom cel-ish lighting model for my game in the form of a CGINC file that I include in every shader that uses the lighting. It works great for the single directional light (sun) but when I try to use point lights for indoor lighting, they just show up as squares.
The cel lighting functions works as follows ("cel" half removed from code so I don't give it all away):
half _CelShadingBlurWidth;
fixed4 LightingToki(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
half4 c;
c.rgb = (cel + 0.3) / 2.5 * s.Albedo * _LightColor0.rgb;
c.a = s.Alpha;
return c;
}
Yes I'm using Forward rendering and yes the pixel light setting is maxed out. Is there anything special I need to do instead of using lightDir and _LightColor0 for calculations so I can use more than 1 light?
Thanks
I would assume you have intentionally redacted the lighting calculation for the purpose of this question. Unfortunately, the reason this is happening is solely down to that lighting calculation, meaning there isn't that much we can do without it. I can understand not wanting to share original code, but it is kinda hard to tell exactly where the calculation is going wrong when we can't see it. If you'd prefer, I'd be happy to try and help over private message (I have no need for a cel shading function; I can easily write my own anyway). To give a quick overview; the square is essentially how Unity culls lights for performance reasons. Ordinarily, the lighting function would attenuate to 0 within the light's range, meaning we can optimise the lighting by ignoring it outside a certain point. However, if you are using custom lighting methods, you can get some weird artefacts due to the attenuation not following 'expected' conventions. Hopefully that helps somewhat.
Your answer
Follow this Question
Related Questions
Shadows on Custom Lit Surface Shader 1 Answer
Remove circular shadow from object 1 Answer
Stencil shader blocking shadows being drawn 'underneath' 2 Answers
Add hard shadows to a Toon Shader 0 Answers
FPS shader fixing 1 Answer