pub struct SdfVolume {Show 13 fields
pub asset_id: AssetId,
pub centre: [f32; 3],
pub extent: [f32; 3],
pub fragment_shader: String,
pub max_gradient: f32,
pub max_steps: u32,
pub max_distance: f32,
pub params: [f32; 32],
pub cast_shadows: bool,
pub receive_shadows: bool,
pub volumetric: bool,
pub visible: bool,
pub locator: Option<PayloadLocator>,
}Expand description
A raymarched signed-distance-field volume. It occupies a world-space bounding box; a user-authored fragment shader sphere-traces an SDF inside the box, composites correctly with the surrounding scene through the depth buffer, and shades hits with the engine’s lighting helpers.
The distance field is one .slang file for every backend. The build
compiles it, so a field that does not compile fails cn build rather than
the renderer, and a shipped player needs no shader compiler of its own.
SdfVolume {
centre: [0.0, 2.0, -4.0],
extent: [2.0, 2.0, 2.0],
max_gradient: 1.0,
max_steps: 64,
max_distance: 12.0,
..Default::default()
};Fields§
§asset_id: AssetIdAsset identity; injected via inject_name. Not part of args.
centre: [f32; 3]World-space centre of the bounding box.
extent: [f32; 3]XYZ half-widths of the bounding box. The raymarch is clipped to the box, so the SDF only has to be well-defined inside this region.
fragment_shader: StringDistance-field source path (e.g. "shaders/chrome_blob.slang"),
resolved relative to the project’s assets/ at build time. The file
defines map and shade, or sampleVolume for a volumetric volume.
max_gradient: f32Worst-case gradient of the SDF, used to size the cone-march step. 1.0
is correct for any well-formed SDF; higher values shorten the step but
stay safe. Must be > 0.
max_steps: u32Maximum cone-march steps per pixel. Clamped to [8, 256].
max_distance: f32Maximum march distance in metres. Must be ≥ 0.1.
params: [f32; 32]Generic parameter block passed to the shader as a uniform buffer; the shader interprets it however it likes. Up to 32 values.
cast_shadows: boolWhen true, the volume casts shadows onto the surrounding scene. Disable for translucent / volumetric effects that shouldn’t block light.
receive_shadows: boolWhen true (the default), the volume is shadowed by the scene. Set to false for unlit / always-bright effects (energy fields, etc.).
volumetric: boolWhen true, the volume renders as a participating medium (clouds, smoke,
fog blobs, energy fields) instead of an opaque surface. The shader must
define sampleVolume(p, params, time) returning per-point density,
scattering colour, and emission instead of map / shade. Volumetrics
never cast shadows (cast_shadows is forced off). The medium fills the
whole bounding box, so don’t overlap it with geometry it should render
behind.
visible: boolWhen false the volume is skipped each frame.
locator: Option<PayloadLocator>Injected at load time from the blob def. Carries the compiled distance field the build produced.
Implementations§
Trait Implementations§
Source§impl Component for SdfVolume
impl Component for SdfVolume
Source§const NAME: &'static str = "SdfVolume"
const NAME: &'static str = "SdfVolume"
Source§fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>
fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>
Source§fn inject_name(&mut self, id: AssetId)
fn inject_name(&mut self, id: AssetId)
Source§fn inject_locator(&mut self, locator: PayloadLocator)
fn inject_locator(&mut self, locator: PayloadLocator)
Source§impl ComponentSlot for SdfVolume
impl ComponentSlot for SdfVolume
Source§const DISCRIMINANT: u8
const DISCRIMINANT: u8
ComponentId.