Skip to main content

PbrMaterial

Struct PbrMaterial 

Source
pub struct PbrMaterial {
Show 16 fields pub base_color: [f32; 4], pub base_color_texture: Option<TextureRef>, pub metallic: f32, pub roughness: f32, pub metallic_roughness_texture: Option<TextureRef>, pub occlusion_texture: Option<TextureRef>, pub occlusion_strength: f32, pub normal_texture: Option<TextureRef>, pub normal_scale: f32, pub emissive: [f32; 3], pub emissive_texture: Option<TextureRef>, pub emissive_strength: f32, pub alpha_mode: AlphaMode, pub double_sided: bool, pub specular: Option<Specular>, pub shading: Shading,
}
Expand description

A baked metal-rough material (component pbr.material).

Fields§

§base_color: [f32; 4]

Linear RGBA multiplied into base_color_texture: RGB finite and >= 0, past 1 where the source’s colour is (an HDR colour a shader multiplies as it is, as Unity’s _BaseColor may be); alpha within 0-1 (verified). A consumer that cannot hold a channel past 1 refuses it or says so by name, never clamping it silently.

§base_color_texture: Option<TextureRef>

sRGB colour, alpha in A.

§metallic: f32

0-1, multiplied into the texture’s B channel.

§roughness: f32

0-1, multiplied into the texture’s G channel.

§metallic_roughness_texture: Option<TextureRef>

Linear: G roughness, B metallic (R may hold occlusion: point occlusion_texture at the same entity).

§occlusion_texture: Option<TextureRef>

Linear: R ambient occlusion.

§occlusion_strength: f32

0-1: how much of the occlusion applies.

§normal_texture: Option<TextureRef>

Tangent-space normal map in glTF’s convention (OpenGL green up, Z stored); a pass converts others first.

§normal_scale: f32

Scales the normal map’s X and Y; finite.

§emissive: [f32; 3]

Linear RGB, each channel within 0-1 (verified), multiplied into emissive_texture.

§emissive_texture: Option<TextureRef>

sRGB colour.

§emissive_strength: f32

Multiplies the emission (KHR_materials_emissive_strength): finite, >= 0, 1 by default. Emission brighter than 1 keeps emissive within 0-1 (normalised by its largest channel) and carries the rest here, so a source’s radiance is kept rather than clamped.

§alpha_mode: AlphaMode§double_sided: bool

Back faces drawn too (and lit with the flipped normal).

§specular: Option<Specular>

The source’s specular reflectance; None: it says nothing (glTF’s default, the extension not written).

§shading: Shading

Lit or not. Whether what it draws casts shadows is the drawing entity’s (crate::Shadows), not the material’s.

Implementations§

Source§

impl PbrMaterial

Source

pub fn slots(&self) -> impl Iterator<Item = (TextureSlot, TextureRef)>

Every texture slot that is set, with its slot, in glTF’s order: base colour, metallic-roughness, normal, occlusion, emissive, then the specular extension’s strength and colour.

Source

pub fn slots_mut( &mut self, ) -> impl Iterator<Item = (TextureSlot, &mut TextureRef)>

PbrMaterial::slots, each mutably.

Source

pub fn textures(&self) -> impl Iterator<Item = TextureRef>

Every texture slot that is set (PbrMaterial::slots without the slots).

Source

pub fn textures_mut(&mut self) -> impl Iterator<Item = &mut TextureRef>

Every texture slot that is set, mutably (PbrMaterial::slots_mut without the slots).

Trait Implementations§

Source§

impl Clone for PbrMaterial

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 Component for PbrMaterial

Source§

const VERSION: u32 = 5

2: emissive_strength; 3: cast_shadows; 4: specular; 5: shading and each texture’s filters, cast_shadows gone (shadow casting is crate::Shadows’, per drawn entity).

Source§

fn verify(&self, _e: Entity, _w: &World) -> Result<(), String>

Every range its fields document: the colours, factors and strengths, the mask cutoff and each texture’s coordinate transform.

Source§

const NAME: &'static str = "pbr.material"

Source§

const GEOMETRY: Geometry = crate::Geometry::None

What the value holds of its entity’s mesh primitives and vertices (Geometry). Stated by every component, with no default, so data that describes a mesh can’t be left behind by an edit of it unawares: the World’s edit paths take it from there.
Source§

