File tree 4 files changed +35
-1
lines changed
render_graph/pbr_pipeline
4 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,13 @@ pub struct StandardMaterial {
42
42
#[ render_resources( ignore) ]
43
43
#[ shader_def]
44
44
pub unlit : bool ,
45
+ /// Use the 'flat' Type Qualifier for the normal vectors.
46
+ /// This allows for flat shading even with indiced meshes.
47
+ /// The normal that is used for the whole primitive in the fragment
48
+ /// shader will be the [Provoking Vertex](https://www.khronos.org/opengl/wiki/Primitive#Provoking_vertex)
49
+ #[ render_resources( ignore) ]
50
+ #[ shader_def]
51
+ pub flat_shading : bool ,
45
52
}
46
53
47
54
impl Default for StandardMaterial {
@@ -69,6 +76,7 @@ impl Default for StandardMaterial {
69
76
emissive : Color :: BLACK ,
70
77
emissive_texture : None ,
71
78
unlit : false ,
79
+ flat_shading : false ,
72
80
}
73
81
}
74
82
}
Original file line number Diff line number Diff line change @@ -50,7 +50,13 @@ struct DirectionalLight {
50
50
};
51
51
52
52
layout (location = 0 ) in vec3 v_WorldPosition;
53
+
54
+ #ifdef STANDARDMATERIAL_FLAT_SHADING
55
+ layout (location = 1 ) flat in vec3 v_WorldNormal;
56
+ #endif
57
+ #ifndef STANDARDMATERIAL_FLAT_SHADING
53
58
layout (location = 1 ) in vec3 v_WorldNormal;
59
+ #endif
54
60
layout (location = 2 ) in vec2 v_Uv;
55
61
56
62
#ifdef STANDARDMATERIAL_NORMAL_MAP
Original file line number Diff line number Diff line change @@ -9,7 +9,12 @@ layout(location = 3) in vec4 Vertex_Tangent;
9
9
#endif
10
10
11
11
layout (location = 0 ) out vec3 v_WorldPosition;
12
+ #ifdef STANDARDMATERIAL_FLAT_SHADING
13
+ layout (location = 1 ) flat out vec3 v_WorldNormal;
14
+ #endif
15
+ #ifndef STANDARDMATERIAL_FLAT_SHADING
12
16
layout (location = 1 ) out vec3 v_WorldNormal;
17
+ #endif
13
18
layout (location = 2 ) out vec2 v_Uv;
14
19
15
20
layout (set = 0 , binding = 0 ) uniform CameraViewProj {
Original file line number Diff line number Diff line change @@ -20,11 +20,26 @@ fn setup(
20
20
material : materials. add ( Color :: rgb ( 0.3 , 0.5 , 0.3 ) . into ( ) ) ,
21
21
..Default :: default ( )
22
22
} ) ;
23
+ // flat shaded Icosphere
24
+ commands. spawn_bundle ( PbrBundle {
25
+ mesh : meshes. add ( Mesh :: from ( shape:: Icosphere {
26
+ radius : 0.45 ,
27
+ subdivisions : 2 ,
28
+ } ) ) ,
29
+ material : materials. add ( StandardMaterial {
30
+ base_color : Color :: hex ( "ffd891" ) . unwrap ( ) ,
31
+ // vary key PBR parameters on a grid of spheres to show the effect
32
+ flat_shading : true ,
33
+ ..Default :: default ( )
34
+ } ) ,
35
+ transform : Transform :: from_xyz ( -0.5 , 0.5 , 0.0 ) ,
36
+ ..Default :: default ( )
37
+ } ) ;
23
38
// cube
24
39
commands. spawn_bundle ( PbrBundle {
25
40
mesh : meshes. add ( Mesh :: from ( shape:: Cube { size : 1.0 } ) ) ,
26
41
material : materials. add ( Color :: rgb ( 0.8 , 0.7 , 0.6 ) . into ( ) ) ,
27
- transform : Transform :: from_xyz ( 0.0 , 0.5 , 0.0 ) ,
42
+ transform : Transform :: from_xyz ( 0.6 , 0.5 , 0.0 ) ,
28
43
..Default :: default ( )
29
44
} ) ;
30
45
// light
You can’t perform that action at this time.
0 commit comments