Hi Everybody,

I’m looking for a mean to get the z coordinate of each pixel (of a triangle per exemple) after rasterization.

But I can’t apply basic math tool such as calculate the plan equation of my triangle (I don’t exactly remember why , i guess that my teacher told me that the normalize operation change it, it change my affine space to another).

So he advised me to use Barycentric coordinates but I can’t because I only have complete edges coordinates of my triangle and just x,y coordinates to each point of it.

I searched on opengl specification 1.5 but it doesn’t explained.

Somebody could help me ?

zuraneur.

The vertices of a triangle define a linear (matrix) transformation N from [u,v,1] to [x,y,z,w]. Concatenating this with the model-view matrix V and projection matrix P gives you the conversion to clip coordinates as a 4x3 matrix M=P.V.N.

Homogeneous division yields normalised device coordinates. Finally, the viewport transformation yields window coordinates.

To reverse the process, start by converting window coordinates to normalised device coordinates.

At this point, you’ll effectively have

```
nx = (m00.u + m01.v + m02) / (m30.u + m31.v + m32)
ny = (m10.u + m11.v + m12) / (m30.u + m31.v + m32)
nz = (m20.u + m21.v + m22) / (m30.u + m31.v + m32)
```

where [nx,ny,nz] are the normalised device coordinates and the m[i,j] are the coefficients of the matrix M above.

Given nx and ny, the first two equations can be solved for u and v. These can then be substituted into the third equation for normalised z or into any of the other equations for object-space, eye-space or clip-space coordinates.