fn to_json(&self) -> Result<Option<Value>, JsonError>

The component as JSON, for glTF extras, the debug text form and golden tests; Ok(None) for components that are not shown (bulk data, handles). The view must never lose a value: components that can be shown derive serde::Serialize and return crate::json::to_value(self).map(Some), which refuses non-finite floats instead of writing them as null.
Source§

fn references(&self, out: &mut Vec<Entity>)

The entities this component refers to (a prototype, materials, textures), appended to out: the edges World::closure follows. A component holding entity references must declare every one of them.
Source§

fn payload_bytes(&self) -> u64

The bytes of bulk payload the value holds (vertex streams and indices, texture levels, triangle soups), for memory reports: element counts times element sizes, not allocated capacity. 0 for small components.
Source§

fn remap_primitives(&self, _from: &[usize]) -> Option<Result<Self, String>>

The component after its entity’s mesh primitives were rebuilt, for a component that holds something per primitive (Geometry::PerPrimitive, Geometry::PerVertex): new primitive i comes from old primitive from[i] (a source may repeat, when a primitive is split, or be absent, when one is dropped). Such a component always answers (a value holding nothing per primitive answers with itself); None, the default, is for components of Geometry::None, and World::remap_primitives refuses a dependent component that gives it. An index the component does not have is an error. remap_list does the work for a list with one entry per primitive.
Source§

fn remap_vertices( &self, _primitive: usize, _from: &[u32], ) -> Option<Result<Self, String>>

The component after the vertices of its entity’s mesh primitive primitive were compacted or reordered, for a component that holds something per vertex (Geometry::PerVertex): new vertex i of that primitive is old vertex from[i] (a source may repeat or be absent). Such a component always answers (with itself when it holds nothing for that primitive); None, the default, is for the others, and World::remap_vertices refuses a per-vertex component that gives it. An index the component does not have is an error. Every pass that compacts or reorders a primitive’s vertices calls World::remap_vertices. After a rebuild of the primitive list (World::rebuild_primitives, Component::remap_primitives) a primitive’s per-vertex data is its source primitive’s, and the vertex map is relative to that source.
Source§

fn blend_vertices( &self, _primitive: usize, _from: &[VertexBlend], ) -> Option<Result<Self, String>>

The component after the vertices of its entity’s mesh primitive primitive were rebuilt as blends of old ones (VertexBlend), for a component that holds something per vertex (Geometry::PerVertex): new vertex i is the combination from[i] of old vertices, in whatever way the component’s data combines (a morph target’s delta is interpolated, the way the surface it moves is). It answers as Component::remap_vertices does: with itself when it holds nothing for that primitive; None, the default, is for a component that does not know how to combine its data, and World::blend_vertices refuses a per-vertex component that gives it. An index the component does not have is an error. A vertex that is a copy of one old vertex (VertexBlend::copy) is the case Component::remap_vertices states, and a component answering one answers the other alike.
Source§

fn apply_linear(&self, _l: &Linear) -> Linearity<Self>

The component after its entity’s local space was mapped by l (a pass that bakes a placement’s mirror or shear into a copy of its geometry, so transforms stay rigid). World::apply_linear calls it for every component of the entity. The default is Linearity::Unsupported: a component that holds local-space geometry and does not say how it follows is never silently left behind; one without geometry says Linearity::Invariant.
Source§

fn restate(&self, _resolved: &Resolved<'_>) -> Restated<Self>

The component after resolve-state (crate::state::ResolveState) gave the axes in resolved their values: a component that holds crate::state::Clauses of its own (a record of parts each present in some states) reduces them as core.condition is reduced (crate::state::Resolved::reduce: a clause that fails is dropped, a clause left with no literal holds whatever the other axes are). Restated::Absent says the entity is not present in this state (every clause failed): it is despawned as one whose core.condition fails is. The default holds no clause: Restated::Unchanged.
Source§

impl Debug for PbrMaterial

Source§

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

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

impl Default for PbrMaterial

Source§

fn default() -> Self

glTF’s default material: white, fully metallic and rough, opaque, single-sided, lit.

Source§

impl PartialEq for PbrMaterial

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 PbrMaterial

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 PbrMaterial

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<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.