1
1
//! `bevy-pbr-rust`-backed `RustGpuMaterial` implementation for `StandardMaterial`.
2
2
3
- use bevy:: prelude:: StandardMaterial ;
3
+ use bevy:: { prelude:: StandardMaterial , render :: render_resource :: ShaderDefVal } ;
4
4
5
5
use crate :: prelude:: { EntryPoint , EntryPointName , EntryPointParameters , RustGpuMaterial } ;
6
6
@@ -31,15 +31,13 @@ impl EntryPoint for PbrFragment {
31
31
const NAME : EntryPointName = "pbr::entry_points::fragment" ;
32
32
const PARAMETERS : EntryPointParameters = & [
33
33
( & [ ( "NO_TEXTURE_ARRAYS_SUPPORT" , "texture" ) ] , "array" ) ,
34
- ( & [ ( "NO_STORAGE_BUFFERS_SUPPORT" , "uniform" ) ] , "storage" ) ,
35
- ( & [ ( "VERTEX_POSITIONS" , "some" ) ] , "none" ) ,
36
- ( & [ ( "VERTEX_NORMALS" , "some" ) ] , "none" ) ,
37
34
( & [ ( "VERTEX_UVS" , "some" ) ] , "none" ) ,
38
35
( & [ ( "VERTEX_TANGENTS" , "some" ) ] , "none" ) ,
39
36
( & [ ( "VERTEX_COLORS" , "some" ) ] , "none" ) ,
40
37
( & [ ( "STANDARDMATERIAL_NORMAL_MAP" , "some" ) ] , "none" ) ,
41
38
( & [ ( "SKINNED" , "some" ) ] , "none" ) ,
42
39
( & [ ( "TONEMAP_IN_SHADER" , "some" ) ] , "none" ) ,
40
+ ( & [ ( "PREMULTIPLY_ALPHA" , "some" ) ] , "none" ) ,
43
41
( & [ ( "DEBAND_DITHER" , "some" ) ] , "none" ) ,
44
42
(
45
43
& [
@@ -56,11 +54,47 @@ impl EntryPoint for PbrFragment {
56
54
"none" ,
57
55
) ,
58
56
] ;
57
+
58
+ fn permutation ( shader_defs : & Vec < ShaderDefVal > ) -> Vec < String > {
59
+ let mut permutation = vec ! [ ] ;
60
+
61
+ for ( defined, undefined) in Self :: PARAMETERS . iter ( ) {
62
+ if let Some ( mapping) = defined. iter ( ) . find_map ( |( def, mapping) | {
63
+ if shader_defs. contains ( & ShaderDefVal :: Bool ( def. to_string ( ) , true ) ) {
64
+ Some ( mapping)
65
+ } else {
66
+ None
67
+ }
68
+ } ) {
69
+ permutation. push ( mapping. to_string ( ) ) ;
70
+ } else {
71
+ permutation. push ( undefined. to_string ( ) )
72
+ } ;
73
+ }
74
+
75
+ if let Some ( ge) = shader_defs. iter ( ) . find_map ( |def| match def {
76
+ bevy:: render:: render_resource:: ShaderDefVal :: UInt ( key, value) => {
77
+ if key. as_str ( ) == "AVAILABLE_STORAGE_BUFFER_BINDINGS" {
78
+ Some ( * value >= 3 )
79
+ } else {
80
+ None
81
+ }
82
+ }
83
+ _ => None ,
84
+ } ) {
85
+ if ge {
86
+ permutation. insert ( 1 , "storage" . to_string ( ) )
87
+ } else {
88
+ permutation. insert ( 1 , "uniform" . to_string ( ) )
89
+ }
90
+ }
91
+
92
+ permutation
93
+ }
59
94
}
60
95
61
96
/// `StandardMaterial` implementation
62
97
impl RustGpuMaterial for StandardMaterial {
63
98
type Vertex = MeshVertex ;
64
99
type Fragment = PbrFragment ;
65
100
}
66
-
0 commit comments