Merge branch 'zesterer/small-fixes' into 'master'

Zesterer/small fixes

See merge request veloren/veloren!517
This commit is contained in:
Joshua Barretto 2019-09-27 13:09:55 +00:00
commit 45fbd75907
4 changed files with 55 additions and 138 deletions

View File

@ -25,14 +25,12 @@ impl Meshable<FigurePipeline, FigurePipeline> for Segment {
for (pos, vox) in self.full_vol_iter() {
if let Some(col) = vox.get_color() {
let col = col.map(|e| e as f32 / 255.0);
vol::push_vox_verts(
&mut mesh,
self,
pos,
offs + pos.map(|e| e as f32),
&[[[Some(col); 3]; 3]; 3],
&[[[Rgba::from_opaque(col); 3]; 3]; 3],
|origin, norm, col, ao, light| {
FigureVertex::new(
origin,
@ -62,7 +60,6 @@ impl Meshable<FigurePipeline, FigurePipeline> for Segment {
ls
},
|vox| vox.is_empty(),
|vox| !vox.is_empty(),
);
}
}
@ -84,14 +81,12 @@ impl Meshable<SpritePipeline, SpritePipeline> for Segment {
for (pos, vox) in self.full_vol_iter() {
if let Some(col) = vox.get_color() {
let col = col.map(|e| e as f32 / 255.0);
vol::push_vox_verts(
&mut mesh,
self,
pos,
offs + pos.map(|e| e as f32),
&[[[Some(col); 3]; 3]; 3],
&[[[Rgba::from_opaque(col); 3]; 3]; 3],
|origin, norm, col, ao, light| {
SpriteVertex::new(
origin,
@ -102,7 +97,6 @@ impl Meshable<SpritePipeline, SpritePipeline> for Segment {
true,
&[[[1.0; 3]; 3]; 3],
|vox| vox.is_empty(),
|vox| !vox.is_empty(),
);
}
}

View File

@ -160,10 +160,11 @@ impl<V: RectRasterableVol<Vox = Block> + ReadVol + Debug> Meshable<TerrainPipeli
.ok()
.filter(|vox| vox.is_opaque())
.and_then(|vox| vox.get_color())
.map(|col| col.map(|e| e as f32 / 255.0))
.map(|col| Rgba::from_opaque(col))
.unwrap_or(Rgba::zero())
};
let mut colors = [[[None; 3]; 3]; 3];
let mut colors = [[[Rgba::zero(); 3]; 3]; 3];
for i in 0..3 {
for j in 0..3 {
for k in 0..3 {
@ -212,7 +213,6 @@ impl<V: RectRasterableVol<Vox = Block> + ReadVol + Debug> Meshable<TerrainPipeli
false,
&lights,
|vox| !vox.is_opaque(),
|vox| vox.is_opaque(),
);
} else if block.map(|vox| vox.is_fluid()).unwrap_or(false) {
vol::push_vox_verts(
@ -227,7 +227,6 @@ impl<V: RectRasterableVol<Vox = Block> + ReadVol + Debug> Meshable<TerrainPipeli
false,
&lights,
|vox| vox.is_air(),
|vox| vox.is_opaque(),
);
}
}

View File

@ -10,32 +10,48 @@ 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<V: ReadVol>(
vol: &V,
pos: Vec3<i32>,
#[allow(unsafe_code)]
fn get_ao_quad(
shift: Vec3<i32>,
dirs: &[Vec3<i32>],
darknesses: &[[[f32; 3]; 3]; 3],
is_opaque: impl Fn(&V::Vox) -> bool,
) -> Vec4<(f32, f32)> {
dirs.windows(2)
.map(|offs| {
let vox_opaque = |pos: Vec3<i32>| {
let pos = (pos + 1).map(|e| e as usize);
unsafe {
darknesses
.get_unchecked(pos.z)
.get_unchecked(pos.y)
.get_unchecked(pos.x)
<= &0.0
}
};
let (s1, s2) = (
vox_opaque(shift + offs[0]),
vox_opaque(shift + offs[1]),
/*
vol.get(pos + shift + offs[0])
.map(&is_opaque)
.unwrap_or(false),
vol.get(pos + shift + offs[1])
.map(&is_opaque)
.unwrap_or(false),
*/
);
let mut darkness = 0.0;
for x in 0..2 {
for y in 0..2 {
let dark_pos = shift + offs[0] * x + offs[1] * y + 1;
darkness += darknesses[dark_pos.z as usize][dark_pos.y as usize]
[dark_pos.x as usize]
/ 4.0;
darkness += unsafe {
darknesses
.get_unchecked(dark_pos.z as usize)
.get_unchecked(dark_pos.y as usize)
.get_unchecked(dark_pos.x as usize)
} / 4.0;
}
}
@ -44,10 +60,7 @@ fn get_ao_quad<V: ReadVol>(
if s1 && s2 {
0.0
} else {
let corner = vol
.get(pos + shift + offs[0] + offs[1])
.map(&is_opaque)
.unwrap_or(false);
let corner = vox_opaque(shift + offs[0] + offs[1]);
// Map both 1 and 2 neighbors to 0.5 occlusion.
if s1 || s2 || corner {
0.5
@ -61,32 +74,27 @@ fn get_ao_quad<V: ReadVol>(
}
#[allow(unsafe_code)]
fn get_col_quad<V: ReadVol>(
_vol: &V,
_pos: Vec3<i32>,
_shift: Vec3<i32>,
dirs: &[Vec3<i32>],
cols: &[[[Option<Rgb<f32>>; 3]; 3]; 3],
_is_opaque: impl Fn(&V::Vox) -> bool,
) -> Vec4<Rgb<f32>> {
fn get_col_quad(dirs: &[Vec3<i32>], cols: &[[[Rgba<u8>; 3]; 3]; 3]) -> Vec4<Rgb<f32>> {
dirs.windows(2)
.map(|offs| {
let primary_col = cols[1][1][1].unwrap_or(Rgb::zero());
let primary_col = Rgb::from(cols[1][1][1]).map(|e: u8| e as f32);
let mut color = Rgb::zero();
let mut total = 0.0;
for x in 0..2 {
for y in 0..2 {
let col_pos = offs[0] * x + offs[1] * y + 1;
if let Some(col) = unsafe {
let col = unsafe {
cols.get_unchecked(col_pos.z as usize)
.get_unchecked(col_pos.y as usize)
.get_unchecked(col_pos.x as usize)
} {
if Vec3::<f32>::from(primary_col).distance_squared(Vec3::from(*col))
< 0.25 * 0.25
};
if col.a > 0 {
let col = Rgb::new(col.r, col.g, col.b).map(|e| e as f32);
if Vec3::<f32>::from(primary_col).distance_squared(Vec3::from(col))
< (0.25f32 * 256.0).powf(2.0)
{
color += *col;
total += 1.0;
color += col;
total += 256.0;
}
}
}
@ -110,7 +118,7 @@ fn create_quad<P: Pipeline, F: Fn(Vec3<f32>, Vec3<f32>, Rgb<f32>, f32, f32) -> P
let darkness = darkness_ao.map(|e| e.0);
let ao = darkness_ao.map(|e| e.1);
let ao_map = ao.map(|e| e); //0.05 + e.powf(1.2) * 0.95);
let ao_map = ao;
if ao[0].min(ao[2]).min(darkness[0]).min(darkness[2])
< ao[1].min(ao[3]).min(darkness[1]).min(darkness[3])
@ -148,12 +156,11 @@ pub fn push_vox_verts<V: ReadVol, P: Pipeline>(
vol: &V,
pos: Vec3<i32>,
offs: Vec3<f32>,
cols: &[[[Option<Rgb<f32>>; 3]; 3]; 3],
cols: &[[[Rgba<u8>; 3]; 3]; 3],
vcons: impl Fn(Vec3<f32>, Vec3<f32>, Rgb<f32>, f32, f32) -> P::Vertex,
error_makes_face: bool,
darknesses: &[[[f32; 3]; 3]; 3],
should_add: impl Fn(&V::Vox) -> bool,
is_opaque: impl Fn(&V::Vox) -> bool,
) {
let (x, y, z) = (Vec3::unit_x(), Vec3::unit_y(), Vec3::unit_z());
@ -168,22 +175,8 @@ pub fn push_vox_verts<V: ReadVol, P: Pipeline>(
Vec3::unit_z(),
Vec3::unit_y(),
-Vec3::unit_x(),
get_col_quad(
vol,
pos,
-Vec3::unit_x(),
&[-z, -y, z, y, -z],
cols,
&is_opaque,
),
get_ao_quad(
vol,
pos,
-Vec3::unit_x(),
&[-z, -y, z, y, -z],
darknesses,
&is_opaque,
),
get_col_quad(&[-z, -y, z, y, -z], cols),
get_ao_quad(-Vec3::unit_x(), &[-z, -y, z, y, -z], darknesses),
&vcons,
));
}
@ -198,22 +191,8 @@ pub fn push_vox_verts<V: ReadVol, P: Pipeline>(
Vec3::unit_y(),
Vec3::unit_z(),
Vec3::unit_x(),
get_col_quad(
vol,
pos,
Vec3::unit_x(),
&[-y, -z, y, z, -y],
cols,
&is_opaque,
),
get_ao_quad(
vol,
pos,
Vec3::unit_x(),
&[-y, -z, y, z, -y],
darknesses,
&is_opaque,
),
get_col_quad(&[-y, -z, y, z, -y], cols),
get_ao_quad(Vec3::unit_x(), &[-y, -z, y, z, -y], darknesses),
&vcons,
));
}
@ -228,22 +207,8 @@ pub fn push_vox_verts<V: ReadVol, P: Pipeline>(
Vec3::unit_x(),
Vec3::unit_z(),
-Vec3::unit_y(),
get_col_quad(
vol,
pos,
-Vec3::unit_y(),
&[-x, -z, x, z, -x],
cols,
&is_opaque,
),
get_ao_quad(
vol,
pos,
-Vec3::unit_y(),
&[-x, -z, x, z, -x],
darknesses,
&is_opaque,
),
get_col_quad(&[-x, -z, x, z, -x], cols),
get_ao_quad(-Vec3::unit_y(), &[-x, -z, x, z, -x], darknesses),
&vcons,
));
}
@ -258,22 +223,8 @@ pub fn push_vox_verts<V: ReadVol, P: Pipeline>(
Vec3::unit_z(),
Vec3::unit_x(),
Vec3::unit_y(),
get_col_quad(
vol,
pos,
Vec3::unit_y(),
&[-z, -x, z, x, -z],
cols,
&is_opaque,
),
get_ao_quad(
vol,
pos,
Vec3::unit_y(),
&[-z, -x, z, x, -z],
darknesses,
&is_opaque,
),
get_col_quad(&[-z, -x, z, x, -z], cols),
get_ao_quad(Vec3::unit_y(), &[-z, -x, z, x, -z], darknesses),
&vcons,
));
}
@ -288,22 +239,8 @@ pub fn push_vox_verts<V: ReadVol, P: Pipeline>(
Vec3::unit_y(),
Vec3::unit_x(),
-Vec3::unit_z(),
get_col_quad(
vol,
pos,
-Vec3::unit_z(),
&[-y, -x, y, x, -y],
cols,
&is_opaque,
),
get_ao_quad(
vol,
pos,
-Vec3::unit_z(),
&[-y, -x, y, x, -y],
darknesses,
&is_opaque,
),
get_col_quad(&[-y, -x, y, x, -y], cols),
get_ao_quad(-Vec3::unit_z(), &[-y, -x, y, x, -y], darknesses),
&vcons,
));
}
@ -318,22 +255,8 @@ pub fn push_vox_verts<V: ReadVol, P: Pipeline>(
Vec3::unit_x(),
Vec3::unit_y(),
Vec3::unit_z(),
get_col_quad(
vol,
pos,
Vec3::unit_z(),
&[-x, -y, x, y, -x],
cols,
&is_opaque,
),
get_ao_quad(
vol,
pos,
Vec3::unit_z(),
&[-x, -y, x, y, -x],
darknesses,
&is_opaque,
),
get_col_quad(&[-x, -y, x, y, -x], cols),
get_ao_quad(Vec3::unit_z(), &[-x, -y, x, y, -x], darknesses),
&vcons,
));
}

View File

@ -246,7 +246,8 @@ impl WorldSim {
for y in pos.y - 1..=pos.y + 1 {
if x >= 0 && y >= 0 && x < WORLD_SIZE.x as i32 && y < WORLD_SIZE.y as i32 {
let posi = vec2_as_uniform_idx(Vec2::new(x, y));
if alt[posi].1.mul(CONFIG.mountain_scale) > 0.0 {
if alt[posi].1.mul(CONFIG.mountain_scale) > -8.0 {
// Account for warping in later stages
return false;
}
}