Mostly fix VAB decal issues

This commit is contained in:
Andrew Cassidy 2024-06-26 22:28:41 -07:00
parent a3a9ad9674
commit 1be7a98835
7 changed files with 27 additions and 18 deletions

View File

@ -61,7 +61,7 @@ inline half4 KSPLightingStandardSpecular_Deferred (SurfaceOutputStandardSpecular
outEmission = half4(s.Emission, s.Alpha); outEmission = half4(s.Emission, s.Alpha);
#ifndef UNITY_HDR_ON #ifndef UNITY_HDR_ON
outEmission.rgb = exp2(-outEmission.rgb); outEmission.rgb = saturate(exp2(-outEmission.rgb));
#endif #endif
return outEmission; return outEmission;

View File

@ -228,7 +228,12 @@ void frag_deferred (v2f IN,
o.Normal = WorldNormal; o.Normal = WorldNormal;
#endif #endif
#ifdef DECAL_PREVIEW
o.Alpha = 1;
#endif
KSPLightingStandardSpecular_Deferred(o, outGBuffer0, outGBuffer1, outGBuffer2, outEmission); KSPLightingStandardSpecular_Deferred(o, outGBuffer0, outGBuffer1, outGBuffer2, outEmission);
outGBuffer0.a = o.Alpha; outGBuffer0.a = o.Alpha;
outGBuffer1 *= o.Alpha; outGBuffer1 *= o.Alpha;
outGBuffer2.a = o.Alpha; outGBuffer2.a = o.Alpha;

View File

@ -18,7 +18,7 @@ void surf(DecalSurfaceInput IN, inout SurfaceOutputStandardSpecular o) {
#ifdef DECAL_SPECMAP #ifdef DECAL_SPECMAP
float4 specular = tex2D(_SpecMap, IN.uv_specmap); float4 specular = tex2D(_SpecMap, IN.uv_specmap);
o.Specular = specular o.Specular = specular;
#endif #endif
o.Smoothness = _Shininess; o.Smoothness = _Shininess;

View File

@ -119,12 +119,7 @@
#pragma fragment frag_deferred_prepass #pragma fragment frag_deferred_prepass
#pragma target 3.0 #pragma target 3.0
#pragma multi_compile_deferred nolightmap nodirlightmap nodynlightmap
#pragma skip_variants SHADOWS_DEPTH SHADOWS_CUBE SHADOWS_SHADOWMASK LIGHTMAP_SHADOW_MIXING POINT_COOKIE
#pragma multi_compile_local __ DECAL_PREVIEW #pragma multi_compile_local __ DECAL_PREVIEW
// #pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP
#pragma multi_compile_local __ DECAL_SPECMAP
// #pragma multi_compile_local __ DECAL_EMISSIVE
#pragma multi_compile_local __ DECAL_SDF_ALPHA #pragma multi_compile_local __ DECAL_SDF_ALPHA
#include "UnityCG.cginc" #include "UnityCG.cginc"
@ -140,21 +135,26 @@
{ {
Name "DEFERRED" Name "DEFERRED"
Tags { "LightMode" = "Deferred" } Tags { "LightMode" = "Deferred" }
ZWrite [_ZWrite] ZWrite On
ZTest LEqual ZTest LEqual
Offset -1, -1 Offset -1, -1
Blend 0 SrcAlpha OneMinusSrcAlpha, Zero One Blend 0 SrcAlpha OneMinusSrcAlpha, One One
Blend 1 One One Blend 1 One One
Blend 2 SrcAlpha OneMinusSrcAlpha, Zero One Blend 2 SrcAlpha OneMinusSrcAlpha, Zero One
Blend 3 SrcAlpha OneMinusSrcAlpha, Zero One Blend 3 SrcAlpha OneMinusSrcAlpha, Zero One
Stencil {
Ref 8
Comp Always
Pass Replace
}
CGPROGRAM CGPROGRAM
#pragma vertex vert #pragma vertex vert
#pragma fragment frag_deferred #pragma fragment frag_deferred
#pragma target 3.0 #pragma target 3.0
#pragma multi_compile_deferred nolightmap nodirlightmap nodynlightmap #pragma multi_compile __ UNITY_HDR_ON
#pragma skip_variants SHADOWS_DEPTH SHADOWS_CUBE SHADOWS_SHADOWMASK LIGHTMAP_SHADOW_MIXING POINT_COOKIE
#pragma multi_compile_local __ DECAL_PREVIEW #pragma multi_compile_local __ DECAL_PREVIEW
#pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP #pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP
#pragma multi_compile_local __ DECAL_SPECMAP #pragma multi_compile_local __ DECAL_SPECMAP
@ -169,5 +169,7 @@
ENDCG ENDCG
} }
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
} }
} }

