Hi! I have a question about the Shadow problem in Shader.
As I show the screenshot, I made simple dissolve shader.
However, you can see that the shadow maintains the shape of the mesh.
There must be needed some simple codes that changes shadow, but I have no idea for that.
I tried find with this issue, but no solution found.
I would appreciate it if you could help me resolve this issue.
And here are my shader codes :
Shader "Custom/URPCustomDissolve"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_NoiseMap ("NoiseMap", 2D) = "white" {}
_DissolveAmount ("DissolveAmount", Range(0,1)) = 0.5
}
SubShader
{
Tags{ "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline"
}
LOD 100
Pass
{
//
Blend SrcAlpha OneMinusSrcAlpha
//Cull Off
//ZWrite Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
//#pragma multi_compile_fog
// Shadow 컴파일
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile_fragment _ _SHADOWS_SOFT
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
struct appdata
{
float4 vertexOS : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertexCS : SV_POSITION; // SV : System Value
};
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
TEXTURE2D(_NoiseMap);
SAMPLER(sampler_NoiseMap);
// SRP Batcher 호환
CBUFFER_START(UnityPerMaterial)
float4 _MainTex_ST;
float4 _NoiseMap_ST;
float _DissolveAmount;
CBUFFER_END
v2f vert (appdata v)
{
v2f o;
o.vertexCS = TransformObjectToHClip(v.vertexOS.xyz);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
// 픽셀처리
half4 frag (v2f i) : SV_Target
{
// sample the texture
half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, TRANSFORM_TEX(i.uv, _MainTex));
half cutOut = SAMPLE_TEXTURE2D(_NoiseMap, sampler_NoiseMap, TRANSFORM_TEX(i.uv, _NoiseMap)).r;
clip(cutOut - _DissolveAmount);
// apply fog
//UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
//ENDCG
ENDHLSL
}
Pass
{
Name "ShadowCaster"
Tags {"LightMode"="ShadowCaster"}
ZWrite On
ZTest LEqual
ColorMask 0
Cull Front
HLSLPROGRAM
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
ENDHLSL
}
}
}
