Jump to content
  • Advertisement
Sign in to follow this  
lomateron

WHAAAATT!

This topic is 2319 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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)

Share this post


Link to post
Share on other sites
Hidden
no man when i say it doesnt works is that the value doesnt pass. Is not because the way i am using the vaule, is the line that doesnt works. it doent matter what vaule i use in the w coordinate the line will not work. ANd it never says somewhere that there is an error, it jusnt doesnt works.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!