spatial doesn't crash at least
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
struct PackedAabb {
|
||||
min_x: f32,
|
||||
min_y: f32,
|
||||
min_z: f32,
|
||||
max_x: f32,
|
||||
max_y: f32,
|
||||
max_z: f32,
|
||||
pad_a: u32,
|
||||
pad_b: u32,
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import package::render::aabb::PackedAabb;
|
||||
import package::render::metadata_types::TapeMetadata;
|
||||
import package::render::implicit::{interval_scene, scene};
|
||||
import package::render::util::{get_internal_pos, get_low_corner, get_high_corner, NAN};
|
||||
|
||||
enable wgpu_binding_array;
|
||||
|
||||
struct AabbBuffer {
|
||||
aabbs: array<PackedAabb>,
|
||||
}
|
||||
struct TapeMetadataBuffer {
|
||||
metadata: array<TapeMetadata>,
|
||||
}
|
||||
struct PushConstants {
|
||||
aabb_buffer_offset: u32,
|
||||
metadata_buffer_offset: u32,
|
||||
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;
|
||||
|
||||
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 main(compute_input: ComputeInput) {
|
||||
let metadata = tape_metadata_buffer.metadata[push_constants.metadata_buffer_offset];
|
||||
|
||||
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 = get_internal_pos(base_index, metadata.subdivision_log2);
|
||||
|
||||
let low_corner = get_low_corner(internal_pos, metadata);
|
||||
let high_corner = get_high_corner(internal_pos, metadata);
|
||||
|
||||
let interval = interval_scene(
|
||||
vec4(low_corner, metadata.time),
|
||||
vec4(high_corner, metadata.time),
|
||||
);
|
||||
|
||||
let aabb = &aabb_buffer.aabbs[push_constants.aabb_buffer_offset + base_index];
|
||||
|
||||
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.));
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,21 @@
|
||||
// These functions will be overwritten
|
||||
import package::render::metadata_types::TapeMetadata;
|
||||
|
||||
fn scene(p: vec4<f32>) -> f32 {
|
||||
fn scene(scene_input_one: vec4<f32>) -> f32 {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
fn interval_scene(pl: vec4<f32>, ph: vec4<f32>) -> vec2<f32> {
|
||||
fn interval_scene(
|
||||
interval_scene_input_one: vec4<f32>,
|
||||
interval_scene_input_two: vec4<f32>,
|
||||
) -> vec2<f32> {
|
||||
return vec2(0.0);
|
||||
}
|
||||
|
||||
fn gradient_scene(p: vec4<f32>) -> vec4<f32> {
|
||||
fn gradient_scene(gradient_scene_input_one: vec4<f32>) -> vec4<f32> {
|
||||
return vec4(0.0);
|
||||
}
|
||||
|
||||
fn spatial_scene(metadata: TapeMetadata, spatial_texture: texture_3d<f32>, spatial_texture_sampler: sampler, p: vec4<f32>) -> f32 {
|
||||
let actual = (p.xyz - metadata.lowest_corner) / metadata.dimensions;
|
||||
return textureSampleLevel(spatial_texture, spatial_texture_sampler, actual, 0.0).x;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
struct TapeMetadata {
|
||||
lowest_corner: vec3<f32>,
|
||||
time: f32,
|
||||
dimensions: vec3<f32>,
|
||||
subdivision_log2: u32,
|
||||
}
|
||||
@@ -73,9 +73,12 @@ pub struct TapeRenderAssetPlugin;
|
||||
|
||||
impl Plugin for TapeRenderAssetPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
load_shader_library!(app, "../../shaders/aabb.wesl");
|
||||
load_shader_library!(app, "../../shaders/metadata_types.wesl");
|
||||
load_shader_library!(app, "../../shaders/implicit.wesl");
|
||||
load_shader_library!(app, "aabb.wesl");
|
||||
load_shader_library!(app, "metadata_types.wesl");
|
||||
load_shader_library!(app, "implicit.wesl");
|
||||
load_shader_library!(app, "trace.wesl");
|
||||
load_shader_library!(app, "util.wesl");
|
||||
load_shader_library!(app, "normal.wesl");
|
||||
|
||||
app.add_plugins(RenderAssetPlugin::<RenderTape>::default())
|
||||
.add_plugins(TapeAllocatorPlugin);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import package::render::metadata_types::TapeMetadata;
|
||||
import package::render::implicit::{spatial_scene};
|
||||
|
||||
const EPSILON = .0001;
|
||||
|
||||
fn get_normal(metadata: TapeMetadata, spatial_texture: texture_3d<f32>, spatial_texture_sampler: sampler, p: vec3<f32>) -> vec3<f32> {
|
||||
let n = vec3(
|
||||
spatial_scene(metadata, spatial_texture, spatial_texture_sampler, vec4(p.x + EPSILON, p.y, p.z, metadata.time)),
|
||||
spatial_scene(metadata, spatial_texture, spatial_texture_sampler, vec4(p.x, p.y + EPSILON, p.z, metadata.time)),
|
||||
spatial_scene(metadata, spatial_texture, spatial_texture_sampler, vec4(p.x, p.y, p.z + EPSILON, metadata.time)),
|
||||
);
|
||||
return normalize(n - (spatial_scene(metadata, spatial_texture, spatial_texture_sampler, vec4(p, metadata.time))));
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import package::render::metadata_types::TapeMetadata;
|
||||
import package::render::implicit::{spatial_scene};
|
||||
import package::render::util::{get_internal_pos, get_low_corner, get_high_corner};
|
||||
|
||||
enable wgpu_binding_array;
|
||||
|
||||
const EPSILON = .001;
|
||||
|
||||
const MAX_STEPS = 50;
|
||||
|
||||
// axis aligned, center at the origin, dimensions "box_size"
|
||||
// https://iquilezles.org/articles/intersectors/
|
||||
fn box_intersection(ro: vec3<f32>, rd: vec3<f32>, box_size: vec3<f32>) -> vec2<f32>
|
||||
{
|
||||
let m = 1.0 / rd; // can precompute if traversing a set of aligned boxes
|
||||
let n = m * ro; // can precompute if traversing a set of aligned boxes
|
||||
let k = abs(m) * box_size;
|
||||
let t1 = -n - k;
|
||||
let t2 = -n + k;
|
||||
let tN = max(max(t1.x, t1.y), t1.z);
|
||||
let tF = min(min(t2.x, t2.y), t2.z);
|
||||
if (tN > tF || tF < 0.0) {
|
||||
return vec2(-1.0); // no intersection
|
||||
}
|
||||
return vec2(tN, tF);
|
||||
}
|
||||
|
||||
fn trace_tape(metadata: TapeMetadata, spatial_texture: texture_3d<f32>, spatial_texture_sampler: sampler, primitive_id: u32, raypos: vec3<f32>, raydir: vec3<f32>) -> f32 {
|
||||
let internal_pos = get_internal_pos(primitive_id, metadata.subdivision_log2);
|
||||
|
||||
let low_corner = get_low_corner(internal_pos, metadata);
|
||||
let high_corner = get_high_corner(internal_pos, metadata);
|
||||
|
||||
let adjusted_raypos = raypos - ((high_corner + low_corner) / 2.0);
|
||||
let dimensions = high_corner - low_corner;
|
||||
|
||||
let near_far = box_intersection(adjusted_raypos, raydir, dimensions);
|
||||
|
||||
if (near_far.x < 0.) {
|
||||
return near_far.x;
|
||||
}
|
||||
|
||||
let near_plane = near_far.x;
|
||||
let far_plane = near_far.y;
|
||||
|
||||
if (false) { // SPEC_BOUNDING_BOXES
|
||||
return near_plane;
|
||||
}
|
||||
|
||||
var total_dist = near_plane;
|
||||
var p = fma(raydir, vec3(total_dist), raypos);
|
||||
for (var i = 0; i < MAX_STEPS; i++) {
|
||||
let dist = spatial_scene(metadata, spatial_texture, spatial_texture_sampler, vec4(p, metadata.time));
|
||||
total_dist += dist;
|
||||
p = fma(raydir, vec3(total_dist), raypos);
|
||||
if (abs(dist) < EPSILON) {
|
||||
return max(total_dist, near_plane);
|
||||
} else if (total_dist > far_plane) {
|
||||
return -1.0;
|
||||
}
|
||||
}
|
||||
return -1.0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import package::render::metadata_types::TapeMetadata;
|
||||
|
||||
fn NAN() -> f32 {
|
||||
return bitcast<f32>(0xFFC00000u);
|
||||
}
|
||||
|
||||
fn get_internal_pos(base_index: u32, subdivision_log2: u32) -> vec3<f32> {
|
||||
return vec3(
|
||||
f32(
|
||||
(base_index >> (subdivision_log2 * 2))
|
||||
& u32((1 << subdivision_log2) - 1),
|
||||
) / f32(1 << subdivision_log2),
|
||||
f32(
|
||||
(base_index >> (subdivision_log2 * 1))
|
||||
& u32((1 << subdivision_log2) - 1),
|
||||
) / f32(1 << subdivision_log2),
|
||||
f32(
|
||||
(base_index >> (subdivision_log2 * 0))
|
||||
& u32((1 << subdivision_log2) - 1),
|
||||
) / f32(1 << subdivision_log2)
|
||||
);
|
||||
}
|
||||
|
||||
fn get_corner(internal_pos: vec3<f32>, metadata: TapeMetadata, pos: vec3<f32>) -> vec3<f32> {
|
||||
return
|
||||
(((vec3(0.0f) / f32(1 << metadata.subdivision_log2)) + internal_pos) * metadata.dimensions)
|
||||
+ metadata.lowest_corner;
|
||||
}
|
||||
|
||||
fn get_low_corner(internal_pos: vec3<f32>, metadata: TapeMetadata) -> vec3<f32> {
|
||||
return get_corner(internal_pos, metadata, vec3(0.0));
|
||||
}
|
||||
|
||||
fn get_high_corner(internal_pos: vec3<f32>, metadata: TapeMetadata) -> vec3<f32> {
|
||||
return get_corner(internal_pos, metadata, vec3(1.0));
|
||||
}
|
||||
Reference in New Issue
Block a user