Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slice shader upgrade to URP? #17

Open
slagatoras opened this issue May 12, 2022 · 1 comment
Open

Slice shader upgrade to URP? #17

slagatoras opened this issue May 12, 2022 · 1 comment

Comments

@slagatoras
Copy link

Any luck with that? has anyone managed to convert it to URP please?

@Rokukkkk
Copy link

Rokukkkk commented Sep 3, 2022

I think URP doesn't support Surface Shader anymore, you should either use Shader Graph or write a Lit Shader you own which clip the pixels manually. Check the code below, the important parts are the 2 Clip() functions. But I'm not sure is this the best way to achieve tho.

SubShader
{
    Tags { "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" "Queue" = "Geometry" }

    HLSLINCLUDE
    // Includes & Structs
    ENDHLSL

    Pass
    {
        Tags { "LightMode" = "UniversalForward" }
        
        HLSLPROGRAM

        #pragma vertex vert
        #pragma fragment frag

        v2f vert(a2v v)
        {
            // Vertex calculations
            return o;
        }
        
        half4 frag(v2f i) : SV_TARGET
        {
            float3 adjustedCenter = sliceCenter + sliceNormal * sliceOffsetDst;
            float3 offsetToSliceCentre = adjustedCenter - i.worldPos;
            clip(dot(offsetToSliceCentre, sliceNormal));

            // Fragment calculations
            
            return color;
        }

        ENDHLSL
    }

    // Important! Have to use a custom shadercaster to clip out the shadow
    Pass
    {
        Tags { "LightMode" = "ShadowCaster" }
        ZWrite On
        ZTest LEqual
        Cull Off  // Set cull off to keep shadow casting from the inner clipped part

        HLSLPROGRAM

        #pragma vertex vert
        #pragma fragment frag

        v2f vert(a2v v)
        {
            // Same as forward pass
            return o;
        }

        half4 frag(v2f i) : SV_TARGET
        {
            float3 adjustedCenter = sliceCenter + sliceNormal * sliceOffsetDst;
            float3 offsetToSliceCentre = adjustedCenter - i.worldPos;
            clip(dot(offsetToSliceCentre, sliceNormal));

            return 0;
        }

        ENDHLSL
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants