convert the replacement modules to wesl
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import package::aabb::PackedAabb;
|
||||
import package::metadata_types::TapeMetadata;
|
||||
import package::implicit::interval_scene;
|
||||
import package::NAN;
|
||||
|
||||
struct AabbBuffer {
|
||||
aabbs: array<PackedAabb>,
|
||||
}
|
||||
struct TapeMetadataBuffer {
|
||||
metadata: array<TapeMetadata>,
|
||||
}
|
||||
struct PushConstants {
|
||||
object_index: u32,
|
||||
time: f32,
|
||||
}
|
||||
|
||||
struct InstanceTapeIds {
|
||||
aabb_buffer_id: u32,
|
||||
aabb_buffer_offset: u32,
|
||||
aabb_count: u32,
|
||||
metadata_buffer_id: u32,
|
||||
metadata_buffer_offset: u32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0)
|
||||
var<storage, read_write> aabb_buffers: binding_array<AabbBuffer>;
|
||||
@group(0) @binding(1)
|
||||
var<storage> tape_metadata_buffers: binding_array<TapeMetadataBuffer>;
|
||||
@group(0) @binding(2)
|
||||
var<storage> tape_ids: array<InstanceTapeIds>;
|
||||
|
||||
var<immediate> push_constants: PushConstants;
|
||||
|
||||
struct ComputeInput {
|
||||
@builtin(global_invocation_id) global_invocation_id: vec3u,
|
||||
@builtin(num_workgroups) num_workgroups: vec3u,
|
||||
@builtin(workgroup_id) workgroup_id: vec3u,
|
||||
}
|
||||
|
||||
@compute @workgroup_size(8, 8, 8)
|
||||
fn enable_gen_entry(compute_input: ComputeInput) {
|
||||
let instance = tape_ids[push_constants.object_index];
|
||||
let metadata = tape_metadata_buffers[instance.metadata_buffer_id].metadata[
|
||||
instance.metadata_buffer_offset
|
||||
];
|
||||
|
||||
let total_invocations = compute_input.num_workgroups * vec3u(8);
|
||||
let base_index =
|
||||
(((compute_input.global_invocation_id.z * total_invocations.y)
|
||||
+ compute_input.global_invocation_id.y) * total_invocations.x)
|
||||
+ compute_input.global_invocation_id.x;
|
||||
|
||||
let internal_pos = vec3(
|
||||
f32(
|
||||
(base_index >> (metadata.subdivision_log2 * 2))
|
||||
& u32((1 << metadata.subdivision_log2) - 1),
|
||||
) / f32(1 << metadata.subdivision_log2),
|
||||
f32(
|
||||
(base_index >> (metadata.subdivision_log2 * 1))
|
||||
& u32((1 << metadata.subdivision_log2) - 1),
|
||||
) / f32(1 << metadata.subdivision_log2),
|
||||
f32(
|
||||
(base_index >> (metadata.subdivision_log2 * 0))
|
||||
& u32((1 << metadata.subdivision_log2) - 1),
|
||||
) / f32(1 << metadata.subdivision_log2),
|
||||
);
|
||||
|
||||
let low_corner =
|
||||
(((vec3(0.0f) / f32(1 << metadata.subdivision_log2)) + internal_pos) * metadata.dimensions)
|
||||
+ metadata.lowest_corner;
|
||||
let high_corner =
|
||||
(((vec3(1.0f) / f32(1 << metadata.subdivision_log2)) + internal_pos) * metadata.dimensions)
|
||||
+ metadata.lowest_corner;
|
||||
|
||||
let interval = interval_scene(
|
||||
vec4(low_corner, push_constants.time),
|
||||
vec4(high_corner, push_constants.time),
|
||||
);
|
||||
|
||||
let aabb = &aabb_buffers[instance.aabb_buffer_id].aabbs[instance.aabb_buffer_offset];
|
||||
|
||||
let en = (interval.x < 0) && (interval.y > 0);
|
||||
|
||||
if en {
|
||||
aabb.min = low_corner;
|
||||
aabb.max = high_corner;
|
||||
} else {
|
||||
aabb.min.x = NAN();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user