
I’ve a custom rock shader and two light sources in the scene. I spawn a load of rocks into a pool and they look like the bottom-left rock. When destroyed, I disable the GameObject, and reenable it when a new rock is spawned. Only now the rocks are glowing. If I disable the fill light, the rocks look like they start, so the second light source isn’t being applied when the rocks are first created. Why is this?
Shader code:
Shader "SG/_rockShader" {
// Applies base colour, texture, and specular normals
Properties {
_BaseColour ("Base colour", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_NormalTex ("Normal map", 2D) = "bump" {}
_SpecColour ("Specular colour", Color) = (1,1,1,1)
_SpecPower ("Specular power", Range (0.0,2.0)) = 0.5
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf BlinnPhongBaseIllumination
fixed4 _BaseColour;
sampler2D _MainTex;
sampler2D _NormalTex;
fixed4 _SpecColour;
half _SpecPower;
half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
half NdotL = dot (s.Normal, lightDir);
half diff = NdotL * 0.5 + 0.5;
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten);
c.a = s.Alpha;
return c;
}
inline fixed4 LightingBlinnPhongBaseIllumination (SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten) {
half3 h = normalize (lightDir + viewDir);
fixed diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular*16.0);// * s.Gloss;
fixed4 c;
c.rgb = _BaseColour;
c.rgb += (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColour.rgb * spec) * (atten);
c.a = 0;//s.Alpha;// + _LightColor0.a * _SpecColor.a * spec * atten;
return c;
}
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = 0;
o.Normal = UnpackNormal(tex2D (_NormalTex, IN.uv_MainTex));
o.Specular = _SpecPower;
o.Gloss = 1;
}
ENDCG
}
FallBack "Diffuse"
}