Skip to content

Commit

Permalink
Change type of GraphicsOptions::bloom_intensity to ZeroOne<f32>.
Browse files Browse the repository at this point in the history
This perfectly constrains it so that no bounds checks are needed.
  • Loading branch information
kpreid committed Oct 21, 2024
1 parent 7cff74a commit ef1a45e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions all-is-cubes-gpu/src/in_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use all_is_cubes::content::palette;
use all_is_cubes::drawing::embedded_graphics::{pixelcolor::Gray8, Drawable as _};
use all_is_cubes::euclid::Size2D;
use all_is_cubes::listen::DirtyFlag;
use all_is_cubes::math::{notnan, VectorOps as _};
use all_is_cubes::math::VectorOps as _;
use all_is_cubes_render::camera::{Layers, RenderMethod, StandardCameras};
use all_is_cubes_render::info_text_drawable;
use all_is_cubes_render::{Flaws, RenderError};
Expand Down Expand Up @@ -833,7 +833,7 @@ impl<I: time::Instant> EverythingRenderer<I> {
);
}

if self.cameras.graphics_options().bloom_intensity > notnan!(0.0) {
if !self.cameras.graphics_options().bloom_intensity.is_zero() {
if let Some(bloom) = &self.fb.bloom {
bloom.run(&mut encoder);
}
Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-render/src/raytracer/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use all_is_cubes::character::Cursor;
use all_is_cubes::content::palette;
use all_is_cubes::euclid::{self, point2, vec2};
use all_is_cubes::listen::ListenableSource;
use all_is_cubes::math::{NotNan, Rgba};
use all_is_cubes::math::{Rgba, ZeroOne};
use all_is_cubes::space::Space;
use all_is_cubes::universe::Handle;

Expand Down Expand Up @@ -253,7 +253,7 @@ impl RtRenderer<()> {

let options = self.cameras.graphics_options();
let mut flaws = Flaws::empty();
if options.bloom_intensity != NotNan::from(0u8) {
if options.bloom_intensity != ZeroOne::ZERO {
flaws |= Flaws::NO_BLOOM;
}
if self.had_cursor {
Expand Down
11 changes: 5 additions & 6 deletions all-is-cubes/src/camera/graphics_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::fmt;
use num_traits::ConstOne as _;
use ordered_float::NotNan;

use crate::math::{notnan, FreeCoordinate, PositiveSign, Rgb, Rgba, ZeroOne};
use crate::math::{notnan, zo32, FreeCoordinate, PositiveSign, Rgb, Rgba, ZeroOne};
use crate::util::ShowStatus;

#[cfg(doc)]
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct GraphicsOptions {

/// Proportion of bloom (blurred image) to mix into the original image.
/// 0.0 is no bloom and 1.0 is no original image.
pub bloom_intensity: NotNan<f32>,
pub bloom_intensity: ZeroOne<f32>,

/// Distance, in unit cubes, from the camera to the farthest visible point.
///
Expand Down Expand Up @@ -134,7 +134,7 @@ impl GraphicsOptions {
// TODO: Change tone mapping default once we have a good implementation.
tone_mapping: ToneMappingOperator::Clamp,
exposure: ExposureOption::Fixed(PositiveSign::<f32>::ONE),
bloom_intensity: notnan!(0.),
bloom_intensity: zo32(0.),
view_distance: notnan!(200.),
lighting_display: LightingOption::None,
transparency: TransparencyOption::Volumetric,
Expand All @@ -153,7 +153,6 @@ impl GraphicsOptions {
#[must_use]
pub fn repair(mut self) -> Self {
self.fov_y = self.fov_y.clamp(NotNan::from(1), NotNan::from(189));
self.bloom_intensity = self.bloom_intensity.clamp(notnan!(0.0), notnan!(1.0));
self.view_distance = self
.view_distance
.clamp(NotNan::from(1), NotNan::from(10000));
Expand Down Expand Up @@ -220,7 +219,7 @@ impl Default for GraphicsOptions {
// TODO: Change tone mapping default once we have a good implementation.
tone_mapping: ToneMappingOperator::Clamp,
exposure: ExposureOption::default(),
bloom_intensity: notnan!(0.125),
bloom_intensity: zo32(0.125),
view_distance: NotNan::from(200),
lighting_display: LightingOption::Smooth,
transparency: TransparencyOption::Volumetric,
Expand Down Expand Up @@ -537,7 +536,7 @@ mod tests {
fog: FogOption::None,
tone_mapping: ToneMappingOperator::Clamp,
exposure: ExposureOption::Fixed(PositiveSign::<f32>::ONE),
bloom_intensity: NotNan::from(0u8),
bloom_intensity: zo32(0.),
lighting_display: LightingOption::None,
antialiasing: AntialiasingOption::None,
..GraphicsOptions::default()
Expand Down
2 changes: 1 addition & 1 deletion test-renderers/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async fn antialias(mut context: RenderTestContext, antialias_option: Antialiasin

async fn bloom(mut context: RenderTestContext, bloom_intensity: f32) {
let mut options = light_test_options();
options.bloom_intensity = NotNan::new(bloom_intensity).unwrap();
options.bloom_intensity = bloom_intensity.try_into().unwrap();
let scene =
StandardCameras::from_constant_for_test(options, COMMON_VIEWPORT, context.universe());
context
Expand Down

0 comments on commit ef1a45e

Please sign in to comment.