Convert Custom Shader To URP?

Hey guys. I have been working on a shader here which is supposed to apply a trilinear filtering effect to the texture like the nintendo 64. Its a really nice shader for my needs and I cant part with its functionality, how would I go about translating it from the old language to the new one? On another note, would this kind of effect be better off as its own custom render pass?

Shader "Custom/Trilinear64"
{
    Properties
    {
        _Color("Color", Color) = (1,1,1,1)
        _MainTex("Albedo (RGB)", 2D) = "white" {}
    [Range(0,1)]
        _Cutoff("Alpha Cutoff", Range(0,1)) = 0.5
    [Range(0,1)]
        _Glossiness("Smoothness", Range(0,1)) = 0.5
    [Range(0,1)]
        _Metallic("Metallic", Range(0,1)) = 0.0
    }
        SubShader
    {
        Tags { "RenderType" = "Opaque" }
        LOD 200
        CGPROGRAM
        #pragma surface surf Standard alphatest:_Cutoff fullforwardshadows
        sampler2D _MainTex;
        float4 _MainTex_TexelSize;
        struct Input
        {
            float2 uv_MainTex;
            float4 vertexColor : COLOR;
        };
        struct v2f {
            float4 pos : SV_POSITION;
            fixed4 color : COLOR;
        };
        fixed4 N64Filtering(sampler2D tex, float2 uv, float4 scale)
        {
            //texel coords
            float2 texel = uv * scale.zw;
            //get mip map coords and scaling
            float2 mipX = ddx(texel), mipY = ddy(texel);
            float delta_max_sqr = max(dot(mipX, mipX), dot(mipY, mipY));
            float mip = max(0.0, 0.5 * log2(delta_max_sqr));
          
            float size = pow(2, floor(mip));
            scale.xy *= size;
            scale.zw /= size;
            texel = texel / size - 0.5;
            //sample points
            float2 fracTexl = frac(texel);
            float2 uv1 = (floor(texel + fracTexl.yx) + 0.5) * scale.xy;
            fixed4 out1 = tex2Dlod(tex, float4(uv1, 0, mip));
            float2 uv2 = (floor(texel) + float2(1.5, 0.5)) * scale.xy;
            fixed4 out2 = tex2Dlod(tex, float4(uv2, 0, mip));
            float2 uv3 = (floor(texel) + float2(0.5, 1.5)) * scale.xy;
            fixed4 out3 = tex2Dlod(tex, float4(uv3, 0, mip));
            //calculate blend and apply
            float3 blend = float3(abs(fracTexl.x + fracTexl.y - 1), min(abs(fracTexl.xx - float2(0, 1)), abs(fracTexl.yy - float2(1, 0))));
            float4 _outTex = out1 * blend.x + out2 * blend.y + out3 * blend.z;
            // blend and return
            return _outTex;
        }
        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
        void surf(Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = N64Filtering(_MainTex, IN.uv_MainTex, _MainTex_TexelSize) * _Color * IN.vertexColor;;
            o.Albedo = c.rgb * IN.vertexColor; // Combine normal color with the vertex color
            // Metallic and smoothness come from slider variables
             o.Metallic = _Metallic;
             o.Smoothness = _Glossiness;
             o.Alpha = c.a;
        }
        ENDCG
    }
        FallBack "Diffuse"
}

Looks easy to translate.
First, try rewriting the surface shader to a vertex-fragment shader.
Instead of CG, we should now be using HLSL, so CGPROGRAM → HLSLPROGRAM
Include the URP ShaderLibrary’s Core.hlsl.
Take reference/Copy-paste from the UnlitShader for the vert inputs and outputs.
Throw all your material property-declared variables into a CBUFFER called UnityPerMaterial

And you are almost done.
If you wish to add light and shadow, do it in the vertex function.

Sidenote: your N64Filtering code appears applicable for fragment shader too.

Im doing everything youre saying however am a bit lost still. Should I be adding this as a seperate shader pass or should I blend my functions into the vert and frag inputs in the existing shader pass? I have this so far. Sorry!

