Skip to content

Commit 0e01ed1

Browse files
committed
Fix top panel background regression and prevent particle blowouts
1 parent df3d073 commit 0e01ed1

3 files changed

Lines changed: 84 additions & 10 deletions

File tree

src/engine.rs

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ pub struct VulkanEngine<'a> {
278278
video_state: Option<VideoState>,
279279
clear_black_pipeline: wgpu::RenderPipeline,
280280
crt_background_pipeline: wgpu::RenderPipeline,
281+
biolum_bg_pipeline: wgpu::RenderPipeline,
281282

282283
// 3D Engine Extensions
283284
camera_uniform_buffer: wgpu::Buffer,
@@ -1139,6 +1140,67 @@ impl<'a> VulkanEngine<'a> {
11391140
cache: None,
11401141
});
11411142

1143+
let solid_biolum_bg_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
1144+
label: Some("Solid Biolum BG Shader"),
1145+
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(r#"
1146+
struct VertexOutput {
1147+
@builtin(position) clip_position: vec4<f32>,
1148+
}
1149+
@vertex
1150+
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> VertexOutput {
1151+
var out: VertexOutput;
1152+
let x = f32((in_vertex_index << 1u) & 2u) * 2.0 - 1.0;
1153+
let y = f32(in_vertex_index & 2u) * 2.0 - 1.0;
1154+
out.clip_position = vec4<f32>(x, y, 1.0, 1.0);
1155+
return out;
1156+
}
1157+
@fragment
1158+
fn fs_main() -> @location(0) vec4<f32> {
1159+
return vec4<f32>(0.001, 0.003, 0.008, 1.0);
1160+
}
1161+
"#)),
1162+
});
1163+
1164+
let biolum_bg_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
1165+
label: Some("Biolum BG Pipeline"),
1166+
layout: Some(&clear_black_layout),
1167+
vertex: wgpu::VertexState {
1168+
module: &solid_biolum_bg_shader,
1169+
entry_point: Some("vs_main"),
1170+
buffers: &[],
1171+
compilation_options: wgpu::PipelineCompilationOptions::default(),
1172+
},
1173+
fragment: Some(wgpu::FragmentState {
1174+
module: &solid_biolum_bg_shader,
1175+
entry_point: Some("fs_main"),
1176+
targets: &[Some(wgpu::ColorTargetState {
1177+
format: config.format,
1178+
blend: Some(wgpu::BlendState::REPLACE),
1179+
write_mask: wgpu::ColorWrites::ALL,
1180+
})],
1181+
compilation_options: wgpu::PipelineCompilationOptions::default(),
1182+
}),
1183+
primitive: wgpu::PrimitiveState {
1184+
topology: wgpu::PrimitiveTopology::TriangleList,
1185+
strip_index_format: None,
1186+
front_face: wgpu::FrontFace::Ccw,
1187+
cull_mode: None,
1188+
polygon_mode: wgpu::PolygonMode::Fill,
1189+
unclipped_depth: false,
1190+
conservative: false,
1191+
},
1192+
depth_stencil: Some(wgpu::DepthStencilState {
1193+
format: wgpu::TextureFormat::Depth32Float,
1194+
depth_write_enabled: Some(true),
1195+
depth_compare: Some(wgpu::CompareFunction::Always),
1196+
stencil: wgpu::StencilState::default(),
1197+
bias: wgpu::DepthBiasState::default(),
1198+
}),
1199+
multisample: wgpu::MultisampleState::default(),
1200+
multiview_mask: None,
1201+
cache: None,
1202+
});
1203+
11421204
let crt_background_shader_src = resolve_shader_includes(r#"
11431205
// INCLUDE: common
11441206
@@ -1998,6 +2060,7 @@ impl<'a> VulkanEngine<'a> {
19982060
video_state: None,
19992061
clear_black_pipeline,
20002062
crt_background_pipeline,
2063+
biolum_bg_pipeline,
20012064

20022065
camera_uniform_buffer,
20032066
camera_bind_group,
@@ -4101,11 +4164,7 @@ impl<'a> VulkanEngine<'a> {
41014164
resolve_target: None,
41024165
depth_slice: None,
41034166
ops: wgpu::Operations {
4104-
load: wgpu::LoadOp::Clear(if vis_def.id == 19 {
4105-
wgpu::Color { r: 0.001, g: 0.003, b: 0.008, a: 1.0 }
4106-
} else {
4107-
wgpu::Color { r: 0.1, g: 0.1, b: 0.1, a: 1.0 }
4108-
}),
4167+
load: wgpu::LoadOp::Clear(wgpu::Color { r: 0.1, g: 0.1, b: 0.1, a: 1.0 }),
41094168
store: wgpu::StoreOp::Store,
41104169
},
41114170
})],
@@ -4157,6 +4216,9 @@ impl<'a> VulkanEngine<'a> {
41574216
if vis_def.id == 11 {
41584217
render_pass.set_pipeline(&self.clear_black_pipeline);
41594218
render_pass.draw(0..3, 0..1);
4219+
} else if vis_def.id == 19 {
4220+
render_pass.set_pipeline(&self.biolum_bg_pipeline);
4221+
render_pass.draw(0..3, 0..1);
41604222
} else if vis_def.id == 17 {
41614223
render_pass.set_pipeline(&self.crt_background_pipeline);
41624224
render_pass.set_bind_group(0, &self.uniform_bind_group, &[]);

src/shaders/biolum_compute.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
129129
vel.y += bass * 4.0 * rnd_impulse.z;
130130
vel.x += (rnd_impulse.x - 0.5) * bass * 2.0;
131131
vel.z += (rnd_impulse.y - 0.5) * bass * 2.0;
132-
energy = max(energy, bass * 2.0);
132+
energy = clamp(max(energy, bass * 2.0), 0.0, 1.5);
133133
}
134134

135135
// Glow when near wave crests due to high shear stress

src/shaders/vis_bioluminescence.wgsl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,27 @@ fn vs_main_3d(in: VertexInput, @builtin(instance_index) inst_idx: u32) -> Vertex
4444
return out;
4545
}
4646

47-
// Scale particle based on energy (pulsing effect)
48-
let size = 0.035 + p.vel.w * 0.09;
47+
// Scale particle based on energy (pulsing effect) and clamp to prevent excessive blowouts
48+
let size = 0.035 + clamp(p.vel.w, 0.0, 1.5) * 0.09;
4949
let local_pos = in.position * size;
5050
let world_pos = local_pos + p.pos.xyz;
5151

52-
out.clip_position = camera.proj_matrix * camera.view_matrix * vec4<f32>(world_pos, 1.0);
52+
let view_pos = camera.view_matrix * vec4<f32>(world_pos, 1.0);
53+
let depth = -view_pos.z;
54+
55+
// Discard/hide particle if it is behind or too close to the camera to prevent huge screen-filling discs
56+
if (depth < 1.2) {
57+
out.clip_position = vec4<f32>(0.0, 0.0, -10.0, 1.0); // behind the camera
58+
out.uv = vec2<f32>(0.0);
59+
out.energy = 0.0;
60+
out.depth = 0.0;
61+
return out;
62+
}
63+
64+
out.clip_position = camera.proj_matrix * view_pos;
5365
out.uv = in.tex_coords;
5466
out.energy = p.vel.w;
55-
out.depth = out.clip_position.w;
67+
out.depth = depth;
5668

5769
return out;
5870
}

0 commit comments

Comments
 (0)