@@ -3,12 +3,28 @@ use bevy_reflect::TypeUuid;
3
3
use bevy_render:: { color:: Color , renderer:: RenderResources , shader:: ShaderDefs , texture:: Texture } ;
4
4
5
5
/// A material with "standard" properties used in PBR lighting
6
+ /// Standard property values with pictures here https://google.github.io/filament/Material%20Properties.pdf
6
7
#[ derive( Debug , RenderResources , ShaderDefs , TypeUuid ) ]
7
8
#[ uuid = "dace545e-4bc6-4595-a79d-c224fc694975" ]
8
9
pub struct StandardMaterial {
9
- pub albedo : Color ,
10
+ /// Doubles as diffuse albedo for non-metallic, specular for metallic and a mix for everything in between
11
+ /// If used together with a base_color_texture, this is factored into the final base color
12
+ /// as `base_color * base_color_texture_value`
13
+ pub base_color : Color ,
10
14
#[ shader_def]
11
- pub albedo_texture : Option < Handle < Texture > > ,
15
+ pub base_color_texture : Option < Handle < Texture > > ,
16
+ /// Linear perceptual roughness, clamped to [0.089, 1.0] in the shader
17
+ /// Defaults to minimum of 0.089
18
+ /// If used together with a roughness/metallic texture, this is factored into the final base color
19
+ /// as `roughness * roughness_texture_value`
20
+ pub roughness : f32 ,
21
+ /// From [0.0, 1.0], dielectric to pure metallic
22
+ /// If used together with a roughness/metallic texture, this is factored into the final base color
23
+ /// as `metallic * metallic_texture_value`
24
+ pub metallic : f32 ,
25
+ /// Specular intensity for non-metals on a linear scale of [0.0, 1.0]
26
+ /// defaults to 0.5 which is mapped to 4% reflectance in the shader
27
+ pub reflectance : f32 ,
12
28
#[ render_resources( ignore) ]
13
29
#[ shader_def]
14
30
pub unlit : bool ,
@@ -17,8 +33,19 @@ pub struct StandardMaterial {
17
33
impl Default for StandardMaterial {
18
34
fn default ( ) -> Self {
19
35
StandardMaterial {
20
- albedo : Color :: rgb ( 1.0 , 1.0 , 1.0 ) ,
21
- albedo_texture : None ,
36
+ base_color : Color :: rgb ( 1.0 , 1.0 , 1.0 ) ,
37
+ base_color_texture : None ,
38
+ // This is the minimum the roughness is clamped to in shader code
39
+ // See https://google.github.io/filament/Filament.html#materialsystem/parameterization/
40
+ // It's the minimum floating point value that won't be rounded down to 0 in the calculations used.
41
+ // Although technically for 32-bit floats, 0.045 could be used.
42
+ roughness : 0.089 ,
43
+ // Few materials are purely dielectric or metallic
44
+ // This is just a default for mostly-dielectric
45
+ metallic : 0.01 ,
46
+ // Minimum real-world reflectance is 2%, most materials between 2-5%
47
+ // Expressed in a linear scale and equivalent to 4% reflectance see https://google.github.io/filament/Material%20Properties.pdf
48
+ reflectance : 0.5 ,
22
49
unlit : false ,
23
50
}
24
51
}
@@ -27,7 +54,7 @@ impl Default for StandardMaterial {
27
54
impl From < Color > for StandardMaterial {
28
55
fn from ( color : Color ) -> Self {
29
56
StandardMaterial {
30
- albedo : color,
57
+ base_color : color,
31
58
..Default :: default ( )
32
59
}
33
60
}
@@ -36,7 +63,7 @@ impl From<Color> for StandardMaterial {
36
63
impl From < Handle < Texture > > for StandardMaterial {
37
64
fn from ( texture : Handle < Texture > ) -> Self {
38
65
StandardMaterial {
39
- albedo_texture : Some ( texture) ,
66
+ base_color_texture : Some ( texture) ,
40
67
..Default :: default ( )
41
68
}
42
69
}
0 commit comments