Shader "Custom/Trilinear64"
{
    Properties
    {
        [MainTexture] _BaseMap("Texture", 2D) = "white" {}
        [MainColor]   _BaseColor("Color", Color) = (1, 1, 1, 1)
        _Cutoff("AlphaCutout", Range(0.0, 1.0)) = 0.5

            // BlendMode
            [HideInInspector] _Surface("__surface", Float) = 0.0
            [HideInInspector] _Blend("__blend", Float) = 0.0
            [HideInInspector] _AlphaClip("__clip", Float) = 0.0
            [HideInInspector] _SrcBlend("Src", Float) = 1.0
            [HideInInspector] _DstBlend("Dst", Float) = 0.0
            [HideInInspector] _ZWrite("ZWrite", Float) = 1.0
            [HideInInspector] _Cull("__cull", Float) = 2.0

            // Editmode props
            [HideInInspector] _QueueOffset("Queue offset", Float) = 0.0

            // ObsoleteProperties
            [HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
            [HideInInspector] _Color("Base Color", Color) = (0.5, 0.5, 0.5, 1)
            [HideInInspector] _SampleGI("SampleGI", float) = 0.0 // needed from bakedlit
    }
        SubShader
            {
                Tags { "RenderType" = "Opaque" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline" }
                LOD 100

                Blend[_SrcBlend][_DstBlend]
                ZWrite[_ZWrite]
                Cull[_Cull]

                Pass
                {
                    Name "Unlit"
                    HLSLPROGRAM
                // Required to compile gles 2.0 with standard srp library
                #pragma prefer_hlslcc gles
                #pragma exclude_renderers d3d11_9x

                #pragma vertex vert
                #pragma fragment frag
                #pragma shader_feature _ALPHATEST_ON
                #pragma shader_feature _ALPHAPREMULTIPLY_ON

                // -------------------------------------
                // Unity defined keywords
                #pragma multi_compile_fog
                #pragma multi_compile_instancing

                #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

                CBUFFER_START(UnityPerMaterial)

        sampler2D _MainTex;
        float4 _MainTex_TexelSize;
CBUFFER_END

                struct Attributes
                {
                    float4 positionOS       : POSITION;
                    float2 uv               : TEXCOORD0;

                    float2 uv_MainTex;
                    float4 vertexColor : COLOR;
                    UNITY_VERTEX_INPUT_INSTANCE_ID
                };

                struct Varyings
                {
                    float2 uv        : TEXCOORD0;
                    float fogCoord : TEXCOORD1;
                    float4 vertex : SV_POSITION;
                    fixed4 color : COLOR;

                    UNITY_VERTEX_INPUT_INSTANCE_ID
                    UNITY_VERTEX_OUTPUT_STEREO
                };

                Varyings vert(Attributes input)
                {
                    Varyings output = (Varyings)0;

                    UNITY_SETUP_INSTANCE_ID(input);
                    UNITY_TRANSFER_INSTANCE_ID(input, output);
                    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

                    VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
                    output.vertex = vertexInput.positionCS;
                    output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
                    output.fogCoord = ComputeFogFactor(vertexInput.positionCS.z);

                    return output;
                }

                half4 frag(Varyings input) : SV_Target
                {
                    UNITY_SETUP_INSTANCE_ID(input);
                    UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

                    half2 uv = input.uv;
                    half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv);
                    half3 color = texColor.rgb * _BaseColor.rgb;
                    half alpha = texColor.a * _BaseColor.a;
                    AlphaDiscard(alpha, _Cutoff);

    #ifdef _ALPHAPREMULTIPLY_ON
                    color *= alpha;
    #endif

                    color = MixFog(color, input.fogCoord);
                    alpha = OutputAlpha(alpha);

                    return half4(color, alpha);
                }
                ENDHLSL
            }
            Pass
            {
                Tags{"LightMode" = "DepthOnly"}

                ZWrite On
                ColorMask 0

                HLSLPROGRAM
                    // Required to compile gles 2.0 with standard srp library
                    #pragma prefer_hlslcc gles
                    #pragma exclude_renderers d3d11_9x
                    #pragma target 2.0

                    #pragma vertex DepthOnlyVertex
                    #pragma fragment DepthOnlyFragment

                    // -------------------------------------
                    // Material Keywords
                    #pragma shader_feature _ALPHATEST_ON

                    //--------------------------------------
                    // GPU Instancing
                    #pragma multi_compile_instancing

                    #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
                    #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
                    ENDHLSL
                }

                    // This pass it not used during regular rendering, only for lightmap baking.
                    Pass
                    {
                        Name "Meta"
                        Tags{"LightMode" = "Meta"}

                        Cull Off

                        HLSLPROGRAM
                    // Required to compile gles 2.0 with standard srp library
                    #pragma prefer_hlslcc gles
                    #pragma exclude_renderers d3d11_9x
                    #pragma vertex UniversalVertexMeta
                    #pragma fragment UniversalFragmentMetaUnlit

                    #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
                    #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitMetaPass.hlsl"

                    ENDHLSL
                }
            }
                FallBack "Hidden/Universal Render Pipeline/FallbackError"
                    CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.UnlitShader"
}

Okay, I am not sure what exactly is the end result you are looking for. But I have translated the shader for you.

Shader "Custom/Trilinear64"
{
    Properties
    {

        _MainTex("BaseMap", 2D) = "white" {}
        _Color("Base Color", Color) = (0.5, 0.5, 0.5, 1)
        _Cutoff("AlphaCutout", Range(0.0, 1.0)) = 0.5
    }
    SubShader
    {
        Tags { "RenderType" = "Opaque" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline" }
        LOD 100
        Pass
        {
            HLSLPROGRAM
            // Required to compile gles 2.0 with standard srp library

            #pragma prefer_hlslcc gles
            #pragma exclude_renderers d3d11_9x
            #pragma vertex vert
            #pragma fragment frag
            // -------------------------------------
            // Unity defined keywords
            #pragma multi_compile_fog
            #pragma multi_compile_instancing
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            TEXTURE2D(_MainTex);
            SAMPLER(sampler_MainTex);
            CBUFFER_START(UnityPerMaterial)
            float4 _MainTex_ST;
            float4 _MainTex_TexelSize;
            float4 _Color;
            float _Cutoff;
            CBUFFER_END
            struct Attributes
            {
                float4 positionOS       : POSITION;
                float2 uv               : TEXCOORD0;
                float4 vertexColor : COLOR;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };
            struct Varyings
            {
                float2 uv        : TEXCOORD0;
                float fogCoord : TEXCOORD1;
                float4 vertex : SV_POSITION;
                float4 color : COLOR;
                UNITY_VERTEX_INPUT_INSTANCE_ID
                UNITY_VERTEX_OUTPUT_STEREO
            };

            Varyings vert(Attributes input)
            {
                Varyings output = (Varyings)0;
                UNITY_SETUP_INSTANCE_ID(input);
                UNITY_TRANSFER_INSTANCE_ID(input, output);
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
                VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
                output.vertex = vertexInput.positionCS;
                output.uv = TRANSFORM_TEX(input.uv, _MainTex);
                output.fogCoord = ComputeFogFactor(vertexInput.positionCS.z);
                output.color = input.vertexColor;
                return output;
            }

            float4 N64Filtering(float2 uv, float4 scale)
            {
                //texel coords

                float2 texel = uv * scale.zw;

                //get mip map coords and scaling

                float2 mipX = ddx(texel), mipY = ddy(texel);
                float delta_max_sqr = max(dot(mipX, mipX), dot(mipY, mipY));
                float mip = max(0.0, 0.5 * log2(delta_max_sqr));
        
                float size = pow(2, floor(mip));
                scale.xy *= size;
                scale.zw /= size;
                texel = texel / size - 0.5;
                //sample points
                float2 fracTexl = frac(texel);
                float2 uv1 = (floor(texel + fracTexl.yx) + 0.5) * scale.xy;
                float4 out1 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv1);
                float2 uv2 = (floor(texel) + float2(1.5, 0.5)) * scale.xy;
                float4 out2 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv2);
                float2 uv3 = (floor(texel) + float2(0.5, 1.5)) * scale.xy;
                float4 out3 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv3);
                //calculate blend and apply
                float3 blend = float3(abs(fracTexl.x + fracTexl.y - 1), min(abs(fracTexl.xx - float2(0, 1)), abs(fracTexl.yy - float2(1, 0))));
                float4 _outTex = out1 * blend.x + out2 * blend.y + out3 * blend.z;
                // blend and return
                return _outTex;
            }
            half4 frag(Varyings input) : SV_Target
            {
                UNITY_SETUP_INSTANCE_ID(input);
                UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
                half2 uv = input.uv;
                half4 texColor = N64Filtering(uv, _MainTex_TexelSize);
                half3 color = texColor.rgb * _Color.rgb;
                half alpha = texColor.a * _Color.a;
                AlphaDiscard(alpha, _Cutoff);
                color = MixFog(color, input.fogCoord);
                return half4(color, alpha);
            }
            ENDHLSL
        }
    }
}
1 Like

