I have some problems understanding the z-Buffer and how to interpolate the values between vertices correctly in respect to perspective.
What I have done so far is take a vertex in World Space (x, y,z) and transform it using my ViewProjection Matrix to get coordinates in clip-space of the form (x, y, z, w). These coordinates still need to be divided by w.
What do I have to use here z or w? And how do I interpolate it?
What I would do is:
- normalize (x,y,z,w) => (x/w, y/w, z/w, 1)
- linearly interpolate z/w
Would that be correct?
Do I have to divide by 1/w at the end? IF no, why not?