Search Unity

Convert Oculus shader to URP

Discussion in 'Shaders' started by AuntieSnow, Feb 9, 2021.

  1. AuntieSnow

    AuntieSnow

    Joined:
    Feb 9, 2021
    Posts:
    1
    Hello everyone, I'm currently having an issue with Universial Render Pipeline. I am newbie to Shader and I need to have this Underlay Imposter shader from Oculus to create a hole that allows the underlay OVROverlay to show thorough.

    It works nicely with Unity build in setup, but it turns into all pink after URP is enabled .I have tried to compare the code with URP Lit shader , but no luck so far.

    Is there any way to make this shader work in URP?

    Code (CSharp):
    1. /*
    2. This shader is used to render the impostor while clearing out the alpha of the eye buffer
    3. The important details here are:
    4. - the use of the Geometry+1 queue to make sure the impostor is drawn after all other opaque objects but before alpha
    5. - the keepalpha parameter that allow unity to actually write the alpha we return at the end of the shader.
    6. */
    7.  
    8. Shader "Oculus/Underlay Impostor" {
    9.     Properties{
    10.         _Color("Color", Color) = (1,1,1,1)
    11.         _MainTex("Albedo (RGB)", 2D) = "white" {}
    12.         _Glossiness("Smoothness", Range(0,1)) = 0.5
    13.         _Metallic("Metallic", Range(0,1)) = 0.0
    14.     }
    15.         SubShader{
    16.             Tags { "Queue" = "Geometry+1" "RenderType" = "Opaque" }
    17.             LOD 200
    18.  
    19.             CGPROGRAM
    20.             // Physically based Standard lighting model, and enable shadows on all light types
    21.             #pragma surface surf Standard fullforwardshadows keepalpha
    22.  
    23.             // Use shader model 3.0 target, to get nicer looking lighting
    24.             #pragma target 3.0
    25.  
    26.             sampler2D _MainTex;
    27.  
    28.             struct Input {
    29.                 float2 uv_MainTex;
    30.             };
    31.  
    32.             half _Glossiness;
    33.             half _Metallic;
    34.             fixed4 _Color;
    35.  
    36.             void surf(Input IN, inout SurfaceOutputStandard o) {
    37.                 // Albedo comes from a texture tinted by color
    38.                 fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    39.                 o.Albedo = c.rgb;
    40.                 // Metallic and smoothness come from slider variables
    41.                 o.Metallic = _Metallic;
    42.                 o.Smoothness = _Glossiness;
    43.                 o.Alpha = 0.f;
    44.             }
    45.             ENDCG
    46.         }
    47.             FallBack "Diffuse"
    48. }
    49.  
     
  2. sbanca

    sbanca

    Joined:
    Mar 5, 2019
    Posts:
    1
    Has anyone found an answer to this problem ?
     
  3. NaudotN

    NaudotN

    Joined:
    Mar 22, 2021
    Posts:
    1
    Hello,

    I had the exact same problem as you

    Try this shader :

    Code (CSharp):
    1. Shader "Unlit/NewUnlitShader"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         Tags { "Queue" = "Transparent" "RenderType"="Opaque" }
    10.         LOD 200
    11.  
    12.         Pass
    13.         {
    14.             CGPROGRAM
    15.             #pragma vertex vert
    16.             #pragma fragment frag
    17.  
    18.             #include "UnityCG.cginc"
    19.  
    20.             struct appdata
    21.             {
    22.                 float4 vertex : POSITION;
    23.                 float2 uv : TEXCOORD0;
    24.             };
    25.  
    26.             struct v2f
    27.             {
    28.                 float2 uv : TEXCOORD0;
    29.                 float4 vertex : SV_POSITION;
    30.             };
    31.  
    32.             sampler2D _MainTex;
    33.             float4 _MainTex_ST;
    34.  
    35.             v2f vert (appdata v)
    36.             {
    37.                 v2f o;
    38.                 o.vertex = UnityObjectToClipPos(v.vertex);
    39.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    40.                 return o;
    41.             }
    42.  
    43.             fixed4 frag (v2f i) : SV_Target
    44.             {
    45.                 return 0;
    46.             }
    47.             ENDCG
    48.         }
    49.     }
    50. }
    51.  
     
  4. smartplay

    smartplay

    Joined:
    Feb 13, 2019
    Posts:
    21
    didn't work
    does anyone fix that