write normals to tiletree texture
This commit is contained in:
@@ -26,7 +26,12 @@ fn compile_replacement_shader(name: &str, entry_point: String, stage: naga::Shad
|
||||
let shader = shader.to_string();
|
||||
|
||||
// Parse the source into a Module.
|
||||
let module: naga::Module = naga::front::wgsl::parse_str(&shader)
|
||||
let module: naga::Module =
|
||||
naga::front::wgsl::Frontend::new_with_options(naga::front::wgsl::Options {
|
||||
parse_doc_comments: false,
|
||||
capabilities: naga::valid::Capabilities::all(),
|
||||
})
|
||||
.parse(&shader)
|
||||
.inspect_err(|e| e.emit_to_stderr_with_path(&shader, format!("{SHADERS_IN}/{name}.wesl")))
|
||||
.expect("Failed to parse WGSL");
|
||||
// Validate the module.
|
||||
|
||||
@@ -31,21 +31,21 @@ impl SphereTapeBuilder {
|
||||
let pos = tape.push_instruction(
|
||||
SSAOpcodeSized {
|
||||
opcode: SSAOpcode::SSAPosition,
|
||||
size: 1,
|
||||
size: 1,
|
||||
},
|
||||
vec![],
|
||||
);
|
||||
let sphere = tape.push_instruction(
|
||||
SSAOpcodeSized {
|
||||
opcode: SSAOpcode::SSASDFSphere,
|
||||
size: 1,
|
||||
size: 1,
|
||||
},
|
||||
vec![pos[0], pos[1], pos[2], SSAInput::Constant(radius)],
|
||||
);
|
||||
tape.push_instruction(
|
||||
SSAOpcodeSized {
|
||||
opcode: SSAOpcode::SSAReturn,
|
||||
size: 1,
|
||||
size: 1,
|
||||
},
|
||||
sphere,
|
||||
);
|
||||
|
||||
@@ -47,9 +47,9 @@ pub struct TapeAllocatorPlugin;
|
||||
pub struct TapeAllocator {
|
||||
/// Holds all buffers and offset allocators.
|
||||
#[deref]
|
||||
slab_allocator: SlabAllocator<TapeSlabItem>,
|
||||
slab_allocator: SlabAllocator<TapeSlabItem>,
|
||||
spatial_texture_allocator: HashMap<AssetId<Tape>, (Texture, TextureView)>,
|
||||
tiletree_allocator: HashMap<AssetId<Tape>, (Texture, TextureView)>,
|
||||
tiletree_allocator: HashMap<AssetId<Tape>, (Texture, TextureView)>,
|
||||
}
|
||||
|
||||
/// Tunable parameters that customize the behavior of the allocator.
|
||||
@@ -70,7 +70,7 @@ impl Default for TapeAllocatorSettings {
|
||||
fn default() -> TapeAllocatorSettings {
|
||||
TapeAllocatorSettings {
|
||||
slab_allocator_settings: SlabAllocatorSettings::default(),
|
||||
extra_buffer_usages: BufferUsages::empty(),
|
||||
extra_buffer_usages: BufferUsages::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,7 @@ impl SlabItem for TapeSlabItem {
|
||||
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
pub struct TapeSlabs {
|
||||
/// The slab storing the tape's aabb data.
|
||||
pub aabb_slab_id: TapeSlabId,
|
||||
pub aabb_slab_id: TapeSlabId,
|
||||
/// The slab storing the tape's metadata.
|
||||
pub metadata_slab_id: TapeSlabId,
|
||||
}
|
||||
@@ -115,7 +115,7 @@ pub struct TapeAllocationKey {
|
||||
/// The ID of the tape asset.
|
||||
pub tape_id: AssetId<Tape>,
|
||||
/// The type of data: vertex data, index data
|
||||
pub class: ElementClass,
|
||||
pub class: ElementClass,
|
||||
}
|
||||
|
||||
impl TapeAllocationKey {
|
||||
@@ -299,7 +299,7 @@ impl TapeAllocator {
|
||||
/// None.
|
||||
pub fn tape_slabs(&self, tape_id: &AssetId<Tape>) -> Option<TapeSlabs> {
|
||||
Some(TapeSlabs {
|
||||
aabb_slab_id: self.tape_id_to_aabb_slab(tape_id).cloned()?,
|
||||
aabb_slab_id: self.tape_id_to_aabb_slab(tape_id).cloned()?,
|
||||
metadata_slab_id: self.tape_id_to_metadata_slab(tape_id).cloned()?,
|
||||
})
|
||||
}
|
||||
@@ -387,16 +387,16 @@ impl TapeAllocator {
|
||||
|
||||
// Allocate spatial texture.
|
||||
let texture = render_device.create_texture(&TextureDescriptor {
|
||||
label: Some(&format!("Tape {} spatial texture", tape_id)),
|
||||
format: TextureFormat::R16Float,
|
||||
dimension: TextureDimension::D3,
|
||||
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING,
|
||||
label: Some(&format!("Tape {} spatial texture", tape_id)),
|
||||
format: TextureFormat::R16Float,
|
||||
dimension: TextureDimension::D3,
|
||||
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
view_formats: &[TextureFormat::R16Float],
|
||||
size: Extent3d {
|
||||
width: tape.subdivision * 8,
|
||||
height: tape.subdivision * 8,
|
||||
sample_count: 1,
|
||||
view_formats: &[TextureFormat::R16Float],
|
||||
size: Extent3d {
|
||||
width: tape.subdivision * 8,
|
||||
height: tape.subdivision * 8,
|
||||
depth_or_array_layers: tape.subdivision * 8,
|
||||
},
|
||||
});
|
||||
@@ -409,16 +409,16 @@ impl TapeAllocator {
|
||||
|
||||
// Allocate worst-case tiletree
|
||||
let texture = render_device.create_texture(&TextureDescriptor {
|
||||
label: Some(&format!("Tape {} tiletree", tape_id)),
|
||||
format: TextureFormat::Rgb10a2Unorm,
|
||||
dimension: TextureDimension::D3,
|
||||
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING,
|
||||
label: Some(&format!("Tape {} tiletree", tape_id)),
|
||||
format: TextureFormat::Rgb10a2Unorm,
|
||||
dimension: TextureDimension::D3,
|
||||
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
view_formats: &[TextureFormat::Rgb10a2Unorm],
|
||||
size: Extent3d {
|
||||
width: tape.subdivision * 128,
|
||||
height: tape.subdivision * 128,
|
||||
sample_count: 1,
|
||||
view_formats: &[TextureFormat::Rgb10a2Unorm],
|
||||
size: Extent3d {
|
||||
width: tape.subdivision * 128,
|
||||
height: tape.subdivision * 128,
|
||||
depth_or_array_layers: tape.subdivision * 6,
|
||||
},
|
||||
});
|
||||
@@ -553,10 +553,10 @@ impl ElementLayout {
|
||||
/// data.
|
||||
fn metadata(_tape: &Tape) -> ElementLayout {
|
||||
ElementLayout {
|
||||
class: ElementClass::Metadata,
|
||||
size: size_of::<TapeMetadata>() as u64,
|
||||
class: ElementClass::Metadata,
|
||||
size: size_of::<TapeMetadata>() as u64,
|
||||
elements_per_slot: 1,
|
||||
buffer_usages: ElementClass::Metadata.buffer_usages(),
|
||||
buffer_usages: ElementClass::Metadata.buffer_usages(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,7 +589,7 @@ impl ElementClass {
|
||||
ElementClass::Metadata => BufferUsages::STORAGE,
|
||||
ElementClass::Aabb => {
|
||||
BufferUsages::union(BufferUsages::STORAGE, BufferUsages::BLAS_INPUT)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import package::render::aabb::PackedAabb;
|
||||
import package::render::metadata_types::TapeMetadata;
|
||||
import package::render::implicit::{interval_scene, scene};
|
||||
import package::render::implicit::{interval_scene, scene, gradient_scene};
|
||||
import package::render::util::{NAN, encode_internal_pos, internal_to_external_pos};
|
||||
import package::render::spatial_implicit::{SPATIAL_SCENE_OFFSET, INVERSE_SPATIAL_SCENE_SCALE};
|
||||
|
||||
@@ -79,10 +79,39 @@ fn main(compute_input: ComputeInput) {
|
||||
|
||||
let point = scene(vec4(mid_point, metadata.time));
|
||||
|
||||
textureStore(spatial_texture, compute_input.global_invocation_id, vec4(point, 0., 0., 0.));
|
||||
textureStore(spatial_texture, uinternal_pos, vec4(point, 0., 0., 0.));
|
||||
}
|
||||
|
||||
if (push_constants.flags & FLAG_FILL_TILETREE) > 0 {
|
||||
// subgroupElect is not implemented in naga
|
||||
//let index = subgroupExclusiveAdd(1);
|
||||
//let elect = subgroupBroadcastFirst(index) == index;
|
||||
|
||||
var exit = 0;
|
||||
//if elect {
|
||||
let base_index = encode_internal_pos(uinternal_pos / vec3u(128, 128, 6), metadata.subdivision_log2);
|
||||
let aabb = &aabb_buffer.aabbs[push_constants.aabb_buffer_offset + base_index];
|
||||
if bitcast<u32>(aabb.min_x) == 0xFFC00000u {
|
||||
exit = 1;
|
||||
}
|
||||
//}
|
||||
//exit = subgroupBroadcastFirst(exit);
|
||||
if exit == 1 {
|
||||
return;
|
||||
}
|
||||
|
||||
let position = internal_to_external_pos(internal_pos / vec3(128.0, 128.0, 6.0), metadata);
|
||||
//let grad = gradient_scene(vec4(position, metadata.time));
|
||||
|
||||
const EPSILON = 0.001;
|
||||
|
||||
let n = vec3(
|
||||
scene(vec4(position.x + EPSILON, position.y, position.z, metadata.time)),
|
||||
scene(vec4(position.x, position.y + EPSILON, position.z, metadata.time)),
|
||||
scene(vec4(position.x, position.y, position.z + EPSILON, metadata.time)),
|
||||
);
|
||||
let grad = normalize(n - (scene(vec4(position, metadata.time))));
|
||||
|
||||
textureStore(tiletree, uinternal_pos, vec4(grad * 0.5 + 0.5, 0.0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ use crate::{
|
||||
#[derive(Default, Pod, Zeroable, Clone, Copy, Debug, ShaderType)]
|
||||
#[repr(C)]
|
||||
pub struct PackedAabb {
|
||||
min: Vec3,
|
||||
max: Vec3,
|
||||
min: Vec3,
|
||||
max: Vec3,
|
||||
pad_a: u32,
|
||||
pad_b: u32,
|
||||
}
|
||||
@@ -52,9 +52,9 @@ pub struct PackedAabb {
|
||||
#[derive(Default, Pod, Zeroable, Clone, Copy, Debug, ShaderType)]
|
||||
#[repr(C)]
|
||||
pub struct TapeMetadata {
|
||||
lowest_corner: Vec3,
|
||||
time: f32,
|
||||
dimensions: Vec3,
|
||||
lowest_corner: Vec3,
|
||||
time: f32,
|
||||
dimensions: Vec3,
|
||||
subdivision_log2: u32,
|
||||
}
|
||||
|
||||
@@ -91,9 +91,9 @@ impl Plugin for TapeRenderAssetPlugin {
|
||||
let enable_gen = include_spirv_raw!("../../shaders_out/enable_gen.spv");
|
||||
|
||||
let modules = ReplacementModules {
|
||||
enable_gen: get_module(enable_gen.clone()),
|
||||
normals: get_module(enable_gen.clone()),
|
||||
trace: get_module(enable_gen.clone()),
|
||||
enable_gen: get_module(enable_gen.clone()),
|
||||
normals: get_module(enable_gen.clone()),
|
||||
trace: get_module(enable_gen.clone()),
|
||||
enable_gen_layout: BindGroupLayoutDescriptor::new(
|
||||
"Enable Gen Layout",
|
||||
&BindGroupLayoutEntries::sequential(
|
||||
@@ -145,7 +145,7 @@ pub struct TapeMetadataFallbackTape(pub Handle<Tape>);
|
||||
#[derive(Resource)]
|
||||
pub struct TapeMetadataFallbackBuffer {
|
||||
pub slab_id: TapeSlabId,
|
||||
pub buffer: Buffer,
|
||||
pub buffer: Buffer,
|
||||
}
|
||||
|
||||
pub fn prepare_tape_metadata_fallback_buffer(
|
||||
@@ -168,8 +168,8 @@ pub fn prepare_tape_metadata_fallback_buffer(
|
||||
#[derive(Resource)]
|
||||
pub struct ReplacementModules {
|
||||
pub enable_gen: Module,
|
||||
pub normals: Module,
|
||||
pub trace: Module,
|
||||
pub normals: Module,
|
||||
pub trace: Module,
|
||||
|
||||
pub enable_gen_layout: BindGroupLayoutDescriptor,
|
||||
}
|
||||
@@ -177,14 +177,14 @@ pub struct ReplacementModules {
|
||||
/// The render world representation of a [`Tape`].
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RenderTape {
|
||||
pub seed: u64,
|
||||
pub seed: u64,
|
||||
pub subdivision: u32,
|
||||
pub time: f32,
|
||||
pub key: u64,
|
||||
pub time: f32,
|
||||
pub key: u64,
|
||||
|
||||
pub enable_gen: Handle<Shader>,
|
||||
pub normals: Handle<Shader>,
|
||||
pub trace: Handle<Shader>,
|
||||
pub normals: Handle<Shader>,
|
||||
pub trace: Handle<Shader>,
|
||||
|
||||
pub enable_gen_pipeline: CachedComputePipelineId,
|
||||
}
|
||||
|
||||
@@ -13,21 +13,21 @@ use crate::{render::PackedAabb, ssa::*};
|
||||
#[derive(Asset, Clone, Debug, Reflect, PartialEq)]
|
||||
#[reflect(Clone)]
|
||||
pub struct Tape {
|
||||
pub raytracing: MeshRaytracingFlags,
|
||||
pub parts: SSATape,
|
||||
pub seed: u64,
|
||||
pub raytracing: MeshRaytracingFlags,
|
||||
pub parts: SSATape,
|
||||
pub seed: u64,
|
||||
pub subdivision: u32,
|
||||
pub time: f32,
|
||||
pub time: f32,
|
||||
}
|
||||
|
||||
impl Default for Tape {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
raytracing: MeshRaytracingFlags::OPAQUE,
|
||||
parts: Default::default(),
|
||||
seed: 0,
|
||||
raytracing: MeshRaytracingFlags::OPAQUE,
|
||||
parts: Default::default(),
|
||||
seed: 0,
|
||||
subdivision: 8,
|
||||
time: 0.0,
|
||||
time: 0.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user