Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Texture on a 3d Object
  Posted by: ToastbrotX
  When: 10/09/2010 at 10:23:08

 Unable to Build
  Posted by: Rich_Zap
  When: 09/09/2010 at 15:39:33

 HLSL calculating normals
  Posted by: Rich_Zap
  When: 09/09/2010 at 15:34:56

 Texture on a 3d Object
  Posted by: ToastbrotX
  When: 09/09/2010 at 11:14:19

 DRIVER ERROR XBOX 360
  Posted by: Anonymous
  When: 09/09/2010 at 01:12:47

 Reflection problem in corners ...
  Posted by: Anonymous
  When: 08/09/2010 at 21:03:35

 Texture on a 3d Object
  Posted by: radulph
  When: 08/09/2010 at 17:34:01

 InvalidDataException???
  Posted by: Anonymous
  When: 08/09/2010 at 09:10:36

 Unable to Build
  Posted by: Anonymous
  When: 08/09/2010 at 07:49:36

 Suggestion to change a few lines
  Posted by: Insomnica
  When: 06/09/2010 at 14:37:05

 Collision with series 1
  Posted by: radulph
  When: 05/09/2010 at 13:33:14

 HLSL calculating normals
  Posted by: miroslavign
  When: 04/09/2010 at 17:26:26

 Collision with series 1
  Posted by: ToastbrotX
  When: 04/09/2010 at 16:52:02

 HLSL calculating normals
  Posted by: Rich_Zap
  When: 04/09/2010 at 15:00:20

 Collision with series 1
  Posted by: ToastbrotX
  When: 04/09/2010 at 12:28:41

 HLSL calculating normals
  Posted by: miroslavign
  When: 04/09/2010 at 08:46:31

 Walk along a wall
  Posted by: Anonymous
  When: 03/09/2010 at 10:28:02

 model problems
  Posted by: muffinman
  When: 03/09/2010 at 06:47:32

 Vertices problem
  Posted by: Anonymous
  When: 03/09/2010 at 05:48:35

 OcTree Question
  Posted by: Zorzomezz
  When: 03/09/2010 at 04:07:03




Topic: Projecting and the z coordinate



  
Goto parent category
  
Create a new user account


   Projecting and the z coordinate
 Poster : Jack
 Posts: 9
 Country : Poland
 City: Lodz

  
Posted by Jack on 08/05/2007 at 10:55:54
I always thought about a projection as a sort of flattening of a 3d image to 2d. So we have  x,y,z and after projecting we obtain x`,y`.  Now I have a look at your code and see something like that:


SMapPixelToFrame ShadowMapPixelShader(SMapVertexToPixel PSIn)
{
    SMapPixelToFrame Output = (SMapPixelToFrame)0;

    Output.Color = PSIn.Position2D.z/xMaxDepth;

    return Output;
}

Position2D is the position which we obtain after tranforming the 3d position by a lightWorldViewProjection matrix. So how is it possible we still have a z coordinate and one that is alive and kicking?

Shouldn't we have a 2d image with 2d coordinates an that's it?

By the way fantastic job!
Thanks for the tremendous work.

I'll just assume for now that somehow this projecting keeps the real z coordinates, apparently it works in your shaders.
 Poster : m_Maky
 Posts: 67
 Country : france
 City: Nice

  
Posted by m_Maky on 08/05/2007 at 12:11:52
Well you also need to know the depth when projecting, so that's why that coordinate is alive
 Poster : Jack
 Posts: 9
 Country : Poland
 City: Lodz

  
Posted by Jack on 08/05/2007 at 13:06:25
Yeah but you don't understand it's not as if I have a choice a projection matrix does what it does, it's math.

So i am a bit surprised to see that xna does this and has the z -coordinate after transformation. How is that? It's against my logic. Tell me if you draw a 3d cube on a piece of paper what are the z coords?

They are all zero because it's flat. That's what I think projection does, could someone explain how it is in xna?
 Poster : riemer
 Posts: 1388
 Country : Belgium
 City: Antwerp

  
Posted by riemer on 08/05/2007 at 15:49:41
Indeed, you could say when going to 2D, you don't need the 3rd coordinate anymore. This would be true in case you would be drawing an image in Paint or Photoshop.
But here, to construct the 2D image, XNA needs to keep track of the distance between each object and the camera (the near clipping plane, actually). This value is stored in the depth buffer, so XNA knows for each pixel in the 2D image at what distance the object is. So when XNA is asked to draw another object on a certain pixel, XNA checks if the new object is in front of the old object. The new object is drawn only if the new object is in front of the old one.

So that's how you should think of this 3rd coordinate: it's the value of the depth buffer.
 Poster : Jack
 Posts: 9
 Country : Poland
 City: Lodz

  
Posted by Jack on 08/05/2007 at 16:07:44
It's the z buffer value?

Thanks i get it now. This depth value is just in a buffer. I was just surprised by the code
Position2D.z :) it still is odd but clear :)
 Poster : m_Maky
 Posts: 67
 Country : france
 City: Nice

  
Posted by m_Maky on 09/05/2007 at 13:50:26
it's not EXACTLY the z-buffer value, as this needs to be mapped between 1 and 0. It's more like the distance between camera and object, and from this you can find the value for in the zbuffer

  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 3.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)