Forum rules - please read before posting.

Can anyone help me with a broken shader?

Apologies if this is the wrong place to ask for this, but I was wondering if anyone has any shader knowledge and could help me out with a shader that was working fine until I switched to URP and now it doesn't work?
It's for a crystal ball and it uses a gradient texture to refract anything behind it, the only error I can see (apart from it's just pink now!) is it says: Material does not have a _Maintext texture property. It is required for Sprite Renderer

using UnityEngine;
Shader "Sprites/CrystalBallShader"
{
Properties
{
[PerRendererData] _Color("Tint", Color) = (1,1,1,1)
[NoScaleOffset] _DistortionTexture("Distortion Texture", 2D) = "white" {}

    _RefractionXOffset("X Refraction Offset", Range(-0.1,0.1)) = 0.01
    _RefractionYOffset("Y Refraction Offset", Range(-0.1,0.1)) = 0.01

    _DistortionScaleX("Distortion Scale X", float) = 1.0
    _DistortionScaleY("Distortion Scale Y", float) = 1.0
}

SubShader
{
    Tags
    {
        "Queue" = "Transparent"
        "IgnoreProjector" = "True"
        "RenderType" = "Opaque"
        "PreviewType" = "Plane"
        "CanUseSpriteAtlas" = "True"
    }

    Cull Off
    Lighting Off
    ZWrite Off
    Fog{ Mode Off }
    Blend One OneMinusSrcAlpha

    Pass
    {
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        #include "UnityCG.cginc"

        struct appdata_t
        {
            float4 vertex : POSITION;
            float4 color : COLOR;
            float2 texcoord : TEXCOORD0;
            float3 normal : NORMAL;
        };

        struct v2f
        {
            float4 vertex : SV_POSITION;
            fixed4 color : COLOR;
            half2 texcoord : TEXCOORD0;
            half2 grabcoord : TEXCOORD1;
        };

        fixed4 _Color;
        sampler2D _CameraOpaqueTexture;
        float _RefractionXOffset;
        float _RefractionYOffset;

        sampler2D _DistortionTexture;
        float _DistortionScaleX;
        float _DistortionScaleY;

        v2f vert(appdata_t input)
        {
            v2f output;
            output.vertex = UnityObjectToClipPos(input.vertex);

            #if UNITY_UV_STARTS_AT_TOP
            float scale = -1.0;
            #else
            float scale = 1.0;
            #endif

            output.grabcoord = (float2(output.vertex.x, output.vertex.y * scale) + output.vertex.w) * 0.5;
            output.texcoord = input.texcoord.xy;

            output.grabcoord.x -= _RefractionXOffset / 2;
            output.grabcoord.y -= _RefractionYOffset / 2;

            output.color = input.color * _Color;

            return output;
        }

        fixed4 frag(v2f input) : SV_Target
        {
            float2 offsetFromCenter = input.texcoord - float2(0.5, 0.5);
            float2 distortionScale = float2(_DistortionScaleX, _DistortionScaleY);
            float distortionIntensity = tex2D(_DistortionTexture, input.texcoord);

            fixed4 c = tex2D(_CameraOpaqueTexture, input.grabcoord + offsetFromCenter * distortionScale * distortionIntensity) * input.color;
            c.rgb *= c.a;

            return c;
        }
        ENDCG
    }
}

}

Hope some one can help, thanks in advance!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.