Skip to main content

NormalEncoding

Enum NormalEncoding 

Source
pub enum NormalEncoding {
    Xyz,
    XyzUnorm,
    Xy,
    XyUnorm,
    XyzBiased {
        bias_bits: u32,
    },
    Octahedral {
        stored: LaneAffine,
        read: LaneAffine,
    },
    OctahedralDiamond,
    CubeFace {
        minor: LaneAffine,
        payload: LaneAffine,
    },
}
Expand description

How a normal is stored in the lanes of an output.

Variants§

§

Xyz

x, y, z as signed values.

§

XyzUnorm

x, y, z mapped to 0-1 (n * 0.5 + 0.5).

§

Xy

x and y signed, z from the unit length.

§

XyUnorm

x and y mapped to 0-1, z from the unit length.

§

XyzBiased

x, y, z stored as n * 0.5 + bias (the bias given by its f32 bits): decoded (v - bias) * 2.

Fields

§bias_bits: u32

The bias, as the bits of an f32.

§

Octahedral

Octahedral mapping in lanes 0 and 1: each stored as e * stored.scale + stored.bias (the producer’s scale and bias, as measured) and read back by the engine as v * read.scale + read.bias before the unfold (z = 1 - |x| - |y|, x and y folded where z < 0, normalised). The two halves are stated as each side measures them and need not be exact inverses: an engine may store 0.4995 e + 0.4995 and read 2 v - 1. The common 0-1 layout is stored LaneAffine::UNORM and read LaneAffine::SIGNED.

Fields

§stored: LaneAffine

The map from the unfolded coordinate to the stored value.

§read: LaneAffine

The map from the stored value to the coordinate the unfold takes.

§

OctahedralDiamond

Octahedral in the diamond layout over three 8-bit UNORM lanes: lanes 0 and 1 are the low eight bits of two 9-bit coordinates u and v (round(255 (c + 1)), 0 to 510 over -1 to 1), lane 2’s bit 1 and bit 2 their ninth bits and its bit 0 the sign of z; the lane’s other five bits are not part of the normal (a payload byte, which an engine may keep a class in). x = (u + v) / 2, y = (u - v) / 2, |z| = 1 - |x| - |y|, normalised (NormalEncoding::decode_octahedral_diamond).

§

CubeFace

The normal by its major axis, over four lanes. The face is D3D’s cube-map face of the axis whose component is largest in magnitude (2 * axis + 1 where that component is negative: +x 0, -x 1, +y 2, -y 3, +z 4, -z 5), and lanes 0 and 1 are that face’s sc and tc components of the normal, not divided by the major component (+x (-z, -y), -x (z, -y), +y (x, z), -y (x, -z), +z (x, -y), -z (-x, -y)), each stored as e * minor.scale + minor.bias. Lane 2 is the major component’s sign by its side of one half (below for a positive face, above for a negative one) and a payload p in 0 to 1 by its distance from one half, p * payload.scale + payload.bias; the payload is not part of the normal (a value an engine keeps beside it). Lane 3 is the axis over three (x 0, y 1/3, z 2/3). The major component’s magnitude is the unit length’s remainder (NormalEncoding::decode_cube_face).

Fields

§minor: LaneAffine

The map applied to the sc and tc components for lanes 0 and 1.

§payload: LaneAffine

The map applied to the payload value in lane 2.

Implementations§

Source§

impl NormalEncoding

Source

pub fn decode_cube_face( minor: LaneAffine, payload: LaneAffine, lanes: [f32; 4], steps: [f32; 4], ) -> Result<([f64; 3], f32), String>

The unit normal and the payload of four lanes stored as NormalEncoding::CubeFace with minor and payload; steps is each lane’s quantisation step in the target’s format (1/1023 for a 10-bit UNORM lane, 1/3 for a 2-bit one). Lane 3 is read as the nearest of 0, 1/3 and 2/3, and lane 2’s side of one half as the major component’s sign; a lane 3 not within half its step of one of them, or a lane 2 within one of its steps of one half, cannot be placed and is refused.

Source

pub fn encode_cube_face( minor: LaneAffine, payload: LaneAffine, normal: [f32; 3], p: f32, ) -> [f32; 4]

The four lanes NormalEncoding::CubeFace with minor and payload stores the unit normal normal and the payload p (0 to 1) as, unquantised. The major axis is z where its magnitude is at least x’s and y’s, else y where it is at least x’s, else x (on an edge between faces either face decodes to the normal).

Source

pub fn decode_octahedral_diamond(lanes: [f32; 3]) -> ([f64; 3], u8)

The normal and the payload byte of three UNORM lanes stored as NormalEncoding::OctahedralDiamond: each lane is taken as the 8-bit value it rounds to.

Source

pub fn encode_octahedral_diamond(normal: [f64; 3], payload: u8) -> [u8; 3]

The three 8-bit lanes NormalEncoding::OctahedralDiamond stores a normal and a payload byte (below 32) as; a z of 0 stores as positive. A vector that is not zero is normalised by the encoding itself.

Trait Implementations§

Source§

impl Clone for NormalEncoding

Source§

fn clone(&self) -> Self

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 Copy for NormalEncoding

Source§

impl Debug for NormalEncoding

Source§

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

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

impl Eq for NormalEncoding

Source§

impl Hash for NormalEncoding

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for NormalEncoding

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for NormalEncoding

Source§

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

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for NormalEncoding

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, !>

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.