Decal shader changes, try to fix lighting additive pass

pull/13/head
Andrew Cassidy 4 years ago
parent a19e225c58
commit 0393ab0263
No known key found for this signature in database
GPG Key ID: 963017B38FD477A1

@ -79,6 +79,22 @@ inline void decalClipAlpha(float alpha) {
#endif
}
// modifed version of the KSP BlinnPhong because it does some weird things
inline fixed4 LightingBlinnPhongDecal(SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
{
s.Normal = normalize(s.Normal);
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*128.0) * s.Gloss;
fixed4 c = 0;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten);
return c;
}
// declare surf function,
// this must be defined in any shader using this cginc
void surf (DecalSurfaceInput IN, inout SurfaceOutput o);
@ -221,7 +237,9 @@ fixed4 frag_forward(v2f IN) : SV_Target
surf(i, o);
#ifdef DECAL_PREVIEW
o.Albedo = lerp(_Color.rgb,o.Albedo, o.Alpha);
if (any(IN.uv_decal > 1) || any(IN.uv_decal < 0)) o.Alpha = 0;
o.Albedo = lerp(_Color.rgb, o.Albedo, o.Alpha);
o.Normal = lerp(float3(0,0,1), o.Normal, o.Alpha);
o.Gloss = lerp(_Color.a, o.Gloss, o.Alpha);
o.Emission = lerp(0, o.Emission, o.Alpha);
@ -239,21 +257,20 @@ fixed4 frag_forward(v2f IN) : SV_Target
WorldNormal = normalize(WorldNormal);
o.Normal = WorldNormal;
//KSP lighting function
c += LightingBlinnPhongSmooth(o, lightDir, worldViewDir, atten);
//call modified KSP lighting function
c += LightingBlinnPhongDecal(o, lightDir, worldViewDir, atten);
// Forward base emission and ambient/vertex lighting
#ifdef UNITY_PASS_FORWARDBASE
c.rgb += o.Emission;
c.rgb += o.Albedo * IN.vlight;
c.a = saturate(c.a);
c.a = o.Alpha;
#endif //UNITY_PASS_FORWARDBASE
// Forward add multiply by alpha
#ifdef UNITY_PASS_FORWARDADD
c.rgb *= c.a;
c.a = 0.0;
#endif
c.rgb *= o.Alpha;
#endif
return c;
}

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:41e91c40e21638fcf49f2c5cede4acf1d0b6706fc8b1ac1d7211edc47fb6635a
oid sha256:9d7714407c3b6b0bde5cd830e9789f837d44310db16272c6b42299e9af9f2907
size 3273

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:680b0c8662bace934a133136cdb52efd484afe1e22806b36d68796a89cdf153a
size 123968
oid sha256:6f9ec40c787677e390877fe37b5957e06b8ca2caea690c64f96789bfe70ccd2d
size 126198

Loading…
Cancel
Save