• FEATURED

View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

WHAAAATT!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

#1lomateron  Members

Posted 16 March 2012 - 11:41 PM

While creating and evolving my program and knowledge, i came to get stuck again by the common brain errors of my self, writing something without sense for a machine. So I have to go again and starte to resolve my error by trying to spot that place where my brain failed in the code, or my code failed in the brain... . Maybe 2 complete days passed trying to find that spot-that error, passing again and again throug all my code, doing another complete simpler program solely to spot the problem, and finally spotting it i came to this very rare simple thing. In a vertex shader method, this:
PS VS( VS input )
{
PS output = (PS)0;
output.Pos = input.Pos; //----> position=float4(5.0f,5.0f,5.0f,5.0f) or whatever value
output.Tex = input.Tex;
return output;
}

is completely different form this

PS VS( VS input )
{
PS output = (PS)0;
output.Pos = float4(5.0f,5.0f,5.0f,5.0f); //----> or whatever value
output.Tex = input.Tex;
return output;
}

the first method works, the second nop, WTFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF!!!!!!!!!!!!!!!!!!!!!!!!!

#2Postie  Members

Posted 17 March 2012 - 01:07 AM

The w-coordinate of the position is used to indicate if the position should be treated as a position or a vector and should be either 1 or 0 respectively.

Your position value is incorrect. It most likely should be float4(5.0f, 5.0f, 5.0f, 1.0f)
Currently working on an open world survival RPG - For info check out my Development blog:

#3lomateron  Members

Posted 17 March 2012 - 01:53 AM

oops with the 1.0f in the w coordinate worked, but WTF were could i find that info?

#4Postie  Members

Posted 17 March 2012 - 03:32 AM

I think it has to do with the fact that to represent a point or vector in 3d space, you need 3 coordinates, and to transform those coordinates using rotations, etc you multiply it against an appropriate matrix. A 3x1 Vector multiplied by a 3x3 Matrix will give you another 3x1 vector, representing the transformed point.

The issue is that a 3x3 Matrix can represent rotation and scaling, but can't include translation. To do that we need to use a 4x4 matrix. But in order for that to work, our original 3x1 point needs to be expanded to 4x1, since you can't multiply a 3x1 vector by a 4x4 matrix. The new coordinate, w, controls if the translation part of the 4x4 matrix is added to the result, so under most circumstances you want it to have a value of 1.0. However, if you're transforming a vector instead of a point, you don't want the translation applied, since a vector is an offset from 0,0,0 and the translation will change the vector's direction and magnitude, so you can use the same transformation matrix as before, but set the w coordinate of the vector to be 0.

I think that ordinarily, Direct3D takes care of adding that w=1.0f term automatically when it expands from a float3 to a float4, so when you use input.Pos, the value would be correct.

I don't fully understand the thing myself, but my explanation makes sense to me. Doesn't mean it's correct though. Maybe someone more knowledgeable like MJP can chime in and correct me if I'm wrong?
Currently working on an open world survival RPG - For info check out my Development blog:

#5L. Spiro  Members

Posted 17 March 2012 - 07:35 AM

That is correct. The 0 W is meant to cancel out any translations a 4×X matrix would do on a 1×4 matrix (a vector) (or an X×4 and 4×1).
And when implicitly adding a 4th component to a vector it is set to 1. All other implicitly added components are set to 0.

L. Spiro

#6fastcall22  Moderators

Posted 17 March 2012 - 09:49 AM

You might be able to find more information on homogeneous coordinates at Wikipedia ...
zlib: eJzVVLsSAiEQ6/1qCwoK i7PxA/2S2zMOZljYB1TO ZG7OhUtiduH9egZQCJH9 KcJyo4Wq9t0/RXkKmjx+ cgU4FIMWHhKCU+o/Nx2R LEPgQWLtnfcErbiEl0u4 0UrMghhZewgYcptoEF42 YMj+Z1kg+bVvqxhyo17h nUf+h4b2W4bR4XO01TJ7 qFNzA7jjbxyL71Avh6Tv odnFk4hnxxAf4w6496Kd OgH7/RxC

#7lomateron  Members

Posted 17 March 2012 - 10:36 AM

mmm ok, i knew that, someway i ignored it when i was learning it(on tutorials), that is one of the simplest things we start learning in directx.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.