Search Unity

Question Standard to URP Surface Shader Conversion

Discussion in 'Shaders' started by CashCache, Nov 27, 2020.

  1. CashCache

    CashCache

    Joined:
    May 16, 2016
    Posts:
    11
    Hi Everyone,

    I have a basic Standard Pipeline shader that does not work in URP. It's very basic from what I can tell, but since I am so new to shaders, I have no idea where to even start with trying to get this working in URP. Hoping someone here can give me some pointers.

    This shader came from an asset I bought a while back. It gets applied to materials used for graffiti, wall stains, dirt transfers, etc. From what I can tell, it uses another texture to "blend" each fragment color and sets the alpha.

    I'm hoping someone can point me in the right direction...

    Code (CSharp):
    1. Shader "Decals/PBRDecals" {
    2.     Properties {
    3.         _Color("Main Color", Color) = (1,1,1,1)
    4.         _MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
    5.         _BumpMap("Normalmap", 2D) = "bump" {}
    6.         _BumpScale("Normalmap strength", Range(0.0, 10.0)) = 1.0
    7.         _Glossiness("Glossiness", 2D) = "white" {}
    8.         _Gloss("Gloss", Range(0.0, 1.0)) = 1.0
    9.         _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
    10.     }
    11.     SubShader {
    12.         Tags { "RenderType"="Transparent" "IgnoreProjector" = "True" "Queue" = "AlphaTest" }
    13.         LOD 200
    14.        
    15.         //Blend SrcAlpha OneMinusSrcAlpha
    16.  
    17.         CGPROGRAM
    18.         // Physically based Standard lighting model, and enable shadows on all light types
    19.         #pragma surface surf Standard fullforwardshadows decal:blend//alpha:blend
    20.  
    21.         // Use shader model 3.0 target, to get nicer looking lighting
    22.         #pragma target 3.0
    23.  
    24.         sampler2D _MainTex;
    25.         sampler2D _BumpMap;
    26.         sampler2D _Glossiness;
    27.         float _Gloss, _Metallic, _BumpScale;
    28.         fixed4 _Color;
    29.  
    30.         struct Input {
    31.             float2 uv_MainTex;
    32.             float2 uv_BumpMap;
    33.             float4 color: Color;
    34.         };
    35.  
    36.         void surf (Input IN, inout SurfaceOutputStandard o) {
    37.             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color  * IN.color;
    38.             o.Albedo = c.rgb;
    39.             o.Alpha = c.a;
    40.             o.Normal = UnpackScaleNormal(tex2D(_BumpMap, IN.uv_BumpMap), _BumpScale);
    41.             half4 glossMap = tex2D(_Glossiness, IN.uv_MainTex);
    42.             o.Metallic = _Metallic;
    43.             o.Smoothness = glossMap.r * _Gloss;
    44.         }
    45.         ENDCG
    46.     }
    47.     FallBack "Decal/Transparent Diffuse"
    48. }