Search Unity

Global Data for All Shaders

Discussion in 'Shaders' started by Brian-Brookwell, May 14, 2015.

  1. Brian-Brookwell

    Brian-Brookwell

    Joined:
    Sep 14, 2012
    Posts:
    47
    I know that Properties apply to a single shader. I was wondering whether there exists the concept of a global piece of information that can be set once and accessed by all shaders that need it. In particular, I want to use the player location to create a transparency cutout through objects between the player and the camera. Camera location, fragment location are fine. But to calculate whether something is visible or not, I need the player location. As several shaders may be involved, it would be a little inconvenient to set a player location for each object's shader every time the player moves.
     
  2. mholub

    mholub

    Joined:
    Oct 3, 2012
    Posts:
    123
  3. Brian-Brookwell

    Brian-Brookwell

    Joined:
    Sep 14, 2012
    Posts:
    47
    Thanks! So do I declare the global in the Properties or is it something special?
     
  4. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    No, you don't need to declare it in the Properties section. Just declare the uniform in your shader pass, the same way you'd declare other uniform values :

    Code (CSharp):
    1. sampler2D _MainTex;
    2. float4 _MyGlobalVector;
    3. // etc...