Search Unity

Vertex shader not rendering anything

Discussion in 'Shaders' started by PinguIsOP, May 17, 2021.

  1. PinguIsOP

    PinguIsOP

    Joined:
    Jul 23, 2018
    Posts:
    16
    I would like to start this off by saying this is my first time doing anything with shaders. What im trying to do is move the vertices of a mesh to the positions I have saved in a texture. The texture holds the RGB value of the vertex positions of a animation frame (so each line in the texture is a new frame, each pixel in the line holds a vertex position), i am only trying to render the first line/frame at the moment

    Code (CSharp):
    1. Shader "Unlit/VertShader"
    2. {
    3.    
    4.     Properties
    5.     {
    6.         [NoScaleOffset] _MainTex("Texture", 2D) = "white" {}
    7.         _AnimVertexTex("Texture", 2D) = "white" {}
    8.     }
    9.     SubShader
    10.     {
    11.  
    12.         Pass
    13.         {
    14.             CGPROGRAM
    15.             #pragma vertex vert
    16.             #pragma fragment frag
    17.             #pragma target 3.5
    18.  
    19.             struct appdata
    20.             {
    21.                 uint vertexId : SV_VertexID;
    22.                 float4 vertex : Position;
    23.                 float2 uv : TEXCOORD0;
    24.             };
    25.  
    26.             struct v2f
    27.             {
    28.                 float4 vertex : SV_POSITION;
    29.                 float2 uv : TEXCOORD0;
    30.             };
    31.  
    32.             sampler2D _AnimVertexTex;
    33.             sampler2D _MainTex;
    34.  
    35.             v2f vert (appdata v)
    36.             {
    37.                 float vertCoords = v.vertexId;
    38.                 float animCoords = 0;
    39.                 float4 texCoords = float4(vertCoords, animCoords, 0, 0);
    40.                 float4 position = tex2Dlod(_AnimVertexTex, texCoords);
    41.  
    42.                 v2f o;
    43.                
    44.                 // Use position values as a standard local space coordinates
    45.                 o.vertex = UnityObjectToClipPos(position);
    46.                 return o;
    47.             }
    48.  
    49.             fixed4 frag(v2f i) : SV_Target
    50.             {
    51.                 fixed4 col = tex2D(_MainTex, i.uv);
    52.                 return col;
    53.             }
    54.  
    55.            
    56.             ENDCG
    57.         }
    58.     }
    59. }
    This is the Shader I have at the moment, I think the problem has something to do with this part but like i said this is the first time I have touched shaders so I really have no idea
    Code (CSharp):
    1.  
    2.                 float vertCoords = v.vertexId;
    3.                 float animCoords = 0;
    4.                 float4 texCoords = float4(vertCoords, animCoords, 0, 0);
    5.                 float4 position = tex2Dlod(_AnimVertexTex, texCoords);
    6.  
    Any help would be greatly appreciated :)