Skip to content

Commit

Permalink
Shrink visbuffer triangle ID to 7 bits
Browse files Browse the repository at this point in the history
  • Loading branch information
JMS55 committed Nov 11, 2023
1 parent c2c439d commit be6c16b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/meshlet/visibility_buffer.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn vertex(@builtin(vertex_index) cull_output: u32) -> VertexOutput {
clip_position.z = min(clip_position.z, 1.0);
#endif

let visibility = (thread_id << 8u) | (index_id / 3u);
let visibility = (thread_id << 7u) | (index_id / 3u);
return VertexOutput(clip_position, visibility, material_id);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/meshlet/visibility_buffer_resolve.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ struct VertexOutput {

fn resolve_vertex_output(frag_coord: vec4<f32>) -> VertexOutput {
let vbuffer = textureLoad(meshlet_visibility_buffer, vec2<i32>(frag_coord.xy), 0).r;
let thread_id = vbuffer >> 8u;
let thread_id = vbuffer >> 7u;
let meshlet_id = meshlet_thread_meshlet_ids[thread_id];
let meshlet = meshlets[meshlet_id];
let triangle_id = extractBits(vbuffer, 0u, 8u);
let triangle_id = extractBits(vbuffer, 0u, 7u);
let index_ids = meshlet.start_index_id + vec3(triangle_id * 3u) + vec3(0u, 1u, 2u);
let indices = meshlet.start_vertex_id + vec3(get_meshlet_index(index_ids.x), get_meshlet_index(index_ids.y), get_meshlet_index(index_ids.z));
let vertex_ids = vec3(meshlet_vertex_ids[indices.x], meshlet_vertex_ids[indices.y], meshlet_vertex_ids[indices.z]);
Expand Down

0 comments on commit be6c16b

Please sign in to comment.