#Shadow caster not responding to alpha clipping

1 messages · Page 1 of 1 (latest)

hard gate
#

Heya yall, I’m trying to make a shadow caster that obeys the alpha clipping on the color pass of my shader. I know there’s something off with my code and I was wondering what to do with it to fix it.

Pass //Shadow Pass
       {
           Name "ShadowCaster"
           Tags { "LightMode" = "ShadowCaster" }
           ZWrite On
           ColorMask 0
           Cull Back
           HLSLPROGRAM
           #pragma vertex vert
           #pragma fragment frag
           #pragma multi_compile_instancing
 
           #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
           #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
 
           TEXTURE2D(_MainTex);
           SAMPLER(sampler_MainTex);
 
           struct Attributes
           {
               float4 positionOS : POSITION;
               float3 normalOS   : NORMAL;
               float2 uv : TEXCOORD2;
           };
           struct Varyings
           {
               float4 positionHCS : SV_POSITION;
               float2 uv : TEXCOORD2;
           };
 
           //Cbuffer Declaration
           CBUFFER_START(UnityPerMaterial)
           float4 _MainTex_ST;
           CBUFFER_END
 
           //Declaring Properties
           float4 _Color;
 
           Varyings vert (Attributes IN)
           {
               Varyings OUT;
               float3 positionWS = TransformObjectToWorld(IN.positionOS.xyz);
               //OUT.positionHCS = TransformWorldToHClip(ApplyShadowBias(positionWS, TransformObjectToWorldNormal(IN.normalOS)));
               OUT.uv = TRANSFORM_TEX(IN.uv, _MainTex); // Transform UVs
               return OUT;
           }
           half4 frag (Varyings IN) : SV_Target
           {
               float culling = step(0.5, 1 - SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uv)); //Create Culling Gradient
               clip(culling);
               return 0;
           }
           ENDHLSL
       }

candid sleet
#

Might be wrong, but I think shadow caster pass is depth only, so it never runs your fragment shader.

hard gate
#

Ah alrighty, so what should I do to make it obey alpha clipping and cast the shadow correctly?

#

Currently it looks like this

candid sleet
idle magnet
#

I would expect clipping would resolve it as is. I don't recall having to modify my shadows

candid sleet
#

The simplest solution would be to make a mesh in that shape.

hard gate
#

It’s important that this responds to alpha clipping

#

This is going to be used for leaves

#

The jigsaw piece is just a stand in

candid sleet
#

That is, if My assumption abot shadow caster is correct

violet relic
#

In Shader Graph I've been using the custom node:
state: Boolean

state = false;

#if SHADERPASS == SHADERPASS_SHADOWCASTER
state = true;
#endif

With alpha clipping enabled
Into a Branch node*
Could try that and view the generated code, if you need a written shader

candid sleet
#

Perhaps there's a way to mak it care about fragment shader🤔

hard gate
#

I know Shadergraph has been able to pull this off so there’s surely a way to do it in hlsl

#

It’s important that it’s done in HLSL as there’s a few important things I need to also add to this shader that can only be done in Hlsl

idle magnet
#

Hmm looking at my custom sprite shader all I do is alpha clip and it seems like the shadowing respects it

hard gate
#

Hmm, strange

#

I must’ve done something wrong

idle magnet
#

assuming you are using clip()

hard gate
#

I am yes

violet relic
#

Correction, the custom node was for having different alpha clipping for shadow caster pass vs for the camera which isn't what you asked I think

hard gate
#

Basically what I want to do is make it so the shadow from the photo is a jigsaw piece and not the square plane it’s on

violet relic
#

Either way since SG uses alpha clipping for shadows by default isn't the obvious solution to view the generated code of an SG shader that does just that

candid sleet
#

Oh, so it does work via SG😲

idle magnet
#
half4 ShadowPassFragment(Varyings IN) : SV_TARGET
{
  Alpha(SampleAlbedoAlpha(IN.uv, TEXTURE2D_ARGS(_MainTex, sampler_MainTex)).a, _BaseColor, _Cutoff);
  return 0;
}

Ah, I have this too I do specify a cutoff of the alpha

hard gate
#

You can view the generated code from shadergraphs?

violet relic
#

Yes

hard gate
#

How can I do this?

violet relic
#

"View Generated Shader"

#

on the SG asset

hard gate
#

Wonderful, that might just help actually

#

I’ll do that in a bit as I need to attend a lecture rn

#

Thank you all for your help

#

I’ll return if I find further issues

idle magnet
#

yeah HLSL is a pain. Really need to find some IDE support for it in vs code

candid sleet
#

Tell us how you fixed it too.

hard gate
violet relic
#

You can also use plenty of HLSL with custom nodes
Could be easier than working with whole URP shaders in code

candid sleet
hard gate
#

As it’s going to be an exclusion to a line art shader for a game I’m working on

#

Hlsl seems to be the best solution for this

#

Always I’ll see yall later, thank you again

idle magnet
#

That site is pretty useful too if you don't have that IDE support ;p

violet relic
idle magnet
hard gate
#

Very little comments and very big

#

The shadow pass made little sense to me