Build renderer and material component foundations

Add dedicated skinned rendering, pose restoration, shared Material and Material Instance slots, registry-driven components, Surface/Solari integration, transactional schema upgrades, navigation authoring, documentation, and evaluation evidence.
This commit is contained in:
Rbanh committed 2026-07-12 00:24:06 -04:00
1 parent 0553a85220
commit 0798aa5d57
169 files changed
+27098 -3469

No files matched your search

+1
View File
@@ -18,6 +18,7 @@ avian3d.workspace = true
bevy.workspace = true
bevy_core_pipeline.workspace = true
bevy_solari.workspace = true
blacksite_surface.workspace = true
protocol.workspace = true
shared.workspace = true
sim.workspace = true
+131 -12
View File
@@ -5,7 +5,7 @@ use bevy::core_pipeline::prepass::{
DeferredPrepass, DeferredPrepassDoubleBuffer, DepthPrepass, DepthPrepassDoubleBuffer,
MotionVectorPrepass,
};
use bevy::mesh::{Indices, PrimitiveTopology};
use bevy::mesh::{morph::MeshMorphWeights, skinning::SkinnedMesh, Indices, PrimitiveTopology};
use bevy::pbr::{DefaultOpaqueRendererMethod, ExtractedDirectionalLight};
use bevy::prelude::*;
use bevy::render::render_resource::TextureUsages;
@@ -14,6 +14,7 @@ use bevy::render::{Render, RenderApp, RenderSystems};
use bevy_solari::prelude::{RaytracingMesh3d, SolariLighting};
use bevy_solari::scene::RaytracingSceneBindings;
use bevy_solari::SolariPlugins;
use blacksite_surface::{SurfaceEvaluatorRegistry, SurfaceMaterial};
use settings::{GiPath, ProjectSettings, RenderingCapabilities};
use shared::{LevelObject, RaytracingExcluded};
use std::sync::{Arc, Mutex};
@@ -24,6 +25,10 @@ pub struct SolariRaytracingSceneStats {
pub tagged_meshes: usize,
pub excluded_meshes: usize,
pub unsupported_meshes: usize,
/// Skinned or morphed meshes deliberately omitted until Solari consumes deformed vertices.
pub deformed_meshes_excluded: usize,
pub surface_material_meshes: usize,
pub surface_materials_missing_evaluator: usize,
pub missing_level_root_meshes: usize,
pub emissive_meshes: usize,
pub compatible_mesh_assets: usize,
@@ -61,7 +66,8 @@ pub struct SolariRenderingPlugin;
impl Plugin for SolariRenderingPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(SolariPlugins)
app.add_plugins(blacksite_surface::SurfaceMaterialPlugin)
.add_plugins(SolariPlugins)
.init_resource::<RenderingCapabilities>()
.init_resource::<settings::EffectiveRenderStack>()
.init_resource::<SolariRaytracingSceneStats>()
@@ -213,11 +219,16 @@ fn sync_hydrated_raytracing_meshes(
mut commands: Commands,
mut stats: ResMut<SolariRaytracingSceneStats>,
materials: Res<Assets<StandardMaterial>>,
surface_materials: Res<Assets<SurfaceMaterial>>,
surface_evaluators: Res<SurfaceEvaluatorRegistry>,
mesh_assets: Res<Assets<Mesh>>,
meshes: Query<(
Entity,
&Mesh3d,
Option<&MeshMaterial3d<StandardMaterial>>,
Option<&MeshMaterial3d<SurfaceMaterial>>,
Option<&SkinnedMesh>,
Option<&MeshMorphWeights>,
Option<&RaytracingMesh3d>,
Option<&RaytracingExcluded>,
)>,
@@ -230,6 +241,9 @@ fn sync_hydrated_raytracing_meshes(
next_stats.tagged_meshes = 0;
next_stats.excluded_meshes = 0;
next_stats.unsupported_meshes = 0;
next_stats.deformed_meshes_excluded = 0;
next_stats.surface_material_meshes = 0;
next_stats.surface_materials_missing_evaluator = 0;
next_stats.missing_level_root_meshes = 0;
next_stats.emissive_meshes = 0;
next_stats.compatible_mesh_assets = 0;
@@ -255,7 +269,9 @@ fn sync_hydrated_raytracing_meshes(
return;
}
for (entity, mesh, material, rt_mesh, excluded) in &meshes {
for (entity, mesh, standard_material, surface_material, skin, morph, rt_mesh, excluded) in
&meshes
{
if excluded.is_some() {
next_stats.excluded_meshes += 1;
if rt_mesh.is_some() {
@@ -271,19 +287,79 @@ fn sync_hydrated_raytracing_meshes(
next_stats.project_meshes += 1;
let Some(material) = material else {
// Bevy 0.19's mesh allocator exposes the source vertex slab to Solari, not the
// morph-then-skin output consumed by raster rendering. Tagging this mesh would trace the
// bind pose, so omit it until the fork owns an instance-keyed deformed vertex/BLAS path.
let mesh_has_morph_targets = mesh_assets
.get(&mesh.0)
.and_then(Mesh::get_morph_targets)
.is_some();
if !solari_deformation_is_supported(skin.is_some(), morph.is_some(), mesh_has_morph_targets)
{
next_stats.deformed_meshes_excluded += 1;
if rt_mesh.is_some() {
commands.entity(entity).remove::<RaytracingMesh3d>();
}
continue;
}
if standard_material.is_none() && surface_material.is_none() {
next_stats.unsupported_meshes += 1;
if rt_mesh.is_some() {
commands.entity(entity).remove::<RaytracingMesh3d>();
}
continue;
};
}
if materials
.get(&material.0)
.is_some_and(|material| material.emissive.to_vec3() != Vec3::ZERO)
{
if let Some(surface_handle) = surface_material {
next_stats.surface_material_meshes += 1;
let Some(material) = surface_materials.get(&surface_handle.0) else {
next_stats.unsupported_meshes += 1;
if rt_mesh.is_some() {
commands.entity(entity).remove::<RaytracingMesh3d>();
}
continue;
};
if !solari_alpha_mode_is_supported(material.base.alpha_mode) {
next_stats.unsupported_meshes += 1;
if rt_mesh.is_some() {
commands.entity(entity).remove::<RaytracingMesh3d>();
}
continue;
}
if !surface_evaluators
.evaluators
.contains_key(&material.extension.uniform.shader_id)
{
next_stats.surface_materials_missing_evaluator += 1;
next_stats.unsupported_meshes += 1;
if rt_mesh.is_some() {
commands.entity(entity).remove::<RaytracingMesh3d>();
}
continue;
}
// A custom evaluator may emit light as a function of parameters, textures, or world
// position. Conservatively register Surface instances as potential emissive sources;
// zero-emission samples contribute no energy.
next_stats.emissive_meshes += 1;
} else if let Some(standard_handle) = standard_material {
let Some(material) = materials.get(&standard_handle.0) else {
next_stats.unsupported_meshes += 1;
if rt_mesh.is_some() {
commands.entity(entity).remove::<RaytracingMesh3d>();
}
continue;
};
if !solari_alpha_mode_is_supported(material.alpha_mode) {
next_stats.unsupported_meshes += 1;
if rt_mesh.is_some() {
commands.entity(entity).remove::<RaytracingMesh3d>();
}
continue;
}
if material.emissive.to_vec3() != Vec3::ZERO {
next_stats.emissive_meshes += 1;
}
}
match mesh_assets
@@ -323,7 +399,7 @@ fn sync_hydrated_raytracing_meshes(
if *stats != next_stats {
info!(
"Solari mesh eligibility: requested={:?} eligible={} tagged={} compatible_assets={} incompatible_assets={} missing_tangents={} missing_u32_indices={} unsupported={} excluded={} outside_level_roots={} emissive={}",
"Solari mesh eligibility: requested={:?} eligible={} tagged={} compatible_assets={} incompatible_assets={} missing_tangents={} missing_u32_indices={} unsupported={} deformed_excluded={} surface_materials={} surface_missing_evaluator={} excluded={} outside_level_roots={} emissive_candidates={}",
caps.requested_gi_path,
next_stats.project_meshes,
next_stats.tagged_meshes,
@@ -332,6 +408,9 @@ fn sync_hydrated_raytracing_meshes(
next_stats.mesh_assets_missing_tangents,
next_stats.mesh_assets_missing_u32_indices,
next_stats.unsupported_meshes,
next_stats.deformed_meshes_excluded,
next_stats.surface_material_meshes,
next_stats.surface_materials_missing_evaluator,
next_stats.excluded_meshes,
next_stats.missing_level_root_meshes,
next_stats.emissive_meshes,
@@ -340,6 +419,21 @@ fn sync_hydrated_raytracing_meshes(
}
}
fn solari_deformation_is_supported(
has_skin: bool,
has_morph_weights: bool,
mesh_has_morph_targets: bool,
) -> bool {
!has_skin && !has_morph_weights && !mesh_has_morph_targets
}
fn solari_alpha_mode_is_supported(alpha_mode: AlphaMode) -> bool {
matches!(
alpha_mode,
AlphaMode::Opaque | AlphaMode::Mask(_) | AlphaMode::AlphaToCoverage
)
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum SolariMeshCompatibility {
Compatible,
@@ -380,17 +474,24 @@ fn mesh_is_solari_project_geometry(
Entity,
&Mesh3d,
Option<&MeshMaterial3d<StandardMaterial>>,
Option<&MeshMaterial3d<SurfaceMaterial>>,
Option<&SkinnedMesh>,
Option<&MeshMorphWeights>,
Option<&RaytracingMesh3d>,
Option<&RaytracingExcluded>,
)>,
parents: &Query<&ChildOf>,
level_roots: &Query<(), With<LevelObject>>,
) -> bool {
let Ok((_, _, material, _, excluded)) = meshes.get(entity) else {
let Ok((_, _, standard_material, surface_material, skin, morph, _, excluded)) =
meshes.get(entity)
else {
return false;
};
excluded.is_none()
&& material.is_some()
&& skin.is_none()
&& morph.is_none()
&& (standard_material.is_some() || surface_material.is_some())
&& has_level_object_ancestor(entity, parents, level_roots)
}
@@ -569,4 +670,22 @@ mod tests {
GiPath::SolariDeferred
);
}
#[test]
fn deformation_is_excluded_instead_of_tracing_the_bind_pose() {
assert!(solari_deformation_is_supported(false, false, false));
assert!(!solari_deformation_is_supported(true, false, false));
assert!(!solari_deformation_is_supported(false, true, false));
assert!(!solari_deformation_is_supported(false, false, true));
assert!(!solari_deformation_is_supported(true, true, true));
}
#[test]
fn solari_accepts_only_opaque_and_cutout_materials() {
assert!(solari_alpha_mode_is_supported(AlphaMode::Opaque));
assert!(solari_alpha_mode_is_supported(AlphaMode::Mask(0.5)));
assert!(solari_alpha_mode_is_supported(AlphaMode::AlphaToCoverage));
assert!(!solari_alpha_mode_is_supported(AlphaMode::Blend));
assert!(!solari_alpha_mode_is_supported(AlphaMode::Premultiplied));
}
}
+6 -5
View File
@@ -7,8 +7,8 @@ use settings::{
ProjectSettings, RenderingCapabilities, RenderingSettings, VolumeContribution,
};
use shared::{
inspector_component_active, InspectorOrder, LevelObject, PostProcessVolumeDesc,
PostProcessVolumeOverrides, COMPONENT_POST_PROCESS_VOLUME,
authoring_component_active, AuthoringComponentStates, InspectorOrder, LevelObject,
PostProcessVolumeDesc, PostProcessVolumeOverrides, COMPONENT_POST_PROCESS_VOLUME,
};
use super::solari::SolariRaytracingSceneStats;
@@ -264,6 +264,7 @@ pub fn sync_active_camera_render_profile(
Entity,
&PostProcessVolumeDesc,
&GlobalTransform,
Option<&AuthoringComponentStates>,
Option<&InspectorOrder>,
),
With<LevelObject>,
@@ -305,10 +306,10 @@ pub fn sync_active_camera_render_profile(
let volume_list: Vec<_> = volumes
.iter()
.filter(|(_, _, _, order)| {
inspector_component_active(*order, COMPONENT_POST_PROCESS_VOLUME)
.filter(|(_, _, _, states, legacy_order)| {
authoring_component_active(*states, *legacy_order, COMPONENT_POST_PROCESS_VOLUME)
})
.map(|(entity, desc, transform, _)| (entity, desc, transform))
.map(|(entity, desc, transform, _, _)| (entity, desc, transform))
.collect();
let (resolved, entries) = resolve_active_camera_render_profile(
camera_tf.translation(),
+36 -8
View File
@@ -4,8 +4,8 @@ use bevy::light::CascadeShadowConfig;
use bevy::prelude::*;
use settings::ProjectSettings;
use shared::{
cascade_config_from_rendering, inspector_component_active, AuthoringLightKind, InspectorOrder,
LevelObject, LightDesc, ProjectSun, COMPONENT_LIGHT_DESC,
authoring_component_active, cascade_config_from_rendering, AuthoringComponentStates,
AuthoringLightKind, InspectorOrder, LevelObject, LightDesc, ProjectSun, COMPONENT_LIGHT_DESC,
};
/// Spawns the directional "sun" from project rendering settings.
@@ -14,7 +14,14 @@ pub fn spawn_sun(
mut commands: Commands,
settings: Res<ProjectSettings>,
existing: Query<(), With<DirectionalLight>>,
scene_suns: Query<(&LightDesc, Option<&InspectorOrder>), With<LevelObject>>,
scene_suns: Query<
(
&LightDesc,
Option<&AuthoringComponentStates>,
Option<&InspectorOrder>,
),
With<LevelObject>,
>,
) {
if !existing.is_empty() {
return;
@@ -39,7 +46,14 @@ pub fn spawn_sun(
#[unsafe(no_mangle)]
pub fn sync_project_sun_visibility(
scene_suns: Query<(&LightDesc, Option<&InspectorOrder>), With<LevelObject>>,
scene_suns: Query<
(
&LightDesc,
Option<&AuthoringComponentStates>,
Option<&InspectorOrder>,
),
With<LevelObject>,
>,
mut project_suns: Query<(&mut DirectionalLight, &mut Visibility), With<ProjectSun>>,
) {
let scene_override = has_scene_sun_override(&scene_suns);
@@ -54,10 +68,17 @@ pub fn sync_project_sun_visibility(
}
fn has_scene_sun_override(
scene_suns: &Query<(&LightDesc, Option<&InspectorOrder>), With<LevelObject>>,
scene_suns: &Query<
(
&LightDesc,
Option<&AuthoringComponentStates>,
Option<&InspectorOrder>,
),
With<LevelObject>,
>,
) -> bool {
scene_suns.iter().any(|(light, order)| {
inspector_component_active(order, COMPONENT_LIGHT_DESC)
scene_suns.iter().any(|(light, states, legacy_order)| {
authoring_component_active(states, legacy_order, COMPONENT_LIGHT_DESC)
&& matches!(light.kind, AuthoringLightKind::Directional)
})
}
@@ -99,7 +120,14 @@ pub fn sync_scene_directional_shadow_cascades(
#[unsafe(no_mangle)]
pub fn sync_project_sun_from_settings(
settings: Res<ProjectSettings>,
scene_suns: Query<(&LightDesc, Option<&InspectorOrder>), With<LevelObject>>,
scene_suns: Query<
(
&LightDesc,
Option<&AuthoringComponentStates>,
Option<&InspectorOrder>,
),
With<LevelObject>,
>,
mut project_suns: Query<(&mut DirectionalLight, &mut Visibility), With<ProjectSun>>,
) {
let scene_override = has_scene_sun_override(&scene_suns);