Hi there!
I want to write a surface shader that does vertex displacement and unculled cutout shading.
The code is very simple, as you can see below. There’s a vertex function for the displacement and a surface function for the shading.
Unfortunately the shader behaves wrong when it’s asked to cast shadows. It seems it takes the solid, un-deformed geometry aswell as the deformed one for shadow calculations. The two sometimes even cast shadows on each other. (see the screenshots).
How can I get only the deformed cutout part to cast shadows?
Thanks!
Shader "Transparent/Cutout/Diffuse Wiggle" {
Properties {
_Color ("_Color", Color) = (1,1,1,1)
_MainTex ("_MainTex", 2D) = "white" {}
_Amount ("_Amount", Range(0,.2)) = 0.1
_Direction ("_Direction", Vector) = (0,0,0,0)
_Scale ("_Scale", Range(0.1,10)) = 1.0
_TimeScale ("_TimeScale", Range(0,10)) = 1.0
_Cutoff ("_Cutoff", Range (0,1)) = 0.5
}
SubShader {
Tags { "RenderType" = "Opaque" "Queue" = "Transparent" }
Cull Off
CGPROGRAM
#pragma surface surf Lambert vertex:vert addshadow alphatest:_Cutoff
struct Input {
float2 uv_MainTex;
};
half4 _Direction;
float _Amount;
float _TimeScale;
float _Scale;
sampler2D _MainTex;
half4 _Color;
void vert(inout appdata_full v) {
// calculate offset amount
float4 offs = float4 (normalize(v.normal), 0) * sin (_Time.y * _TimeScale + (v.vertex.y * _Scale)) * _Amount;
// offset vertex
v.vertex += offs * _Direction;
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb * _Color.rgb;
o.Alpha = c.a * _Color.a;
}
ENDCG
}
Fallback "Transparent/Cutout/Diffuse"
}