drawObjects method

Texture drawObjects({
  1. NodeFilter filter = const NodeFilter.all(),
  2. Vector4? color,
  3. Vector4 colorOf(
    1. Object node
    )?,
  4. Vector4? clearColor,
})

Draws a filtered set of the scene's geometry flat into a returned mask texture, each object filled with a color (coverage in alpha), with its own cleared depth so the objects self-occlude but are not occluded by the rest of the scene (an x-ray silhouette). The building block for masks, outlines, and highlights; sample the result in applyShader.

filter selects which nodes draw. colorOf gives a per-node color (linear RGBA); when null every object uses color (default opaque white). The mask is view-sized and valid for the rest of the frame.

Implementation

gpu.Texture drawObjects({
  NodeFilter filter = const NodeFilter.all(),
  Vector4? color,
  Vector4 Function(Object node)? colorOf,
  Vector4? clearColor,
}) {
  final width = dimensions.width.toInt();
  final height = dimensions.height.toInt();
  final index = _drawCounter++;
  final mask = _context.texturePool.acquire(
    TransientTextureDescriptor.color(
      width: width,
      height: height,
      format: _destination.format,
      debugName: 'custom_mask_${_passKey}_$index',
    ),
  );
  final depth = _context.texturePool.acquire(
    TransientTextureDescriptor.depth(
      width: width,
      height: height,
      format: gpu.gpuContext.defaultDepthStencilFormat,
      debugName: 'custom_mask_depth_${_passKey}_$index',
    ),
  );
  final fill = color ?? Vector4(1, 1, 1, 1);
  renderObjectMask(
    target: mask,
    depth: depth,
    clearColor: clearColor ?? Vector4.zero(),
    cameraTransform: camera.getViewTransform(dimensions),
    cameraPosition: camera.position,
    renderScene: _renderScene,
    transientsBuffer: _context.transientsBuffer,
    layerMask: _viewLayerMask,
    filter: filter,
    colorOf: colorOf == null
        ? (_) => fill
        : (item) {
            final node = item.sourceNode;
            return node == null ? fill : colorOf(node);
          },
  );
  return mask;
}