Skip to content

Commit 7b2e5fc

Browse files
water
1 parent 4e7d5fb commit 7b2e5fc

16 files changed

Lines changed: 1481 additions & 1328 deletions

File tree

demos/Demo3D/res/scenes/demos/water.scn

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -729,19 +729,20 @@ parent = @FloatCrateF
729729
parent = @WaterDemo
730730
[WaterBody3D]
731731
shape = { type = "cube" size = (100, 15, 100) }
732-
fidelity = 0.12
732+
fidelity = 0.05
733733
depth = 8.0
734-
wave_speed = 0.52
735-
wave_scale = 0.72
736-
wave_length = 16.0
734+
wave_speed = 0.35
735+
wave_scale = 0.75
736+
wave_length = 24.0
737737
buoyancy = 4.0
738738
drag = 0.55
739+
idle = "calm"
739740
foam_strength = 1.05
740741
sample_readback_rate = 1
741-
shallow_depth = 7.5
742+
shallow_depth = 1.0
742743
deep_color = (0.0, 0.018, 0.075, 1.0)
743744
shallow_color = (0.010, 0.115, 0.18, 1.0)
744-
material = { transparency = 0.0 reflectivity = 0.58 roughness = 0.16 fresnel_power = 4.2 normal_strength = 1.85 ripple_scale = 0.74 foam_color = (0.76, 0.93, 1.0, 1.0) foam_amount = 0.88 crest_foam_threshold = 0.42 caustic_strength = 0.05 refraction_strength = 0.02 scattering_strength = 0.05 distance_fog_strength = 0.58 }
745+
material = { transparency = 0.0 reflectivity = 0.58 roughness = 0.24 fresnel_power = 4.2 normal_strength = 1.95 ripple_scale = 0.74 foam_color = (0.78, 0.95, 1.0, 1.0) foam_amount = 0.89 crest_foam_threshold = 0.42 caustic_strength = 0.05 refraction_strength = 0.02 scattering_strength = 0.05 distance_fog_strength = 0.58 }
745746
lod_near = 25
746747
lod_mid = 100
747748
lod_far = 500.0

demos/Demo3D/res/scripts/demo_profiling_overlay.rs

Lines changed: 107 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const FPS_LABEL_NODE_NAME: &str = "profiling_overlay_fps";
66
const SIM_LABEL_NODE_NAME: &str = "profiling_overlay_sim";
77
const GRAPHICS_LABEL_NODE_NAME: &str = "profiling_overlay_graphics";
88
const ROW_NODE_NAME: &str = "profiling_overlay_row";
9-
const REFRESH_SECONDS: f32 = 1.0;
9+
10+
const REFRESH_SECONDS: f32 = 2.0;
11+
const PROFILE_SAMPLE_EVERY_FRAMES: u32 = 60;
1012

