Skip to main content

SdfVolume

Struct SdfVolume 

Source
pub struct SdfVolume {
Show 14 fields pub asset_id: AssetId, pub centre: [f32; 3], pub extent: [f32; 3], pub fragment_shader: String, pub fragment_shaders: Option<BTreeMap<String, 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 fragment shader is selected per backend: a fragment_shaders map keyed by "metal" / "hlsl" / "glsl" lets one volume target multiple backends, and the build only requires the entry for the backend it is building for. A single fragment_shader path is the fallback when no map entry matches.

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: AssetId

Asset 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: String

Single-platform fragment shader source path (e.g. "shaders/chrome_blob.metal"), resolved relative to the project’s assets/ at build time. Used when fragment_shaders has no entry for the building backend; the file extension must match the backend (.metal / .hlsl). The file defines the SDF’s map and shade functions.

§fragment_shaders: Option<BTreeMap<String, String>>

Per-backend fragment shader source paths keyed by "metal", "hlsl", or "glsl". Takes priority over fragment_shader, letting one volume target multiple backends from a single declaration.

§max_gradient: f32

Worst-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: u32

Maximum cone-march steps per pixel. Clamped to [8, 256].

§max_distance: f32

Maximum 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: bool

When true, the volume casts shadows onto the surrounding scene. Disable for translucent / volumetric effects that shouldn’t block light.

§receive_shadows: bool

When true (the default), the volume is shadowed by the scene. Set to false for unlit / always-bright effects (energy fields, etc.).

§volumetric: bool

When 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: bool

When false the volume is skipped each frame.

§locator: Option<PayloadLocator>

Injected at load time from the blob def. Carries the user shader source bytes packed at build time.

Implementations§

Source§

impl SdfVolume

Source

pub fn cone_ratio(&self) -> f32

Effective cone-march step ratio derived from the Lipschitz constant. A 1-Lipschitz SDF (gradient ≤ 1) cone-marches at ratio 1; larger gradients shorten the step proportionally.

Trait Implementations§

Source§

impl Clone for SdfVolume

Source§

fn clone(&self) -> SdfVolume

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for SdfVolume

Source§

const NAME: &'static str = "SdfVolume"

The registry name a world authors this component under.
Source§

fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>

Reconstruct this component from a blob record, whose bytes are the serialized runtime component (cook already ran the asset -> component translation). The default rejects: runtime-only components are never stored in a blob, so only loadable types provide an implementation.
Source§

fn inject_name(&mut self, id: AssetId)

Called after construction to inject the asset’s identity from the blob def. Only meaningful for components that look themselves up by id at runtime. The default implementation does nothing.
Source§

fn inject_locator(&mut self, locator: PayloadLocator)

Called after construction to inject the payload locator from the blob def. Only meaningful for components with a compiled payload. The default implementation does nothing (correct for most components).
Source§

impl ComponentSlot for SdfVolume

Source§

const DISCRIMINANT: u8

The component type’s stable id, used as its ComponentId.
Source§

fn slot(s: &ComponentStorage) -> &Column<Self>

Borrow this type’s column out of the storage.
Source§

fn slot_mut(s: &mut ComponentStorage) -> &mut Column<Self>

Mutably borrow this type’s column out of the storage.
Source§

impl Debug for SdfVolume

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for SdfVolume

Source§

fn default() -> SdfVolume

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SdfVolume

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<SdfVolume, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<SdfVolume> for ComponentAsset

Source§

fn from(c: SdfVolume) -> Self

Converts to this type from the input type.
Source§

impl RuntimeComponent for SdfVolume

Source§

impl Serialize for SdfVolume

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.