work around the texture parameter thing

This commit is contained in:
2026-10-25 22:58:04 +00:00
parent d18c28d05a
commit 68e57737c0
6 changed files with 23 additions and 22 deletions
@@ -148,8 +148,7 @@ const LIGHT_NOT_PRESENT_THIS_FRAME = 0xFFFFFFFFu;
@group(0) @binding(1) var<storage> index_buffers: binding_array<IndexBuffer>; @group(0) @binding(1) var<storage> index_buffers: binding_array<IndexBuffer>;
@group(0) @binding(2) var<storage> aabb_buffers: binding_array<AabbBuffer>; @group(0) @binding(2) var<storage> aabb_buffers: binding_array<AabbBuffer>;
@group(0) @binding(3) var<storage> tape_metadata_buffers: binding_array<TapeMetadataBuffer>; @group(0) @binding(3) var<storage> tape_metadata_buffers: binding_array<TapeMetadataBuffer>;
@group(0) @binding(4) var spatial_textures: binding_array<texture_3d<f32>>;
@group(0) @binding(5) var spatial_texture_sampler: sampler;
@group(0) @binding(6) var textures: binding_array<texture_2d<f32>>; @group(0) @binding(6) var textures: binding_array<texture_2d<f32>>;
@group(0) @binding(7) var samplers: binding_array<sampler>; @group(0) @binding(7) var samplers: binding_array<sampler>;
@group(0) @binding(8) var<storage> materials: array<Material>; @group(0) @binding(8) var<storage> materials: array<Material>;
@@ -398,9 +397,8 @@ fn resolve_triangle_data_full(instance_id: u32, triangle_id: u32, barycentrics:
fn tape_confirm_intersection(instance_id: u32, geometry_index: u32, ray_position: vec3<f32>, ray_direction: vec3<f32>) -> f32 { fn tape_confirm_intersection(instance_id: u32, geometry_index: u32, ray_position: vec3<f32>, ray_direction: vec3<f32>) -> f32 {
let instance_tape_ids = tape_ids[instance_id]; let instance_tape_ids = tape_ids[instance_id];
let metadata = tape_metadata_buffers[instance_tape_ids.metadata_buffer_id].metadata[instance_tape_ids.metadata_buffer_offset]; let metadata = tape_metadata_buffers[instance_tape_ids.metadata_buffer_id].metadata[instance_tape_ids.metadata_buffer_offset];
let spatial_texture = spatial_textures[instance_tape_ids.spatial_texture_id];
return trace_tape(metadata, spatial_texture, spatial_texture_sampler, geometry_index, ray_position, ray_direction); return trace_tape(metadata, instance_tape_ids.spatial_texture_id, geometry_index, ray_position, ray_direction);
} }
fn resolve_tape_data_full(instance_id: u32, geometry_index: u32, position: vec3<f32>) -> ResolvedRayHitFull { fn resolve_tape_data_full(instance_id: u32, geometry_index: u32, position: vec3<f32>) -> ResolvedRayHitFull {
@@ -412,7 +410,6 @@ fn resolve_tape_data_full(instance_id: u32, geometry_index: u32, position: vec3<
let instance_tape_ids = tape_ids[instance_id]; let instance_tape_ids = tape_ids[instance_id];
let metadata = tape_metadata_buffers[instance_tape_ids.metadata_buffer_id].metadata[instance_tape_ids.metadata_buffer_offset]; let metadata = tape_metadata_buffers[instance_tape_ids.metadata_buffer_id].metadata[instance_tape_ids.metadata_buffer_offset];
let spatial_texture = spatial_textures[instance_tape_ids.spatial_texture_id];
let local_position = position; // dont think about it let local_position = position; // dont think about it
@@ -431,7 +428,7 @@ fn resolve_tape_data_full(instance_id: u32, geometry_index: u32, position: vec3<
let local_tangent = vec3(1.0, 0.0, 0.0); // Implicit surfaces don't have tangent vectors let local_tangent = vec3(1.0, 0.0, 0.0); // Implicit surfaces don't have tangent vectors
let world_tangent: vec4<f32> = vec4(normalize(transform_3x3 * local_tangent), 1.0); let world_tangent: vec4<f32> = vec4(normalize(transform_3x3 * local_tangent), 1.0);
let local_normal: vec3<f32> = get_normal(metadata, spatial_texture, spatial_texture_sampler, local_position); let local_normal: vec3<f32> = get_normal(metadata, instance_tape_ids.spatial_texture_id, local_position);
var world_normal: vec3<f32> = normalize(determinant_sign * (cofactor * local_normal)); var world_normal: vec3<f32> = normalize(determinant_sign * (cofactor * local_normal));
let geometric_world_normal: vec3<f32> = world_normal; let geometric_world_normal: vec3<f32> = world_normal;
@@ -1,5 +1,3 @@
import package::render::metadata_types::TapeMetadata;
fn scene(scene_input_one: vec4<f32>) -> f32 { fn scene(scene_input_one: vec4<f32>) -> f32 {
return 0.0; return 0.0;
} }
@@ -14,8 +12,3 @@ fn interval_scene(
fn gradient_scene(gradient_scene_input_one: vec4<f32>) -> vec4<f32> { fn gradient_scene(gradient_scene_input_one: vec4<f32>) -> vec4<f32> {
return vec4(0.0); 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;
}
+1
View File
@@ -76,6 +76,7 @@ impl Plugin for TapeRenderAssetPlugin {
load_shader_library!(app, "aabb.wesl"); load_shader_library!(app, "aabb.wesl");
load_shader_library!(app, "metadata_types.wesl"); load_shader_library!(app, "metadata_types.wesl");
load_shader_library!(app, "implicit.wesl"); load_shader_library!(app, "implicit.wesl");
load_shader_library!(app, "spatial_implicit.wesl");
load_shader_library!(app, "trace.wesl"); load_shader_library!(app, "trace.wesl");
load_shader_library!(app, "util.wesl"); load_shader_library!(app, "util.wesl");
load_shader_library!(app, "normal.wesl"); load_shader_library!(app, "normal.wesl");
+6 -6
View File
@@ -1,13 +1,13 @@
import package::render::metadata_types::TapeMetadata; import package::render::metadata_types::TapeMetadata;
import package::render::implicit::{spatial_scene}; import package::render::spatial_implicit::spatial_scene;
const EPSILON = .0001; const EPSILON = .0001;
fn get_normal(metadata: TapeMetadata, spatial_texture: texture_3d<f32>, spatial_texture_sampler: sampler, p: vec3<f32>) -> vec3<f32> { fn get_normal(metadata: TapeMetadata, spatial_texture: u32, p: vec3<f32>) -> vec3<f32> {
let n = vec3( 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, 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, 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)), spatial_scene(metadata, spatial_texture, 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)))); return normalize(n - (spatial_scene(metadata, spatial_texture, vec4(p, metadata.time))));
} }
@@ -0,0 +1,10 @@
import package::render::metadata_types::TapeMetadata;
// This is to work around that you can't pass textures as parameters, it seems.
@group(0) @binding(4) var spatial_textures: binding_array<texture_3d<f32>>;
@group(0) @binding(5) var spatial_texture_sampler: sampler;
fn spatial_scene(metadata: TapeMetadata, spatial_texture: u32, p: vec4<f32>) -> f32 {
let actual = (p.xyz - metadata.lowest_corner) / metadata.dimensions;
return textureSampleLevel(spatial_textures[spatial_texture], spatial_texture_sampler, actual, 0.0).x;
}
+3 -3
View File
@@ -1,5 +1,5 @@
import package::render::metadata_types::TapeMetadata; import package::render::metadata_types::TapeMetadata;
import package::render::implicit::{spatial_scene}; import package::render::spatial_implicit::spatial_scene;
import package::render::util::{get_internal_pos, get_low_corner, get_high_corner}; import package::render::util::{get_internal_pos, get_low_corner, get_high_corner};
enable wgpu_binding_array; enable wgpu_binding_array;
@@ -25,7 +25,7 @@ fn box_intersection(ro: vec3<f32>, rd: vec3<f32>, box_size: vec3<f32>) -> vec2<f
return vec2(tN, tF); 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 { fn trace_tape(metadata: TapeMetadata, spatial_texture: u32, primitive_id: u32, raypos: vec3<f32>, raydir: vec3<f32>) -> f32 {
let internal_pos = get_internal_pos(primitive_id, metadata.subdivision_log2); let internal_pos = get_internal_pos(primitive_id, metadata.subdivision_log2);
let low_corner = get_low_corner(internal_pos, metadata); let low_corner = get_low_corner(internal_pos, metadata);
@@ -50,7 +50,7 @@ fn trace_tape(metadata: TapeMetadata, spatial_texture: texture_3d<f32>, spatial_
var total_dist = near_plane; var total_dist = near_plane;
var p = fma(raydir, vec3(total_dist), raypos); var p = fma(raydir, vec3(total_dist), raypos);
for (var i = 0; i < MAX_STEPS; i++) { for (var i = 0; i < MAX_STEPS; i++) {
let dist = spatial_scene(metadata, spatial_texture, spatial_texture_sampler, vec4(p, metadata.time)); let dist = spatial_scene(metadata, spatial_texture, vec4(p, metadata.time));
total_dist += dist; total_dist += dist;
p = fma(raydir, vec3(total_dist), raypos); p = fma(raydir, vec3(total_dist), raypos);
if (abs(dist) < EPSILON) { if (abs(dist) < EPSILON) {