I've got a problem with light. Again. The problem is that UNITY_LIGHT_ATTENUATION always returns a white color. Code (CSharp): Shader "Unlit/Test" { Properties { } SubShader { Tags { "Queue" = "Geometry" "RenderType" = "Opaque" } LOD 100 Pass { Tags { "LightMode" = "ForwardBase" } CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma target 3.0 #include "UnityCG.cginc" #include "AutoLight.cginc" #pragma multi_compile_fwdbase struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 pos : SV_POSITION; float4 vert : TEXCOORD3; LIGHTING_COORDS(1, 2) }; v2f vert (appdata v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.uv = v.uv; o.vert = mul(unity_ObjectToWorld, v.vertex); TRANSFER_VERTEX_TO_FRAGMENT(o); return o; } fixed4 frag (v2f i) : SV_Target { UNITY_LIGHT_ATTENUATION(atten, i, i.vert.xyz); return atten; } ENDCG } } } Any help will be appretiated.
You need a shadowcaster pass, or a fallback with a shadowcaster pass. Add this before the last close brace (}). FallBack "Legacy Shaders/VertexLit"
@bgolus, but I don't need shadow casting. Or is it strictly required for UNITY_LIGHT_ATTENUATION to run?
Unity's main directional light shadow receiving also uses the shadow caster pass. Unity renders out a depth texture, then casts the main directional light's shadow on the world position extrapolated from the depth texture. The depth texture is generated by rendering opaque objects' shadow caster pass.