1113
#[State]
1214
struct DemoProfilingOverlayState {
@@ -16,73 +18,103 @@ struct DemoProfilingOverlayState {
1618
pub sim_label: NodeID,
1719
#[default = NodeID::nil()]
1820
pub graphics_label: NodeID,
21+
1922
pub refresh_timer: f32,
23+
24+
#[default = 0]
25+
pub frame_counter: u32,
26+
2027
pub fps_value: f32,
2128
pub dt_us_value: f32,
2229
pub sim_us_value: f32,
2330
pub graphics_us_value: f32,
31+
32+
pub fps_sum: f32,
2433
pub dt_us_sum: f32,
2534
pub sim_us_sum: f32,
2635
pub graphics_us_sum: f32,
36+
2737
pub timing_samples: u32,
2838
}
2939

3040
lifecycle!({
3141
fn on_init(&self, ctx: &mut ScriptContext<'_, API>) {
3242
let row = get_child!(ctx.run, ctx.id, ROW_NODE_NAME).unwrap_or(NodeID::nil());
33-
let fps_label = get_child!(ctx.run, row, FPS_LABEL_NODE_NAME).unwrap_or(NodeID::nil());
34-
let sim_label = get_child!(ctx.run, row, SIM_LABEL_NODE_NAME).unwrap_or(NodeID::nil());
43+
44+
let fps_label =
45+
get_child!(ctx.run, row, FPS_LABEL_NODE_NAME).unwrap_or(NodeID::nil());
46+
47+
let sim_label =
48+
get_child!(ctx.run, row, SIM_LABEL_NODE_NAME).unwrap_or(NodeID::nil());
49+
3550
let graphics_label =
36-
get_child!(ctx.run, row, GRAPHICS_LABEL_NODE_NAME).unwrap_or(NodeID::nil());
51+
get_child!(ctx.run, row, GRAPHICS_LABEL_NODE_NAME)
52+
.unwrap_or(NodeID::nil());
53+
3754
with_state_mut!(ctx.run, DemoProfilingOverlayState, ctx.id, |state| {
3855
state.fps_label = fps_label;
3956
state.sim_label = sim_label;
4057
state.graphics_label = graphics_label;
4158
});
59+
4260
self.refresh_text(ctx);
4361
}
4462

4563
fn on_update(&self, ctx: &mut ScriptContext<'_, API>) {
4664
let dt = delta_time!(ctx.run).max(0.0);
47-
let p = profiling!(ctx.run);
48-
let fps = if p.fps.is_finite() && p.fps > 0.0 {
49-
p.fps
50-
} else {
51-
0.0
52-
};
53-
let dt_us = dt * 1_000_000.0;
54-
let sim_us = p.simulation_time.as_micros() as f32;
55-
let graphics_us = p.graphics_time.as_micros() as f32;
56-
57-
let should_refresh = with_state_mut!(ctx.run, DemoProfilingOverlayState, ctx.id, |state| {
58-
state.refresh_timer += dt;
59-
if fps > 0.0 {
60-
state.fps_value = fps;
61-
}
62-
if dt_us > 0.0 || sim_us > 0.0 || graphics_us > 0.0 {
63-
state.dt_us_sum += dt_us;
64-
state.sim_us_sum += sim_us;
65-
state.graphics_us_sum += graphics_us;
66-
state.timing_samples = state.timing_samples.saturating_add(1);
67-
}
68-
if state.refresh_timer >= REFRESH_SECONDS {
69-
state.refresh_timer = 0.0;
70-
if state.timing_samples > 0 {
71-
let samples = state.timing_samples as f32;
72-
state.dt_us_value = state.dt_us_sum / samples;
73-
state.sim_us_value = state.sim_us_sum / samples;
74-
state.graphics_us_value = state.graphics_us_sum / samples;
75-
state.dt_us_sum = 0.0;
76-
state.sim_us_sum = 0.0;
77-
state.graphics_us_sum = 0.0;
78-
state.timing_samples = 0;
65+
66+
let (should_sample, should_refresh) =
67+
with_state_mut!(ctx.run, DemoProfilingOverlayState, ctx.id, |state| {
68+
state.refresh_timer += dt;
69+
state.frame_counter = state.frame_counter.wrapping_add(1);
70+
let should_sample =
71+
state.frame_counter % PROFILE_SAMPLE_EVERY_FRAMES == 0;
72+
73+
if state.refresh_timer >= REFRESH_SECONDS {
74+
state.refresh_timer = 0.0;
75+
76+
if state.timing_samples > 0 {
77+
let samples = state.timing_samples as f32;
78+
79+
state.fps_value = state.fps_sum / samples;
80+
state.dt_us_value = state.dt_us_sum / samples;
81+
state.sim_us_value = state.sim_us_sum / samples;
82+
state.graphics_us_value =
83+
state.graphics_us_sum / samples;
84+
85+
state.fps_sum = 0.0;
86+
state.dt_us_sum = 0.0;
87+
state.sim_us_sum = 0.0;
88+
state.graphics_us_sum = 0.0;
89+
90+
state.timing_samples = 0;
91+
}
92+
93+
(should_sample, true)
94+
} else {
95+
(should_sample, false)
7996
}
80-
true
81-
} else {
82-
false
83-
}
84-
})
85-
.unwrap_or(true);
97+
})
98+
.unwrap_or((false, false));
99+
100+
if should_sample {
101+
let p = profiling!(ctx.run);
102+
103+
with_state_mut!(ctx.run, DemoProfilingOverlayState, ctx.id, |state| {
104+
let fps = if p.fps.is_finite() && p.fps > 0.0 {
105+
p.fps
106+
} else {
107+
0.0
108+
};
109+
110+
state.fps_sum += fps;
111+
state.dt_us_sum += dt * 1_000_000.0;
112+
state.sim_us_sum += p.simulation_time.as_micros() as f32;
113+
state.graphics_us_sum += p.graphics_time.as_micros() as f32;
114+
state.timing_samples = state.timing_samples.saturating_add(1);
115+
});
116+
}
117+
86118
if should_refresh {
87119
self.refresh_text(ctx);
88120
}
@@ -91,8 +123,19 @@ lifecycle!({
91123

92124
methods!({
93125
fn refresh_text(&self, ctx: &mut ScriptContext<'_, API>) {
94-
let (fps_label, sim_label, graphics_label, fps, dt_us, sim_us, graphics_us) =
95-
with_state!(ctx.run, DemoProfilingOverlayState, ctx.id, |state| {
126+
let (
127+
fps_label,
128+
sim_label,
129+
graphics_label,
130+
fps,
131+
dt_us,
132+
sim_us,
133+
graphics_us,
134+
) = with_state!(
135+
ctx.run,
136+
DemoProfilingOverlayState,
137+
ctx.id,
138+
|state| {
96139
(
97140
state.fps_label,
98141
state.sim_label,
@@ -102,11 +145,26 @@ methods!({
102145
state.sim_us_value,
103146
state.graphics_us_value,
104147
)
105-
});
148+
}
149+
);
150+
151+
set_label_text(
152+
ctx,
153+
fps_label,
154+
format!("FPS {:.1}", fps),
155+
);
106156

107-
set_label_text(ctx, fps_label, format!("FPS {:.1}", fps));
108-
set_label_text(ctx, sim_label, format!("Sim {:.0} us | dt {:.0} us", sim_us, dt_us));
109-
set_label_text(ctx, graphics_label, format!("Gfx {:.0} us", graphics_us));
157+
set_label_text(
158+
ctx,
159+
sim_label,
160+
format!("Sim {:.0} us | dt {:.0} us", sim_us, dt_us),
161+
);
162+
163+
set_label_text(
164+
ctx,
165+
graphics_label,
166+
format!("Gfx {:.0} us", graphics_us),
167+
);
110168
}
111169
});
112170

@@ -118,6 +176,7 @@ fn set_label_text<API: ScriptAPI + ?Sized>(
118176
if id.is_nil() {
119177
return;
120178
}
179+
121180
with_node_mut!(ctx.run, UiLabel, id, |label| {
122181
label.text = text.into();
123182
});

perro_source/api_modules/perro_resource_api/src/sub_apis/draw_2d.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ impl<'res, R: Draw2DAPI + ?Sized> Draw2DModule<'res, R> {
3737

3838
#[inline]
3939
pub fn rect_stroke(&self, center: Vector2, size: Vector2, color: [f32; 4], thickness: f32) {
40-
self.push(DrawShape2D::rect_stroke(size, color.into(), thickness), center);
40+
self.push(
41+
DrawShape2D::rect_stroke(size, color.into(), thickness),
42+
center,
43+
);
4144
}
4245

4346
#[inline]

perro_source/build_pipeline/perro_static_pipeline/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ mod tests {
345345
size_min: 0.65,
346346
size_max: 1.35,
347347
force: [0.0, 0.0, 0.0],
348-
color_start: [1.0, 1.0, 1.0, 1.0],
349-
color_end: [1.0, 0.4, 0.1, 0.0],
348+
color_start: Color::WHITE,
349+
color_end: Color::new(1.0, 0.4, 0.1, 0.0),
350350
emissive: [0.0, 0.0, 0.0],
351351
spin_angular_velocity: 0.0,
352352
};
@@ -654,7 +654,7 @@ mod tests {
654654
normal,
655655
uv,
656656
joints: [0, 0, 0, 0],
657-
weights: [1.0, 0.0, 0.0, 0.0],
657+
weights: perro_structs::Unorm8x4::new([1.0, 0.0, 0.0, 0.0]),
658658
});
659659
}
660660
let mut indices = Vec::with_capacity(index_count);

perro_source/build_pipeline/perro_static_pipeline/src/particles.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub fn generate_static_particles(project_root: &Path) -> Result<(), StaticPipeli
6868
out.push_str(
6969
"use perro_render_bridge::{ParticleExprOp3D, ParticlePath3D, ParticleProfile3D};\n",
7070
);
71+
out.push_str("use perro_structs::Color;\n");
7172
out.push_str("use std::borrow::Cow;\n\n");
7273

7374
for (index, particle) in unique_particles.iter().enumerate() {
@@ -77,7 +78,7 @@ pub fn generate_static_particles(project_root: &Path) -> Result<(), StaticPipeli
7778
}
7879
out.push('\n');
7980
out.push_str(
80-
"static EMPTY_PARTICLE: ParticleProfile3D = ParticleProfile3D { path: ParticlePath3D::None, expr_x_ops: None, expr_y_ops: None, expr_z_ops: None, lifetime_min: 0.6, lifetime_max: 1.4, speed_min: 1.0, speed_max: 3.0, spread_radians: core::f32::consts::FRAC_PI_3, size: 6.0, size_min: 0.65, size_max: 1.35, force: [0.0, 0.0, 0.0], color_start: [1.0, 1.0, 1.0, 1.0], color_end: [1.0, 0.4, 0.1, 0.0], emissive: [0.0, 0.0, 0.0], spin_angular_velocity: 0.0 };\n\n",
81+
"static EMPTY_PARTICLE: ParticleProfile3D = ParticleProfile3D { path: ParticlePath3D::None, expr_x_ops: None, expr_y_ops: None, expr_z_ops: None, lifetime_min: 0.6, lifetime_max: 1.4, speed_min: 1.0, speed_max: 3.0, spread_radians: core::f32::consts::FRAC_PI_3, size: 6.0, size_min: 0.65, size_max: 1.35, force: [0.0, 0.0, 0.0], color_start: Color::WHITE, color_end: Color::new(1.0, 0.4, 0.1, 0.0), emissive: [0.0, 0.0, 0.0], spin_angular_velocity: 0.0 };\n\n",
8182
);
8283
for (index, (path, _)) in particle_refs.iter().enumerate() {
8384
write_hash_const(&mut out, &format!("PARTICLE_HASH_{index}"), path);
@@ -280,7 +281,7 @@ fn emit_particle_literal(particle: &ParticleLiteral) -> String {
280281
.map(|ops| format!("Some(Cow::Borrowed(&[{}]))", emit_ops_literal(ops)))
281282
.unwrap_or_else(|| "None".to_string());
282283
format!(
283-
"ParticleProfile3D {{ path: {path}, expr_x_ops: {expr_x_ops}, expr_y_ops: {expr_y_ops}, expr_z_ops: {expr_z_ops}, lifetime_min: {:?}, lifetime_max: {:?}, speed_min: {:?}, speed_max: {:?}, spread_radians: {:?}, size: {:?}, size_min: {:?}, size_max: {:?}, force: [{:?}, {:?}, {:?}], color_start: [{:?}, {:?}, {:?}, {:?}], color_end: [{:?}, {:?}, {:?}, {:?}], emissive: [{:?}, {:?}, {:?}], spin_angular_velocity: {:?} }}",
284+
"ParticleProfile3D {{ path: {path}, expr_x_ops: {expr_x_ops}, expr_y_ops: {expr_y_ops}, expr_z_ops: {expr_z_ops}, lifetime_min: {:?}, lifetime_max: {:?}, speed_min: {:?}, speed_max: {:?}, spread_radians: {:?}, size: {:?}, size_min: {:?}, size_max: {:?}, force: [{:?}, {:?}, {:?}], color_start: Color::new({:?}, {:?}, {:?}, {:?}), color_end: Color::new({:?}, {:?}, {:?}, {:?}), emissive: [{:?}, {:?}, {:?}], spin_angular_velocity: {:?} }}",
284285
particle.lifetime_min,
285286
particle.lifetime_max,
286287
particle.speed_min,

perro_source/render_stack/perro_app/src/threaded.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,10 @@ impl<B: GraphicsBackend> SnapshotPresenter<B> {
576576
where
577577
I: IntoIterator<Item = RenderCommand>,
578578
{
579-
if let Some(snapshot) = bridge.take_latest_snapshot() {
580-
if let Some(old_snapshot) = self.current_snapshot.replace(snapshot) {
581-
bridge.recycle_command_buffer(old_snapshot.commands);
582-
}
579+
if let Some(snapshot) = bridge.take_latest_snapshot()
580+
&& let Some(old_snapshot) = self.current_snapshot.replace(snapshot)
581+
{
582+
bridge.recycle_command_buffer(old_snapshot.commands);
583583
}
584584
if let Some(snapshot) = &self.current_snapshot {
585585
self.graphics.submit_many(snapshot.commands.iter().cloned());
@@ -599,10 +599,10 @@ impl<B: GraphicsBackend> SnapshotPresenter<B> {
599599
I: IntoIterator<Item = RenderCommand>,
600600
{
601601
let total_start = Instant::now();
602-
if let Some(snapshot) = bridge.take_latest_snapshot() {
603-
if let Some(old_snapshot) = self.current_snapshot.replace(snapshot) {
604-
bridge.recycle_command_buffer(old_snapshot.commands);
605-
}
602+
if let Some(snapshot) = bridge.take_latest_snapshot()
603+
&& let Some(old_snapshot) = self.current_snapshot.replace(snapshot)
604+
{
605+
bridge.recycle_command_buffer(old_snapshot.commands);
606606
}
607607
if let Some(snapshot) = &self.current_snapshot {
608608
self.graphics.submit_many(snapshot.commands.iter().cloned());

perro_source/render_stack/perro_graphics/src/gpu.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,7 @@ impl Gpu {
10101010
&& !accessibility_enabled
10111011
&& self.render_format == self.config.format;
10121012
let depth_prepass_needed = !waters_3d.is_empty()
1013-
|| (camera_post_enabled
1014-
&& PostProcessor::uses_depth(camera_post_chain))
1013+
|| (camera_post_enabled && PostProcessor::uses_depth(camera_post_chain))
10151014
|| (global_post_enabled && PostProcessor::uses_depth(global_post_chain));
10161015
let mut frame = None;
10171016
let mut swap_view = None;

0 commit comments

Comments
 (0)