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.
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: LaneAffineThe map from the unfolded coordinate to the stored value.
read: LaneAffineThe 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: LaneAffineThe map applied to the sc and tc components for lanes 0 and 1.
payload: LaneAffineThe map applied to the payload value in lane 2.
Implementations§
Source§impl NormalEncoding
impl NormalEncoding
Sourcepub fn decode_cube_face(
minor: LaneAffine,
payload: LaneAffine,
lanes: [f32; 4],
steps: [f32; 4],
) -> Result<([f64; 3], f32), String>
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.
Sourcepub fn encode_cube_face(
minor: LaneAffine,
payload: LaneAffine,
normal: [f32; 3],
p: f32,
) -> [f32; 4]
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).
Sourcepub fn decode_octahedral_diamond(lanes: [f32; 3]) -> ([f64; 3], u8)
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.
Sourcepub fn encode_octahedral_diamond(normal: [f64; 3], payload: u8) -> [u8; 3]
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
impl Clone for NormalEncoding
impl Copy for NormalEncoding
Source§impl Debug for NormalEncoding
impl Debug for NormalEncoding
impl Eq for NormalEncoding
Source§impl Hash for NormalEncoding
impl Hash for NormalEncoding
Source§impl PartialEq for NormalEncoding
impl PartialEq for NormalEncoding
Source§impl Serialize for NormalEncoding
impl Serialize for NormalEncoding
impl StructuralPartialEq for NormalEncoding
Auto Trait Implementations§
impl Forget for NormalEncoding
impl Freeze for NormalEncoding
impl RefUnwindSafe for NormalEncoding
impl Send for NormalEncoding
impl Sync for NormalEncoding
impl Unpin for NormalEncoding
impl UnsafeUnpin for NormalEncoding
impl UnwindSafe for NormalEncoding
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.