- Home /

# Difference between pos.z and pos.w?

I'd like some clarification on what's stored in the builtin float4's at different stages.

What value does the .w parameter of a vertex Position hold in the stages prior to the Projection stage? Is it 1? (is it at all useful in the vertex program of a unity CG shader?)

From theory I know that if you want to do a perspective divide on your view frustum in your clip / projection stage, you need to divide the current position by the inverse of its distance from camera. Which in (viewspace and) clipspace should be 1/ the .z component (and same as 1/ depth), no?

But in opengl books and articles I see it's always divided by .w, not by .z.

Is .w actually == 1/.z and is it only there for homogenous space coordinates reasons (and also to save you having to do an extra 1/ division?)? I'm asking because you have to turn .z into 1/.z (and then back) anyway in order to keep it linear during interpolation (and OpenGL does that automatically between vert and frag), so I'm a bit confused.

As well I see in unity's shader variables that `_ProjectionParams.w == 1/FarPlane`

and `ProjectionParams.z == FarPlane`

.

Does `ProjectionParams`

contain the camera's near and far clip plane positions in worldspace if you access it in the vert program, vs it being in normalized device coordinates in frag?

### People who like this

3D points are stored as 4D vectors so that homogeneous transforms can be used. The 4-vector (x,y,z,1) represents the point (x,y,z).

Points are passed into the vertex shaders as (x,y,z,1), which is then multiplied at some point by the perspective projection matrix:

The resulting point then goes through the perspective divide, and so on.

ProjectionParams is just a structure that allows you to obtain certain properties about the current view. Think of it as four separate variables that are stored together instead of a point in 3D space.

### Your answer

### Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.