6

I am writing a shader and I would like to pass a vec3 along to the input. however everything I could find is always passing either a single float a vec4, texture or number range. Is it possible to send a vanilla vec3 along to a shader in unity?

Properties
{
    offset ("formula Offset", Vector) = (0, 0, 0)
}

Doesn't seem to work as I hoped. To get it to compile I have been doing this:

Properties
{
    offset ("formula Offset", Vector) = (0, 0, 0, 0)
}

// offset.xyz //Extract relevant data from vector

this just doesn't feel right. Is there a better way?

17th Dimension
  • 73
  • 1
  • 2
  • 4

1 Answers1

5

Looks like when you mark a property as Vector it has to have 4 components. Even the documentation says: "Vector properties are displayed as four number fields."

This really isn't as bad as it looks, just set the last components to zero.


Note that annoyingly the matching variable is NOT "vector", it's "float4".

Full list:

https://stackoverflow.com/a/37749687/294884

Fattie
  • 27,874
  • 70
  • 431
  • 719
Iggy
  • 4,767
  • 5
  • 23
  • 34
  • I found a bonus that makes it look a little better when I declare it as a uniform in the shader, I just put vec3 and it ignores the extra value I've also found the Shader.setGlobal method contains both matrixes and Vector3 – 17th Dimension May 16 '16 at 16:15