fix aabb alignment
This commit is contained in:
@@ -180,9 +180,12 @@ fn trace_ray(ray_origin: vec3<f32>, ray_direction: vec3<f32>, ray_t_min: f32, ra
|
|||||||
rayQueryInitialize(&rq, tlas, ray);
|
rayQueryInitialize(&rq, tlas, ray);
|
||||||
while rayQueryProceed(&rq) {
|
while rayQueryProceed(&rq) {
|
||||||
let candidate = rayQueryGetCandidateIntersection(&rq);
|
let candidate = rayQueryGetCandidateIntersection(&rq);
|
||||||
if passes_alpha_test(candidate) {
|
if candidate.kind == RAY_QUERY_INTERSECTION_TRIANGLE {
|
||||||
rayQueryConfirmIntersection(&rq);
|
if passes_alpha_test(candidate) {
|
||||||
|
rayQueryConfirmIntersection(&rq);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
rayQueryTerminate(&rq);
|
||||||
}
|
}
|
||||||
return rayQueryGetCommittedIntersection(&rq);
|
return rayQueryGetCommittedIntersection(&rq);
|
||||||
}
|
}
|
||||||
@@ -193,9 +196,12 @@ fn trace_ray_previous_frame(ray_origin: vec3<f32>, ray_direction: vec3<f32>, ray
|
|||||||
rayQueryInitialize(&rq, previous_frame_tlas, ray);
|
rayQueryInitialize(&rq, previous_frame_tlas, ray);
|
||||||
while rayQueryProceed(&rq) {
|
while rayQueryProceed(&rq) {
|
||||||
let candidate = rayQueryGetCandidateIntersection(&rq);
|
let candidate = rayQueryGetCandidateIntersection(&rq);
|
||||||
if passes_alpha_test(candidate) {
|
if candidate.kind == RAY_QUERY_INTERSECTION_TRIANGLE {
|
||||||
rayQueryConfirmIntersection(&rq);
|
if passes_alpha_test(candidate) {
|
||||||
|
rayQueryConfirmIntersection(&rq);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
rayQueryTerminate(&rq);
|
||||||
}
|
}
|
||||||
return rayQueryGetCommittedIntersection(&rq);
|
return rayQueryGetCommittedIntersection(&rq);
|
||||||
}
|
}
|
||||||
@@ -268,8 +274,13 @@ fn resolve_material(material: Material, uv: vec2<f32>) -> ResolvedMaterial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_ray_hit_full(ray_hit: RayIntersection) -> ResolvedRayHitFull {
|
fn resolve_ray_hit_full(ray_hit: RayIntersection) -> ResolvedRayHitFull {
|
||||||
let barycentrics = vec3(1.0 - ray_hit.barycentrics.x - ray_hit.barycentrics.y, ray_hit.barycentrics);
|
var resolved: ResolvedRayHitFull;
|
||||||
var resolved = resolve_triangle_data_full(ray_hit.instance_custom_data, ray_hit.primitive_index, barycentrics);
|
if ray_hit.kind == RAY_QUERY_INTERSECTION_TRIANGLE {
|
||||||
|
let barycentrics = vec3(1.0 - ray_hit.barycentrics.x - ray_hit.barycentrics.y, ray_hit.barycentrics);
|
||||||
|
resolved = resolve_triangle_data_full(ray_hit.instance_custom_data, ray_hit.primitive_index, barycentrics);
|
||||||
|
} else {
|
||||||
|
resolved = resolve_tape_data_full(ray_hit.instance_custom_data, vec3());
|
||||||
|
}
|
||||||
|
|
||||||
// Flip normals for backfacing hits of double sided materials
|
// Flip normals for backfacing hits of double sided materials
|
||||||
if !ray_hit.front_face && resolved.double_sided {
|
if !ray_hit.front_face && resolved.double_sided {
|
||||||
@@ -369,3 +380,26 @@ fn resolve_triangle_data_full(instance_id: u32, triangle_id: u32, barycentrics:
|
|||||||
(material.flags & MATERIAL_FLAG_DOUBLE_SIDED) != 0u,
|
(material.flags & MATERIAL_FLAG_DOUBLE_SIDED) != 0u,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn resolve_tape_data_full(instance_id: u32, position: vec3<f32>) -> ResolvedRayHitFull {
|
||||||
|
let material_id = material_ids[instance_id];
|
||||||
|
let material = materials[material_id];
|
||||||
|
|
||||||
|
let transform = affine3_to_square(transforms[instance_id]);
|
||||||
|
let previous_frame_transform = affine3_to_square(previous_frame_transforms[instance_id]);
|
||||||
|
|
||||||
|
let resolved_material = resolve_material(material, vec2());
|
||||||
|
|
||||||
|
return ResolvedRayHitFull(
|
||||||
|
position,
|
||||||
|
position,
|
||||||
|
vec3(1.0, 0.0, 0.0),
|
||||||
|
vec3(1.0, 0.0, 0.0),
|
||||||
|
vec4(0.0, 1.0, 0.0, 1.0),
|
||||||
|
vec2(),
|
||||||
|
0.0,
|
||||||
|
0,
|
||||||
|
resolved_material,
|
||||||
|
(material.flags & MATERIAL_FLAG_DOUBLE_SIDED) != 0u,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ pub fn compile_raytracing_blas(
|
|||||||
|
|
||||||
let geometry = BlasAabbGeometry {
|
let geometry = BlasAabbGeometry {
|
||||||
size: blas_size,
|
size: blas_size,
|
||||||
stride: size_of::<bevy_tape_load::render::Aabb>() as u64,
|
stride: size_of::<bevy_tape_load::render::PackedAabb>() as u64,
|
||||||
aabb_buffer: aabbs_slice.buffer,
|
aabb_buffer: aabbs_slice.buffer,
|
||||||
primitive_offset: aabbs_slice.range.start,
|
primitive_offset: aabbs_slice.range.start,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,4 +5,6 @@ struct PackedAabb {
|
|||||||
max_x: f32,
|
max_x: f32,
|
||||||
max_y: f32,
|
max_y: f32,
|
||||||
max_z: f32,
|
max_z: f32,
|
||||||
|
pad_a: u32,
|
||||||
|
pad_b: u32,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use bevy_render::{
|
|||||||
};
|
};
|
||||||
use wgpu::{BufferUsages, COPY_BUFFER_ALIGNMENT};
|
use wgpu::{BufferUsages, COPY_BUFFER_ALIGNMENT};
|
||||||
|
|
||||||
use super::{Aabb, RenderTape, TapeMetadata};
|
use super::{PackedAabb, RenderTape, TapeMetadata};
|
||||||
use crate::tape::Tape;
|
use crate::tape::Tape;
|
||||||
|
|
||||||
/// A plugin that manages GPU memory for tape data.
|
/// A plugin that manages GPU memory for tape data.
|
||||||
@@ -491,7 +491,7 @@ impl ElementLayout {
|
|||||||
/// Creates the appropriate [`ElementLayout`] for the given tape's aabb
|
/// Creates the appropriate [`ElementLayout`] for the given tape's aabb
|
||||||
/// data.
|
/// data.
|
||||||
fn aabb(_tape: &Tape) -> ElementLayout {
|
fn aabb(_tape: &Tape) -> ElementLayout {
|
||||||
ElementLayout::new(ElementClass::Aabb, size_of::<Aabb>() as u64)
|
ElementLayout::new(ElementClass::Aabb, size_of::<PackedAabb>() as u64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use bevy_ecs::{
|
|||||||
system::{SystemParamItem, lifetimeless::SRes},
|
system::{SystemParamItem, lifetimeless::SRes},
|
||||||
};
|
};
|
||||||
use bevy_math::Vec3;
|
use bevy_math::Vec3;
|
||||||
use bevy_reflect::Reflect;
|
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
Render, RenderApp, RenderSystems,
|
Render, RenderApp, RenderSystems,
|
||||||
render_asset::{
|
render_asset::{
|
||||||
@@ -38,6 +37,8 @@ use crate::{
|
|||||||
pub struct PackedAabb {
|
pub struct PackedAabb {
|
||||||
min: Vec3,
|
min: Vec3,
|
||||||
max: Vec3,
|
max: Vec3,
|
||||||
|
pad_a: u32,
|
||||||
|
pad_b: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Per-tape metadata, stored in [`super::allocator::TapeAllocator`].
|
/// Per-tape metadata, stored in [`super::allocator::TapeAllocator`].
|
||||||
@@ -168,15 +169,6 @@ pub fn prepare_tape_metadata_fallback_buffer(
|
|||||||
commands.insert_resource(TapeMetadataFallbackBuffer { slab_id, buffer });
|
commands.insert_resource(TapeMetadataFallbackBuffer { slab_id, buffer });
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy, Reflect)]
|
|
||||||
#[reflect(Debug, PartialEq, Clone)]
|
|
||||||
pub struct Aabb {
|
|
||||||
/// The minimum point of the box
|
|
||||||
pub min: Vec3,
|
|
||||||
/// The maximum point of the box
|
|
||||||
pub max: Vec3,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct ReplacementModules {
|
pub struct ReplacementModules {
|
||||||
pub enable_gen: Module,
|
pub enable_gen: Module,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use bevy_shader::Shader;
|
|||||||
use bevy_shape::Aabb3d;
|
use bevy_shape::Aabb3d;
|
||||||
use rspirv::{binary::Assemble as _, dr::Module};
|
use rspirv::{binary::Assemble as _, dr::Module};
|
||||||
|
|
||||||
use crate::{render::Aabb, ssa::*};
|
use crate::{render::PackedAabb, ssa::*};
|
||||||
|
|
||||||
/// A tape drive tape.
|
/// A tape drive tape.
|
||||||
#[derive(Asset, Clone, Debug, Reflect, PartialEq, Hash)]
|
#[derive(Asset, Clone, Debug, Reflect, PartialEq, Hash)]
|
||||||
@@ -38,7 +38,8 @@ impl Tape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_aabb_buffer_size(&self) -> u64 {
|
pub fn get_aabb_buffer_size(&self) -> u64 {
|
||||||
((self.subdivision * self.subdivision * self.subdivision) as u64) * size_of::<Aabb>() as u64
|
((self.subdivision * self.subdivision * self.subdivision) as u64)
|
||||||
|
* size_of::<PackedAabb>() as u64
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_tape_key(&self) -> u64 {
|
pub fn get_tape_key(&self) -> u64 {
|
||||||
|
|||||||
Reference in New Issue
Block a user