View File

@ -120,12 +120,7 @@
#pragma fragment frag_deferred_prepass #pragma fragment frag_deferred_prepass
#pragma target 3.0 #pragma target 3.0
#pragma multi_compile_deferred nolightmap nodirlightmap nodynlightmap
#pragma skip_variants SHADOWS_DEPTH SHADOWS_CUBE SHADOWS_SHADOWMASK LIGHTMAP_SHADOW_MIXING POINT_COOKIE
#pragma multi_compile_local __ DECAL_PREVIEW #pragma multi_compile_local __ DECAL_PREVIEW
// #pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP
#pragma multi_compile_local __ DECAL_SPECMAP
// #pragma multi_compile_local __ DECAL_EMISSIVE
#pragma multi_compile_local __ DECAL_SDF_ALPHA #pragma multi_compile_local __ DECAL_SDF_ALPHA
#include "UnityCG.cginc" #include "UnityCG.cginc"
@ -149,13 +144,18 @@
Blend 2 SrcAlpha OneMinusSrcAlpha, Zero One Blend 2 SrcAlpha OneMinusSrcAlpha, Zero One
Blend 3 SrcAlpha OneMinusSrcAlpha, Zero One Blend 3 SrcAlpha OneMinusSrcAlpha, Zero One
Stencil {
Ref 8
Comp Always
Pass Replace
}
CGPROGRAM CGPROGRAM
#pragma vertex vert #pragma vertex vert
#pragma fragment frag_deferred #pragma fragment frag_deferred
#pragma target 3.0 #pragma target 3.0
#pragma multi_compile_deferred nolightmap nodirlightmap nodynlightmap #pragma multi_compile __ UNITY_HDR_ON
#pragma skip_variants SHADOWS_DEPTH SHADOWS_CUBE SHADOWS_SHADOWMASK LIGHTMAP_SHADOW_MIXING POINT_COOKIE
#pragma multi_compile_local __ DECAL_PREVIEW #pragma multi_compile_local __ DECAL_PREVIEW
#pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP #pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP
#pragma multi_compile_local __ DECAL_SPECMAP #pragma multi_compile_local __ DECAL_SPECMAP

View File

@ -45,6 +45,7 @@ namespace ConformalDecals.MaterialProperties {
_decalMaterial.SetInt(DecalPropertyIDs._Cull, (int) CullMode.Off); _decalMaterial.SetInt(DecalPropertyIDs._Cull, (int) CullMode.Off);
_decalMaterial.SetInt(DecalPropertyIDs._ZWrite, 0); _decalMaterial.SetInt(DecalPropertyIDs._ZWrite, 0);
_decalMaterial.renderQueue = RenderQueue; _decalMaterial.renderQueue = RenderQueue;
_decalMaterial.SetShaderPassEnabled("SHADOWCASTER", false);
} }
return _decalMaterial; return _decalMaterial;
@ -59,6 +60,7 @@ namespace ConformalDecals.MaterialProperties {
_previewMaterial.EnableKeyword("DECAL_PREVIEW"); _previewMaterial.EnableKeyword("DECAL_PREVIEW");
_previewMaterial.SetInt(DecalPropertyIDs._Cull, (int) CullMode.Back); _previewMaterial.SetInt(DecalPropertyIDs._Cull, (int) CullMode.Back);
_previewMaterial.SetInt(DecalPropertyIDs._ZWrite, 1); _previewMaterial.SetInt(DecalPropertyIDs._ZWrite, 1);
_previewMaterial.SetShaderPassEnabled("DEFERRED_PREPASS", false);
} }
return _previewMaterial; return _previewMaterial;