Beautiful! The shader was meant to apply Nintendo 64 texture filtering in the URP.

The left is your shader(the intended result) and the right is the standard URP Shader. Its still missing lighting and vertex colors, but Ill try to figure it out and post my results

Hi, i tried to convert my shader in URP by adding the render pipeline on it but it gives me an error, if someone can help me or explaoin how to convert would be really awesome!
The shader is this one.

Shader "Custom/VertexColors"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _GridTex("Grid Texture", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags
        {
            "RenderType"="Opaque"
        }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.5

        sampler2D _MainTex;

        sampler2D _GridTex;

        struct Input
        {
            //float2 uv_MainTex;
            float4 color : COLOR;
            float3 worldPos;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            float2 uv = IN.worldPos.xy * 0.02;
            fixed4 c = tex2D (_MainTex, float3(uv,0)/*IN.uv_MainTex*/) * _Color;

            float2 gridUV = IN.worldPos.xz;
            gridUV.x *= 1 / (4 * 8.66025404);
            gridUV.y *= 1 / (2 * 15.0);

            fixed4 grid = tex2D(_GridTex, gridUV);

            o.Albedo = c.rgb * grid * _Color;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

Your code is a surface shader. Unity did not implement surface shaders or a replacement for them into SRPs, forcing you into a brittle and much more complex vertex/fragment pipeline, or forcing you to use a shader graph instead. I also wrote a replacement surface shader like system called Better Shaders as another option.

3 Likes

I have a same issue
could you translate this shader as well?

Shader “Toon/Custom/IK_Smooth_Outline” {
Properties {
_MainTex (“Base (RGB)”, 2D) = “white” {}
_ShadeTex (“Shade Tex”, 2D) = “white” {}

_RimColor ( “Rim Color” , Color ) = (0.26,0.19,0.16,0.0)
_RimPower ( “Rim Power” , Range(0.5,8.0)) = 3.0

_OutlineColor(“Outline Color”, Color) = (0,0,0,1)
_Outline(“Outline Width”, Range(.001, 0.1)) = .0016

//_AmbientFactor(“Outline Width”, Range(0.1, 5)) = 2.7
}
SubShader {
Tags { “RenderType”=“Opaque” }
LOD 200
Cull Off

CGPROGRAM
#pragma surface surf Shade noambient

sampler2D _MainTex;
sampler2D _ShadeTex;

float4 _RimColor;
float _RimPower;

//uniform float _AmbientFactor;

struct Input {
float2 uv_MainTex;
float3 viewDir;
};

struct SurfaceOutputCustom {
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
half Specular;
fixed Gloss;
fixed Alpha;
};

half4 LightingShade(SurfaceOutputCustom s,half3 lightDir,half attend)
{

half NdotL = dot(s.Normal,lightDir);

float3 d_Albedo = s.Albedo * s.Albedo;

//어두운 부분은 좀 더 밝게,
float shadeOffset = lerp(0.50, 0.40, NdotL);
half shade = NdotL0.1 + shadeOffset;
//half shade = NdotL
0.1+0.5;
half cell_shade = saturate(shade * 6 -3 );

half3 ramp = tex2D(_ShadeTex,float2(shade,shade));

fixed3 ambient = 0;
ambient = UNITY_LIGHTMODEL_AMBIENT * 2.7;

float3 light = clamp(_LightColor0.rgb, 0.0, 1.0);
ambient = clamp(ambient, 1.4, 1.7)*light;

half4 c;
c.rgb = lerp(d_Albedo, s.Albedo, cell_shade) * ramp * ambient;
c.a = s.Alpha;

return c;
}

void surf (Input IN, inout SurfaceOutputCustom o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);

o.Albedo = c.rgb ;// * diffuse;
o.Alpha = c.a;

half rim = 1.0 - saturate(dot (normalize(IN.viewDir) , o.Normal));
o.Emission = _RimColor.rgb * pow(rim,_RimPower);
}
ENDCG

CGINCLUDE
#include “UnityCG.cginc”

struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
};

struct v2f {
float4 pos : POSITION;
float4 color : COLOR;
};

uniform float _Outline;
uniform float4 _OutlineColor;

v2f vert(appdata v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
float3 clipNormal = mul((float3x3) UNITY_MATRIX_VP, mul((float3x3) UNITY_MATRIX_M, v.normal));

float2 offset = normalize(clipNormal.xy) * _Outline * o.pos.w;
//float2 offset = normalize(clipNormal.xy) / _ScreenParams.xy * _Outline * o.pos.w;

o.pos.xy += offset;
o.color = _OutlineColor;

/*o.pos = v.vertex;
o.pos.xyz += v.normal.xyz * _Outline;
o.pos = UnityObjectToClipPos(o.pos);

o.color = _OutlineColor;*/

return o;
}
ENDCG

Pass{
Name “OUTLINE”
Tags{ “LightMode” = “Always” }
Cull Front
ZWrite Off
ColorMask RGB
Blend SrcAlpha OneMinusSrcAlpha

CGPROGRAM
#pragma vertex vert
#pragma fragment frag
half4 frag(v2f i) :COLOR{ return i.color; }
ENDCG
}
}
FallBack “Diffuse”
}

