Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a float3 / vec3 to a shader via unity properties

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?

like image 568
17th Dimension Avatar asked May 16 '16 07:05

17th Dimension


People also ask

Does Unity use CG or HLSL?

In Unity, you write shader programs using the HLSL programming language.

What is Shaderlab Unity?

Shaderlab files are collections of fixed function settings, vertex, fragment and surface shaders which tell Unity how to render meshes. They allow you to fully specify how an object will be rendered on different types of hardware.

What is a fragment shader Unity?

Fragment Shader is a shader program to modify image properties in the render window. It is executed for each pixel and the output is the color info of the pixel. The directive #pragma fragment defines the name of the function of the fragment shader. float4 vert(float4 v:POSITION) : SV_POSITION.

What is Transform_tex?

TRANSFORM_TEX(texture coordinate/uvs, Texture variable) is used to transform texture by uvs and scale/bias property of Texture Map.


1 Answers

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

like image 113
Iggy Avatar answered Oct 23 '22 04:10

Iggy