Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Mapping a texture using UV's in the vertex function of a surface shader

Discussion in 'Shaders' started by lewdoo, Mar 21, 2019.

  1. lewdoo

    lewdoo

    Joined:
    Sep 7, 2018
    Posts:
    9
    Does anyone know how to do this, i'm aware of mapping tex2Dlod and how to get uv_Maintex into the vertex function, however using the two together doesn't seem to give any results. Any thoughts?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238
    The Surface Shader's vertex function runs before uv_MainTex has been calculated, so while you can access the value in the Input struct, it is going to be the default uninitialized value of float2(0,0). If you want to get the equivalent value, you'll have to calculate the UV yourself like you would if you were writing a vertex fragment shader.

    float2 uv_MainTex = TRANSFORM_TEX(v.texcoord.xy, _MainTex);
     
  3. lewdoo

    lewdoo

    Joined:
    Sep 7, 2018
    Posts:
    9
    Thanks for the explanation dude, I just figured it out and was about to post it, but I didn't know the reason so great!! I was just trying to find the documentation for the variable name that represents 'vertex' in surf shader, being texcoord. Thanks again for the explanation!