pub struct ReliefData { /* private fields */ }Expand description
The relief a mesh slot reads: 8-bit RGBA holding a normal and, where
the constructor declares one, a depth per texel in place of color, row by
row from the top left.
A relief holds no sampler of its own; it is sampled the way its slot’s color texture is.
Implementations§
Source§impl ReliefData
impl ReliefData
Sourcepub fn rgba8(size: UVec2, pixels: Vec<u8>) -> Self
pub fn rgba8(size: UVec2, pixels: Vec<u8>) -> Self
A size-sized relief over pixels, 4 bytes per pixel: a normal in
RGB and a depth in A.
The length must match size; checked only in debug builds.
Sourcepub fn normals(size: UVec2, pixels: Vec<u8>) -> Self
pub fn normals(size: UVec2, pixels: Vec<u8>) -> Self
The same over pixels holding normals alone, whose alpha byte no
draw reads.
Required if you want a relief that lights a surface without moving
its texels off the plane; a .glb normal texture is read as one.
Examples found in repository?
examples/material-playground.rs (line 354)
339fn relief_bumps() -> ReliefData {
340 let size = MAP_SIZE;
341 let turns = core::f32::consts::TAU * BUMP_WAVES;
342 let mut pixels = Vec::with_capacity((size.x * size.y * 4) as usize);
343 for y in 0..size.y {
344 for x in 0..size.x {
345 let u = (x as f32 + 0.5) / size.x as f32;
346 let v = (y as f32 + 0.5) / size.y as f32;
347 let slope_u = BUMP_SLOPE * (turns * u).cos() * (turns * v).sin();
348 let slope_v = BUMP_SLOPE * (turns * u).sin() * (turns * v).cos();
349 let normal = Vec3::new(-slope_u, -slope_v, 1.0).normalize();
350 let encode = |signed: f32| ((signed * 0.5 + 0.5) * 255.0).round() as u8;
351 pixels.extend_from_slice(&[encode(normal.x), encode(normal.y), encode(normal.z), 0]);
352 }
353 }
354 ReliefData::normals(size, pixels)
355}Trait Implementations§
Source§impl Clone for ReliefData
impl Clone for ReliefData
Source§fn clone(&self) -> ReliefData
fn clone(&self) -> ReliefData
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ReliefData
impl Debug for ReliefData
Source§impl Default for ReliefData
impl Default for ReliefData
Source§fn default() -> ReliefData
fn default() -> ReliefData
Returns the “default value” for a type. Read more
Source§impl PartialEq for ReliefData
impl PartialEq for ReliefData
impl StructuralPartialEq for ReliefData
Auto Trait Implementations§
impl Freeze for ReliefData
impl RefUnwindSafe for ReliefData
impl Send for ReliefData
impl Sync for ReliefData
impl Unpin for ReliefData
impl UnsafeUnpin for ReliefData
impl UnwindSafe for ReliefData
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
Mutably borrows from an owned value. Read more
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,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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> ⓘ
Converts
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> ⓘ
Converts
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 more