|
Essentially what the title says. When writing CG programs, the Unity docs say to create the texcoords in a structure as a
when most of the time I just use the xy components. EDIT: I just looked at the CG documentation page, and it looks like it stores texcoords as a float2 in every example that I looked at.
(comments are locked)
|
|
Graphics cards use float4's to store and manipulate everything. They literally don't have simple variables in their chips or have simple math circuits. You ask one to add 4+7, it gets confused, then prints, "oh, you mean (4,0,0,0) plus (7,0,0,0)!!." For UV's the 3rd is the 3rd dimension (if you have 64 textures, all 64x64, you can think of the 3rd as picking/blending which textures to use.) The 4th is the scale factor (backwards: 2 is one half size.) They are always (0,1.) But, the lookup command is generally I personally use float2s for UVs, but a float2 is really a float4 with the last two slots taped over, and saves 0 time over using a float4. Most likely someone just typed float4 way back and there was never a reason to change it. So, are all numerical data types created "implicitly" as 4 component vectors?
Mar 20 '11 at 02:46 AM
Peter G
If you look at the Terrain shader, the blend weights of the 1st four textures are packed into one
Mar 20 '11 at 03:12 AM
Owen Reynolds
What about, say, multiplications of two vectors? Is it really not faster to multiply a vec2 rather than a vec4?
Mar 20 '11 at 03:21 AM
Jessy
The GPU math circuits are made by welding four "normal" math units side-by-side. They take two float4's as input, and give a float4 as output. In a normal CPU, float2's don't really exist -- it adds them using two normal adds, one after another, so of course adding 4 is slower. Think of a car that seats 4.
Mar 20 '11 at 04:50 PM
Owen Reynolds
Thanks for the detailed explanation.
Mar 20 '11 at 06:26 PM
Peter G
(comments are locked)
|
|
After conducting a little more experimentation, Unity will let you create the texcoords as a float2.
Owenpat does a nice job explaining why the Unity docs recommends creating them as a
(comments are locked)
|
|
that's pretty cool Please, don't post comments as answers.
Jul 04 '11 at 01:36 PM
Paulius Liekis
(comments are locked)
|

I have no answer other than "for nothing", can you say where it forces a float 4? why can't you just use a float 2? I am sure there is a reason, else you would not have asked...
I was pretty sure they did this so you could use your 4x4 transformation matrices on them without a hassle. But that's just a theory.