From d10ef375289efd0020440d201c4610184ad2ad96 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Tue, 18 Jun 2019 22:37:48 +0100 Subject: [PATCH] Fixed AO lighting issue --- voxygen/src/mesh/segment.rs | 2 +- voxygen/src/mesh/terrain.rs | 2 +- voxygen/src/mesh/vol.rs | 33 +++++++++++++++++++-------------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/voxygen/src/mesh/segment.rs b/voxygen/src/mesh/segment.rs index 3ef53159f5..aba4d187cf 100644 --- a/voxygen/src/mesh/segment.rs +++ b/voxygen/src/mesh/segment.rs @@ -27,7 +27,7 @@ impl Meshable for Segment { pos, offs + pos.map(|e| e as f32), col, - |origin, norm, col, light| FigureVertex::new(origin, norm, col * light, 0), + |origin, norm, col, ao, light| FigureVertex::new(origin, norm, col * ao * light, 0), true, &[[[1.0; 3]; 3]; 3], ); diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index e299f9635f..8b4bd913e3 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -106,7 +106,7 @@ impl + ReadVol + Debug, S: VolSize + Clone> Meshable for pos, offs, col, - |pos, norm, col, light| TerrainVertex::new(pos, norm, col, light), + |pos, norm, col, ao, light| TerrainVertex::new(pos, norm, col * ao, light), false, &neighbour_light, ); diff --git a/voxygen/src/mesh/vol.rs b/voxygen/src/mesh/vol.rs index bb866297a6..0effa4f4b9 100644 --- a/voxygen/src/mesh/vol.rs +++ b/voxygen/src/mesh/vol.rs @@ -10,7 +10,7 @@ use crate::render::{ /// Given volume, position, and cardinal directions, compute each vertex's AO value. /// `dirs` should be a slice of length 5 so that the sliding window of size 2 over the slice /// yields each vertex' adjacent positions. -fn get_ao_quad(vol: &V, pos: Vec3, shift: Vec3, dirs: &[Vec3], corners: &[[usize; 3]; 4], darknesses: &[[[f32; 3]; 3]; 3]) -> Vec4 { +fn get_ao_quad(vol: &V, pos: Vec3, shift: Vec3, dirs: &[Vec3], corners: &[[usize; 3]; 4], darknesses: &[[[f32; 3]; 3]; 3]) -> Vec4<(f32, f32)> { dirs.windows(2) .enumerate() .map(|(i, offs)| { @@ -32,7 +32,7 @@ fn get_ao_quad(vol: &V, pos: Vec3, shift: Vec3, dirs: &[Ve .flatten() .fold(0.0, |a: f32, x| a.max(*x)); - darkness * if s1 && s2 { + (darkness, if s1 && s2 { 0.0 } else { let corner = vol @@ -41,53 +41,58 @@ fn get_ao_quad(vol: &V, pos: Vec3, shift: Vec3, dirs: &[Ve .unwrap_or(false); // Map both 1 and 2 neighbors to 0.5 occlusion. if s1 || s2 || corner { - 0.3 + 0.5 } else { 1.0 } - } + }) }) - .collect::>() + .collect::>() } // Utility function -fn create_quad, Vec3, Rgb, f32) -> P::Vertex>( +fn create_quad, Vec3, Rgb, f32, f32) -> P::Vertex>( origin: Vec3, unit_x: Vec3, unit_y: Vec3, norm: Vec3, col: Rgb, - ao: Vec4, + darkness_ao: Vec4<(f32, f32)>, vcons: &F, ) -> Quad

{ let ao_scale = 0.95; let dark = col * (1.0 - ao_scale); + let darkness = darkness_ao.map(|e| e.0); + let ao = darkness_ao.map(|e| e.1); + let ao_map = ao;//ao.map(|e| 0.2 + e.powf(1.0) * 0.8); if ao[0].min(ao[2]) < ao[1].min(ao[3]) { Quad::new( - vcons(origin + unit_y, norm, col, ao_map[3]), - vcons(origin, norm, col, ao_map[0]), - vcons(origin + unit_x, norm, col, ao_map[1]), + vcons(origin + unit_y, norm, col, darkness[3], ao_map[3]), + vcons(origin, norm, col, darkness[0], ao_map[0]), + vcons(origin + unit_x, norm, col, darkness[1], ao_map[1]), vcons( origin + unit_x + unit_y, norm, col, + darkness[2], ao_map[2], ), ) } else { Quad::new( - vcons(origin, norm, col, ao_map[0]), - vcons(origin + unit_x, norm, col, ao_map[1]), + vcons(origin, norm, col, darkness[0], ao_map[0]), + vcons(origin + unit_x, norm, col, darkness[1], ao_map[1]), vcons( origin + unit_x + unit_y, norm, col, + darkness[2], ao_map[2], ), - vcons(origin + unit_y, norm, col, ao_map[3]), + vcons(origin + unit_y, norm, col, darkness[3], ao_map[3]), ) } } @@ -95,7 +100,7 @@ fn create_quad, Vec3, Rgb, f32) -> P::Ver pub fn push_vox_verts< V: ReadVol, P: Pipeline, - F: Fn(Vec3, Vec3, Rgb, f32) -> P::Vertex, + F: Fn(Vec3, Vec3, Rgb, f32, f32) -> P::Vertex, >( mesh: &mut Mesh

, vol: &V,