Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


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

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

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

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

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

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

#6 fastcall22   Crossbones+   -  Reputation: 5061

Like
0Likes
Like

Posted 17 March 2012 - 09:49 AM

You might be able to find more information on homogeneous coordinates at Wikipedia ...
QWxsIHRvYXN0LXRvYXN0aW5nIHRvYXN0ZXJzIGNhbiB0b2FzdCB0b2FzdGVkIHRvYXN0LCBhbHRob3Vn aCByZS10b2FzdGluZyB0b2FzdGVkIHRvYXN0IGlzIGdlbmVyYWxseSBub3QgcmVjb21tZW5kZWQgYnkg dGhlIG1hbnVmYWN0dXJlcnMgb2YgdG9hc3QtdG9hc3RpbmcgdG9hc3RlcnMuLi4=

#7 lomateron   Members   -  Reputation: 385

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