AnsweredAssumed Answered

How depth is interpolated in rasterizer?(linear depth instead of 1/z)

Question asked by ckotinko1 on Dec 14, 2012
Latest reply on Dec 21, 2012 by nuclear.bro



I'm trying to implement linear depth to z-buffer mapping in my minecraft-like game. However, there is one big problem: I want to use early depth tests(conservative depth to be precise). As far as I know, these tests are implemented in fixed function hardware, and I cannot control the value used for early depth test. Instead, I can only hack-hack-hack clip coordinates produced by my vertex/geometry shader to emulate perspective projection. So, my question is: how exactly the hardware calculates and interpolates values(especially depth) for each pixel(gl_FragCoord.z)?


For example, texture coordinates: s/z, r/z, t/z are interpolated, and are divided by interpolated(1/z) for each pixel to obtain smoothly interpolated s,r,t. Question is: what is '1/z'? is it interpolated(gl_Position.z/gl_Position.w produced by vertex shader) or interpolated(1/gl_Position.w) or or interpolated(1/gl_Position.z)?

What kind of interpolation is used to obtain fragment depth used for early depth tests?