Skip to content

Commit

Permalink
Use per-face colors in light propagation.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Nov 16, 2023
1 parent f4bd20f commit b5e3cbc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[?25l ▄▄▄▄▄▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄▄▄▄▄▄
[?25l ▄▄▄▄▄▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄▄▄▄▄▄
 
 
 
Expand Down
9 changes: 8 additions & 1 deletion all-is-cubes/src/block/evaluated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use euclid::Vector3D;
use ordered_float::NotNan;

use crate::content::palette;
use crate::math::{Cube, Face6, FaceMap, GridAab, OpacityCategory, Rgb, Rgba, Vol};
use crate::math::{Cube, Face6, Face7, FaceMap, GridAab, OpacityCategory, Rgb, Rgba, Vol};
use crate::raytracer;
use crate::universe::RefError;
use crate::{
Expand Down Expand Up @@ -314,6 +314,13 @@ impl EvaluatedBlock {
self.voxels.bounds()
}

pub(crate) fn face7_color(&self, face: Face7) -> Rgba {
match Face6::try_from(face) {
Ok(face) => self.face_colors[face],
Err(_) => self.color,
}
}

/// Expresses the opacity of the block as an [`OpacityCategory`].
///
/// If the return value is [`OpacityCategory::Partial`], this does not necessarily mean
Expand Down
9 changes: 7 additions & 2 deletions all-is-cubes/src/space/light/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,8 @@ impl LightBuffer {
}
let stored_light = current_light.get(light_cube);

let surface_color = ev_hit.color.clamp().to_rgb() * SURFACE_ABSORPTION
let surface_color = ev_hit.face7_color(hit.face()).clamp().to_rgb()
* SURFACE_ABSORPTION
+ Rgb::ONE * (1. - SURFACE_ABSORPTION);
let light_from_struck_face =
ev_hit.light_emission + stored_light.value() * surface_color;
Expand Down Expand Up @@ -728,7 +729,11 @@ impl LightBuffer {
// as opposed to passing through it.
// The block evaluation algorithm incidentally computes a suitable
// approximation as an alpha value.
let coverage = ev_hit.color.alpha().into_inner().clamp(0.0, 1.0);
let coverage = ev_hit
.face7_color(hit.face())
.alpha()
.into_inner()
.clamp(0.0, 1.0);
self.incoming_light += (ev_hit.light_emission + stored_light)
* coverage
* ray_state.alpha
Expand Down
Binary file modified test-renderers/expected/icons-all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b5e3cbc

Please sign in to comment.