Jump to content

  • Log In with Google      Sign In   
  • Create Account


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.

  • You cannot reply to this topic
6 replies to this topic

#1 lomateron   Members   -  Reputation: 302

Like
0Likes
Like

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!!!!!!!!!!!!!!!!!!!!!!!!!

Sponsor:

#2 Postie   Members   -  Reputation: 882

Like
1Likes
Like

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: ByteWrangler

#3 lomateron   Members   -  Reputation: 302

Like
0Likes
Like

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?

#4 Postie   Members   -  Reputation: 882

Like
1Likes
Like

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: ByteWrangler

#5 L. Spiro   Crossbones+   -  Reputation: 12671

Like
0Likes
Like

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
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#6 fastcall22   Crossbones+   -  Reputation: 4108

Like
0Likes
Like

Posted 17 March 2012 - 09:49 AM

You might be able to find more information on homogeneous coordinates at Wikipedia ...
c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=

#7 lomateron   Members   -  Reputation: 302

Like
0Likes
Like

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.



PARTNERS