fix the segfault
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
|
#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
|
||||||
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
//! Provides raytraced lighting.
|
//! Provides raytraced lighting.
|
||||||
//!
|
//!
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use super::{prepare::PathtracerAccumulationTexture, Pathtracer};
|
use super::{Pathtracer, prepare::PathtracerAccumulationTexture};
|
||||||
use bevy_camera::Camera;
|
use bevy_camera::Camera;
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
change_detection::DetectChanges,
|
change_detection::DetectChanges,
|
||||||
system::{Commands, Query},
|
system::{Commands, Query},
|
||||||
world::Ref,
|
world::Ref,
|
||||||
};
|
};
|
||||||
use bevy_render::{sync_world::RenderEntity, Extract};
|
use bevy_render::{Extract, sync_world::RenderEntity};
|
||||||
use bevy_transform::components::GlobalTransform;
|
use bevy_transform::components::GlobalTransform;
|
||||||
|
|
||||||
pub fn extract_pathtracer(
|
pub fn extract_pathtracer(
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ mod extract;
|
|||||||
mod node;
|
mod node;
|
||||||
mod prepare;
|
mod prepare;
|
||||||
|
|
||||||
use crate::{scene::RaytracingSceneBindings, SolariPlugins};
|
use crate::{SolariPlugins, scene::RaytracingSceneBindings};
|
||||||
use bevy_app::{App, Plugin, PostUpdate};
|
use bevy_app::{App, Plugin, PostUpdate};
|
||||||
use bevy_asset::embedded_asset;
|
use bevy_asset::embedded_asset;
|
||||||
use bevy_camera::Hdr;
|
use bevy_camera::Hdr;
|
||||||
@@ -19,10 +19,10 @@ use bevy_ecs::{
|
|||||||
system::{Commands, Query},
|
system::{Commands, Query},
|
||||||
};
|
};
|
||||||
use bevy_light::AtmosphereEnvironmentMapLight;
|
use bevy_light::AtmosphereEnvironmentMapLight;
|
||||||
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
use bevy_reflect::{Reflect, std_traits::ReflectDefault};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
init_gpu_resource, renderer::RenderDevice, ExtractSchedule, Render, RenderApp, RenderStartup,
|
ExtractSchedule, Render, RenderApp, RenderStartup, RenderSystems, init_gpu_resource,
|
||||||
RenderSystems,
|
renderer::RenderDevice,
|
||||||
};
|
};
|
||||||
use extract::extract_pathtracer;
|
use extract::extract_pathtracer;
|
||||||
use node::{init_pathtracer_pipelines, pathtracer};
|
use node::{init_pathtracer_pipelines, pathtracer};
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
use super::{prepare::PathtracerAccumulationTexture, Pathtracer};
|
use super::{Pathtracer, prepare::PathtracerAccumulationTexture};
|
||||||
use crate::scene::RaytracingSceneBindings;
|
use crate::scene::RaytracingSceneBindings;
|
||||||
use bevy_asset::{load_embedded_asset, AssetServer};
|
use bevy_asset::{AssetServer, load_embedded_asset};
|
||||||
use bevy_ecs::{prelude::*, resource::Resource, system::Commands};
|
use bevy_ecs::{prelude::*, resource::Resource, system::Commands};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
camera::ExtractedCamera,
|
camera::ExtractedCamera,
|
||||||
render_resource::{
|
render_resource::{
|
||||||
binding_types::{texture_storage_2d, uniform_buffer},
|
|
||||||
BindGroupEntries, BindGroupLayoutDescriptor, BindGroupLayoutEntries,
|
BindGroupEntries, BindGroupLayoutDescriptor, BindGroupLayoutEntries,
|
||||||
CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor,
|
CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor,
|
||||||
ImageSubresourceRange, PipelineCache, ShaderStages, StorageTextureAccess, TextureFormat,
|
ImageSubresourceRange, PipelineCache, ShaderStages, StorageTextureAccess, TextureFormat,
|
||||||
|
binding_types::{texture_storage_2d, uniform_buffer},
|
||||||
},
|
},
|
||||||
renderer::{RenderContext, RenderDevice, ViewQuery},
|
renderer::{RenderContext, RenderDevice, ViewQuery},
|
||||||
view::{ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms},
|
view::{ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms},
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use super::{prepare::SolariLightingResources, SolariLighting};
|
use super::{SolariLighting, prepare::SolariLightingResources};
|
||||||
use bevy_camera::Camera;
|
use bevy_camera::Camera;
|
||||||
use bevy_ecs::system::{Commands, ResMut};
|
use bevy_ecs::system::{Commands, ResMut};
|
||||||
use bevy_pbr::deferred::SkipDeferredLighting;
|
use bevy_pbr::deferred::SkipDeferredLighting;
|
||||||
use bevy_render::{sync_world::RenderEntity, MainWorld};
|
use bevy_render::{MainWorld, sync_world::RenderEntity};
|
||||||
|
|
||||||
pub fn extract_solari_lighting(mut main_world: ResMut<MainWorld>, mut commands: Commands) {
|
pub fn extract_solari_lighting(mut main_world: ResMut<MainWorld>, mut commands: Commands) {
|
||||||
let mut cameras_3d = main_world.query::<(RenderEntity, &Camera, Option<&mut SolariLighting>)>();
|
let mut cameras_3d = main_world.query::<(RenderEntity, &Camera, Option<&mut SolariLighting>)>();
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ mod node;
|
|||||||
mod prepare;
|
mod prepare;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
scene::{prepare_raytracing_scene_resources, RaytracingSceneBindings},
|
|
||||||
SolariPlugins,
|
SolariPlugins,
|
||||||
|
scene::{RaytracingSceneBindings, prepare_raytracing_scene_resources},
|
||||||
};
|
};
|
||||||
use bevy_app::{App, Plugin, PostUpdate};
|
use bevy_app::{App, Plugin, PostUpdate};
|
||||||
use bevy_asset::embedded_asset;
|
use bevy_asset::embedded_asset;
|
||||||
@@ -27,10 +27,10 @@ use bevy_ecs::{
|
|||||||
};
|
};
|
||||||
use bevy_light::AtmosphereEnvironmentMapLight;
|
use bevy_light::AtmosphereEnvironmentMapLight;
|
||||||
use bevy_pbr::DefaultOpaqueRendererMethod;
|
use bevy_pbr::DefaultOpaqueRendererMethod;
|
||||||
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
use bevy_reflect::{Reflect, std_traits::ReflectDefault};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
init_gpu_resource, renderer::RenderDevice, ExtractSchedule, Render, RenderApp, RenderStartup,
|
ExtractSchedule, Render, RenderApp, RenderStartup, RenderSystems, init_gpu_resource,
|
||||||
RenderSystems,
|
renderer::RenderDevice,
|
||||||
};
|
};
|
||||||
use bevy_shader::load_shader_library;
|
use bevy_shader::load_shader_library;
|
||||||
use extract::extract_solari_lighting;
|
use extract::extract_solari_lighting;
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
use super::prepare::{
|
use super::prepare::{
|
||||||
SolariLightingResources, LIGHT_TILE_BLOCKS, WORLD_CACHE_ACTIVE_CELLS_COUNT_OFFSET,
|
LIGHT_TILE_BLOCKS, SolariLightingResources, WORLD_CACHE_ACTIVE_CELLS_COUNT_OFFSET,
|
||||||
WORLD_CACHE_SIZE,
|
WORLD_CACHE_SIZE,
|
||||||
};
|
};
|
||||||
use crate::scene::RaytracingSceneBindings;
|
use crate::scene::RaytracingSceneBindings;
|
||||||
#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))]
|
#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))]
|
||||||
use bevy_anti_alias::dlss::ViewDlssRayReconstructionTextures;
|
use bevy_anti_alias::dlss::ViewDlssRayReconstructionTextures;
|
||||||
use bevy_asset::{load_embedded_asset, AssetServer, Handle};
|
use bevy_asset::{AssetServer, Handle, load_embedded_asset};
|
||||||
use bevy_core_pipeline::prepass::{
|
use bevy_core_pipeline::prepass::{
|
||||||
PreviousViewData, PreviousViewUniformOffset, PreviousViewUniforms, ViewPrepassTextures,
|
MOTION_VECTOR_PREPASS_FORMAT, PreviousViewData, PreviousViewUniformOffset,
|
||||||
MOTION_VECTOR_PREPASS_FORMAT,
|
PreviousViewUniforms, ViewPrepassTextures,
|
||||||
};
|
};
|
||||||
use bevy_ecs::{prelude::*, resource::Resource, system::Commands};
|
use bevy_ecs::{prelude::*, resource::Resource, system::Commands};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
diagnostic::RecordDiagnostics as _,
|
diagnostic::RecordDiagnostics as _,
|
||||||
render_resource::{
|
render_resource::{
|
||||||
binding_types::{
|
|
||||||
storage_buffer_sized, texture_2d, texture_depth_2d, texture_storage_2d, uniform_buffer,
|
|
||||||
uniform_buffer_sized,
|
|
||||||
},
|
|
||||||
BindGroupEntries, BindGroupLayoutDescriptor, BindGroupLayoutEntries,
|
BindGroupEntries, BindGroupLayoutDescriptor, BindGroupLayoutEntries,
|
||||||
CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor, LoadOp,
|
CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor, LoadOp,
|
||||||
PipelineCache, RenderPassDescriptor, ShaderStages, StorageTextureAccess, TextureFormat,
|
PipelineCache, RenderPassDescriptor, ShaderStages, StorageTextureAccess, TextureFormat,
|
||||||
TextureFormatFeatureFlags, TextureSampleType,
|
TextureFormatFeatureFlags, TextureSampleType,
|
||||||
|
binding_types::{
|
||||||
|
storage_buffer_sized, texture_2d, texture_depth_2d, texture_storage_2d, uniform_buffer,
|
||||||
|
uniform_buffer_sized,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
renderer::{RenderAdapter, RenderContext, RenderDevice, ViewQuery},
|
renderer::{RenderAdapter, RenderContext, RenderDevice, ViewQuery},
|
||||||
view::{ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms},
|
view::{ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use super::{
|
use super::{
|
||||||
|
StandardMaterialAssets,
|
||||||
allocator::{RetainedBindingArray, SlotAllocator},
|
allocator::{RetainedBindingArray, SlotAllocator},
|
||||||
instances::InstanceState,
|
instances::InstanceState,
|
||||||
StandardMaterialAssets,
|
|
||||||
};
|
};
|
||||||
use bevy_asset::AssetId;
|
use bevy_asset::AssetId;
|
||||||
use bevy_color::{ColorToComponents, LinearRgba};
|
use bevy_color::{ColorToComponents, LinearRgba};
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ impl BindGroupCacheState {
|
|||||||
// Binding arrays are dense, so freed slots still need something valid
|
// Binding arrays are dense, so freed slots still need something valid
|
||||||
// bound into them
|
// bound into them
|
||||||
let dummy_buffer = render_device.create_buffer(&BufferDescriptor {
|
let dummy_buffer = render_device.create_buffer(&BufferDescriptor {
|
||||||
label: Some("solari_dummy_binding_array_buffer"),
|
label: Some("solari_dummy_binding_array_buffer"),
|
||||||
size: 48,
|
size: 48,
|
||||||
usage: BufferUsages::STORAGE,
|
usage: BufferUsages::STORAGE,
|
||||||
mapped_at_creation: false,
|
mapped_at_creation: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ impl RaytracingSceneBindings {
|
|||||||
let light_sources = BufferBinding {
|
let light_sources = BufferBinding {
|
||||||
buffer: self.lights.sources.buffer().unwrap(),
|
buffer: self.lights.sources.buffer().unwrap(),
|
||||||
offset: 0,
|
offset: 0,
|
||||||
size: BufferSize::new(
|
size: BufferSize::new(
|
||||||
self.lights.index.len() as u64 * size_of::<GpuLightSource>() as u64,
|
self.lights.index.len() as u64 * size_of::<GpuLightSource>() as u64,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@@ -341,7 +341,7 @@ pub fn prepare_raytracing_scene_bind_group(
|
|||||||
#[derive(ShaderType, Default)]
|
#[derive(ShaderType, Default)]
|
||||||
pub struct GpuEnvironmentMapLight {
|
pub struct GpuEnvironmentMapLight {
|
||||||
pub light_from_world: Mat3,
|
pub light_from_world: Mat3,
|
||||||
pub intensity: f32,
|
pub intensity: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_environment_map_light<'a>(
|
fn prepare_environment_map_light<'a>(
|
||||||
@@ -364,7 +364,7 @@ fn prepare_environment_map_light<'a>(
|
|||||||
light_from_world: Mat3::from_quat(
|
light_from_world: Mat3::from_quat(
|
||||||
extracted_environment_map_light.rotation.inverse(),
|
extracted_environment_map_light.rotation.inverse(),
|
||||||
),
|
),
|
||||||
intensity: extracted_environment_map_light.intensity,
|
intensity: extracted_environment_map_light.intensity,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
None => (
|
None => (
|
||||||
|
|||||||
@@ -35,20 +35,20 @@ pub const MAX_TAPE_SLAB_COUNT: NonZeroU32 = NonZeroU32::new(500).unwrap();
|
|||||||
#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)]
|
#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct GpuInstanceGeometryIds {
|
pub struct GpuInstanceGeometryIds {
|
||||||
vertex_buffer_id: u32,
|
vertex_buffer_id: u32,
|
||||||
vertex_buffer_offset: u32,
|
vertex_buffer_offset: u32,
|
||||||
index_buffer_id: u32,
|
index_buffer_id: u32,
|
||||||
index_buffer_offset: u32,
|
index_buffer_offset: u32,
|
||||||
triangle_count: u32,
|
triangle_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)]
|
#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct GpuInstanceTapeIds {
|
pub struct GpuInstanceTapeIds {
|
||||||
aabb_buffer_id: u32,
|
aabb_buffer_id: u32,
|
||||||
aabb_buffer_offset: u32,
|
aabb_buffer_offset: u32,
|
||||||
aabb_count: u32,
|
aabb_count: u32,
|
||||||
metadata_buffer_id: u32,
|
metadata_buffer_id: u32,
|
||||||
metadata_buffer_offset: u32,
|
metadata_buffer_offset: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,27 +100,27 @@ pub enum BlasKey {
|
|||||||
/// Everything tracked per raytracing instance.
|
/// Everything tracked per raytracing instance.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
struct MeshInstance {
|
struct MeshInstance {
|
||||||
slot: u32,
|
slot: u32,
|
||||||
mesh: AssetId<Mesh>,
|
mesh: AssetId<Mesh>,
|
||||||
material: AssetId<StandardMaterial>,
|
material: AssetId<StandardMaterial>,
|
||||||
opacity: MeshBlasOpacity,
|
opacity: MeshBlasOpacity,
|
||||||
buffers: Option<(BufferId, BufferId)>,
|
buffers: Option<(BufferId, BufferId)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Everything tracked per raytracing instance.
|
/// Everything tracked per raytracing instance.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
struct TapeInstance {
|
struct TapeInstance {
|
||||||
slot: u32,
|
slot: u32,
|
||||||
tape: AssetId<Tape>,
|
tape: AssetId<Tape>,
|
||||||
material: AssetId<StandardMaterial>,
|
material: AssetId<StandardMaterial>,
|
||||||
opacity: TapeBlasOpacity,
|
opacity: TapeBlasOpacity,
|
||||||
buffers: Option<(BufferId, BufferId)>,
|
buffers: Option<(BufferId, BufferId)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MeshInstance {
|
impl MeshInstance {
|
||||||
fn blas_key(&self) -> MeshBlasKey {
|
fn blas_key(&self) -> MeshBlasKey {
|
||||||
MeshBlasKey {
|
MeshBlasKey {
|
||||||
mesh: self.mesh,
|
mesh: self.mesh,
|
||||||
opacity: self.opacity,
|
opacity: self.opacity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ impl MeshInstance {
|
|||||||
impl TapeInstance {
|
impl TapeInstance {
|
||||||
fn blas_key(&self) -> TapeBlasKey {
|
fn blas_key(&self) -> TapeBlasKey {
|
||||||
TapeBlasKey {
|
TapeBlasKey {
|
||||||
tape: self.tape,
|
tape: self.tape,
|
||||||
opacity: self.opacity,
|
opacity: self.opacity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,24 +262,24 @@ pub struct InstanceState {
|
|||||||
impl InstanceState {
|
impl InstanceState {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
vertex_buffers: RetainedBindingArray::new(),
|
vertex_buffers: RetainedBindingArray::new(),
|
||||||
index_buffers: RetainedBindingArray::new(),
|
index_buffers: RetainedBindingArray::new(),
|
||||||
aabb_buffers: RetainedBindingArray::new(),
|
aabb_buffers: RetainedBindingArray::new(),
|
||||||
tape_metadata_buffers: RetainedBindingArray::new(),
|
tape_metadata_buffers: RetainedBindingArray::new(),
|
||||||
transforms: storage_buffer("solari_transforms"),
|
transforms: storage_buffer("solari_transforms"),
|
||||||
previous_frame_transforms: storage_buffer("solari_previous_frame_transforms"),
|
previous_frame_transforms: storage_buffer("solari_previous_frame_transforms"),
|
||||||
geometry_ids: storage_buffer("solari_geometry_ids"),
|
geometry_ids: storage_buffer("solari_geometry_ids"),
|
||||||
tape_ids: storage_buffer("solari_tape_ids"),
|
tape_ids: storage_buffer("solari_tape_ids"),
|
||||||
material_ids: storage_buffer("solari_material_ids"),
|
material_ids: storage_buffer("solari_material_ids"),
|
||||||
blas_refs: storage_buffer("solari_blas_refs"),
|
blas_refs: storage_buffer("solari_blas_refs"),
|
||||||
slots: IndexAllocator::new(),
|
slots: IndexAllocator::new(),
|
||||||
retired_mesh_buffers: Vec::new(),
|
retired_mesh_buffers: Vec::new(),
|
||||||
retired_tape_buffers: Vec::new(),
|
retired_tape_buffers: Vec::new(),
|
||||||
records: EntityHashMap::default(),
|
records: EntityHashMap::default(),
|
||||||
live_count: 0,
|
live_count: 0,
|
||||||
pending_refresh: EntityHashSet::default(),
|
pending_refresh: EntityHashSet::default(),
|
||||||
object_instances: HashMap::default(),
|
object_instances: HashMap::default(),
|
||||||
material_instances: HashMap::default(),
|
material_instances: HashMap::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,11 +339,11 @@ pub type ChangedTapeInstanceFilter = (
|
|||||||
|
|
||||||
/// The scene state an instance resolves its GPU data against.
|
/// The scene state an instance resolves its GPU data against.
|
||||||
pub struct InstanceInputs<'a> {
|
pub struct InstanceInputs<'a> {
|
||||||
pub assets: &'a AssetState,
|
pub assets: &'a AssetState,
|
||||||
pub mesh_blas_manager: &'a MeshBlasManager,
|
pub mesh_blas_manager: &'a MeshBlasManager,
|
||||||
pub mesh_allocator: &'a MeshAllocator,
|
pub mesh_allocator: &'a MeshAllocator,
|
||||||
pub tape_blas_manager: &'a TapeBlasManager,
|
pub tape_blas_manager: &'a TapeBlasManager,
|
||||||
pub tape_allocator: &'a TapeAllocator,
|
pub tape_allocator: &'a TapeAllocator,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unlink<K: Eq + Hash>(map: &mut HashMap<K, EntityHashSet>, key: &K, entity: Entity) {
|
fn unlink<K: Eq + Hash>(map: &mut HashMap<K, EntityHashSet>, key: &K, entity: Entity) {
|
||||||
@@ -442,11 +442,11 @@ impl InstanceState {
|
|||||||
match mesh_instances.get(entity) {
|
match mesh_instances.get(entity) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
self.refresh_instance(inputs, lights, entity, InstanceQueryData::Mesh(data))
|
self.refresh_instance(inputs, lights, entity, InstanceQueryData::Mesh(data))
|
||||||
},
|
}
|
||||||
Err(_) => match tape_instances.get(entity) {
|
Err(_) => match tape_instances.get(entity) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
self.refresh_instance(inputs, lights, entity, InstanceQueryData::Tape(data))
|
self.refresh_instance(inputs, lights, entity, InstanceQueryData::Tape(data))
|
||||||
},
|
}
|
||||||
Err(_) => self.remove_instance(lights, entity),
|
Err(_) => self.remove_instance(lights, entity),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -529,10 +529,10 @@ impl InstanceState {
|
|||||||
match instance {
|
match instance {
|
||||||
Instance::Mesh(instance) => {
|
Instance::Mesh(instance) => {
|
||||||
self.resolve_mesh_instance(inputs, lights, entity, instance)
|
self.resolve_mesh_instance(inputs, lights, entity, instance)
|
||||||
},
|
}
|
||||||
Instance::Tape(instance) => {
|
Instance::Tape(instance) => {
|
||||||
self.resolve_tape_instance(inputs, lights, entity, instance)
|
self.resolve_tape_instance(inputs, lights, entity, instance)
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -838,10 +838,10 @@ impl InstanceState {
|
|||||||
match instance {
|
match instance {
|
||||||
Instance::Mesh(mut instance) => {
|
Instance::Mesh(mut instance) => {
|
||||||
self.deactivate_mesh_instance(lights, entity, &mut instance)
|
self.deactivate_mesh_instance(lights, entity, &mut instance)
|
||||||
},
|
}
|
||||||
Instance::Tape(mut instance) => {
|
Instance::Tape(mut instance) => {
|
||||||
self.deactivate_tape_instance(lights, entity, &mut instance)
|
self.deactivate_tape_instance(lights, entity, &mut instance)
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.slots.retire(instance.get_slot());
|
self.slots.retire(instance.get_slot());
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::scene::extract::{
|
|||||||
ExtractedRaytracingRectLight, ExtractedRaytracingSpotLight,
|
ExtractedRaytracingRectLight, ExtractedRaytracingSpotLight,
|
||||||
};
|
};
|
||||||
use bevy_ecs::{entity::Entity, query::Changed, system::Query};
|
use bevy_ecs::{entity::Entity, query::Changed, system::Query};
|
||||||
use bevy_math::{ops::cos, Vec3};
|
use bevy_math::{Vec3, ops::cos};
|
||||||
use bevy_platform::collections::{HashMap, HashSet};
|
use bevy_platform::collections::{HashMap, HashSet};
|
||||||
use bevy_render::render_resource::{AtomicSparseBufferVec, BufferUsages};
|
use bevy_render::render_resource::{AtomicSparseBufferVec, BufferUsages};
|
||||||
use bevy_render::{impl_atomic_pod, render_resource::AtomicPod};
|
use bevy_render::{impl_atomic_pod, render_resource::AtomicPod};
|
||||||
|
|||||||
@@ -227,11 +227,11 @@ pub fn prepare_raytracing_scene_resources(
|
|||||||
.instances
|
.instances
|
||||||
.remove_instances(&mut bindings.lights, removed_tape_instances.read());
|
.remove_instances(&mut bindings.lights, removed_tape_instances.read());
|
||||||
let inputs = InstanceInputs {
|
let inputs = InstanceInputs {
|
||||||
assets: &bindings.assets,
|
assets: &bindings.assets,
|
||||||
mesh_blas_manager: &mesh_blas_manager,
|
mesh_blas_manager: &mesh_blas_manager,
|
||||||
mesh_allocator: &mesh_allocator,
|
mesh_allocator: &mesh_allocator,
|
||||||
tape_blas_manager: &tape_blas_manager,
|
tape_blas_manager: &tape_blas_manager,
|
||||||
tape_allocator: &tape_allocator,
|
tape_allocator: &tape_allocator,
|
||||||
};
|
};
|
||||||
bindings.instances.refresh_instances(
|
bindings.instances.refresh_instances(
|
||||||
&inputs,
|
&inputs,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use super::{
|
|||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct TlasInstanceSetupPipeline {
|
pub struct TlasInstanceSetupPipeline {
|
||||||
pub layout: BindGroupLayoutDescriptor,
|
pub layout: BindGroupLayoutDescriptor,
|
||||||
pub id: Option<CachedComputePipelineId>,
|
pub id: Option<CachedComputePipelineId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromWorld for TlasInstanceSetupPipeline {
|
impl FromWorld for TlasInstanceSetupPipeline {
|
||||||
@@ -280,9 +280,9 @@ impl TlasState {
|
|||||||
|
|
||||||
let capacity = tlas_capacity_for(needed);
|
let capacity = tlas_capacity_for(needed);
|
||||||
self.instance_descriptors = Some(render_device.create_buffer(&BufferDescriptor {
|
self.instance_descriptors = Some(render_device.create_buffer(&BufferDescriptor {
|
||||||
label: Some("solari_tlas_instance_descriptors"),
|
label: Some("solari_tlas_instance_descriptors"),
|
||||||
size: u64::from(capacity) * tlas_build::INSTANCE_DESCRIPTOR_SIZE,
|
size: u64::from(capacity) * tlas_build::INSTANCE_DESCRIPTOR_SIZE,
|
||||||
usage: BufferUsages::STORAGE | BufferUsages::TLAS_INPUT,
|
usage: BufferUsages::STORAGE | BufferUsages::TLAS_INPUT,
|
||||||
mapped_at_creation: false,
|
mapped_at_creation: false,
|
||||||
}));
|
}));
|
||||||
self.instance_descriptor_capacity = capacity;
|
self.instance_descriptor_capacity = capacity;
|
||||||
@@ -332,9 +332,9 @@ impl TlasState {
|
|||||||
let capacity = tlas_capacity_for(needed);
|
let capacity = tlas_capacity_for(needed);
|
||||||
self.structures[current_index] = Some(render_device.wgpu_device().create_tlas(
|
self.structures[current_index] = Some(render_device.wgpu_device().create_tlas(
|
||||||
&CreateTlasDescriptor {
|
&CreateTlasDescriptor {
|
||||||
label: Some("tlas"),
|
label: Some("tlas"),
|
||||||
flags: AccelerationStructureFlags::PREFER_FAST_TRACE,
|
flags: AccelerationStructureFlags::PREFER_FAST_TRACE,
|
||||||
update_mode: AccelerationStructureUpdateMode::Build,
|
update_mode: AccelerationStructureUpdateMode::Build,
|
||||||
max_instances: capacity,
|
max_instances: capacity,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
@@ -356,18 +356,25 @@ pub fn build_raytracing_tlas(
|
|||||||
let bindings = &mut *bindings;
|
let bindings = &mut *bindings;
|
||||||
let current_index = bindings.tlas.current_index;
|
let current_index = bindings.tlas.current_index;
|
||||||
|
|
||||||
let built = match bindings.tlas.raw {
|
//let built = match bindings.tlas.raw {
|
||||||
Some(backend) => {
|
// Some(backend) => {
|
||||||
setup_tlas_instances(bindings, &pipeline_cache, &pipeline, &mut render_context)
|
// setup_tlas_instances(bindings, &pipeline_cache, &pipeline, &mut render_context)
|
||||||
&& build_tlas_raw(bindings, backend, &mut render_context)
|
// && build_tlas_raw(bindings, backend, &mut render_context)
|
||||||
},
|
// }
|
||||||
None => build_tlas_through_wgpu_core(
|
// None => build_tlas_through_wgpu_core(
|
||||||
bindings,
|
// bindings,
|
||||||
&mesh_blas_manager,
|
// &mesh_blas_manager,
|
||||||
&tape_blas_manager,
|
// &tape_blas_manager,
|
||||||
&mut render_context,
|
// &mut render_context,
|
||||||
),
|
// ),
|
||||||
};
|
//};
|
||||||
|
|
||||||
|
let built = build_tlas_through_wgpu_core(
|
||||||
|
bindings,
|
||||||
|
&mesh_blas_manager,
|
||||||
|
&tape_blas_manager,
|
||||||
|
&mut render_context,
|
||||||
|
);
|
||||||
|
|
||||||
if built {
|
if built {
|
||||||
bindings.tlas.built[current_index] = true;
|
bindings.tlas.built[current_index] = true;
|
||||||
@@ -424,7 +431,7 @@ fn setup_tlas_instances(
|
|||||||
let time_span = diagnostics.time_span(command_encoder, "setup_tlas_instances");
|
let time_span = diagnostics.time_span(command_encoder, "setup_tlas_instances");
|
||||||
{
|
{
|
||||||
let mut pass = command_encoder.begin_compute_pass(&ComputePassDescriptor {
|
let mut pass = command_encoder.begin_compute_pass(&ComputePassDescriptor {
|
||||||
label: Some("setup_tlas_instances"),
|
label: Some("setup_tlas_instances"),
|
||||||
timestamp_writes: None,
|
timestamp_writes: None,
|
||||||
});
|
});
|
||||||
pass.set_pipeline(compute_pipeline);
|
pass.set_pipeline(compute_pipeline);
|
||||||
@@ -437,11 +444,11 @@ fn setup_tlas_instances(
|
|||||||
[
|
[
|
||||||
BufferTransition {
|
BufferTransition {
|
||||||
buffer: &**instances,
|
buffer: &**instances,
|
||||||
state: BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
|
state: BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
|
||||||
},
|
},
|
||||||
BufferTransition {
|
BufferTransition {
|
||||||
buffer: &**scratch,
|
buffer: &**scratch,
|
||||||
state: BufferUses::ACCELERATION_STRUCTURE_SCRATCH,
|
state: BufferUses::ACCELERATION_STRUCTURE_SCRATCH,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ use bevy_render::{
|
|||||||
renderer::RenderDevice,
|
renderer::RenderDevice,
|
||||||
};
|
};
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use wgpu::{hal, BufferUses};
|
use wgpu::{BufferUses, hal};
|
||||||
|
|
||||||
/// Size of one TLAS instance descriptor, on both Vulkan and DXR.
|
/// Size of one TLAS instance descriptor, on both Vulkan and DXR.
|
||||||
pub const INSTANCE_DESCRIPTOR_SIZE: u64 = 64;
|
pub const INSTANCE_DESCRIPTOR_SIZE: u64 = 64;
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ pub fn extract_raytracing_scene_tapes_and_materials(
|
|||||||
/// world.
|
/// world.
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
pub struct StandardMaterialAssets {
|
pub struct StandardMaterialAssets {
|
||||||
materials: HashMap<AssetId<StandardMaterial>, StandardMaterial>,
|
materials: HashMap<AssetId<StandardMaterial>, StandardMaterial>,
|
||||||
/// Materials added or modified this frame.
|
/// Materials added or modified this frame.
|
||||||
pub changed: Vec<AssetId<StandardMaterial>>,
|
pub changed: Vec<AssetId<StandardMaterial>>,
|
||||||
/// Materials removed this frame.
|
/// Materials removed this frame.
|
||||||
@@ -213,54 +213,54 @@ pub fn extract_raytracing_material_assets(
|
|||||||
render_materials.materials.insert(*id, material.clone());
|
render_materials.materials.insert(*id, material.clone());
|
||||||
render_materials.changed.push(*id);
|
render_materials.changed.push(*id);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
AssetEvent::Removed { id } => {
|
AssetEvent::Removed { id } => {
|
||||||
render_materials.materials.remove(id);
|
render_materials.materials.remove(id);
|
||||||
render_materials.removed.push(*id);
|
render_materials.removed.push(*id);
|
||||||
},
|
}
|
||||||
AssetEvent::Unused { .. } | AssetEvent::LoadedWithDependencies { .. } => {},
|
AssetEvent::Unused { .. } | AssetEvent::LoadedWithDependencies { .. } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy, PartialEq, Debug)]
|
#[derive(Component, Clone, Copy, PartialEq, Debug)]
|
||||||
pub struct ExtractedRaytracingDirectionalLight {
|
pub struct ExtractedRaytracingDirectionalLight {
|
||||||
pub direction_to_light: Vec3,
|
pub direction_to_light: Vec3,
|
||||||
pub illuminance: Vec3,
|
pub illuminance: Vec3,
|
||||||
pub sun_disk_angular_size: f32,
|
pub sun_disk_angular_size: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy, PartialEq, Debug)]
|
#[derive(Component, Clone, Copy, PartialEq, Debug)]
|
||||||
pub struct ExtractedRaytracingPointLight {
|
pub struct ExtractedRaytracingPointLight {
|
||||||
pub position: Vec3,
|
pub position: Vec3,
|
||||||
pub radius: f32,
|
pub radius: f32,
|
||||||
pub intensity: Vec3,
|
pub intensity: Vec3,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy, PartialEq, Debug)]
|
#[derive(Component, Clone, Copy, PartialEq, Debug)]
|
||||||
pub struct ExtractedRaytracingSpotLight {
|
pub struct ExtractedRaytracingSpotLight {
|
||||||
pub position: Vec3,
|
pub position: Vec3,
|
||||||
pub radius: f32,
|
pub radius: f32,
|
||||||
pub intensity: Vec3,
|
pub intensity: Vec3,
|
||||||
pub axis: Vec3,
|
pub axis: Vec3,
|
||||||
pub cos_inner: f32,
|
pub cos_inner: f32,
|
||||||
pub cos_outer: f32,
|
pub cos_outer: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy, PartialEq, Debug)]
|
#[derive(Component, Clone, Copy, PartialEq, Debug)]
|
||||||
pub struct ExtractedRaytracingRectLight {
|
pub struct ExtractedRaytracingRectLight {
|
||||||
pub center: Vec3,
|
pub center: Vec3,
|
||||||
pub edge_x: Vec3,
|
pub edge_x: Vec3,
|
||||||
pub edge_y: Vec3,
|
pub edge_y: Vec3,
|
||||||
pub area: f32,
|
pub area: f32,
|
||||||
pub radiance: Vec3,
|
pub radiance: Vec3,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource, Default, Clone, PartialEq)]
|
#[derive(Resource, Default, Clone, PartialEq)]
|
||||||
pub struct ExtractedEnvironmentMapLight {
|
pub struct ExtractedEnvironmentMapLight {
|
||||||
pub cubemap: Option<Handle<Image>>,
|
pub cubemap: Option<Handle<Image>>,
|
||||||
pub intensity: f32,
|
pub intensity: f32,
|
||||||
pub rotation: Quat,
|
pub rotation: Quat,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lights whose extracted data needs updating.
|
/// Lights whose extracted data needs updating.
|
||||||
@@ -337,8 +337,8 @@ pub fn extract_raytracing_directional_lights(
|
|||||||
}
|
}
|
||||||
|
|
||||||
entity_commands.insert(ExtractedRaytracingDirectionalLight {
|
entity_commands.insert(ExtractedRaytracingDirectionalLight {
|
||||||
direction_to_light: transform.back().into(),
|
direction_to_light: transform.back().into(),
|
||||||
illuminance: LinearRgba::from(directional_light.color).to_vec3()
|
illuminance: LinearRgba::from(directional_light.color).to_vec3()
|
||||||
* directional_light.illuminance,
|
* directional_light.illuminance,
|
||||||
sun_disk_angular_size: sun_disk.unwrap_or_default().angular_size,
|
sun_disk_angular_size: sun_disk.unwrap_or_default().angular_size,
|
||||||
});
|
});
|
||||||
@@ -370,8 +370,8 @@ pub fn extract_raytracing_point_lights(
|
|||||||
}
|
}
|
||||||
|
|
||||||
entity_commands.insert(ExtractedRaytracingPointLight {
|
entity_commands.insert(ExtractedRaytracingPointLight {
|
||||||
position: transform.translation(),
|
position: transform.translation(),
|
||||||
radius: point_light.radius,
|
radius: point_light.radius,
|
||||||
// Map from luminous power in lumens to luminous intensity in candela
|
// Map from luminous power in lumens to luminous intensity in candela
|
||||||
intensity: LinearRgba::from(point_light.color).to_vec3() * point_light.intensity
|
intensity: LinearRgba::from(point_light.color).to_vec3() * point_light.intensity
|
||||||
/ (4.0 * PI),
|
/ (4.0 * PI),
|
||||||
@@ -407,11 +407,11 @@ pub fn extract_raytracing_spot_lights(
|
|||||||
let inner_angle = spot_light.inner_angle.min(outer_angle);
|
let inner_angle = spot_light.inner_angle.min(outer_angle);
|
||||||
|
|
||||||
entity_commands.insert(ExtractedRaytracingSpotLight {
|
entity_commands.insert(ExtractedRaytracingSpotLight {
|
||||||
position: transform.translation(),
|
position: transform.translation(),
|
||||||
radius: spot_light.radius,
|
radius: spot_light.radius,
|
||||||
intensity: LinearRgba::from(spot_light.color).to_vec3() * spot_light.intensity
|
intensity: LinearRgba::from(spot_light.color).to_vec3() * spot_light.intensity
|
||||||
/ (4.0 * PI),
|
/ (4.0 * PI),
|
||||||
axis: transform.forward().into(),
|
axis: transform.forward().into(),
|
||||||
cos_inner: cos(inner_angle),
|
cos_inner: cos(inner_angle),
|
||||||
cos_outer: cos(outer_angle),
|
cos_outer: cos(outer_angle),
|
||||||
});
|
});
|
||||||
@@ -478,9 +478,9 @@ pub fn extract_raytracing_environment_map_light(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let env_map_light = ExtractedEnvironmentMapLight {
|
let env_map_light = ExtractedEnvironmentMapLight {
|
||||||
cubemap: Some(env_map.specular_map.clone()),
|
cubemap: Some(env_map.specular_map.clone()),
|
||||||
intensity: env_map.intensity,
|
intensity: env_map.intensity,
|
||||||
rotation: env_map.rotation,
|
rotation: env_map.rotation,
|
||||||
};
|
};
|
||||||
|
|
||||||
if extracted_env_map_light.cubemap.is_none() {
|
if extracted_env_map_light.cubemap.is_none() {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ use bevy_platform::collections::HashMap;
|
|||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
diagnostic::{DiagnosticsRecorder, RecordDiagnostics},
|
diagnostic::{DiagnosticsRecorder, RecordDiagnostics},
|
||||||
mesh::{
|
mesh::{
|
||||||
allocator::{MeshAllocator, MeshBufferSlice},
|
|
||||||
RenderMesh,
|
RenderMesh,
|
||||||
|
allocator::{MeshAllocator, MeshBufferSlice},
|
||||||
},
|
},
|
||||||
render_asset::ExtractedAssets,
|
render_asset::ExtractedAssets,
|
||||||
render_resource::*,
|
render_resource::*,
|
||||||
@@ -174,6 +174,11 @@ pub fn prepare_raytracing_blas(
|
|||||||
render_queue: Res<RenderQueue>,
|
render_queue: Res<RenderQueue>,
|
||||||
mut diagnostics: Option<ResMut<DiagnosticsRecorder>>,
|
mut diagnostics: Option<ResMut<DiagnosticsRecorder>>,
|
||||||
) {
|
) {
|
||||||
|
std::process::Command::new("touch")
|
||||||
|
.arg("/tmp/trigger")
|
||||||
|
.status()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
blas_manager.changed.clear();
|
blas_manager.changed.clear();
|
||||||
|
|
||||||
// Delete BLAS for deleted or modified meshes
|
// Delete BLAS for deleted or modified meshes
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use bevy_derive::{Deref, DerefMut};
|
|||||||
use bevy_ecs::{component::Component, prelude::ReflectComponent, template::FromTemplate};
|
use bevy_ecs::{component::Component, prelude::ReflectComponent, template::FromTemplate};
|
||||||
use bevy_mesh::Mesh;
|
use bevy_mesh::Mesh;
|
||||||
use bevy_pbr::{MeshMaterial3d, StandardMaterial};
|
use bevy_pbr::{MeshMaterial3d, StandardMaterial};
|
||||||
use bevy_reflect::{prelude::ReflectDefault, Reflect};
|
use bevy_reflect::{Reflect, prelude::ReflectDefault};
|
||||||
use bevy_render::sync_world::SyncToRenderWorld;
|
use bevy_render::sync_world::SyncToRenderWorld;
|
||||||
use bevy_transform::components::Transform;
|
use bevy_transform::components::Transform;
|
||||||
use derive_more::derive::From;
|
use derive_more::derive::From;
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ use bevy_ecs::{
|
|||||||
use bevy_mesh::MeshRaytracingFlags;
|
use bevy_mesh::MeshRaytracingFlags;
|
||||||
use bevy_platform::collections::HashMap;
|
use bevy_platform::collections::HashMap;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
diagnostic::{DiagnosticsRecorder, RecordDiagnostics},
|
diagnostic::RecordDiagnostics,
|
||||||
render_asset::{ExtractedAssets, RenderAssets},
|
render_asset::{ExtractedAssets, RenderAssets},
|
||||||
render_resource::*,
|
render_resource::*,
|
||||||
renderer::{RenderDevice, RenderQueue},
|
renderer::{RenderContext, RenderDevice, RenderQueue},
|
||||||
};
|
};
|
||||||
use bevy_tape_load::{
|
use bevy_tape_load::{
|
||||||
Tape,
|
Tape,
|
||||||
@@ -217,17 +217,14 @@ pub fn compile_raytracing_blas(
|
|||||||
tapes: Res<RenderAssets<RenderTape>>,
|
tapes: Res<RenderAssets<RenderTape>>,
|
||||||
tape_allocator: Res<TapeAllocator>,
|
tape_allocator: Res<TapeAllocator>,
|
||||||
render_device: Res<RenderDevice>,
|
render_device: Res<RenderDevice>,
|
||||||
render_queue: Res<RenderQueue>,
|
mut render_context: RenderContext,
|
||||||
pipeline_cache: Res<PipelineCache>,
|
pipeline_cache: Res<PipelineCache>,
|
||||||
replacement_modules: Res<ReplacementModules>,
|
replacement_modules: Res<ReplacementModules>,
|
||||||
mut diagnostics: Option<ResMut<DiagnosticsRecorder>>,
|
|
||||||
) {
|
) {
|
||||||
let mut command_encoder = render_device.create_command_encoder(&CommandEncoderDescriptor {
|
let diagnostics = render_context.diagnostic_recorder();
|
||||||
label: Some("blas_build_command_encoder"),
|
let diagnostics = diagnostics.as_deref();
|
||||||
});
|
let mut command_encoder = render_context.command_encoder();
|
||||||
let time_span = diagnostics
|
let time_span = diagnostics.time_span(command_encoder, "tape_blas_build");
|
||||||
.as_mut()
|
|
||||||
.map(|diagnostics| diagnostics.time_span(&mut command_encoder, "tape_blas_build"));
|
|
||||||
let mut compute_pass = command_encoder.begin_compute_pass(&ComputePassDescriptor {
|
let mut compute_pass = command_encoder.begin_compute_pass(&ComputePassDescriptor {
|
||||||
label: Some("enable_gen"),
|
label: Some("enable_gen"),
|
||||||
timestamp_writes: None,
|
timestamp_writes: None,
|
||||||
@@ -303,10 +300,7 @@ pub fn compile_raytracing_blas(
|
|||||||
drop(compute_pass);
|
drop(compute_pass);
|
||||||
|
|
||||||
command_encoder.build_acceleration_structures(&build_entries, &[]);
|
command_encoder.build_acceleration_structures(&build_entries, &[]);
|
||||||
if let Some(time_span) = time_span {
|
time_span.end(&mut command_encoder);
|
||||||
time_span.end(&mut command_encoder);
|
|
||||||
}
|
|
||||||
render_queue.submit([command_encoder.finish()]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_raytracing_blas(
|
pub fn delete_raytracing_blas(
|
||||||
|
|||||||
@@ -142,9 +142,6 @@ fn compile_replacement_shader(name: &str, entry_point: String, stage: naga::Shad
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo::rerun-if-changed=build.rs");
|
|
||||||
println!("cargo::rerun-if-changed=Cargo.lock");
|
|
||||||
|
|
||||||
if std::fs::exists("shaders_out").unwrap() {
|
if std::fs::exists("shaders_out").unwrap() {
|
||||||
std::fs::remove_dir_all("shaders_out").unwrap();
|
std::fs::remove_dir_all("shaders_out").unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
|
#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
|
||||||
|
#![recursion_limit = "256"]
|
||||||
/**
|
/**
|
||||||
* Defines the [Tape] asset, which responds to a Tape Drive tape.
|
* Defines the [Tape] asset, which responds to a Tape Drive tape.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -31,21 +31,21 @@ impl SphereTapeBuilder {
|
|||||||
let pos = tape.push_instruction(
|
let pos = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAPosition,
|
opcode: SSAOpcode::SSAPosition,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![],
|
vec![],
|
||||||
);
|
);
|
||||||
let sphere = tape.push_instruction(
|
let sphere = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSASDFSphere,
|
opcode: SSAOpcode::SSASDFSphere,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![pos[0], pos[1], pos[2], SSAInput::Constant(radius)],
|
vec![pos[0], pos[1], pos[2], SSAInput::Constant(radius)],
|
||||||
);
|
);
|
||||||
tape.push_instruction(
|
tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAReturn,
|
opcode: SSAOpcode::SSAReturn,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
sphere,
|
sphere,
|
||||||
);
|
);
|
||||||
|
|||||||
+24
-24
@@ -42,7 +42,7 @@ use rand::{RngExt, SeedableRng, rngs::SmallRng};
|
|||||||
struct Args {
|
struct Args {
|
||||||
/// use the reference pathtracer instead of the realtime lighting system.
|
/// use the reference pathtracer instead of the realtime lighting system.
|
||||||
#[argh(switch)]
|
#[argh(switch)]
|
||||||
pathtracer: Option<bool>,
|
pathtracer: Option<bool>,
|
||||||
/// stress test a scene with many lights.
|
/// stress test a scene with many lights.
|
||||||
#[argh(switch)]
|
#[argh(switch)]
|
||||||
many_lights: Option<bool>,
|
many_lights: Option<bool>,
|
||||||
@@ -102,14 +102,14 @@ fn create_csg(seed: u64) -> SSATape {
|
|||||||
let pos = tape.push_instruction(
|
let pos = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAPosition,
|
opcode: SSAOpcode::SSAPosition,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![],
|
vec![],
|
||||||
);
|
);
|
||||||
let offset = tape.push_instruction(
|
let offset = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAAdd,
|
opcode: SSAOpcode::SSAAdd,
|
||||||
size: 3,
|
size: 3,
|
||||||
},
|
},
|
||||||
vec![
|
vec![
|
||||||
pos[0],
|
pos[0],
|
||||||
@@ -123,14 +123,14 @@ fn create_csg(seed: u64) -> SSATape {
|
|||||||
let sin = tape.push_instruction(
|
let sin = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSASin,
|
opcode: SSAOpcode::SSASin,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![pos[3]],
|
vec![pos[3]],
|
||||||
);
|
);
|
||||||
let offset = tape.push_instruction(
|
let offset = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAAdd,
|
opcode: SSAOpcode::SSAAdd,
|
||||||
size: 3,
|
size: 3,
|
||||||
},
|
},
|
||||||
vec![
|
vec![
|
||||||
offset[0],
|
offset[0],
|
||||||
@@ -144,7 +144,7 @@ fn create_csg(seed: u64) -> SSATape {
|
|||||||
let sphere = tape.push_instruction(
|
let sphere = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSASDFSphere,
|
opcode: SSAOpcode::SSASDFSphere,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![
|
vec![
|
||||||
offset[0],
|
offset[0],
|
||||||
@@ -156,7 +156,7 @@ fn create_csg(seed: u64) -> SSATape {
|
|||||||
let torus = tape.push_instruction(
|
let torus = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSASDFTorus,
|
opcode: SSAOpcode::SSASDFTorus,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![
|
vec![
|
||||||
pos[0],
|
pos[0],
|
||||||
@@ -169,21 +169,21 @@ fn create_csg(seed: u64) -> SSATape {
|
|||||||
let min = tape.push_instruction(
|
let min = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAMin,
|
opcode: SSAOpcode::SSAMin,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![sphere[0], torus[0]],
|
vec![sphere[0], torus[0]],
|
||||||
);
|
);
|
||||||
let scaled_time = tape.push_instruction(
|
let scaled_time = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAMul,
|
opcode: SSAOpcode::SSAMul,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![pos[3], SSAInput::Constant(0.2)],
|
vec![pos[3], SSAInput::Constant(0.2)],
|
||||||
);
|
);
|
||||||
let moving_pos = tape.push_instruction(
|
let moving_pos = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAAdd,
|
opcode: SSAOpcode::SSAAdd,
|
||||||
size: 3,
|
size: 3,
|
||||||
},
|
},
|
||||||
vec![
|
vec![
|
||||||
pos[0],
|
pos[0],
|
||||||
@@ -197,7 +197,7 @@ fn create_csg(seed: u64) -> SSATape {
|
|||||||
let pos_times_20 = tape.push_instruction(
|
let pos_times_20 = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAMul,
|
opcode: SSAOpcode::SSAMul,
|
||||||
size: 3,
|
size: 3,
|
||||||
},
|
},
|
||||||
vec![
|
vec![
|
||||||
moving_pos[0],
|
moving_pos[0],
|
||||||
@@ -211,14 +211,14 @@ fn create_csg(seed: u64) -> SSATape {
|
|||||||
let sine_of_the_times = tape.push_instruction(
|
let sine_of_the_times = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSASin,
|
opcode: SSAOpcode::SSASin,
|
||||||
size: 3,
|
size: 3,
|
||||||
},
|
},
|
||||||
pos_times_20,
|
pos_times_20,
|
||||||
);
|
);
|
||||||
let sine_of_the_times = tape.push_instruction(
|
let sine_of_the_times = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAMul,
|
opcode: SSAOpcode::SSAMul,
|
||||||
size: 3,
|
size: 3,
|
||||||
},
|
},
|
||||||
vec![
|
vec![
|
||||||
sine_of_the_times[0],
|
sine_of_the_times[0],
|
||||||
@@ -232,28 +232,28 @@ fn create_csg(seed: u64) -> SSATape {
|
|||||||
let multiply_out_1 = tape.push_instruction(
|
let multiply_out_1 = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAMul,
|
opcode: SSAOpcode::SSAMul,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![sine_of_the_times[0], sine_of_the_times[1]],
|
vec![sine_of_the_times[0], sine_of_the_times[1]],
|
||||||
);
|
);
|
||||||
let multiply_out_2 = tape.push_instruction(
|
let multiply_out_2 = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAMul,
|
opcode: SSAOpcode::SSAMul,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![multiply_out_1[0], sine_of_the_times[2]],
|
vec![multiply_out_1[0], sine_of_the_times[2]],
|
||||||
);
|
);
|
||||||
let displacement = tape.push_instruction(
|
let displacement = tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAAdd,
|
opcode: SSAOpcode::SSAAdd,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
vec![min[0], multiply_out_2[0]],
|
vec![min[0], multiply_out_2[0]],
|
||||||
);
|
);
|
||||||
tape.push_instruction(
|
tape.push_instruction(
|
||||||
SSAOpcodeSized {
|
SSAOpcodeSized {
|
||||||
opcode: SSAOpcode::SSAReturn,
|
opcode: SSAOpcode::SSAReturn,
|
||||||
size: 1,
|
size: 1,
|
||||||
},
|
},
|
||||||
displacement,
|
displacement,
|
||||||
);
|
);
|
||||||
@@ -320,9 +320,9 @@ fn setup_pica_pica(
|
|||||||
let csg = create_csg(0);
|
let csg = create_csg(0);
|
||||||
|
|
||||||
let tape = Tape {
|
let tape = Tape {
|
||||||
raytracing: MeshRaytracingFlags::OPAQUE,
|
raytracing: MeshRaytracingFlags::OPAQUE,
|
||||||
parts: csg,
|
parts: csg,
|
||||||
seed: 0,
|
seed: 0,
|
||||||
subdivision: 8,
|
subdivision: 8,
|
||||||
};
|
};
|
||||||
let loaded_tape = asset_server.add(tape);
|
let loaded_tape = asset_server.add(tape);
|
||||||
@@ -423,7 +423,7 @@ fn setup_many_lights(
|
|||||||
match plane_mesh.attribute_mut(Mesh::ATTRIBUTE_UV_0).unwrap() {
|
match plane_mesh.attribute_mut(Mesh::ATTRIBUTE_UV_0).unwrap() {
|
||||||
VertexAttributeValues::Float32x2(items) => {
|
VertexAttributeValues::Float32x2(items) => {
|
||||||
items.iter_mut().flatten().for_each(|x| *x *= 3.0);
|
items.iter_mut().flatten().for_each(|x| *x *= 3.0);
|
||||||
},
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
let plane_mesh = meshes.add(plane_mesh);
|
let plane_mesh = meshes.add(plane_mesh);
|
||||||
@@ -737,7 +737,7 @@ fn toggle_lights(
|
|||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct PatrolPath {
|
struct PatrolPath {
|
||||||
path: Vec<(Vec3, Quat)>,
|
path: Vec<(Vec3, Quat)>,
|
||||||
i: usize,
|
i: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn patrol_path(mut query: Query<(&mut PatrolPath, &mut Transform)>, time: Res<Time<Virtual>>) {
|
fn patrol_path(mut query: Query<(&mut PatrolPath, &mut Transform)>, time: Res<Time<Virtual>>) {
|
||||||
@@ -802,10 +802,10 @@ fn update_control_text(
|
|||||||
match robot_light_material.and_then(|m| materials.get(&m.0)) {
|
match robot_light_material.and_then(|m| materials.get(&m.0)) {
|
||||||
Some(robot_light_material) if robot_light_material.emissive != LinearRgba::BLACK => {
|
Some(robot_light_material) if robot_light_material.emissive != LinearRgba::BLACK => {
|
||||||
text.0.push_str("\n(2): Disable robot emissive light");
|
text.0.push_str("\n(2): Disable robot emissive light");
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
text.0.push_str("\n(2): Enable robot emissive light");
|
text.0.push_str("\n(2): Enable robot emissive light");
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user