Hey, I made an utility to automatically convert Surface Shaders to URP/HDRP shaders : Surface Shader Converter | Utilities Tools | Unity Asset Store
If you have any issues with it, send me an email and I’ll fix it.

2 Likes

I just bought your asset. I only have URP, not HDRP, so a lot of errors prompts into the console:

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(151)

Compiling Subshader: 0, Pass: ShadowCaster, Fragment program with _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(875)

Compiling Subshader: 0, Pass: META, Fragment program with _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(1675)

Compiling Subshader: 0, Pass: ScenePickingPass, Vertex program with _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(2474)

Compiling Subshader: 0, Pass: SceneSelectionPass, Vertex program with _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(3290)

Compiling Subshader: 0, Pass: MotionVectors, Vertex program with _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(4108)

Compiling Subshader: 0, Pass: TransparentDepthPrepass, Fragment program with _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(4840)

Compiling Subshader: 0, Pass: FullScreenDebug, Fragment program with _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(5651)

Compiling Subshader: 0, Pass: DepthOnly, Vertex program with _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(6484)

Compiling Subshader: 0, Pass: GBuffer, Fragment program with DECALS_OFF PROBE_VOLUMES_OFF _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(7330)

Compiling Subshader: 0, Pass: Forward, Fragment program with AREA_SHADOW_MEDIUM DECALS_OFF DIRECTIONAL_SHADOW_LOW PROBE_VOLUMES_OFF PUNCTUAL_SHADOW_LOW SCREEN_SPACE_SHADOWS_OFF USE_FPTL_LIGHTLIST _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(8148)

