Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ShaderDefVal to avoid redundant code #9408

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions crates/bevy_pbr/src/render/mesh_bindings.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@

#import bevy_pbr::mesh_types Mesh

#ifdef MESH_BINDGROUP_1

#ifdef PER_OBJECT_BUFFER_BATCH_SIZE
@group(1) @binding(0)
var<uniform> mesh: array<Mesh, #{PER_OBJECT_BUFFER_BATCH_SIZE}u>;

@group(#{MESH_BINDGROUP}) @binding(0)
var<uniform> mesh: array<Mesh, #{PER_OBJECT_BUFFER_BATCH_SIZE}u>;
#else
@group(1) @binding(0)
var<storage> mesh: array<Mesh>;
#endif // PER_OBJECT_BUFFER_BATCH_SIZE

#else // MESH_BINDGROUP_1
@group(#{MESH_BINDGROUP}) @binding(0)
var<storage> mesh: array<Mesh>;

#ifdef PER_OBJECT_BUFFER_BATCH_SIZE
@group(2) @binding(0)
var<uniform> mesh: array<Mesh, #{PER_OBJECT_BUFFER_BATCH_SIZE}u>;
#else
@group(2) @binding(0)
var<storage> mesh: array<Mesh>;
#endif // PER_OBJECT_BUFFER_BATCH_SIZE

#endif // MESH_BINDGROUP_1
15 changes: 2 additions & 13 deletions crates/bevy_pbr/src/render/morph.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,12 @@

#import bevy_pbr::mesh_types MorphWeights

#ifdef MESH_BINDGROUP_1

@group(1) @binding(2)
@group(#{MESH_BINDGROUP}) @binding(2)
var<uniform> morph_weights: MorphWeights;
@group(1) @binding(3)
var morph_targets: texture_3d<f32>;

#else

@group(2) @binding(2)
var<uniform> morph_weights: MorphWeights;
@group(2) @binding(3)
@group(#{MESH_BINDGROUP}) @binding(3)
var morph_targets: texture_3d<f32>;

#endif


// NOTE: Those are the "hardcoded" values found in `MorphAttributes` struct
// in crates/bevy_render/src/mesh/morph/visitors.rs
// In an ideal world, the offsets are established dynamically and passed as #defines
Expand Down
14 changes: 2 additions & 12 deletions crates/bevy_pbr/src/render/skinning.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@

#ifdef SKINNED

#ifdef MESH_BINDGROUP_1

@group(1) @binding(1)
var<uniform> joint_matrices: SkinnedMesh;

#else

@group(2) @binding(1)
var<uniform> joint_matrices: SkinnedMesh;

#endif

@group(#{MESH_BINDGROUP}) @binding(1)
var<uniform> joint_matrices: SkinnedMesh;

fn skin_model(
indexes: vec4<u32>,
Expand Down