Search Unity

Question Shader to display Texture to CustomRenderTexture on RawImage

Discussion in 'Shaders' started by aubrian, May 20, 2021.

  1. aubrian

    aubrian

    Joined:
    Apr 18, 2020
    Posts:
    8
    Hi,

    I'm attempting to write a (theoretically) simple shader for a CustomRenderTexture. I'd like to render an inputted Texture as-is onto a RawImage. My CustomRenderTexture with this shader is attached to a RawImage component on my UI GameObject. But nothing is being rendered to the RawImage.

    Does anyone have any experience with CustomRenderTexture shaders? Any tips or advice would be greatly appreciated. Thank you!

    Code (Csharp):
    1. Shader "Custom/DrawTexture"
    2. {
    3.     Properties {
    4.         _SnapshotTex ("Snapshot Texture", 2D) = "white" {}
    5.     }
    6.  
    7.     SubShader {
    8.  
    9.         Lighting Off
    10.         Blend One Zero
    11.  
    12.         Pass {
    13.  
    14.             CGPROGRAM
    15.  
    16.             #include "UnityCustomRenderTexture.cginc"
    17.             #pragma vertex CustomRenderTextureVertexShader
    18.             #pragma fragment frag
    19.  
    20.             sampler2D _SnapshotTex;
    21.  
    22.             float4 frag (v2f_customrendertexture inputFrag) : COLOR
    23.             {
    24.                 return tex2D(_SnapshotTex, inputFrag.globalTexcoord.xy);
    25.             }
    26.  
    27.             ENDCG
    28.         }
    29.     }
    30. }
    31.