0
Under review

BUG: If you use specular color with mask texture and lightmap support, SF will generate a wrong shader.

Alfred Chang 9 years ago updated by Freya Holmér (Developer) 9 years ago 8
Hi,

I created a shader in SF. I defined a SpecColor with a mask texture to control which area should accept specular lighting and enable lightmap support. SF generated a wrong shader. FYI, I pasted the wrong part in deferred rendering path (PrePassFinal pass) below:

#ifndef LIGHTMAP_OFF
half3 lightmapAccumulation = half3(0,0,0);
#ifdef DIRLIGHTMAP_OFF
half lmFade = length (i.lmapFadePos) * unity_LightmapFade.z + unity_LightmapFade.w;
half3 lmFull = DecodeLightmap (tex2D(unity_Lightmap, i.uvLM));
half3 lmIndirect = DecodeLightmap (tex2D(unity_LightmapInd, i.uvLM));
half3 lm = lerp (lmIndirect, lmFull, saturate(lmFade));
lightmapAccumulation.rgb += lm;
#else
fixed4 lmIndTex = tex2D(unity_LightmapInd, i.uvLM);
half3 scalePerBasisVectorDiffuse;
half3 lm = DirLightmapDiffuse (unity_DirBasis, lmtex, lmIndTex, half3(0,0,1), 1, scalePerBasisVectorDiffuse);
half3 lightDir = normalize (scalePerBasisVectorDiffuse.x * unity_DirBasis[0] + scalePerBasisVectorDiffuse.y * unity_DirBasis[1] + scalePerBasisVectorDiffuse.z * unity_DirBasis[2]);
lightDir = mul(lightDir, tangentTransform);
half3 h = normalize (lightDir + viewDirection);
float nh = max (0, dot (normalDirection, h));
float lmspec = pow (nh, _Shininess * 128.0);
float4 _SpecMask_var = tex2D(_SpecMask,TRANSFORM_TEX(i.uv0, _SpecMask));
half3 specColor = lm * (_SpecMask_var.r*_SpecColor.rgb) * lmspec;
lightmapAccumulation += half4(lm + specColor, lmspec);
#endif
#endif
////// Specular:
float3 specularColor = (_SpecMask_var.r*_SpecColor.rgb);
float3 directSpecular = (lightAccumulation.rgb * 2)*lightAccumulation.a;
float3 specular = directSpecular * specularColor;
#ifndef LIGHTMAP_OFF
#ifndef DIRLIGHTMAP_OFF
specular += specColor;
#endif
#endif

You can see the bold line. _SpecMask is not defined in LIGHTMAP_OFF path. Would you help me to figure it out? Thanks.

Cheers,
Alfred
Under review
Which version of SF and which version of Unity?
I use SF v1.02 and unity3d v4.5.4. Thanks.
I tried in SF 1.04 and the problem still persists and Unity 4.6.b20. I'll try with beta5 later tonight.
In Unity 5.0.0.b18 I get a gi error.
We are going to be showing our game at various shows in the near future and would greatly benefit from the performance increase of lightmapping. Any eta on a fix for 4.6?
It's going to be after GDC at the very earliest, so I'm guessing late March?
You should come check us out. We are going to be at GDC and we use SF for just about everything. Good Mood Creators booth number PL100.
Neat, I'll see if I can make it there!