Page 1 of 1

HLSL: What represents the 4th component in a float4/vector?

Posted: Sat Jan 31, 2009 12:26 pm
by OnyxIdol
Ok, the internet didn't turn anything up on this, maybe its just too obvious. What, exactly, represents the 4th component in a float4/vector variable?

I am currently writing a shader, using Nvidia FxComposer(Great tool btw) and setting the 4th component of my global variables to zero produces some strange effects, such as stretching an object to infinity in case of a position vector. Setting it to 1 seems straightforward enough, yet I'd like to know what I'm dealing with.

Posted: Sat Jan 31, 2009 12:32 pm
by Mel
Normally, in position vectors it is always 1. In fact float4() is a flexible object, and thus, the 4th component can be used in many ways. for example, in colors, the 4th component is the alpha channel. So, if you want to use position vectors, just stick to the 3 first, and ignore the 4th. It will work well in any case :)

Posted: Sat Jan 31, 2009 12:40 pm
by OnyxIdol
Thx for the answer. But As I said, setting the 4th component in a position Vector creates really strange effects, i.e. it must have some meaning in a position vector as well.

Posted: Sat Jan 31, 2009 12:47 pm
by BlindSide
It has to do with perspective projection. It's called the W component. Read up on that.

Posted: Sat Jan 31, 2009 12:50 pm
by OnyxIdol
I will do that. Thank You.

Edit:
This thread can now be considered closed.

Re: HLSL: What represents the 4th component in a float4/vect

Posted: Sat Jan 31, 2009 5:51 pm
by Acki
OnyxIdol wrote:some strange effects, such as stretching an object to infinity in case of a position vector. Setting it to 1 seems straightforward enough
I'm just guessing, but this sounds to me that in your case the 4th number could be a scale factor !?!?! :o