0
À l'étude
BUG: If you use specular color with mask texture and lightmap support, SF will generate a wrong shader.
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
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
0
À l'étude
Freya Holmér (Developer) il y a 10 ans
Which version of SF and which version of Unity?
0
Alfred Chang il y a 10 ans
I use SF v1.02 and unity3d v4.5.4. Thanks.
0
Skaarah il y a 10 ans
I tried in SF 1.04 and the problem still persists and Unity 4.6.b20. I'll try with beta5 later tonight.
0
Skaarah il y a 10 ans
In Unity 5.0.0.b18 I get a gi error.
0
Skaarah il y a 10 ans
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?
0
Freya Holmér (Developer) il y a 10 ans
It's going to be after GDC at the very earliest, so I'm guessing late March?
0
Skaarah il y a 10 ans
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.
0
Freya Holmér (Developer) il y a 10 ans
Neat, I'll see if I can make it there!
Service d'assistance aux clients par UserEcho