1use bevy_asset::{Asset, Handle};
2use bevy_color::{Color, LinearRgba};
3use bevy_image::Image;
4use bevy_material::AlphaMode;
5use bevy_math::Affine2;
6use bevy_mesh::UvChannel;
7use bevy_reflect::TypePath;
8use wgpu_types::Face;
910/// Data to build a Gltf Material
11///
12/// See [`StandardMaterial`](https://docs.rs/bevy/latest/bevy/pbr/struct.StandardMaterial.html) for details
13#[derive(impl bevy_asset::VisitAssetDependencies for GltfMaterial {
fn visit_dependencies(&self,
visit: &mut impl ::core::ops::FnMut(bevy_asset::UntypedAssetId)) {}
}Asset, #[automatically_derived]
impl ::core::fmt::Debug for GltfMaterial {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["base_color", "base_color_channel", "base_color_texture",
"emissive", "emissive_channel", "emissive_texture",
"perceptual_roughness", "metallic",
"metallic_roughness_channel", "metallic_roughness_texture",
"reflectance", "specular_channel", "specular_texture",
"specular_tint", "specular_tint_channel",
"specular_tint_texture", "specular_transmission",
"specular_transmission_channel",
"specular_transmission_texture", "thickness",
"thickness_channel", "thickness_texture", "ior",
"attenuation_distance", "attenuation_color",
"normal_map_channel", "normal_map_texture",
"occlusion_channel", "occlusion_texture", "clearcoat",
"clearcoat_perceptual_roughness", "clearcoat_channel",
"clearcoat_texture", "clearcoat_roughness_channel",
"clearcoat_roughness_texture", "clearcoat_normal_channel",
"clearcoat_normal_texture", "anisotropy_strength",
"anisotropy_rotation", "anisotropy_channel",
"anisotropy_texture", "double_sided", "cull_mode", "unlit",
"alpha_mode", "uv_transform"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.base_color, &self.base_color_channel,
&self.base_color_texture, &self.emissive,
&self.emissive_channel, &self.emissive_texture,
&self.perceptual_roughness, &self.metallic,
&self.metallic_roughness_channel,
&self.metallic_roughness_texture, &self.reflectance,
&self.specular_channel, &self.specular_texture,
&self.specular_tint, &self.specular_tint_channel,
&self.specular_tint_texture, &self.specular_transmission,
&self.specular_transmission_channel,
&self.specular_transmission_texture, &self.thickness,
&self.thickness_channel, &self.thickness_texture, &self.ior,
&self.attenuation_distance, &self.attenuation_color,
&self.normal_map_channel, &self.normal_map_texture,
&self.occlusion_channel, &self.occlusion_texture,
&self.clearcoat, &self.clearcoat_perceptual_roughness,
&self.clearcoat_channel, &self.clearcoat_texture,
&self.clearcoat_roughness_channel,
&self.clearcoat_roughness_texture,
&self.clearcoat_normal_channel,
&self.clearcoat_normal_texture, &self.anisotropy_strength,
&self.anisotropy_rotation, &self.anisotropy_channel,
&self.anisotropy_texture, &self.double_sided,
&self.cull_mode, &self.unlit, &self.alpha_mode,
&&self.uv_transform];
::core::fmt::Formatter::debug_struct_fields_finish(f, "GltfMaterial",
names, values)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for GltfMaterial {
#[inline]
fn clone(&self) -> GltfMaterial {
GltfMaterial {
base_color: ::core::clone::Clone::clone(&self.base_color),
base_color_channel: ::core::clone::Clone::clone(&self.base_color_channel),
base_color_texture: ::core::clone::Clone::clone(&self.base_color_texture),
emissive: ::core::clone::Clone::clone(&self.emissive),
emissive_channel: ::core::clone::Clone::clone(&self.emissive_channel),
emissive_texture: ::core::clone::Clone::clone(&self.emissive_texture),
perceptual_roughness: ::core::clone::Clone::clone(&self.perceptual_roughness),
metallic: ::core::clone::Clone::clone(&self.metallic),
metallic_roughness_channel: ::core::clone::Clone::clone(&self.metallic_roughness_channel),
metallic_roughness_texture: ::core::clone::Clone::clone(&self.metallic_roughness_texture),
reflectance: ::core::clone::Clone::clone(&self.reflectance),
specular_channel: ::core::clone::Clone::clone(&self.specular_channel),
specular_texture: ::core::clone::Clone::clone(&self.specular_texture),
specular_tint: ::core::clone::Clone::clone(&self.specular_tint),
specular_tint_channel: ::core::clone::Clone::clone(&self.specular_tint_channel),
specular_tint_texture: ::core::clone::Clone::clone(&self.specular_tint_texture),
specular_transmission: ::core::clone::Clone::clone(&self.specular_transmission),
specular_transmission_channel: ::core::clone::Clone::clone(&self.specular_transmission_channel),
specular_transmission_texture: ::core::clone::Clone::clone(&self.specular_transmission_texture),
thickness: ::core::clone::Clone::clone(&self.thickness),
thickness_channel: ::core::clone::Clone::clone(&self.thickness_channel),
thickness_texture: ::core::clone::Clone::clone(&self.thickness_texture),
ior: ::core::clone::Clone::clone(&self.ior),
attenuation_distance: ::core::clone::Clone::clone(&self.attenuation_distance),
attenuation_color: ::core::clone::Clone::clone(&self.attenuation_color),
normal_map_channel: ::core::clone::Clone::clone(&self.normal_map_channel),
normal_map_texture: ::core::clone::Clone::clone(&self.normal_map_texture),
occlusion_channel: ::core::clone::Clone::clone(&self.occlusion_channel),
occlusion_texture: ::core::clone::Clone::clone(&self.occlusion_texture),
clearcoat: ::core::clone::Clone::clone(&self.clearcoat),
clearcoat_perceptual_roughness: ::core::clone::Clone::clone(&self.clearcoat_perceptual_roughness),
clearcoat_channel: ::core::clone::Clone::clone(&self.clearcoat_channel),
clearcoat_texture: ::core::clone::Clone::clone(&self.clearcoat_texture),
clearcoat_roughness_channel: ::core::clone::Clone::clone(&self.clearcoat_roughness_channel),
clearcoat_roughness_texture: ::core::clone::Clone::clone(&self.clearcoat_roughness_texture),
clearcoat_normal_channel: ::core::clone::Clone::clone(&self.clearcoat_normal_channel),
clearcoat_normal_texture: ::core::clone::Clone::clone(&self.clearcoat_normal_texture),
anisotropy_strength: ::core::clone::Clone::clone(&self.anisotropy_strength),
anisotropy_rotation: ::core::clone::Clone::clone(&self.anisotropy_rotation),
anisotropy_channel: ::core::clone::Clone::clone(&self.anisotropy_channel),
anisotropy_texture: ::core::clone::Clone::clone(&self.anisotropy_texture),
double_sided: ::core::clone::Clone::clone(&self.double_sided),
cull_mode: ::core::clone::Clone::clone(&self.cull_mode),
unlit: ::core::clone::Clone::clone(&self.unlit),
alpha_mode: ::core::clone::Clone::clone(&self.alpha_mode),
uv_transform: ::core::clone::Clone::clone(&self.uv_transform),
}
}
}Clone, const _: () =
{
#[allow(deprecated, reason =
"derives on a deprecated type shouldn't be considered a usage")]
impl bevy_reflect::TypePath for GltfMaterial where {
fn type_path() -> &'static str {
"bevy_gltf::material::GltfMaterial"
}
fn short_type_path() -> &'static str { "GltfMaterial" }
fn type_ident() -> ::core::option::Option<&'static str> {
::core::option::Option::Some("GltfMaterial")
}
fn crate_name() -> ::core::option::Option<&'static str> {
::core::option::Option::Some("bevy_gltf::material".split(':').next().unwrap())
}
fn module_path() -> ::core::option::Option<&'static str> {
::core::option::Option::Some("bevy_gltf::material")
}
}
};TypePath)]
14pub struct GltfMaterial {
15/// The color of the surface of the material before lighting.
16pub base_color: Color,
1718/// The UV channel to use for the [`GltfMaterial::base_color_texture`].
19pub base_color_channel: UvChannel,
2021/// The texture component of the material's color before lighting.
22pub base_color_texture: Option<Handle<Image>>,
2324/// Color the material "emits" to the camera.
25pub emissive: LinearRgba,
2627/// The UV channel to use for the [`GltfMaterial::emissive_texture`].
28pub emissive_channel: UvChannel,
2930/// The emissive map, multiplies pixels with [`GltfMaterial::emissive`]
31 /// to get the final "emitting" color of a surface.
32pub emissive_texture: Option<Handle<Image>>,
3334/// Linear perceptual roughness.
35pub perceptual_roughness: f32,
3637/// How "metallic" the material appears, within `[0.0, 1.0]`.
38pub metallic: f32,
3940/// The UV channel to use for the [`GltfMaterial::metallic_roughness_texture`].
41pub metallic_roughness_channel: UvChannel,
4243/// Metallic and roughness maps, stored as a single texture.
44pub metallic_roughness_texture: Option<Handle<Image>>,
4546/// Specular intensity for non-metals on a linear scale of `[0.0, 1.0]`.
47pub reflectance: f32,
4849/// The UV channel to use for the [`GltfMaterial::specular_texture`].
50#[cfg(feature = "pbr_specular_textures")]
51pub specular_channel: UvChannel,
5253/// A map that specifies reflectance for non-metallic materials.
54#[cfg(feature = "pbr_specular_textures")]
55pub specular_texture: Option<Handle<Image>>,
5657/// A color with which to modulate the [`GltfMaterial::reflectance`] for
58 /// non-metals.
59pub specular_tint: Color,
6061/// The UV channel to use for the
62 /// [`GltfMaterial::specular_tint_texture`].
63#[cfg(feature = "pbr_specular_textures")]
64pub specular_tint_channel: UvChannel,
6566/// A map that specifies color adjustment to be applied to the specular
67 /// reflection for non-metallic materials.
68#[cfg(feature = "pbr_specular_textures")]
69pub specular_tint_texture: Option<Handle<Image>>,
7071/// The amount of light transmitted _specularly_ through the material (i.e. via refraction).
72pub specular_transmission: f32,
7374/// The UV channel to use for the [`GltfMaterial::specular_transmission_texture`].
75#[cfg(feature = "pbr_transmission_textures")]
76pub specular_transmission_channel: UvChannel,
7778/// A map that modulates specular transmission via its red channel. Multiplied by [`GltfMaterial::specular_transmission`]
79 /// to obtain the final result.
80#[cfg(feature = "pbr_transmission_textures")]
81pub specular_transmission_texture: Option<Handle<Image>>,
8283/// Thickness of the volume beneath the material surface.
84pub thickness: f32,
85#[cfg(feature = "pbr_transmission_textures")]
8687/// The UV channel to use for the [`GltfMaterial::thickness_texture`].
88pub thickness_channel: UvChannel,
8990/// A map that modulates thickness via its green channel. Multiplied by [`GltfMaterial::thickness`]
91 /// to obtain the final result.
92#[cfg(feature = "pbr_transmission_textures")]
93pub thickness_texture: Option<Handle<Image>>,
9495/// The [index of refraction](https://en.wikipedia.org/wiki/Refractive_index) of the material.
96pub ior: f32,
9798/// How far, on average, light travels through the volume beneath the material's
99 /// surface before being absorbed.
100pub attenuation_distance: f32,
101102/// The resulting (non-absorbed) color after white light travels through the attenuation distance.
103pub attenuation_color: Color,
104105/// The UV channel to use for the [`GltfMaterial::normal_map_texture`].
106pub normal_map_channel: UvChannel,
107108/// Used to fake the lighting of bumps and dents on a material.
109pub normal_map_texture: Option<Handle<Image>>,
110111/// The UV channel to use for the [`GltfMaterial::occlusion_texture`].
112pub occlusion_channel: UvChannel,
113114/// Specifies the level of exposure to ambient light.
115pub occlusion_texture: Option<Handle<Image>>,
116117/// An extra thin translucent layer on top of the main PBR layer. This is
118 /// typically used for painted surfaces.
119pub clearcoat: f32,
120121/// The roughness of the clearcoat material. This is specified in exactly
122 /// the same way as the [`GltfMaterial::perceptual_roughness`].
123pub clearcoat_perceptual_roughness: f32,
124125/// The UV channel to use for the [`GltfMaterial::clearcoat_texture`].
126#[cfg(feature = "pbr_multi_layer_material_textures")]
127pub clearcoat_channel: UvChannel,
128129/// An image texture that specifies the strength of the clearcoat layer in
130 /// the red channel. Values sampled from this texture are multiplied by the
131 /// main [`GltfMaterial::clearcoat`] factor.
132#[cfg(feature = "pbr_multi_layer_material_textures")]
133pub clearcoat_texture: Option<Handle<Image>>,
134135/// The UV channel to use for the [`GltfMaterial::clearcoat_roughness_texture`].
136#[cfg(feature = "pbr_multi_layer_material_textures")]
137pub clearcoat_roughness_channel: UvChannel,
138139/// An image texture that specifies the roughness of the clearcoat level in
140 /// the green channel. Values from this texture are multiplied by the main
141 /// [`GltfMaterial::clearcoat_perceptual_roughness`] factor.
142#[cfg(feature = "pbr_multi_layer_material_textures")]
143pub clearcoat_roughness_texture: Option<Handle<Image>>,
144145/// The UV channel to use for the [`GltfMaterial::clearcoat_normal_texture`].
146#[cfg(feature = "pbr_multi_layer_material_textures")]
147pub clearcoat_normal_channel: UvChannel,
148149/// An image texture that specifies a normal map that is to be applied to
150 /// the clearcoat layer. This can be used to simulate, for example,
151 /// scratches on an outer layer of varnish. Normal maps are in the same
152 /// format as [`GltfMaterial::normal_map_texture`].
153#[cfg(feature = "pbr_multi_layer_material_textures")]
154pub clearcoat_normal_texture: Option<Handle<Image>>,
155156/// Increases the roughness along a specific direction, so that the specular
157 /// highlight will be stretched instead of being a circular lobe.
158pub anisotropy_strength: f32,
159160/// The direction of increased roughness, in radians relative to the mesh
161 /// tangent.
162pub anisotropy_rotation: f32,
163164/// The UV channel to use for the [`GltfMaterial::anisotropy_texture`].
165#[cfg(feature = "pbr_anisotropy_texture")]
166pub anisotropy_channel: UvChannel,
167168/// An image texture that allows the
169 /// [`GltfMaterial::anisotropy_strength`] and
170 /// [`GltfMaterial::anisotropy_rotation`] to vary across the mesh.
171#[cfg(feature = "pbr_anisotropy_texture")]
172pub anisotropy_texture: Option<Handle<Image>>,
173174/// Support two-sided lighting by automatically flipping the normals for "back" faces
175 /// within the PBR lighting shader.
176pub double_sided: bool,
177178/// Support two-sided lighting by automatically flipping the normals for "back" faces
179 /// within the PBR lighting shader.
180pub cull_mode: Option<Face>,
181182/// Whether to apply only the base color to this material.
183pub unlit: bool,
184185/// How to apply the alpha channel of the `base_color_texture`.
186pub alpha_mode: AlphaMode,
187188/// The transform applied to the UVs corresponding to `ATTRIBUTE_UV_0` on the mesh before sampling. Default is identity.
189pub uv_transform: Affine2,
190}
191192impl Defaultfor GltfMaterial {
193fn default() -> Self {
194GltfMaterial {
195// White because it gets multiplied with texture values if someone uses
196 // a texture.
197base_color: Color::WHITE,
198 base_color_channel: UvChannel::Uv0,
199 base_color_texture: None,
200 emissive: LinearRgba::BLACK,
201 emissive_channel: UvChannel::Uv0,
202 emissive_texture: None,
203// Matches Blender's default roughness.
204perceptual_roughness: 0.5,
205// Metallic should generally be set to 0.0 or 1.0.
206metallic: 0.0,
207 metallic_roughness_channel: UvChannel::Uv0,
208 metallic_roughness_texture: None,
209// Minimum real-world reflectance is 2%, most materials between 2-5%
210 // Expressed in a linear scale and equivalent to 4% reflectance see
211 // <https://google.github.io/filament/Material%20Properties.pdf>
212reflectance: 0.5,
213 specular_transmission: 0.0,
214#[cfg(feature = "pbr_transmission_textures")]
215specular_transmission_channel: UvChannel::Uv0,
216#[cfg(feature = "pbr_transmission_textures")]
217specular_transmission_texture: None,
218 thickness: 0.0,
219#[cfg(feature = "pbr_transmission_textures")]
220thickness_channel: UvChannel::Uv0,
221#[cfg(feature = "pbr_transmission_textures")]
222thickness_texture: None,
223 ior: 1.5,
224 attenuation_color: Color::WHITE,
225 attenuation_distance: f32::INFINITY,
226 occlusion_channel: UvChannel::Uv0,
227 occlusion_texture: None,
228 normal_map_channel: UvChannel::Uv0,
229 normal_map_texture: None,
230#[cfg(feature = "pbr_specular_textures")]
231specular_channel: UvChannel::Uv0,
232#[cfg(feature = "pbr_specular_textures")]
233specular_texture: None,
234 specular_tint: Color::WHITE,
235#[cfg(feature = "pbr_specular_textures")]
236specular_tint_channel: UvChannel::Uv0,
237#[cfg(feature = "pbr_specular_textures")]
238specular_tint_texture: None,
239 clearcoat: 0.0,
240 clearcoat_perceptual_roughness: 0.5,
241#[cfg(feature = "pbr_multi_layer_material_textures")]
242clearcoat_channel: UvChannel::Uv0,
243#[cfg(feature = "pbr_multi_layer_material_textures")]
244clearcoat_texture: None,
245#[cfg(feature = "pbr_multi_layer_material_textures")]
246clearcoat_roughness_channel: UvChannel::Uv0,
247#[cfg(feature = "pbr_multi_layer_material_textures")]
248clearcoat_roughness_texture: None,
249#[cfg(feature = "pbr_multi_layer_material_textures")]
250clearcoat_normal_channel: UvChannel::Uv0,
251#[cfg(feature = "pbr_multi_layer_material_textures")]
252clearcoat_normal_texture: None,
253 anisotropy_strength: 0.0,
254 anisotropy_rotation: 0.0,
255#[cfg(feature = "pbr_anisotropy_texture")]
256anisotropy_channel: UvChannel::Uv0,
257#[cfg(feature = "pbr_anisotropy_texture")]
258anisotropy_texture: None,
259 double_sided: false,
260 cull_mode: Some(Face::Back),
261 unlit: false,
262 alpha_mode: AlphaMode::Opaque,
263 uv_transform: Affine2::IDENTITY,
264 }
265 }
266}