Does Unity shader support single parameter for float3?

sometimes i want to simplify vector initialize.
for example
o.Albedo = float3(1.0,1.0,1.0);
i want to write as
o.Albedo = float3(1.0);
because some shader tutorial like shadertoy,and hlsl.
they can just write like this.
and i grab some unity tutorial project from github,some of them write like this.
but i can’t compile them correctly.
I dont know if there is a platform issuse,I use windows 7 64 bit with unity4.6 and 5.1
none can init with single parameter for float3.

so i just want to ask,does unity support default single parameter for float3?

Just write it correctly such as = float3(1.0, 1.0, 1.0);

Writing it incorrectly might work (I’m pretty sure just o.Albedo = 1; would work for example), but, depending on the platform, you will get casting errors eventually.

Just write it properly as hippo said.

yeah,i know write with 3 parameter will work,i just want to know why single parameter not work.
It all comes from this project.

https://github.com/candycat1992/Shadertoy_Lab

This Unity example just write this way.

Why i cant compile it correctly?

Since i always write with 3 parameter.Until now i find someone can write as single.

Make me wondering how can they do that.

Try to contact the author,not replying though.

And by the way,the shader I’m looking at is ‘WaterColorBackground.shader’

And the author use
#define vec2 float2
#define vec3 float3
make it work like shadertoy style.

You’re being difficult. Unity doesn’t support shorthand like that. Simply convert your shaders.

o.Albedo = float3(1.0) is not a valid syntax, but o.Albedo = 1.0 is, because a float can be implicitly cast into any vector type.
Or if you want to be explicit about it, o.Albedo = (1.0).xxx

1 Like