Fixed water in caves, made water reflection vary with lighting

This commit is contained in:
Joshua Barretto 2019-08-16 12:38:59 +01:00
parent 3c214c62a8
commit e02a2142cf
5 changed files with 40 additions and 23 deletions

View File

@ -28,8 +28,8 @@ void main() {
vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz); vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
vec3 warped_norm = normalize(f_norm + smooth_rand(f_pos * 0.35, tick.x) * 0.2); vec3 warped_norm = normalize(f_norm + smooth_rand(f_pos * 0.35, tick.x) * 0.2);
vec3 reflect_color = get_sky_color(reflect(cam_to_frag, warped_norm), time_of_day.x); vec3 reflect_color = get_sky_color(reflect(cam_to_frag, warped_norm), time_of_day.x) * light;
float passthrough = max(dot(f_norm, -cam_to_frag), 0.0); float passthrough = dot(faceforward(f_norm, f_norm, cam_to_frag), -cam_to_frag);
vec4 color = mix(vec4(reflect_color, 1.0), vec4(surf_color, f_opac), passthrough); vec4 color = mix(vec4(reflect_color, 1.0), vec4(surf_color, f_opac), passthrough);

View File

@ -108,7 +108,7 @@ impl<'a> System<'a> for Sys {
if terrain if terrain
.get(block_pos) .get(block_pos)
.map(|vox| !vox.is_empty()) .map(|vox| vox.is_solid())
.unwrap_or(false) .unwrap_or(false)
{ {
let player_aabb = Aabb { let player_aabb = Aabb {
@ -183,7 +183,7 @@ impl<'a> System<'a> for Sys {
.filter(|(block_pos, _)| { .filter(|(block_pos, _)| {
terrain terrain
.get(*block_pos) .get(*block_pos)
.map(|vox| !vox.is_empty()) .map(|vox| vox.is_solid())
.unwrap_or(false) .unwrap_or(false)
}) })
// Find the maximum of the minimum collision axes (this bit is weird, trust me that it works) // Find the maximum of the minimum collision axes (this bit is weird, trust me that it works)

View File

@ -34,6 +34,14 @@ impl BlockKind {
_ => true, _ => true,
} }
} }
pub fn is_solid(&self) -> bool {
match self {
BlockKind::Air => false,
BlockKind::Water => false,
_ => true,
}
}
} }
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]

View File

@ -13,12 +13,12 @@ use vek::*;
type TerrainVertex = <TerrainPipeline as render::Pipeline>::Vertex; type TerrainVertex = <TerrainPipeline as render::Pipeline>::Vertex;
type FluidVertex = <FluidPipeline as render::Pipeline>::Vertex; type FluidVertex = <FluidPipeline as render::Pipeline>::Vertex;
fn block_shadow_density(kind: BlockKind) -> Option<f32> { fn block_shadow_density(kind: BlockKind) -> (f32, f32) {
match kind { match kind {
BlockKind::Air => None, BlockKind::Air => (0.0, 0.0),
BlockKind::Normal => Some(0.85), BlockKind::Normal => (0.085, 0.3),
BlockKind::Dense => Some(3.0), BlockKind::Dense => (0.3, 0.0),
BlockKind::Water => Some(0.8), BlockKind::Water => (0.08, 0.0),
} }
} }
@ -94,16 +94,14 @@ impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone> Meshable for
// Accumulate shade under opaque blocks // Accumulate shade under opaque blocks
for i in 0..3 { for i in 0..3 {
for j in 0..3 { for j in 0..3 {
neighbour_light[0][i][j] = if let Some(density) = self let (density, cap) = self
.get(pos + Vec3::new(i as i32 - 1, j as i32 - 1, -1)) .get(pos + Vec3::new(i as i32 - 1, j as i32 - 1, -1))
.ok() .ok()
.and_then(|vox| block_shadow_density(vox.kind())) .map(|vox| block_shadow_density(vox.kind()))
{ .unwrap_or((0.0, 0.0));
(neighbour_light[0][i][j] * (1.0 - density * 0.1))
.max(1.0 - density) neighbour_light[0][i][j] =
} else { (neighbour_light[0][i][j] * (1.0 - density)).max(cap);
(neighbour_light[0][i][j] * 1.025).min(1.0)
};
} }
} }

View File

@ -163,7 +163,7 @@ impl<'a> BlockGen<'a> {
let (definitely_underground, height, water_height) = let (definitely_underground, height, water_height) =
if (wposf.z as f32) < alt - 64.0 * chaos { if (wposf.z as f32) < alt - 64.0 * chaos {
// Shortcut warping // Shortcut warping
(true, alt, water_level) (true, alt, CONFIG.sea_level /*water_level*/)
} else { } else {
// Apply warping // Apply warping
let warp = (world let warp = (world
@ -204,7 +204,11 @@ impl<'a> BlockGen<'a> {
(alt + warp).max(cliff_height) (alt + warp).max(cliff_height)
}; };
(false, height, (water_level + warp).max(CONFIG.sea_level)) (
false,
height,
/*(water_level + warp).max(*/ CONFIG.sea_level, /*)*/
)
}; };
// Sample blocks // Sample blocks
@ -250,9 +254,6 @@ impl<'a> BlockGen<'a> {
BlockKind::Normal, BlockKind::Normal,
saturate_srgb(col, 0.45).map(|e| (e * 255.0) as u8), saturate_srgb(col, 0.45).map(|e| (e * 255.0) as u8),
)) ))
} else if (wposf.z as f32) < water_height {
// Ocean
Some(water)
} else { } else {
None None
}; };
@ -296,6 +297,16 @@ impl<'a> BlockGen<'a> {
} }
}); });
// Water
let block = block.or_else(|| {
if (wposf.z as f32) < water_height {
// Ocean
Some(water)
} else {
None
}
});
let block = structures let block = structures
.iter() .iter()
.find_map(|st| { .find_map(|st| {