Compiling Subshader: 0, Pass: RayTracingPrepass, Vertex program with _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(8958)

Compiling Subshader: 1, Pass: IndirectDXR, RayTracing program with PROBE_VOLUMES_OFF _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(9560)

Compiling Subshader: 1, Pass: VisibilityDXR, RayTracing program with _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(10154)

Compiling Subshader: 1, Pass: ForwardDXR, RayTracing program with PROBE_VOLUMES_OFF _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(10757)

Compiling Subshader: 1, Pass: GBufferDXR, RayTracing program with PROBE_VOLUMES_OFF _BLENDMODE_OFF _REFRACTION_OFF

Shader error in 'M_Chair': Couldn't open include file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. at Assets/SurfaceShaderConverter/HDRPGraphShader.shader(11350)

Compiling Subshader: 1, Pass: PathTracingDXR, RayTracing program with _BLENDMODE_OFF _REFRACTION_OFF

Also, URP shader fails:

Shader error in 'M_Chair': 'SurfaceReplacement': no matching 2 parameter function at Assets/SurfaceShaderConverter/URPGraphShader.shader(332) (on d3d11)

Compiling Subshader: 0, Pass: Universal Forward, Fragment program with <no keywords>

Shader error in 'M_Chair': undeclared identifier 'Out' at Assets/SurfaceShaderConverter/URPGraphShader.shader(332) (on d3d11)

