Search Unity

Get Vertex Color from Texture

Discussion in 'Shaders' started by Deleted member 1123102, Jul 20, 2017.

  1. Hey guys!
    Newbie here, have a question.

    I need to check if a vertex is a certain color by getting its color from its main texture.

    This is what i'm trying to do:

    fixed4 tex = tex2Dlod (_MainTex, float4(v.texcoord.xy,0,0)); // Doesn't return the right color

    Any help would be appreciated!
     
  2. For some more context: This is my code

    Code (CSharp):
    1. void vert( inout appdata_full v )
    2.         {    
    3.             #if !defined(SHADER_API_OPENGL)
    4.             float4 tex = tex2Dlod (_MainTex, float4(v.texcoord.xy, 0, 0));
    5.             #endif
    6.                      
    7.             bool test = (tex.r == _ColorT.r)? true:false;
    8.                          
    9.         }
    In the editor, i change the R value of ColorT. No matter what value i use, the test bool is never true.
     
    Last edited by a moderator: Jul 20, 2017