File tree 4 files changed +64
-12
lines changed
4 files changed +64
-12
lines changed Original file line number Diff line number Diff line change @@ -566,12 +566,19 @@ impl SpecializedMeshPipeline for MeshPipeline {
566
566
key : Self :: Key ,
567
567
layout : & MeshVertexBufferLayout ,
568
568
) -> Result < RenderPipelineDescriptor , SpecializedMeshPipelineError > {
569
- let mut vertex_attributes = vec ! [
570
- Mesh :: ATTRIBUTE_POSITION . at_shader_location( 0 ) ,
571
- Mesh :: ATTRIBUTE_NORMAL . at_shader_location( 1 ) ,
572
- ] ;
573
-
574
569
let mut shader_defs = Vec :: new ( ) ;
570
+ let mut vertex_attributes = Vec :: new ( ) ;
571
+
572
+ if layout. contains ( Mesh :: ATTRIBUTE_POSITION ) {
573
+ shader_defs. push ( String :: from ( "VERTEX_POSITIONS" ) ) ;
574
+ vertex_attributes. push ( Mesh :: ATTRIBUTE_POSITION . at_shader_location ( 0 ) ) ;
575
+ }
576
+
577
+ if layout. contains ( Mesh :: ATTRIBUTE_NORMAL ) {
578
+ shader_defs. push ( String :: from ( "VERTEX_NORMALS" ) ) ;
579
+ vertex_attributes. push ( Mesh :: ATTRIBUTE_NORMAL . at_shader_location ( 1 ) ) ;
580
+ }
581
+
575
582
if layout. contains ( Mesh :: ATTRIBUTE_UV_0 ) {
576
583
shader_defs. push ( String :: from ( "VERTEX_UVS" ) ) ;
577
584
vertex_attributes. push ( Mesh :: ATTRIBUTE_UV_0 . at_shader_location ( 2 ) ) ;
Original file line number Diff line number Diff line change 5
5
#import bevy_pbr ::mesh_functions
6
6
7
7
struct Vertex {
8
+ #ifdef VERTEX_POSITIONS
8
9
@location (0 ) position : vec3 <f32 >,
10
+ #endif
11
+ #ifdef VERTEX_NORMALS
9
12
@location (1 ) normal : vec3 <f32 >,
13
+ #endif
10
14
#ifdef VERTEX_UVS
11
15
@location (2 ) uv : vec2 <f32 >,
12
16
#endif
@@ -30,25 +34,34 @@ struct VertexOutput {
30
34
@vertex
31
35
fn vertex (vertex : Vertex ) -> VertexOutput {
32
36
var out : VertexOutput ;
37
+
38
+ #ifdef VERTEX_NORMALS
33
39
#ifdef SKINNED
34
40
var model = skin_model (vertex . joint_indices, vertex . joint_weights);
35
41
out . world_normal = skin_normals (model , vertex . normal);
36
42
#else
37
43
var model = mesh . model;
38
44
out . world_normal = mesh_normal_local_to_world (vertex . normal);
39
45
#endif
46
+ #endif
47
+
48
+ #ifdef VERTEX_POSITIONS
40
49
out . world_position = mesh_position_local_to_world (model , vec4 <f32 >(vertex . position, 1.0 ));
50
+ out . clip_position = mesh_position_world_to_clip (out . world_position);
51
+ #endif
52
+
41
53
#ifdef VERTEX_UVS
42
54
out . uv = vertex . uv;
43
55
#endif
56
+
44
57
#ifdef VERTEX_TANGENTS
45
58
out . world_tangent = mesh_tangent_local_to_world (model , vertex . tangent);
46
59
#endif
60
+
47
61
#ifdef VERTEX_COLORS
48
62
out . color = vertex . color;
49
63
#endif
50
64
51
- out . clip_position = mesh_position_world_to_clip (out . world_position);
52
65
return out ;
53
66
}
54
67
Original file line number Diff line number Diff line change @@ -325,13 +325,24 @@ impl SpecializedMeshPipeline for Mesh2dPipeline {
325
325
key : Self :: Key ,
326
326
layout : & MeshVertexBufferLayout ,
327
327
) -> Result < RenderPipelineDescriptor , SpecializedMeshPipelineError > {
328
- let mut vertex_attributes = vec ! [
329
- Mesh :: ATTRIBUTE_POSITION . at_shader_location( 0 ) ,
330
- Mesh :: ATTRIBUTE_NORMAL . at_shader_location( 1 ) ,
331
- Mesh :: ATTRIBUTE_UV_0 . at_shader_location( 2 ) ,
332
- ] ;
333
-
334
328
let mut shader_defs = Vec :: new ( ) ;
329
+ let mut vertex_attributes = Vec :: new ( ) ;
330
+
331
+ if layout. contains ( Mesh :: ATTRIBUTE_POSITION ) {
332
+ shader_defs. push ( String :: from ( "VERTEX_POSITIONS" ) ) ;
333
+ vertex_attributes. push ( Mesh :: ATTRIBUTE_POSITION . at_shader_location ( 0 ) ) ;
334
+ }
335
+
336
+ if layout. contains ( Mesh :: ATTRIBUTE_NORMAL ) {
337
+ shader_defs. push ( String :: from ( "VERTEX_NORMALS" ) ) ;
338
+ vertex_attributes. push ( Mesh :: ATTRIBUTE_NORMAL . at_shader_location ( 1 ) ) ;
339
+ }
340
+
341
+ if layout. contains ( Mesh :: ATTRIBUTE_UV_0 ) {
342
+ shader_defs. push ( String :: from ( "VERTEX_UVS" ) ) ;
343
+ vertex_attributes. push ( Mesh :: ATTRIBUTE_UV_0 . at_shader_location ( 2 ) ) ;
344
+ }
345
+
335
346
if layout. contains ( Mesh :: ATTRIBUTE_TANGENT ) {
336
347
shader_defs. push ( String :: from ( "VERTEX_TANGENTS" ) ) ;
337
348
vertex_attributes. push ( Mesh :: ATTRIBUTE_TANGENT . at_shader_location ( 3 ) ) ;
Original file line number Diff line number Diff line change 5
5
#import bevy_sprite ::mesh2d_functions
6
6
7
7
struct Vertex {
8
+ #ifdef VERTEX_POSITIONS
8
9
@location (0 ) position : vec3 <f32 >,
10
+ #endif
11
+ #ifdef VERTEX_NORMALS
9
12
@location (1 ) normal : vec3 <f32 >,
13
+ #endif
14
+ #ifdef VERTEX_UVS
10
15
@location (2 ) uv : vec2 <f32 >,
16
+ #endif
11
17
#ifdef VERTEX_TANGENTS
12
18
@location (3 ) tangent : vec4 <f32 >,
13
19
#endif
@@ -24,13 +30,24 @@ struct VertexOutput {
24
30
@vertex
25
31
fn vertex (vertex : Vertex ) -> VertexOutput {
26
32
var out : VertexOutput ;
33
+
34
+ #ifdef VERTEX_UVS
27
35
out . uv = vertex . uv;
36
+ #endif
37
+
38
+ #ifdef VERTEX_POSITIONS
28
39
out . world_position = mesh2d_position_local_to_world (mesh . model, vec4 <f32 >(vertex . position, 1.0 ));
29
40
out . clip_position = mesh2d_position_world_to_clip (out . world_position);
41
+ #endif
42
+
43
+ #ifdef VERTEX_NORMALS
30
44
out . world_normal = mesh2d_normal_local_to_world (vertex . normal);
45
+ #endif
46
+
31
47
#ifdef VERTEX_TANGENTS
32
48
out . world_tangent = mesh2d_tangent_local_to_world (mesh . model, vertex . tangent);
33
49
#endif
50
+
34
51
#ifdef VERTEX_COLORS
35
52
out . color = vertex . color;
36
53
#endif
@@ -44,5 +61,9 @@ struct FragmentInput {
44
61
45
62
@fragment
46
63
fn fragment (in : FragmentInput ) -> @location (0 ) vec4 <f32 > {
64
+ #ifdef VERTEX_COLORS
65
+ return in . color;
66
+ #else
47
67
return vec4 <f32 >(1.0 , 0.0 , 1.0 , 1.0 );
68
+ #endif
48
69
}
You can’t perform that action at this time.
0 commit comments