Category: 2D Overlay
Syntax:
b2dDrawQuadDepth:Void(x1:Int, y1:Int, z1:Double, x2:Int, y2:Int, z2:Double, x3:Int, y3:Int, z3:Double, x4:Int, y4:Int, z4:Double, fill:Int)
Void
Draws a four-cornered polygon where each corner carries its own depth, interpolated
across the face per pixel.
It is b2dDrawQuad in every other respect: the same two triangles
fanned from point 1, the same absence of backface culling (either winding draws), the current
colour and alpha, and the clip rect all behave identically. Only the depth differs — a
quad drawn this way is a genuine depth plane rather than a flat card at one distance.
Returns nothing.
Why it exists. b2dSetDepth gives a whole quad one flat
depth, so two faces of the same solid that overlap on screen cannot be told apart by the depth
buffer — a spinning object shows its own inside through itself. Backface culling hides
that for simple convex shapes, but interpenetrating or steeply tilted faces still come out in
the wrong order. A depth per corner resolves them pixel by pixel, so faces can be drawn in any
order with no sorting and no culling.
The one rule: the depths must be perspective-correct. They are interpolated
linearly across the screen, but a real 3D face's depth is not linear in screen space
— it is projective, of the form a + b/z. Pass raw view-space z and a flat
face's depth creases along the diagonal where the quad splits into two triangles, giving a
visible kink where faces meet. Map view-z to depth like this and it stays flat:
dep = (FARZ * (z - NEARZ)) / (z * (FARZ - NEARZ))
That is the caller's job, not the runtime's — the runtime faithfully interpolates
whatever it is given, so "the depth looks wrong" is usually non-projective input rather than a
fault in the drawing.
Depths outside 0..1 are clamped. Images and text are never depth-tested. Render targets carry
no depth buffer, so primitives drawn into one are not depth-tested; neither is anything drawn
while a screen shader is applied.
View detailed documentation online
; one face of a 3D model, with each corner's own perspective-correct depth dA = (FARZ * (tzA - NEARZ)) / (tzA * (FARZ - NEARZ)) dB = (FARZ * (tzB - NEARZ)) / (tzB * (FARZ - NEARZ)) dC = (FARZ * (tzC - NEARZ)) / (tzC * (FARZ - NEARZ)) dD = (FARZ * (tzD - NEARZ)) / (tzD * (FARZ - NEARZ)) b2dSetColor(r * lit, g * lit, b * lit) b2dDrawQuadDepth(sxA,syA,dA, sxB,syB,dB, sxC,syC,dC, sxD,syD,dD, 1)
BambooBasic © 2026 Michael Denathorn