Home > Back-end >  How do I make the shader working for the standard pipeline work for the urp pipeline?
How do I make the shader working for the standard pipeline work for the urp pipeline?

Time:11-20

I have a shader that provides texture repeat. But it doesn't work in urp. How do I make it work for urp?

More precisely, the shader works, but the material turns pink. I made the option Rendering>Generate shader includes. I will be glad if you can help me how to do it.

My RepeatShader:

Shader "Custom/RepeatShader" {
Properties{
    _Color("Main Color", Color) = (1,1,1,1)



    _MainTex("Base (RGB)", 2D) = "white" {}
_Scale("Texture Scale", Float) = 1.0



}
    SubShader{
    Tags{ "RenderType" = "Opaque" }
    LOD 200

    CGPROGRAM
#pragma surface surf Lambert
    sampler2D _MainTex;
fixed4 _Color;
float _Scale;

struct Input {
    float3 worldNormal;
    float3 worldPos;
};

void surf(Input IN, inout SurfaceOutput o) {
    float2 UV;
    fixed4 c;

    if (abs(IN.worldNormal.x) > 0.5) {
        UV = IN.worldPos.yz; // side
        c = tex2D(_MainTex, UV* _Scale); // use WALLSIDE texture
    }
    else if (abs(IN.worldNormal.z) > 0.5) {
        UV = IN.worldPos.xy; // front
        c = tex2D(_MainTex, UV* _Scale); // use WALL texture
    }
    else {
        UV = IN.worldPos.xz; // top
        c = tex2D(_MainTex, UV* _Scale); // use FLR texture
    }

    o.Albedo = c.rgb * _Color;
}
ENDCG
}

    Fallback "Legacy Shaders/VertexLit"
}

CodePudding user response:

I don't know in which version of Unity and URP you are, but here's what I did:

First, right-click with your mouse and select Create > Shader Graph > URP > Lit Shader Graph (or Unlit if your shader should not react to light).

Inside your shader, create a Texture2D property called Main Tex, a float property called Scale and a color property called Color.

This is what your shader graph result should look like:

enter image description here

This should replicate exactly what you have in your shader. There are a few possible improvements, like using the Custom Function node to extract what you need without using all those nodes but this should help you start.

  • Related