Skip to content

Commit

Permalink
bake setting
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Nov 29, 2024
1 parent b4feff1 commit 9bbf6cc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
21 changes: 21 additions & 0 deletions crates/common/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ pub struct AppConfig {
pub scene_unload_extra_distance: f32,
pub scene_imposter_distances: Vec<f32>,
pub scene_imposter_multisample: bool,
pub scene_imposter_bake: SceneImposterBake,
pub sysinfo_visible: bool,
pub scene_log_to_console: bool,
pub max_avatars: usize,
Expand Down Expand Up @@ -213,6 +214,7 @@ impl Default for AppConfig {
scene_unload_extra_distance: 15.0,
scene_imposter_distances: vec![150.0, 300.0, 600.0, 1200.0, 2400.0, 4800.0],
scene_imposter_multisample: true,
scene_imposter_bake: SceneImposterBake::Off,
sysinfo_visible: true,
scene_log_to_console: false,
max_avatars: 100,
Expand Down Expand Up @@ -627,3 +629,22 @@ pub const PRIMARY_AVATAR_LIGHT_LAYER: RenderLayers = RenderLayers::layer(1);
pub const PROFILE_UI_RENDERLAYER: RenderLayers = RenderLayers::layer(3);
// layer for ground
pub const GROUND_RENDERLAYER: RenderLayers = RenderLayers::layer(4);

#[derive(PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
pub enum SceneImposterBake {
Off,
FullSpeed,
HalfSpeed,
QuarterSpeed,
}

impl SceneImposterBake {
pub fn as_mult(&self) -> f32 {
match self {
SceneImposterBake::Off => panic!(),
SceneImposterBake::FullSpeed => 1.0,
SceneImposterBake::HalfSpeed => 0.5,
SceneImposterBake::QuarterSpeed => 0.25,
}
}
}
24 changes: 21 additions & 3 deletions crates/imposters/src/bake_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use boimp::{
bake::{BakeState, ImposterBakeBundle, ImposterBakeCamera},
GridMode, ImposterBakePlugin,
};
use common::{sets::SceneSets, structs::PrimaryUser};
use common::{
sets::SceneSets,
structs::{AppConfig, PrimaryUser, SceneImposterBake},
};
use ipfs::{CurrentRealm, IpfsAssetServer};
use scene_material::{BoundRegion, SceneBound, SceneMaterial};

Expand Down Expand Up @@ -175,6 +178,7 @@ fn bake_scene_imposters(
bound_materials: Query<&Handle<SceneMaterial>>,
mut materials: ResMut<Assets<SceneMaterial>>,
lookup: Res<ImposterEntities>,
config: Res<AppConfig>,
) {
if let Ok((baking_ent, mut oven)) = baking.get_single_mut() {
let current_scene_ent = {
Expand Down Expand Up @@ -296,12 +300,16 @@ fn bake_scene_imposters(
.clamp(2.0, TILE_SIZE as f32 * 2.0) as u32;
warn!("tile size: {tile_size}");

let max_tiles_per_frame = ((GRID_SIZE * GRID_SIZE) as f32
* config.scene_imposter_bake.as_mult())
.ceil() as usize;

let mut camera = ImposterBakeCamera {
radius,
grid_size: GRID_SIZE,
tile_size,
grid_mode: GridMode::Hemispherical,
// max_tiles_per_frame: 5,
max_tiles_per_frame,
..Default::default()
};

Expand Down Expand Up @@ -388,6 +396,7 @@ fn bake_imposter_imposter(
current_realm: Res<CurrentRealm>,
mut layers: Query<&mut RenderLayers>,
tick: Res<FrameCount>,
config: Res<AppConfig>,
) {
if baking.is_some() {
let all_cams_finished = all_baking_cams
Expand Down Expand Up @@ -480,12 +489,16 @@ fn bake_imposter_imposter(
.clamp(2.0, 256.0) as u32;
warn!("tile size: {tile_size}");

let max_tiles_per_frame = ((GRID_SIZE * GRID_SIZE) as f32
* config.scene_imposter_bake.as_mult())
.ceil() as usize;

let mut camera = ImposterBakeCamera {
radius,
grid_size: GRID_SIZE,
tile_size,
grid_mode: GridMode::Hemispherical,
// max_tiles_per_frame: 5,
max_tiles_per_frame,
multisample: 8,
..Default::default()
};
Expand Down Expand Up @@ -564,7 +577,12 @@ fn pick_imposter_to_bake(
live_scenes: Res<LiveScenes>,
mut baking: ResMut<ImposterBakeList>,
current_realm: Res<CurrentRealm>,
config: Res<AppConfig>,
) {
if config.scene_imposter_bake == SceneImposterBake::Off {
return;
}

if current_realm.is_changed() {
baking.0.clear();
return;
Expand Down
1 change: 0 additions & 1 deletion crates/scene_runner/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ fn init_test_app(entity_json: &str) -> App {
load: 1.0,
unload: 0.0,
load_imposter: 0.0,
imposter_height_ratio: 6.0,
});
app.init_resource::<PreviewMode>();
app.finish();
Expand Down
14 changes: 12 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ use common::{
sets::SetupSets,
structs::{
AppConfig, AttachPoints, GraphicsSettings, IVec2Arg, PrimaryCamera, PrimaryCameraRes,
PrimaryPlayerRes, PrimaryUser, SceneLoadDistance, Version, GROUND_RENDERLAYER,
PRIMARY_AVATAR_LIGHT_LAYER,
PrimaryPlayerRes, PrimaryUser, SceneImposterBake, SceneLoadDistance, Version,
GROUND_RENDERLAYER, PRIMARY_AVATAR_LIGHT_LAYER,
},
util::{config_file, project_directories, UtilsPlugin},
};
Expand Down Expand Up @@ -171,6 +171,16 @@ fn main() {
.value_from_str("--unload")
.ok()
.unwrap_or(base_config.scene_unload_extra_distance),
scene_imposter_bake: args
.value_from_str("--bake")
.ok()
.map(|bake: String| match bake.to_lowercase().chars().next() {
None | Some("f") => SceneImposterBake::FullSpeed,
Some("h") => SceneImposterBake::HalfSpeed,
Some("q") => SceneImposterBake::QuarterSpeed,
Some("o") => SceneImposterBake::Off,
})
.unwrap_or(SceneImposterBake::Off),
scene_imposter_distances: args
.value_from_str("--impost")
.ok()
Expand Down

0 comments on commit 9bbf6cc

Please sign in to comment.