Skip to content

Commit

Permalink
bound scene heights
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Oct 21, 2024
1 parent 2626a4f commit 74da949
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 12 deletions.
5 changes: 4 additions & 1 deletion assets/shaders/bound_material.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

struct SceneBounds {
bounds: vec4<f32>,
height: f32,
distance: f32,
flags: u32,
}
Expand Down Expand Up @@ -88,7 +89,9 @@ fn fragment(

// check bounds
let world_position = pbr_input.world_position.xyz;
let outside_amt = max(max(max(0.0, bounds.bounds.x - world_position.x), max(world_position.x - bounds.bounds.z, bounds.bounds.y - world_position.z)), world_position.z - bounds.bounds.w);
let outside_xy = max(max(max(0.0, bounds.bounds.x - world_position.x), max(world_position.x - bounds.bounds.z, bounds.bounds.y - world_position.z)), world_position.z - bounds.bounds.w);
let outside_height = max(world_position.y - bounds.height, 0.0);
let outside_amt = max(outside_height, outside_xy);

var noise = 0.05;
var should_discard = false;
Expand Down
2 changes: 1 addition & 1 deletion assets/ui/chat.dui
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<button img="images/redx.png" tooltip="Hide Chat Panel" onclick="@close" image-width="3.3vmin" image-height="3.3vmin" />
</div>
<div style="flex-direction: row; max-height: 100%;">
<div style="flex-direction: column; flex-grow: 1; padding: 1vmin 0px 1vmin 1vmin; justify-content: flex-end;">
<div style="flex-direction: column; flex-grow: 1; max-width: 44.4vmin; padding: 1vmin 0px 1vmin 1vmin; justify-content: flex-end;">
<div>
<tab-group id="tabs" style="justify-content: flex-start; width: 100%; flex-wrap: wrap-reverse;" tabs="@chat-tabs" onchanged="@tab-changed" initial="@initial-tab" edge-scale="1px 1px -0px 1px"/>
</div>
Expand Down
1 change: 1 addition & 0 deletions crates/avatar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,7 @@ fn process_avatar(
halign: 0.0,
add_y_pix: 0.0,
bounds: Vec4::new(f32::MIN, f32::MIN, f32::MAX, f32::MAX),
height: f32::INFINITY,
view: ui_view.view,
ui_node: label_ui,
},
Expand Down
5 changes: 4 additions & 1 deletion crates/scene_material/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ pub struct SceneBound {
}

impl SceneBound {
pub fn new(bounds: Vec4, distance: f32) -> Self {
pub fn new(bounds: Vec4, height: f32, distance: f32) -> Self {
Self {
data: SceneBoundData {
bounds,
height,
distance,
flags: 0,
},
Expand All @@ -70,6 +71,7 @@ impl SceneBound {
f32::INFINITY,
f32::INFINITY,
),
height: f32::INFINITY,
distance: 0.0,
flags: SCENE_MATERIAL_OUTLINE
+ if force_outline {
Expand All @@ -85,6 +87,7 @@ impl SceneBound {
#[derive(ShaderType, Clone)]
pub struct SceneBoundData {
pub bounds: Vec4,
pub height: f32,
pub distance: f32,
pub flags: u32,
}
Expand Down
4 changes: 3 additions & 1 deletion crates/scene_runner/src/initialize_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ pub(crate) fn load_scene_javascript(
// populate pointers
let mut extent_min = IVec2::MAX;
let mut extent_max = IVec2::MIN;
let parcels = meta
let parcels: HashSet<_> = meta
.scene
.parcels
.iter()
Expand All @@ -287,6 +287,7 @@ pub(crate) fn load_scene_javascript(
-extent_min.y * 16,
)
.as_vec4();
let height = f32::log2(parcels.len() as f32 + 1.0) * 20.0;

// get main.crdt
let maybe_serialized_crdt = match crdt {
Expand Down Expand Up @@ -343,6 +344,7 @@ pub(crate) fn load_scene_javascript(
base,
parcels,
bounds,
height,
meta.spawn_points.clone().unwrap_or_default(),
root,
size,
Expand Down
3 changes: 3 additions & 0 deletions crates/scene_runner/src/renderer_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct RendererSceneContext {
pub parcels: HashSet<IVec2>,
// world-space bounds for the scene
pub bounds: Vec4,
pub height: f32,
pub spawn_points: Vec<SpawnPoint>,
pub priority: f32,
pub size: UVec2,
Expand Down Expand Up @@ -103,6 +104,7 @@ impl RendererSceneContext {
base: IVec2,
parcels: HashSet<IVec2>,
bounds: Vec4,
height: f32,
spawn_points: Vec<SpawnPoint>,
root: Entity,
size: UVec2,
Expand All @@ -119,6 +121,7 @@ impl RendererSceneContext {
base,
parcels,
bounds,
height,
spawn_points,
size,
nascent: Default::default(),
Expand Down
6 changes: 5 additions & 1 deletion crates/scene_runner/src/update_world/gltf_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,11 @@ fn update_ready_gltfs(
};
let h_scene_material = bound_mats.add(ExtendedMaterial {
base: base.clone(),
extension: SceneBound::new(context.bounds, config.graphics.oob),
extension: SceneBound::new(
context.bounds,
context.height,
config.graphics.oob,
),
});
resource_lookup
.materials
Expand Down
6 changes: 3 additions & 3 deletions crates/scene_runner/src/update_world/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ fn update_materials(
}
}

let bounds = scenes
let (bounds, height) = scenes
.get(container.root)
.map(|c| c.bounds)
.map(|c| (c.bounds, c.height))
.unwrap_or_default();

let mut commands = commands.entity(ent);
Expand All @@ -452,7 +452,7 @@ fn update_materials(
.or(base.and_then(|b| b.material.normal_map_texture.clone())),
..defn.material.clone()
},
extension: SceneBound::new(bounds, config.graphics.oob),
extension: SceneBound::new(bounds, height, config.graphics.oob),
}),
);
if defn.shadow_caster {
Expand Down
6 changes: 3 additions & 3 deletions crates/scene_runner/src/update_world/mesh_renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ pub fn update_mesh(

if maybe_material.is_none() {
let mat = default_material.entry(scene_ent.root).or_insert_with(|| {
let bounds = scenes
let (bounds, height) = scenes
.get(scene_ent.root)
.map(|c| c.bounds)
.map(|c| (c.bounds, c.height))
.unwrap_or_default();
materials.add(SceneMaterial {
base: StandardMaterial {
..Default::default()
},
extension: SceneBound::new(bounds, config.graphics.oob),
extension: SceneBound::new(bounds, height, config.graphics.oob),
})
});

Expand Down
1 change: 1 addition & 0 deletions crates/scene_runner/src/update_world/text_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ fn update_text_shapes(
halign: halign_wui,
add_y_pix,
bounds: scene.bounds,
height: scene.height,
view: world_ui.view,
ui_node,
},
Expand Down
3 changes: 2 additions & 1 deletion crates/world_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct WorldUi {
pub halign: f32,
pub add_y_pix: f32,
pub bounds: Vec4,
pub height: f32,
pub view: Entity,
pub ui_node: Entity,
}
Expand Down Expand Up @@ -124,7 +125,7 @@ pub fn add_worldui_materials(
alpha_mode: AlphaMode::Blend,
..Default::default()
},
extension: SceneBound::new(wui.bounds, config.graphics.oob),
extension: SceneBound::new(wui.bounds, wui.height, config.graphics.oob),
},
extension: TextQuad {
data: material_data,
Expand Down

0 comments on commit 74da949

Please sign in to comment.