Skip to main content

Module implicit

Module implicit 

Source
Expand description

CPU sphere-marching of implicit surfaces (signed-distance functions). CPU sphere-marching of implicit surfaces (signed-distance functions).

[march_implicit_surface] and [march_implicit_surface_colour] accept a user-supplied SDF closure, fire rays from the camera for each pixel, and produce a [crate::renderer::types::ScreenImageItem] with per-pixel NDC depth suitable for depth-compositing against scene geometry via Phase 12.

§Usage

let opts = ImplicitRenderOptions {
    width: 320,
    height: 240,
    ..Default::default()
};
// Sphere of radius 1.5:
let img = march_implicit_surface(&camera, &opts, |p| p.length() - 1.5);
fd.scene.screen_images.push(img);

For coloured surfaces supply a closure returning (sdf_value, [r, g, b, a]):

let img = march_implicit_surface_colour(&camera, &opts, |p| {
    let d = p.length() - 1.5;
    let colour = [200u8, 100, 50, 255];
    (d, colour)
});

The returned item has depth: Some(depths) and anchor: TopLeft with scale: 1.0. Adjust scale on the returned item if you rendered at a reduced resolution (e.g. scale = 2.0 for half-resolution rendering that still covers the full viewport).

Structs§

ImplicitRenderOptions
Configuration for sphere-marching an implicit surface.

Functions§

march_implicit_surface
Sphere-march a signed-distance function and produce a depth-composited ScreenImageItem.
march_implicit_surface_colour
Sphere-march a coloured signed-distance function and produce a depth-composited ScreenImageItem.