Search Unity

Accessing to a texture file within cginclude

Discussion in 'Shaders' started by jmssun, Jun 6, 2013.

  1. jmssun

    jmssun

    Joined:
    Jun 5, 2013
    Posts:
    2
    Does anybody know how to assign a specific texture files to a shader that do not work with material, and access to that texture from it? I am talking about shaders like unitycg.ctgInc.or any internal shader files.

    I need the shader helper file to read a look up texture that works globally. But have no idea about how to do it.

    Thanks for any help!
    James
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    You can set a global texture with this in script;
    Shader.SetGlobalTexture("_MyTextureVariableName", myTexture);

    Then inside your shader you simply call
    sampler2D _MyTextureVariableName;

    and you can use it like any other texture in your shader.
     
  3. jmssun

    jmssun

    Joined:
    Jun 5, 2013
    Posts:
    2
    @Farfarer
    Thank you so much for this tip!

    It is exactly what I need!