(I've re-written this post like 3 times, sorry for the update confusion... Now it should make sense.)
Every DirectX coordinate is a homogeneous coordinate to allow stuff like translation and perspective transforms, and allow transformations matrices that "stack" by multiplying them even with translation & perspective inside them.
Before the perspective transform, the "w" component is obligatorily 1. So for example, this allows the 3 first components of the 4th row of the 4x4 world matrix to represent translation in 3D space. This probably sounds confusing, but the "Translation" part of
this page explains it better.
Following the perspective transform (or after multiplying by the Projection matrix), the Z component holds the INVERSE distance to the camera, between 0 and 1. An object at near-plane distance has a Z of 1, and at far-plane distance has a Z of 0.
The W component then has the original Z distance, before perspective transformation, so the actual distance to the eye in world units.
In short, Z = 1 - (W - NearPlane) / FarPlane
After leaving the vertex shader, D3D does another transformation before writing to the depth buffer, which does not really matter to you unless you want to change the distribution of depth values to a W-Buffer manually. Kind of off-topic...
My sources...
http://www.mvps.org/directx/articles/linear_z/linearz.htmhttp://en.wikipedia.org/wiki/Homogeneous_coordinatesProof : I made a little test app with 10 planes that go from z=1 to z=11, where the near plane is 1 and far plane 11. That causes the first and tenth planes to be clipped.
Then I made a simple shader that takes the depth of every vertex and send it to the pixel shader, which then writes it into the blue channel. Either with 1-Z, or (W-Near)/Far, I get linear distribution of blue color values from 10% to 90% by steps of 10%.
