probeDepthConflicts method
Finds the surfaces that flicker against each other (z-fighting) in
camera's view, and reports them by node.
Renders an object-id image of the view several times, changing the
depth mapping by amounts too small to move anything on screen, nudging
surfaces two depth steps toward or away from the camera, and reversing
the draw order, and reports each pair of nodes whose pixels change
hands: what camera motion does to surfaces closer together than the
depth buffer can tell apart. It uses this scene's depth settings, so
Material.depthLayer, reversedDepth, fitNearPlane, and
coplanarTieBreak all count and a reported pair still flickers. A
single screenshot cannot show this, since a fight can resolve one way in
any one frame. Every image is drawn from one snapshot of the scene, so
motion while the probe waits for the GPU does not count. Alpha-masked
materials cover only what they show. Blended surfaces, which never hide
what is behind them, and a .fmat whose own Surface() cuts it are
listed in DepthConflictReport.untested instead.
Call it after the scene has rendered at least one frame. It renders
offscreen at width by height (the view's aspect ratio is width over
height) and waits for the GPU, so it takes a few frames' time; it is a
verification tool, not something to run every frame. camera defaults
to the camera of the last view drawn on screen, then the scene's
primary camera.
Implementation
Future<depth_conflicts.DepthConflictReport> probeDepthConflicts({
Camera? camera,
int width = 960,
int height = 540,
int layerMask = kRenderLayerAll,
int minPixels = 4,
}) async {
await initializeStaticResources();
renderScene.rebuildIfDirty();
final view = RenderView(
camera: camera ?? _probeCamera ?? PerspectiveCamera(),
layerMask: layerMask,
);
final size = ui.Size(width.toDouble(), height.toDouble());
final bound = ViewportBoundCamera(
view.camera,
size,
raster: _depthRasterFor(view, size, -1),
);
return depth_conflicts.probeDepthConflicts(
renderScene: renderScene,
camera: bound,
width: width,
height: height,
transients: uniformTransients,
layerMask: layerMask,
minPixels: minPixels,
);
}