From 71aef1eb6a46d527046d3f42b395078748f77405 Mon Sep 17 00:00:00 2001 From: lLcrowe Date: Thu, 21 Aug 2025 17:58:06 +0900 Subject: [PATCH] StencilShadowVolume.Shader from CesiumJS to Unity --- .../CesiumForUnityStencilShadowVolume.shader | 84 +++++++++++++++++++ ...iumForUnityStencilShadowVolume.shader.meta | 9 ++ .../CesiumForUnityStencilShadowVolume_Mat.mat | 30 +++++++ ...umForUnityStencilShadowVolume_Mat.mat.meta | 8 ++ 4 files changed, 131 insertions(+) create mode 100644 Runtime/Resources/CesiumForUnityStencilShadowVolume.shader create mode 100644 Runtime/Resources/CesiumForUnityStencilShadowVolume.shader.meta create mode 100644 Runtime/Resources/CesiumForUnityStencilShadowVolume_Mat.mat create mode 100644 Runtime/Resources/CesiumForUnityStencilShadowVolume_Mat.mat.meta diff --git a/Runtime/Resources/CesiumForUnityStencilShadowVolume.shader b/Runtime/Resources/CesiumForUnityStencilShadowVolume.shader new file mode 100644 index 00000000..1c09addb --- /dev/null +++ b/Runtime/Resources/CesiumForUnityStencilShadowVolume.shader @@ -0,0 +1,84 @@ +Shader "Custom/CesiumForUnityStencilShadowVolume" +{ + Properties + { + _Color ("Color",Color) = (1,1,1,1) + } + SubShader + { + Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" } + + //Using double-sided stencil, configured with 2 passes + Pass + { + Name "StencilDepthRenderState" + Tags{"LightMode" = "Step1"} + Cull Off + Stencil + { + Ref 0 + //Comp always//equal + + CompFront Always + FailFront Keep + ZFailFront DecrWrap + PassFront Keep + + CompBack Always + FailBack Keep + ZFailBack IncrWrap + PassBack Keep + } + ZTest On + ZWrite Off + ColorMask 0 + } + Pass + { + Name "StencilColorRenderState" + Tags{"LightMode" = "Step2"} + Cull Off + Stencil + { + Ref 0 + + CompFront NotEqual + FailFront Zero + ZFailFront Zero + PassFront Zero + + CompBack NotEqual + FailBack Zero + ZFailBack Zero + PassBack Zero + } + ZTest Off + ZWrite Off + Blend SrcAlpha OneMinusSrcAlpha + + HLSLPROGRAM + #pragma vertex vert + #pragma fragment frag + # include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + + //Using To UnityProperty + half4 _Color; + + float4 vert(float4 positionOS:POSITION): SV_POSITION + { + //ObjectSpace To ClipSpace + float4 OUT; + OUT = TransformObjectToHClip(positionOS.xyz); + return OUT; + } + half4 frag(): SV_Target + { + //Set to Color + //half4 color = half4(0,1,0,1); + half4 color = _Color; + return color; + } + ENDHLSL + } + } +} \ No newline at end of file diff --git a/Runtime/Resources/CesiumForUnityStencilShadowVolume.shader.meta b/Runtime/Resources/CesiumForUnityStencilShadowVolume.shader.meta new file mode 100644 index 00000000..bc7cbd10 --- /dev/null +++ b/Runtime/Resources/CesiumForUnityStencilShadowVolume.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: b89edf0f547ce004ca69ca33d00656bd +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Resources/CesiumForUnityStencilShadowVolume_Mat.mat b/Runtime/Resources/CesiumForUnityStencilShadowVolume_Mat.mat new file mode 100644 index 00000000..9b0a3d0e --- /dev/null +++ b/Runtime/Resources/CesiumForUnityStencilShadowVolume_Mat.mat @@ -0,0 +1,30 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CesiumForUnityStencilShadowVolume_Mat + m_Shader: {fileID: 4800000, guid: b89edf0f547ce004ca69ca33d00656bd, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: [] + m_Ints: [] + m_Floats: [] + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + m_BuildTextureStacks: [] diff --git a/Runtime/Resources/CesiumForUnityStencilShadowVolume_Mat.mat.meta b/Runtime/Resources/CesiumForUnityStencilShadowVolume_Mat.mat.meta new file mode 100644 index 00000000..bcb4283d --- /dev/null +++ b/Runtime/Resources/CesiumForUnityStencilShadowVolume_Mat.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b9e291af1c5ae4148a2cc5760b804025 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: