mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fixed AO lighting issue
This commit is contained in:
parent
451bbe9921
commit
d10ef37528
@ -27,7 +27,7 @@ impl Meshable for Segment {
|
|||||||
pos,
|
pos,
|
||||||
offs + pos.map(|e| e as f32),
|
offs + pos.map(|e| e as f32),
|
||||||
col,
|
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,
|
true,
|
||||||
&[[[1.0; 3]; 3]; 3],
|
&[[[1.0; 3]; 3]; 3],
|
||||||
);
|
);
|
||||||
|
@ -106,7 +106,7 @@ impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone> Meshable for
|
|||||||
pos,
|
pos,
|
||||||
offs,
|
offs,
|
||||||
col,
|
col,
|
||||||
|pos, norm, col, light| TerrainVertex::new(pos, norm, col, light),
|
|pos, norm, col, ao, light| TerrainVertex::new(pos, norm, col * ao, light),
|
||||||
false,
|
false,
|
||||||
&neighbour_light,
|
&neighbour_light,
|
||||||
);
|
);
|
||||||
|
@ -10,7 +10,7 @@ use crate::render::{
|
|||||||
/// Given volume, position, and cardinal directions, compute each vertex's AO value.
|
/// 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
|
/// `dirs` should be a slice of length 5 so that the sliding window of size 2 over the slice
|
||||||
/// yields each vertex' adjacent positions.
|
/// yields each vertex' adjacent positions.
|
||||||
fn get_ao_quad<V: ReadVol>(vol: &V, pos: Vec3<i32>, shift: Vec3<i32>, dirs: &[Vec3<i32>], corners: &[[usize; 3]; 4], darknesses: &[[[f32; 3]; 3]; 3]) -> Vec4<f32> {
|
fn get_ao_quad<V: ReadVol>(vol: &V, pos: Vec3<i32>, shift: Vec3<i32>, dirs: &[Vec3<i32>], corners: &[[usize; 3]; 4], darknesses: &[[[f32; 3]; 3]; 3]) -> Vec4<(f32, f32)> {
|
||||||
dirs.windows(2)
|
dirs.windows(2)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, offs)| {
|
.map(|(i, offs)| {
|
||||||
@ -32,7 +32,7 @@ fn get_ao_quad<V: ReadVol>(vol: &V, pos: Vec3<i32>, shift: Vec3<i32>, dirs: &[Ve
|
|||||||
.flatten()
|
.flatten()
|
||||||
.fold(0.0, |a: f32, x| a.max(*x));
|
.fold(0.0, |a: f32, x| a.max(*x));
|
||||||
|
|
||||||
darkness * if s1 && s2 {
|
(darkness, if s1 && s2 {
|
||||||
0.0
|
0.0
|
||||||
} else {
|
} else {
|
||||||
let corner = vol
|
let corner = vol
|
||||||
@ -41,53 +41,58 @@ fn get_ao_quad<V: ReadVol>(vol: &V, pos: Vec3<i32>, shift: Vec3<i32>, dirs: &[Ve
|
|||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
// Map both 1 and 2 neighbors to 0.5 occlusion.
|
// Map both 1 and 2 neighbors to 0.5 occlusion.
|
||||||
if s1 || s2 || corner {
|
if s1 || s2 || corner {
|
||||||
0.3
|
0.5
|
||||||
} else {
|
} else {
|
||||||
1.0
|
1.0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect::<Vec4<f32>>()
|
})
|
||||||
|
.collect::<Vec4<(f32, f32)>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility function
|
// Utility function
|
||||||
fn create_quad<P: Pipeline, F: Fn(Vec3<f32>, Vec3<f32>, Rgb<f32>, f32) -> P::Vertex>(
|
fn create_quad<P: Pipeline, F: Fn(Vec3<f32>, Vec3<f32>, Rgb<f32>, f32, f32) -> P::Vertex>(
|
||||||
origin: Vec3<f32>,
|
origin: Vec3<f32>,
|
||||||
unit_x: Vec3<f32>,
|
unit_x: Vec3<f32>,
|
||||||
unit_y: Vec3<f32>,
|
unit_y: Vec3<f32>,
|
||||||
norm: Vec3<f32>,
|
norm: Vec3<f32>,
|
||||||
col: Rgb<f32>,
|
col: Rgb<f32>,
|
||||||
ao: Vec4<f32>,
|
darkness_ao: Vec4<(f32, f32)>,
|
||||||
vcons: &F,
|
vcons: &F,
|
||||||
) -> Quad<P> {
|
) -> Quad<P> {
|
||||||
let ao_scale = 0.95;
|
let ao_scale = 0.95;
|
||||||
let dark = col * (1.0 - ao_scale);
|
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);
|
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]) {
|
if ao[0].min(ao[2]) < ao[1].min(ao[3]) {
|
||||||
Quad::new(
|
Quad::new(
|
||||||
vcons(origin + unit_y, norm, col, ao_map[3]),
|
vcons(origin + unit_y, norm, col, darkness[3], ao_map[3]),
|
||||||
vcons(origin, norm, col, ao_map[0]),
|
vcons(origin, norm, col, darkness[0], ao_map[0]),
|
||||||
vcons(origin + unit_x, norm, col, ao_map[1]),
|
vcons(origin + unit_x, norm, col, darkness[1], ao_map[1]),
|
||||||
vcons(
|
vcons(
|
||||||
origin + unit_x + unit_y,
|
origin + unit_x + unit_y,
|
||||||
norm,
|
norm,
|
||||||
col,
|
col,
|
||||||
|
darkness[2],
|
||||||
ao_map[2],
|
ao_map[2],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Quad::new(
|
Quad::new(
|
||||||
vcons(origin, norm, col, ao_map[0]),
|
vcons(origin, norm, col, darkness[0], ao_map[0]),
|
||||||
vcons(origin + unit_x, norm, col, ao_map[1]),
|
vcons(origin + unit_x, norm, col, darkness[1], ao_map[1]),
|
||||||
vcons(
|
vcons(
|
||||||
origin + unit_x + unit_y,
|
origin + unit_x + unit_y,
|
||||||
norm,
|
norm,
|
||||||
col,
|
col,
|
||||||
|
darkness[2],
|
||||||
ao_map[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<P: Pipeline, F: Fn(Vec3<f32>, Vec3<f32>, Rgb<f32>, f32) -> P::Ver
|
|||||||
pub fn push_vox_verts<
|
pub fn push_vox_verts<
|
||||||
V: ReadVol,
|
V: ReadVol,
|
||||||
P: Pipeline,
|
P: Pipeline,
|
||||||
F: Fn(Vec3<f32>, Vec3<f32>, Rgb<f32>, f32) -> P::Vertex,
|
F: Fn(Vec3<f32>, Vec3<f32>, Rgb<f32>, f32, f32) -> P::Vertex,
|
||||||
>(
|
>(
|
||||||
mesh: &mut Mesh<P>,
|
mesh: &mut Mesh<P>,
|
||||||
vol: &V,
|
vol: &V,
|
||||||
|
Loading…
Reference in New Issue
Block a user