Passing a float3 / vec3 to a shader via unity properties

14,680

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

Share:
14,680
17th Dimension
Author by

17th Dimension

Updated on June 21, 2022

Comments

  • 17th Dimension
    17th Dimension almost 2 years

    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
    17th Dimension almost 8 years
    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