Compiling Subshader: 0, Pass: Universal Forward, Fragment program with <no keywords>

Shader error in 'M_Chair': 'SurfaceReplacement': no matching 2 parameter function at Assets/SurfaceShaderConverter/URPGraphShader.shader(722) (on d3d11)

Compiling Subshader: 0, Pass: GBuffer, Vertex program with <no keywords>

Shader error in 'M_Chair': undeclared identifier 'Out' at Assets/SurfaceShaderConverter/URPGraphShader.shader(722) (on d3d11)

Compiling Subshader: 0, Pass: GBuffer, Vertex program with <no keywords>

Shader error in 'M_Chair': 'SurfaceReplacement': no matching 2 parameter function at Assets/SurfaceShaderConverter/URPGraphShader.shader(998) (on d3d11)

Compiling Subshader: 0, Pass: ShadowCaster, Fragment program with <no keywords>

Shader error in 'M_Chair': undeclared identifier 'Out' at Assets/SurfaceShaderConverter/URPGraphShader.shader(998) (on d3d11)

Compiling Subshader: 0, Pass: ShadowCaster, Fragment program with <no keywords>

Shader error in 'M_Chair': 'SurfaceReplacement': no matching 2 parameter function at Assets/SurfaceShaderConverter/URPGraphShader.shader(2392) (on d3d11)

Compiling Subshader: 1, Pass: Universal Forward, Vertex program with _ADDITIONAL_LIGHTS_VERTEX

Shader error in 'M_Chair': undeclared identifier 'Out' at Assets/SurfaceShaderConverter/URPGraphShader.shader(2392) (on d3d11)

Compiling Subshader: 1, Pass: Universal Forward, Vertex program with _ADDITIONAL_LIGHTS_VERTEX

Shader error in 'M_Chair': 'SurfaceReplacement': no matching 2 parameter function at Assets/SurfaceShaderConverter/URPGraphShader.shader(2668) (on d3d11)

Compiling Subshader: 1, Pass: ShadowCaster, Fragment program with <no keywords>

Shader error in 'M_Chair': undeclared identifier 'Out' at Assets/SurfaceShaderConverter/URPGraphShader.shader(2668) (on d3d11)

Compiling Subshader: 1, Pass: ShadowCaster, Fragment program with <no keywords>

I’m using Unity 6000.2.

After pressing ConvertSelection:

Please check this. Thanks. I’ll test your asset.

UPDATE:
After a few days of work I added support for vertex shaders under URP to my converter and fixed z3nth10n’s errors.

1 Like

Yes, we are keeping in contact in private to solve my errors. Thanks @relativegames

I guess your converter has some target shaders in URP and HDRP and possibly it could be Lit shaders, which are default.
So if I give it some surface shader it will convert it to a version of URP or HDRP shader?
Adding all the passes present in these shader? Forward, ShadowCaster and so on?

Kind of. I use a template based on shadergraph shaders that contains all the passes for Forward/Deferred/Raytracing shaders and I make it work with surface shaders.

1 Like