Skip to content

Commit

Permalink
Add fog to the hardware 3D renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
kelpsyberry committed Mar 23, 2024
1 parent be8dc9d commit cea9237
Show file tree
Hide file tree
Showing 16 changed files with 1,103 additions and 564 deletions.
1 change: 1 addition & 0 deletions frontend/desktop/src/ui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl GfxDevice {
required_features: features,
required_limits: wgpu::Limits {
max_texture_dimension_2d: 4096,
max_bind_groups: 5,
..wgpu::Limits::downlevel_webgl2_defaults()
},
},
Expand Down
4 changes: 2 additions & 2 deletions render/soft-3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,8 @@ impl Renderer {
}};
}

let fog_color = rgb5_to_rgb6(rendering_data.fog_color.cast());
if rendering_data.control.fog_only_alpha() {
let fog_alpha = fog_color[3];
let fog_alpha = rendering_data.fog_color[3] as u16;
for x in 0..256 {
let attrs = self.attr_buffer.0[x];
if !attrs.fog_enabled() {
Expand All @@ -846,6 +845,7 @@ impl Renderer {
((fog_alpha * density + alpha * (0x80 - density)) >> 7) as u8;
}
} else {
let fog_color = rgb5_to_rgb6(rendering_data.fog_color.cast());
for x in 0..256 {
let attrs = self.attr_buffer.0[x];
if !attrs.fog_enabled() {
Expand Down
27 changes: 14 additions & 13 deletions render/wgpu-2d/src/common/gfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
Arc,
},
thread,
time::Duration,
// time::Duration,
};

pub enum Renderer3dRx {
Expand Down Expand Up @@ -787,18 +787,19 @@ impl GfxThreadData {

drop(render_pass);

if let Renderer3dGfxThreadData::Accel {
last_submitted_frame,
..
} = &self.renderer_3d_data
{
while last_submitted_frame.0.load(Ordering::Relaxed) < frame.frame_index {
if self.shared_data.stopped.load(Ordering::Relaxed) {
return;
}
thread::park_timeout(Duration::from_millis(1));
}
}
// TODO: Proper synchronization
// if let Renderer3dGfxThreadData::Accel {
// last_submitted_frame,
// ..
// } = &self.renderer_3d_data
// {
// while last_submitted_frame.0.load(Ordering::Relaxed) < frame.frame_index {
// if self.shared_data.stopped.load(Ordering::Relaxed) {
// return;
// }
// thread::park_timeout(Duration::from_millis(1));
// }
// }

self.queue.submit([command_encoder.finish()]);
} else {
Expand Down
21 changes: 15 additions & 6 deletions render/wgpu-3d/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ impl GxData {
}
}

#[derive(Clone, PartialEq, Eq)]
pub struct FogData {
pub depth_shift: u8,
pub offset: u16,
pub densities: [u8; 0x20],
pub color: Color,
}

pub struct RenderingData {
pub control: RenderingControl,

Expand All @@ -50,12 +58,10 @@ pub struct RenderingData {
pub clear_image_offset: [u8; 2],
pub clear_depth: u32,

pub fog_offset: u16,
pub fog_densities: [u8; 0x20],
pub fog_data: FogData,
pub rear_plane_fog_enabled: bool,

pub clear_color: Color,
pub fog_color: Color,
pub edge_colors: [Color; 8],
pub toon_colors: [Color; 0x20],

Expand Down Expand Up @@ -85,9 +91,12 @@ impl RenderingData {
self.toon_colors = state.toon_colors;
self.edge_colors = state.edge_colors;

self.fog_color = state.fog_color;
self.fog_densities = state.fog_densities;
self.fog_offset = state.fog_offset;
self.fog_data = FogData {
depth_shift: state.control.fog_depth_shift(),
color: state.fog_color,
densities: state.fog_densities,
offset: state.fog_offset,
};
self.rear_plane_fog_enabled = state.rear_plane_fog_enabled;
}

Expand Down
Loading

0 comments on commit cea9237

Please sign in to comment.