Skip to main content

Material

Struct Material 

Source
pub struct Material {
    pub base_color_factor: [f32; 4],
    pub metallic_factor: f32,
    pub roughness_factor: f32,
    pub emissive_factor: [f32; 3],
    pub alpha_mode: AlphaMode,
    pub alpha_cutoff: f32,
    /* private fields */
}
Expand description

Common glTF material data with an optional MToon extension.

Fields§

§base_color_factor: [f32; 4]

Linear RGBA multiplier for the base color.

§metallic_factor: f32

Metallic multiplier used by the glTF PBR model.

§roughness_factor: f32

Roughness multiplier used by the glTF PBR model.

§emissive_factor: [f32; 3]

Linear RGB emissive color before the HDR strength multiplier.

§alpha_mode: AlphaMode

Alpha composition mode used by the material.

§alpha_cutoff: f32

Alpha-test threshold used when Self::alpha_mode is AlphaMode::Mask.

Implementations§

Source§

impl Material

Source

pub fn new() -> Self

Creates a glTF metallic-roughness material with specification defaults.

Source

pub const fn with_base_color_factor(self, factor: [f32; 4]) -> Self

Sets the base-color factor shared by the supported shading models.

Source

pub const fn with_metallic_factor(self, factor: f32) -> Self

Sets the metallic factor of the core glTF material model.

Source

pub const fn with_roughness_factor(self, factor: f32) -> Self

Sets the roughness factor of the core glTF material model.

Source

pub const fn with_emissive_factor(self, factor: [f32; 3]) -> Self

Sets the emissive color before applying Self::emissive_strength.

Source

pub const fn with_base_color_texture(self, texture: TextureInfo) -> Self

Sets the base-color texture.

Source

pub const fn with_metallic_roughness_texture(self, texture: TextureInfo) -> Self

Sets the texture whose green and blue channels provide roughness and metalness.

Source

pub const fn with_normal_texture(self, texture: NormalTextureInfo) -> Self

Sets the tangent-space normal map.

Source

pub const fn with_occlusion_texture(self, texture: OcclusionTextureInfo) -> Self

Sets the red-channel occlusion map.

Source

pub const fn with_emissive_texture(self, texture: TextureInfo) -> Self

Sets the emissive texture.

Source

pub const fn with_unlit(self, unlit: bool) -> Self

Enables or disables the KHR_materials_unlit shading model.

Source

pub const fn with_emissive_strength(self, strength: f32) -> Self

Sets the KHR_materials_emissive_strength multiplier.

Source

pub const fn with_alpha_mode(self, alpha_mode: AlphaMode) -> Self

Sets the alpha composition mode.

Source

pub const fn with_alpha_cutoff(self, alpha_cutoff: f32) -> Self

Sets the cutoff used by AlphaMode::Mask.

Source

pub const fn with_double_sided(self, double_sided: bool) -> Self

Enables or disables rendering both sides of each triangle.

Source

pub fn with_mtoon(self, mtoon: MToonMaterial) -> Self

Adds an MToon model, which takes precedence over Unlit and PBR rendering.

Source

pub fn base_color_texture(&self) -> Option<&TextureInfo>

Returns the base-color texture used by every supported material model.

Source

pub fn metallic_roughness_texture(&self) -> Option<&TextureInfo>

Returns the texture whose green and blue channels contain roughness and metalness.

Source

pub fn normal_texture(&self) -> Option<&NormalTextureInfo>

Returns the tangent-space normal map and its scale.

Source

pub fn occlusion_texture(&self) -> Option<&OcclusionTextureInfo>

Returns the red-channel occlusion map and its strength.

Source

pub fn emissive_texture(&self) -> Option<&TextureInfo>

Returns the emissive texture.

Source

pub fn unlit(&self) -> bool

Returns whether KHR_materials_unlit was declared.

This remains true when MToon is also present. Use Self::shading_model when selecting a renderer because MToon takes precedence over Unlit.

Source

pub fn emissive_strength(&self) -> f32

Returns the selected emissive multiplier, defaulting to one.

KHR_materials_emissive_strength takes precedence over the archived VRM multiplier when both extensions are present.

Source

pub fn emissive_strength_source(&self) -> EmissiveStrengthSource

Returns the extension that supplied Self::emissive_strength.

Source

pub fn legacy_emissive_multiplier(&self) -> Option<f32>

Returns the archived VRM emissive multiplier when it was declared.

The value is retained even when the modern KHR extension overrides it so callers can emit a deprecation or precedence diagnostic.

Source

pub fn effective_emissive_factor(&self) -> [f32; 3]

Returns emissive_factor after applying the selected HDR multiplier.

Source

pub fn shading_model(&self) -> MaterialShadingModel

Returns the material model that takes precedence for rendering.

Source

pub fn double_sided(&self) -> bool

Reports whether back-face culling must be disabled.

Source

pub fn mtoon(&self) -> Option<&MToonMaterial>

Returns the MToon extension parameters, if present.

Trait Implementations§

Source§

impl Clone for Material

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 Debug for Material

Source§

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

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

impl Default for Material

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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