Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GLSL arrays can't be size 1?

Discussion in 'Shaders' started by Big_Friggin_Al, Mar 8, 2016.

  1. Big_Friggin_Al

    Big_Friggin_Al

    Joined:
    Jan 9, 2014
    Posts:
    37
    In my shader, I was playing around with different values and noticed something bizarre (to me).

    I have an array, and if I size it to any number it works fine, but if I size it to 1, I'm unable to access the data at index 0 (either in a loop or not).

    To set the data I do a setFloat from my .cs script and I know it works, because when I getFloat it returns the correct value, but the shader will not reflect that unless I change the array to be size 2 or higher (at which point it totally works to access the data at index 0).

    Is this some kind of built-in limitation of the language that I'm not aware of?
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    It's possible that setFloat, when given a single value, is just calling the "single value" version of the API's "setFloat", rather than the array one.