#Slice shader upgrade

1 messages · Page 1 of 1 (latest)

tame zinc
#

I’ve been using the assets from this video to learn how the teleportation visuals and depth effects work for a portal system. The asset and code are from Unity 2019, so porting them to a later Unity version produced a number of compatibility issues. I was able to fix most of them, but the visual slicer shader still isn’t working correctly.

For context: when an object passes from Portal A into Portal B, the slicer should clip the object as it goes through Portal A and simultaneously create a temporary duplicate that emerges from Portal B. Once the object has fully passed through the portal, that temporary duplicate is deleted. The mechanics are a bit tricky to explain in words, but the referenced part of the tutorial demonstrates the slicing behavior: https://youtu.be/cWpFZbjtSQg?si=TQks2IW_h30-_K-I&t=600

Experimenting with portals, for science.

The project is available here: https://github.com/SebLague/Portals/tree/master
If you'd like to get early access to new projects, or simply want to support me in creating more videos, please visit https://www.patreon.com/SebastianLague

Resources I used:
http://tomhulton.blogspot.com/2015/08/portal-rende...

▶ Play video
#
Shader "Custom/Slice"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0

        sliceNormal("normal", Vector) = (0,0,0,0)
        sliceCentre ("centre", Vector) = (0,0,0,0)
        sliceOffsetDst("offset", Float) = 0
    }
    SubShader
    {
        Tags { "Queue" = "Geometry" "IgnoreProjector" = "True"  "RenderType"="Geometry" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard addshadow
        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
            float3 worldPos;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // World space normal of slice, anything along this direction from centre will be invisible
        float3 sliceNormal;
        // World space centre of slice
        float3 sliceCentre;
        // Increasing makes more of the mesh visible, decreasing makes less of the mesh visible
        float sliceOffsetDst;

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            float3 adjustedCentre = sliceCentre + sliceNormal * sliceOffsetDst;
            float3 offsetToSliceCentre = adjustedCentre - IN.worldPos;
            clip (dot(offsetToSliceCentre, sliceNormal));
            
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;

            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "VertexLit"
}
#

any help with this would be greatly appreciated!

real mantle
#

Screenshots or a video of the issue would be helpful.

tame zinc
#

It visibly looks awful geez

#

No clue why it’s shifting like that either

#

But you can see where it’s trying to split, but there clearly seems to be a few issues

real mantle
#

Well, for starters there's a problem unrelated to any rendering: you mess up the 2 object's positions/offsets. You can see that they shift up and down from time to time. I'd start with investigating this issue first.

#

Look around any logic that changes the object's position. Or perhaps the the issue is that the clone object is not synced with the real one properly. Anyways, that's an issue in C#, not the shader code. Once you get that fixed, and if there are more issues, we can continue from there.

tame zinc
#

this is the original github

#

i suspect the issue is in Portal.cs in void HandleClipping () {

#

but take that with a grain of salt

#

again, this code worked on an older version of unity,