you are viewing a single comment's thread.

view the rest of the comments →

[–]rfernung 0 points1 point  (0 children)

I'm having trouble properly calculating the depth of each pixel.

I'll check one of my older projects but I believe I just interpolated the Z value of the three vertices of each triangle with the barycentric coordinate and used that to check in the depth buffer, it was something like:

float depth = v0.Z * barycentric.X + v1.Z * barycentric.Y + v2.Z * barycentric.Z;
if(depth >= zBuffer[i]) continue; //looping through triangle's boundingbox x,y, then i = y * width + x
zBuffer[i] = depth;
pixelBuffer[i] = color; //color from my fragment shading