Search Unity

Get Texture UV Coordinate in Custom Lighting

Discussion in 'Shaders' started by jujunosuke, Aug 19, 2014.

  1. jujunosuke

    jujunosuke

    Joined:
    Apr 30, 2011
    Posts:
    190
    Hi Everyone,

    I can't figure how i can get the UV coordinate of my texture in my Custom Lighting model.
    I am working on a surface shader and basically i would like to control the intensity of the light with an alpha map.

    Code (csharp):
    1.  
    2. half4 LightingCustom (SurfaceOutputs, half3lightDir, half3viewDir, halfatten)
    3.  {
    4.       float3 tex = tex2D(_AlphaTexture, how to get alphaTexture uv ?).rgb;
    5.      ///////////
    6.      return lightResult * tex;
    7.  }
    8.  
    Any help would be greatly appreciated.
    Best regards.
     
  2. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    You can't, you need to sample your texture in the surface shader and pass it as some component of SurfaceOutput. You can then read it in your lighting function.
     
  3. jujunosuke

    jujunosuke

    Joined:
    Apr 30, 2011
    Posts:
    190
    I see, i get the idea of the concept, however, do you have any example of how i could do that ?
    I have no idea where to start :/