backends.wgsl.codegen.compile_scene_to_wgsl

backends.wgsl.codegen.compile_scene_to_wgsl(
    geometry,
    example_point=None,
    *,
    uniforms=False,
    culling=True,
    scope='free',
)

Compile an SDF and its material evaluation to one WGSL module.

The returned source has three stable point-query functions:

  • sdf(p) -> f32
  • material_base(p) -> vec4<f32> containing RGB and roughness
  • material_optics(p) -> vec4<f32> containing metallic, opacity, IOR, and reflectivity

All functions are built from the same functionalized geometry snapshot, so CSG material selection and transformed material coordinates match the distance field. Generated helper functions are namespaced per entry point, making the returned source safe to embed as one WGSL module.

Design parameters are inlined as float literals by default, which is what the frontend consumes today: the whole module changes when any value does. Pass uniforms=True for the form that reads them out of a uniform buffer instead — see :func:compile_scene_with_uniforms, whose :class:ShaderProgram this then returns in place of the source string.

Parameters

Name Type Description Default
geometry Root CADJOINT SDF node with optional per-primitive materials. required
example_point jnp.ndarray | None Example input for shape inference. Defaults to zeros. None
uniforms bool Emit parameters as a uniform buffer rather than as literals, returning a :class:ShaderProgram instead of a string. False
culling bool Skip a boolean’s far-away operands with a real branch (see :mod:cadjoint.backends.wgsl._culling). The field is identical either way; off is the flat form the culled one is tested against. True
scope str Which parameters the uniform buffer holds when uniforms is set — "free" or "all". Ignored otherwise. See :func:compile_scene_with_uniforms for why the default is "free" and why "all" must not be shipped. 'free'

Returns

Name Type Description
str | ShaderProgram WGSL source containing the distance and two packed material functions, or a :class:ShaderProgram when uniforms is set.