06 Space, camera and depth
The depth buffer: who hides whom
The box and the sphere intersect; the two panels behind are almost touching.
-40
Exercise
Drag the underlined numbers left and rightDrag numbers, or edit the code
camera.near = ;camera.far = 100;material.depthTest = ;// normal colours// the two panels are only 0.004 apart
Depth testA new fragment is written only if its depth is less than the buffer’s; otherwise it is dropped.JS side
The depth buffer keeps a “nearest distance” per pixel. A tiny near plane wastes precision, so distant faces flicker against each other (z-fighting).
Try it
- Turn the depth test off: whatever is drawn last ends up in front
- Set near to 0.0001 and watch the two back panels flicker
- Switch to the depth buffer view