mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Decal shader changes, try to fix lighting additive pass
This commit is contained in:
parent
a8313127e2
commit
5376611eae
@ -79,6 +79,22 @@ inline void decalClipAlpha(float alpha) {
|
|||||||
#endif
|
#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,
|
// declare surf function,
|
||||||
// this must be defined in any shader using this cginc
|
// this must be defined in any shader using this cginc
|
||||||
void surf (DecalSurfaceInput IN, inout SurfaceOutput o);
|
void surf (DecalSurfaceInput IN, inout SurfaceOutput o);
|
||||||
@ -221,6 +237,8 @@ fixed4 frag_forward(v2f IN) : SV_Target
|
|||||||
surf(i, o);
|
surf(i, o);
|
||||||
|
|
||||||
#ifdef DECAL_PREVIEW
|
#ifdef DECAL_PREVIEW
|
||||||
|
if (any(IN.uv_decal > 1) || any(IN.uv_decal < 0)) o.Alpha = 0;
|
||||||
|
|
||||||
o.Albedo = lerp(_Color.rgb, o.Albedo, o.Alpha);
|
o.Albedo = lerp(_Color.rgb, o.Albedo, o.Alpha);
|
||||||
o.Normal = lerp(float3(0,0,1), o.Normal, o.Alpha);
|
o.Normal = lerp(float3(0,0,1), o.Normal, o.Alpha);
|
||||||
o.Gloss = lerp(_Color.a, o.Gloss, o.Alpha);
|
o.Gloss = lerp(_Color.a, o.Gloss, o.Alpha);
|
||||||
@ -239,20 +257,19 @@ fixed4 frag_forward(v2f IN) : SV_Target
|
|||||||
WorldNormal = normalize(WorldNormal);
|
WorldNormal = normalize(WorldNormal);
|
||||||
o.Normal = WorldNormal;
|
o.Normal = WorldNormal;
|
||||||
|
|
||||||
//KSP lighting function
|
//call modified KSP lighting function
|
||||||
c += LightingBlinnPhongSmooth(o, lightDir, worldViewDir, atten);
|
c += LightingBlinnPhongDecal(o, lightDir, worldViewDir, atten);
|
||||||
|
|
||||||
// Forward base emission and ambient/vertex lighting
|
// Forward base emission and ambient/vertex lighting
|
||||||
#ifdef UNITY_PASS_FORWARDBASE
|
#ifdef UNITY_PASS_FORWARDBASE
|
||||||
c.rgb += o.Emission;
|
c.rgb += o.Emission;
|
||||||
c.rgb += o.Albedo * IN.vlight;
|
c.rgb += o.Albedo * IN.vlight;
|
||||||
c.a = saturate(c.a);
|
c.a = o.Alpha;
|
||||||
#endif //UNITY_PASS_FORWARDBASE
|
#endif //UNITY_PASS_FORWARDBASE
|
||||||
|
|
||||||
// Forward add multiply by alpha
|
// Forward add multiply by alpha
|
||||||
#ifdef UNITY_PASS_FORWARDADD
|
#ifdef UNITY_PASS_FORWARDADD
|
||||||
c.rgb *= c.a;
|
c.rgb *= o.Alpha;
|
||||||
c.a = 0.0;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user