Search Unity

Question [URP][SHADERS] Editors grid rendering on top of my custom HLSL shader.

Discussion in 'Universal Render Pipeline' started by M4n5o, May 12, 2023.

  1. M4n5o

    M4n5o

    Joined:
    Mar 27, 2021
    Posts:
    1
    Hello people!

    I really need some help with custom shaders in Unity.
    When writing my shaders, the grid on the editor window is rendered on top of any material that has this shader applied.

    upload_2023-5-11_20-30-27.png

    Note that the grid is only obscured when behind the cylinder (that is using the standard URP built-in shader).

    Here is this simple shader that I'm using on this sphere:

    Code (CSharp):
    1. Shader "Unlit/HelloWorld"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.         _BaseColor("Base Color", Color) = (1,1,1,1)
    7.     }
    8.     SubShader
    9.     {
    10.         Tags { "RenderType"="Opaque" "Queue"="Transparent"}
    11.         LOD 100
    12.  
    13.        
    14.         HLSLINCLUDE
    15.        
    16.         #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    17.  
    18.         CBUFFER_START(UnityPerMaterial)
    19.             float4 _BaseColor;
    20.         CBUFFER_END
    21.  
    22.         TEXTURE2D(_MainTex);
    23.         SAMPLER(sampler_MainTex);
    24.  
    25.         struct VertexInput
    26.         {
    27.             float4 position : POSITION;
    28.             float2 uv : TEXCOORD0;
    29.         };
    30.  
    31.         struct VertexOutput
    32.         {
    33.             float4 position : SV_POSITION;
    34.             float2 uv : TEXCOORD0;
    35.         };
    36.  
    37.         ENDHLSL
    38.  
    39.         Pass
    40.         {
    41.             HLSLPROGRAM
    42.             #pragma vertex vert
    43.             #pragma fragment frag
    44.  
    45.             VertexOutput vert(VertexInput i)
    46.             {
    47.                 VertexOutput o;
    48.                 o.position = TransformObjectToHClip(i.position.xyz);
    49.                 o.uv = i.uv;
    50.                 return o;
    51.             }
    52.  
    53.             float4 frag(VertexOutput i) : SV_TARGET0
    54.             {
    55.                 return _BaseColor;
    56.             }
    57.  
    58.             ENDHLSL
    59.         }
    60.     }
    61. }