Skybox, render order and clipping thoughts

Started by
10 comments, last by cozzie 11 years, 3 months ago
The short version of the 'w' trick is -- the GPU computes each pixels depth buffer value as 'zbuf = pos.z / pos.w'.
So, if you set "z = w", then you get 'zbuf = w/w' or 'zbuf = 1'.

To explain what 'pos.w' is, is a bit harder. It's sometimes called the 'homogeneous coordinate' of the position.
To do our 3D perspective projections, it's easier to work in 4D space. In the vertex shader, we convert our euclidean position to a homogenous position by giving it a 4th (w) coordinate of 1. Our matrices then operate on these 4D values, producing a 4D position output. The GPU hardware automatically divides the position by its 'w' value per pixel, which is how we convert from homogenous coordinates back to euclidean coordinates.

All your other vertex-shader outputs (e.g. Texture coordinates) are also divided by 'pos.w' per pixel in order to achieve "perspective correct" interpolation. So, it's an important detail in 3D projection (and linear algebra) even if you don't understand it's meaning ;-)
Advertisement

Hi Hodgman,

Thanks, I think I understand, actually working my way through Getting started with DX9 book from Frank Luna :)

If I understand correct:

- if W = 0, we talk about the vector

- if W = 1, we talk about a point, 1 makes sure translations etc. will succeed

- Mapping back from X, Y, Z, W to X,Y,Z, is done by dividing X,Y and Z by W

Reflecting this, doing homegenous transformation on pos, would mean that pos.z / W = z / 1 = still Z?

And W/W = W (1).

Does this means that saying pos.z = pos.w, that for my skybox shader vertices, Z is always 1?

(and therefor is always rendered within Z visible, assuming minimum Z = 0.0 and max. is 1.0?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement