Depth-Evaluation in Screen Space
Combining Circle In-Out Test and Depth Evaluation
Kenny Hoff
6/17/97
We have the following problem, given a center and radius of a circle
in screen space (pixel coordinates) and an associated depth range from
the closest sphere point to the circle center's depth, we must find the
pixels that are inside the circle while evaluating their depths. This is
slightly different than our previous techniques because this operation
is done entirely in screen space where the XY-plane is the pixel coordinate
plane and the Z-axis is the fixed-point 32-bit Z-value that was scaled
from the range [0,1] where 0 is the closest and 1 is the farthest.
Since we know we are approximating the front-half of the sphere with
a paraboloid, we know that are effective depth range covered by the circle
must be the depth range from the closest point on the sphere (the minimum
point in the paraboloid) to the depth of the sphere's center; we will call
these depth values MinZ and MaxZ respectively.
In screen space, given the CircleCenter (a,b,MaxZ), a pixel radius r,
and a minimum and maximum depth range [MinZ,MaxZ], we must solve for a
paraboloid equation that has the following properties:
-
Oriented symmetrically about an axis parallel to the Z-axis through the
XY-point (a,b)
-
Minimum point is (a,b,MinZ)
-
Passes through the following points in the XY-plane through Z=MaxZ: (a+r,b,MaxZ),
(a-r,b,MaxZ), (a,b+r,MaxZ), (a,b-r,MaxZ)
-
Extends to infinity in the positive Z direction
Given such an equation, we will have a function for depth given a pixel
location (x,y); we will call it Depth(x,y). This will effectively combine
depth evaluation and the circle in-out test by comparing the result to
the MaxZ. If Depth(x,y) is greater than MaxZ, then the pixel is outside
the circle and should be disabled. The pixel is also disabled if the result
is not less-than the value already stored in the Zbuffer at pixel (x,y).
So we can find the paraboloid equation by using the same technique as
described previously to obtain the following equations:
A=(MaxZ-MinZ)/r2
B=0
C=MinZ
XZ-plane: f(x) = z = A*(x-a)2 + B*(x-a) + C
= ((MaxZ-MinZ)/r2)*(x-a)2 + MinZ
YZ-plane: f(y) = z = A*(y-b)2 + B*(y-b) + C
= ((MaxZ-MinZ)/r2)*(y-b)2 + MinZ
Paraboloid: f(x,y) = z = f(x) + (f(y)-MinZ)
= ((MaxZ-MinZ)/r2)*((x-a)2 + (y-b)2) + MinZ