Spatial texture writing works
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import package::aabb::PackedAabb;
|
||||
import package::metadata_types::TapeMetadata;
|
||||
import package::implicit::interval_scene;
|
||||
import package::implicit::{interval_scene, scene};
|
||||
import package::NAN;
|
||||
|
||||
enable wgpu_binding_array;
|
||||
@@ -14,13 +14,18 @@ struct TapeMetadataBuffer {
|
||||
struct PushConstants {
|
||||
aabb_buffer_offset: u32,
|
||||
metadata_buffer_offset: u32,
|
||||
time: f32,
|
||||
flags: u32
|
||||
}
|
||||
|
||||
const FLAG_FILL_ENABLE_GEN = 1 << 0;
|
||||
const FLAG_FILL_SPATIAL_TEXTURE = 1 << 1;
|
||||
|
||||
@group(0) @binding(0)
|
||||
var<storage, read_write> aabb_buffer: AabbBuffer;
|
||||
@group(0) @binding(1)
|
||||
var<storage> tape_metadata_buffer: TapeMetadataBuffer;
|
||||
@group(0) @binding(2)
|
||||
var spatial_texture: texture_storage_3d<r32float, write>;
|
||||
|
||||
var<immediate> push_constants: PushConstants;
|
||||
|
||||
@@ -34,51 +39,66 @@ struct ComputeInput {
|
||||
fn main(compute_input: ComputeInput) {
|
||||
let metadata = &tape_metadata_buffer.metadata[push_constants.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;
|
||||
if (push_constants.flags & FLAG_FILL_ENABLE_GEN) > 0 {
|
||||
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 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 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 aabb = &aabb_buffer.aabbs[push_constants.aabb_buffer_offset + base_index];
|
||||
let interval = interval_scene(
|
||||
vec4(low_corner, metadata.time),
|
||||
vec4(high_corner, metadata.time),
|
||||
);
|
||||
|
||||
let en = (interval.x < 0) && (interval.y > 0);
|
||||
let aabb = &aabb_buffer.aabbs[push_constants.aabb_buffer_offset + base_index];
|
||||
|
||||
if en {
|
||||
aabb.min_x = low_corner.x;
|
||||
aabb.min_y = low_corner.y;
|
||||
aabb.min_z = low_corner.z;
|
||||
aabb.max_x = high_corner.x;
|
||||
aabb.max_y = high_corner.y;
|
||||
aabb.max_z = high_corner.z;
|
||||
} else {
|
||||
aabb.min_x = NAN();
|
||||
let en = (interval.x < 0) && (interval.y > 0);
|
||||
|
||||
if en {
|
||||
aabb.min_x = low_corner.x;
|
||||
aabb.min_y = low_corner.y;
|
||||
aabb.min_z = low_corner.z;
|
||||
aabb.max_x = high_corner.x;
|
||||
aabb.max_y = high_corner.y;
|
||||
aabb.max_z = high_corner.z;
|
||||
} else {
|
||||
aabb.min_x = NAN();
|
||||
}
|
||||
}
|
||||
|
||||
if (push_constants.flags & FLAG_FILL_SPATIAL_TEXTURE) > 0 {
|
||||
let internal_pos = vec3f(compute_input.global_invocation_id);
|
||||
|
||||
let mid_point =
|
||||
(((internal_pos + 0.5f) / f32(1 << metadata.subdivision_log2)) * metadata.dimensions)
|
||||
+ metadata.lowest_corner;
|
||||
|
||||
let point = scene(vec4(mid_point, metadata.time));
|
||||
|
||||
textureStore(spatial_texture, compute_input.global_invocation_id, vec4(point, 0., 0., 0.));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user