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<SdfVolume, CnResult>
fn from_baked(bytes: &[u8]) -> Result<SdfVolume, 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.Source§impl<'de> Deserialize<'de> for SdfVolume
impl<'de> Deserialize<'de> for SdfVolume
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SdfVolume, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SdfVolume, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<SdfVolume> for ComponentAsset
impl From<SdfVolume> for ComponentAsset
Source§fn from(c: SdfVolume) -> ComponentAsset
fn from(c: SdfVolume) -> ComponentAsset
impl RuntimeComponent for SdfVolume
Source§impl Serialize for SdfVolume
impl Serialize for SdfVolume
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for SdfVolume
impl RefUnwindSafe for SdfVolume
impl Send for SdfVolume
impl Sync for SdfVolume
impl Unpin for SdfVolume
impl UnsafeUnpin for SdfVolume
impl UnwindSafe for SdfVolume
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().