#Need help animating shadow caster pass with vertex shader

1 messages · Page 1 of 1 (latest)

compact kestrel
#

Here is my code ``` Pass
{
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
ZWrite On
ColorMask 0
Cull Off

        HLSLPROGRAM
        #pragma vertex ShadowCasterVert
        #pragma fragment ShadowCasterFrag
        #pragma multi_compile_shadowcaster

        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
        #include "Assets/_Art/_Shaders/Includes/sdr_Inc_MathUtilities.hlsl"


        struct Attributes
        {
            float4 positionOS : POSITION;
            UNITY_VERTEX_INPUT_INSTANCE_ID
        };

        struct Varyings
        {
            float4 positionHCS : SV_POSITION;
        };

        float _Speed;
        float4 _Range;
        float3 _Axis;

        Varyings ShadowCasterVert(Attributes IN)
        {

            Varyings OUT;

            UNITY_SETUP_INSTANCE_ID(IN);

            //Creating Linier, Sine and Cosine Time
            float Time = _TimeParameters * _Speed;
            float SinTime = Remapper(sin(Time), -1, 1, _Range.x, _Range.y);
            float CosTime = Remapper(cos(Time), -1, 1, _Range.z, _Range.w);

            float3 Pos = IN.positionOS.xyz;
            Pos.y += SinTime; 
            Pos = RotateAboutAxis_Radians(Pos, _Axis, CosTime);
            //float4 PosOS = float4(Pos.x,Pos.y,Pos.z,1);

            //Transform to light-space for shadow map
            //float4 posWS = TransformObjectToWorld(float4(PosOS));
           // OUT.positionHCS = TransformWorldToShadowCoord(posWS.xyz);

            float4 clipPos = TransformObjectToHClip(Pos);
            return clipPos;
        }

        float4 ShadowCasterFrag() : SV_Target { 
            return 0; 
            }

        ENDHLSL
    }```
indigo loom
compact kestrel
#

There is no change. It's a static shader unfortunatently

indigo loom
#

Static shader?
Anyways, start from looking at the frame debugger to see if your object shadows use this shader.

compact kestrel
#

Oh when I say static I mean it's still, there's no change in the shadow caster

#

It is casting a shadow currently, the shadow is just still

#

My apologies, I do not know how to use the frame debugger very well

indigo loom
#

Might want to look at the docs then.

Basically need to find the shadows pass and find your object draw call there. The look at the used shader.

compact kestrel
#

it is using the shader yes

indigo loom
#

Does it show the shader variant perhaps?

ruby ridge
#

Not understanding why you need to modify the caster. Deforming the verts should update the casted shadow anyway, no?

compact kestrel
indigo loom
#

No. If the movement is thanks to vertex displacement, you have to do this in the shadow caster pass too.

compact kestrel
#

Yeah I just tested it with the default shadow caster pass, and it doesn't seem to change it

ruby ridge
#

I don't really recall doing much about it with a tree shader (wind params) I've made, but it's been a minute

indigo loom
ruby ridge
#

then again, my billboard sprites do project correctly without modifying the caster

indigo loom
#

It seems like there are cases where unity would use the normal pass vertex shader in shadow caster.

#

Under certain conditions

#

A shader graph would probably do it automatically in most cases

ruby ridge
#

Ah, ok yeah another vertex shader I do similar logic in the caster yeah

#

guess that's why it's called ShadowPassVertex anyway

cerulean pike
#

Are some objects here static / using baked GI? If the shadows are part of the lightmap they wouldn't move

#

The shadows on the boat seem to be moving with the object fine, so I suspect either everything is using baked shadows or the dock is at least?

compact kestrel
#

There are no baked shadows

#

everything is using a single directional light

#

Realtime

ruby ridge
cerulean pike
#

Would apply shadow bias values to prevent acne but should still displace without it

ruby ridge
#
Varyings ShadowPassVertex(Attributes IN)
{
    Varyings OUT;
    UNITY_SETUP_INSTANCE_ID(IN);

    VertexNormalInputs normalInputs = GetVertexNormalInputs(IN.normalOS);
    
    float cameraAngleRad = CameraRotation(normalInputs.tangentWS);
    float4 rotatedOS = RotateAroundYInRads(IN.positionOS, cameraAngleRad);

    VertexPositionInputs positionInputs = GetVertexPositionInputs(rotatedOS);

    OUT.uv = TRANSFORM_TEX(IN.texcoord, _MainTex);

    OUT.positionCS = TransformWorldToHClip(ApplyShadowBias(positionInputs.positionWS, normalInputs.normalWS, _LightDirection));
 
    #if UNITY_REVERSED_Z
        OUT.positionCS.z = min(OUT.positionCS.z, OUT.positionCS.w * UNITY_NEAR_CLIP_VALUE);
    #else
        OUT.positionCS.z = max(OUT.positionCS.z, OUT.positionCS.w * UNITY_NEAR_CLIP_VALUE);
    #endif

    return OUT;
}```
Had some similar shader here and this was my caster
#

actually broke up that method here

indigo loom
#

Probably need to displace the normals too

compact kestrel
indigo loom
#

Good question. Multiply them by a matrix..?🤔

compact kestrel
#

Better question, would I displace the normals in the shadow caster or forwardlit?

indigo loom
#

shadow caster, as this is an issue with the shadow caster. Probably the bias is not calculated correctly

#

see if changing the normal bias to 0 in shadow settings removes that issue

compact kestrel
indigo loom
#

Then not sure.

ruby ridge
#

At least they're moving now lol

compact kestrel
#

lol

indigo loom
#

You could install PIX, output shader debug symbols and debug the shader to know for sure, though I'm not sure you'd want to go that far.😬

compact kestrel
#

probably not haha, I'm sure there's just something small I missed haha