Hey guys,
I’m trying to write a fragment shader that can take multiple lights. Here’s what I have, a bare-bones shader:
Shader "Custom/TileShader New"
{
Properties {
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "LightMode" = "ForwardBase" }
Pass
{
Lighting On
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdaddd
#include "UnityCG.cginc"
#include "AutoLight.cginc"
uniform sampler2D _MainTex;
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD1;
LIGHTING_COORDS(3,4)
};
v2f vert (appdata_full v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
float4 frag (v2f i) : COLOR
{
float4 c = tex2D(_MainTex, i.uv);
return c * LIGHT_ATTENUATION(i);
}
ENDCG
}
}
FallBack "Diffuse"
}
It sounds like I should be using ForwardAdd as the LightMode, since I’d like a pass per light, but when I do that, it doesn’t render any lights at all. Right now it’s only picking the most important light to be used. What should I do to get multiple lights working?