use bevy_asset::{Asset, Handle};1use bevy_color::{Color, LinearRgba};2use bevy_image::Image;3use bevy_material::AlphaMode;4use bevy_math::Affine2;5use bevy_mesh::UvChannel;6use bevy_reflect::TypePath;7use wgpu_types::Face;89/// Data to build a Gltf Material10///11/// See [`StandardMaterial`](https://docs.rs/bevy/latest/bevy/pbr/struct.StandardMaterial.html) for details12#[derive(Asset, Debug, Clone, TypePath)]13pub struct GltfMaterial {14/// The color of the surface of the material before lighting.15pub base_color: Color,1617/// The UV channel to use for the [`GltfMaterial::base_color_texture`].18pub base_color_channel: UvChannel,1920/// The texture component of the material's color before lighting.21pub base_color_texture: Option<Handle<Image>>,2223/// Color the material "emits" to the camera.24pub emissive: LinearRgba,2526/// The UV channel to use for the [`GltfMaterial::emissive_texture`].27pub emissive_channel: UvChannel,2829/// The emissive map, multiplies pixels with [`GltfMaterial::emissive`]30/// to get the final "emitting" color of a surface.31pub emissive_texture: Option<Handle<Image>>,3233/// Linear perceptual roughness.34pub perceptual_roughness: f32,3536/// How "metallic" the material appears, within `[0.0, 1.0]`.37pub metallic: f32,3839/// The UV channel to use for the [`GltfMaterial::metallic_roughness_texture`].40pub metallic_roughness_channel: UvChannel,4142/// Metallic and roughness maps, stored as a single texture.43pub metallic_roughness_texture: Option<Handle<Image>>,4445/// Specular intensity for non-metals on a linear scale of `[0.0, 1.0]`.46pub reflectance: f32,4748/// The UV channel to use for the [`GltfMaterial::specular_texture`].49#[cfg(feature = "pbr_specular_textures")]50pub specular_channel: UvChannel,5152/// A map that specifies reflectance for non-metallic materials.53#[cfg(feature = "pbr_specular_textures")]54pub specular_texture: Option<Handle<Image>>,5556/// A color with which to modulate the [`GltfMaterial::reflectance`] for57/// non-metals.58pub specular_tint: Color,5960/// The UV channel to use for the61/// [`GltfMaterial::specular_tint_texture`].62#[cfg(feature = "pbr_specular_textures")]63pub specular_tint_channel: UvChannel,6465/// A map that specifies color adjustment to be applied to the specular66/// reflection for non-metallic materials.67#[cfg(feature = "pbr_specular_textures")]68pub specular_tint_texture: Option<Handle<Image>>,6970/// The amount of light transmitted _specularly_ through the material (i.e. via refraction).71pub specular_transmission: f32,7273/// The UV channel to use for the [`GltfMaterial::specular_transmission_texture`].74#[cfg(feature = "pbr_transmission_textures")]75pub specular_transmission_channel: UvChannel,7677/// A map that modulates specular transmission via its red channel. Multiplied by [`GltfMaterial::specular_transmission`]78/// to obtain the final result.79#[cfg(feature = "pbr_transmission_textures")]80pub specular_transmission_texture: Option<Handle<Image>>,8182/// Thickness of the volume beneath the material surface.83pub thickness: f32,84#[cfg(feature = "pbr_transmission_textures")]8586/// The UV channel to use for the [`GltfMaterial::thickness_texture`].87pub thickness_channel: UvChannel,8889/// A map that modulates thickness via its green channel. Multiplied by [`GltfMaterial::thickness`]90/// to obtain the final result.91#[cfg(feature = "pbr_transmission_textures")]92pub thickness_texture: Option<Handle<Image>>,9394/// The [index of refraction](https://en.wikipedia.org/wiki/Refractive_index) of the material.95pub ior: f32,9697/// How far, on average, light travels through the volume beneath the material's98/// surface before being absorbed.99pub attenuation_distance: f32,100101/// The resulting (non-absorbed) color after white light travels through the attenuation distance.102pub attenuation_color: Color,103104/// The UV channel to use for the [`GltfMaterial::normal_map_texture`].105pub normal_map_channel: UvChannel,106107/// Used to fake the lighting of bumps and dents on a material.108pub normal_map_texture: Option<Handle<Image>>,109110/// The UV channel to use for the [`GltfMaterial::occlusion_texture`].111pub occlusion_channel: UvChannel,112113/// Specifies the level of exposure to ambient light.114pub occlusion_texture: Option<Handle<Image>>,115116/// An extra thin translucent layer on top of the main PBR layer. This is117/// typically used for painted surfaces.118pub clearcoat: f32,119120/// The roughness of the clearcoat material. This is specified in exactly121/// the same way as the [`GltfMaterial::perceptual_roughness`].122pub clearcoat_perceptual_roughness: f32,123124/// The UV channel to use for the [`GltfMaterial::clearcoat_texture`].125#[cfg(feature = "pbr_multi_layer_material_textures")]126pub clearcoat_channel: UvChannel,127128/// An image texture that specifies the strength of the clearcoat layer in129/// the red channel. Values sampled from this texture are multiplied by the130/// main [`GltfMaterial::clearcoat`] factor.131#[cfg(feature = "pbr_multi_layer_material_textures")]132pub clearcoat_texture: Option<Handle<Image>>,133134/// The UV channel to use for the [`GltfMaterial::clearcoat_roughness_texture`].135#[cfg(feature = "pbr_multi_layer_material_textures")]136pub clearcoat_roughness_channel: UvChannel,137138/// An image texture that specifies the roughness of the clearcoat level in139/// the green channel. Values from this texture are multiplied by the main140/// [`GltfMaterial::clearcoat_perceptual_roughness`] factor.141#[cfg(feature = "pbr_multi_layer_material_textures")]142pub clearcoat_roughness_texture: Option<Handle<Image>>,143144/// The UV channel to use for the [`GltfMaterial::clearcoat_normal_texture`].145#[cfg(feature = "pbr_multi_layer_material_textures")]146pub clearcoat_normal_channel: UvChannel,147148/// An image texture that specifies a normal map that is to be applied to149/// the clearcoat layer. This can be used to simulate, for example,150/// scratches on an outer layer of varnish. Normal maps are in the same151/// format as [`GltfMaterial::normal_map_texture`].152#[cfg(feature = "pbr_multi_layer_material_textures")]153pub clearcoat_normal_texture: Option<Handle<Image>>,154155/// Increases the roughness along a specific direction, so that the specular156/// highlight will be stretched instead of being a circular lobe.157pub anisotropy_strength: f32,158159/// The direction of increased roughness, in radians relative to the mesh160/// tangent.161pub anisotropy_rotation: f32,162163/// The UV channel to use for the [`GltfMaterial::anisotropy_texture`].164#[cfg(feature = "pbr_anisotropy_texture")]165pub anisotropy_channel: UvChannel,166167/// An image texture that allows the168/// [`GltfMaterial::anisotropy_strength`] and169/// [`GltfMaterial::anisotropy_rotation`] to vary across the mesh.170#[cfg(feature = "pbr_anisotropy_texture")]171pub anisotropy_texture: Option<Handle<Image>>,172173/// Support two-sided lighting by automatically flipping the normals for "back" faces174/// within the PBR lighting shader.175pub double_sided: bool,176177/// Support two-sided lighting by automatically flipping the normals for "back" faces178/// within the PBR lighting shader.179pub cull_mode: Option<Face>,180181/// Whether to apply only the base color to this material.182pub unlit: bool,183184/// How to apply the alpha channel of the `base_color_texture`.185pub alpha_mode: AlphaMode,186187/// The transform applied to the UVs corresponding to `ATTRIBUTE_UV_0` on the mesh before sampling. Default is identity.188pub uv_transform: Affine2,189}190191impl Default for GltfMaterial {192fn default() -> Self {193GltfMaterial {194// White because it gets multiplied with texture values if someone uses195// a texture.196base_color: Color::WHITE,197base_color_channel: UvChannel::Uv0,198base_color_texture: None,199emissive: LinearRgba::BLACK,200emissive_channel: UvChannel::Uv0,201emissive_texture: None,202// Matches Blender's default roughness.203perceptual_roughness: 0.5,204// Metallic should generally be set to 0.0 or 1.0.205metallic: 0.0,206metallic_roughness_channel: UvChannel::Uv0,207metallic_roughness_texture: None,208// Minimum real-world reflectance is 2%, most materials between 2-5%209// Expressed in a linear scale and equivalent to 4% reflectance see210// <https://google.github.io/filament/Material%20Properties.pdf>211reflectance: 0.5,212specular_transmission: 0.0,213#[cfg(feature = "pbr_transmission_textures")]214specular_transmission_channel: UvChannel::Uv0,215#[cfg(feature = "pbr_transmission_textures")]216specular_transmission_texture: None,217thickness: 0.0,218#[cfg(feature = "pbr_transmission_textures")]219thickness_channel: UvChannel::Uv0,220#[cfg(feature = "pbr_transmission_textures")]221thickness_texture: None,222ior: 1.5,223attenuation_color: Color::WHITE,224attenuation_distance: f32::INFINITY,225occlusion_channel: UvChannel::Uv0,226occlusion_texture: None,227normal_map_channel: UvChannel::Uv0,228normal_map_texture: None,229#[cfg(feature = "pbr_specular_textures")]230specular_channel: UvChannel::Uv0,231#[cfg(feature = "pbr_specular_textures")]232specular_texture: None,233specular_tint: Color::WHITE,234#[cfg(feature = "pbr_specular_textures")]235specular_tint_channel: UvChannel::Uv0,236#[cfg(feature = "pbr_specular_textures")]237specular_tint_texture: None,238clearcoat: 0.0,239clearcoat_perceptual_roughness: 0.5,240#[cfg(feature = "pbr_multi_layer_material_textures")]241clearcoat_channel: UvChannel::Uv0,242#[cfg(feature = "pbr_multi_layer_material_textures")]243clearcoat_texture: None,244#[cfg(feature = "pbr_multi_layer_material_textures")]245clearcoat_roughness_channel: UvChannel::Uv0,246#[cfg(feature = "pbr_multi_layer_material_textures")]247clearcoat_roughness_texture: None,248#[cfg(feature = "pbr_multi_layer_material_textures")]249clearcoat_normal_channel: UvChannel::Uv0,250#[cfg(feature = "pbr_multi_layer_material_textures")]251clearcoat_normal_texture: None,252anisotropy_strength: 0.0,253anisotropy_rotation: 0.0,254#[cfg(feature = "pbr_anisotropy_texture")]255anisotropy_channel: UvChannel::Uv0,256#[cfg(feature = "pbr_anisotropy_texture")]257anisotropy_texture: None,258double_sided: false,259cull_mode: Some(Face::Back),260unlit: false,261alpha_mode: AlphaMode::Opaque,262uv_transform: Affine2::IDENTITY,263}264}265}266267268