Improved long-range depth precision, removed unnecessary LoD polygons

This commit is contained in:
Joshua Barretto 2019-11-22 10:09:00 +00:00
parent 63d1b2bb22
commit f6a200d0cb
7 changed files with 19 additions and 14 deletions

View File

@ -31,14 +31,14 @@ vec3 lod_norm(vec2 pos) {
vec3 lod_col(vec2 pos) { vec3 lod_col(vec2 pos) {
vec3 warmth = mix( vec3 warmth = mix(
vec3(0.05, 0.4, 0.15), vec3(0.05, 0.4, 0.1),
vec3(0.5, 0.4, 0.0), vec3(0.5, 0.4, 0.0),
(texture(t_noise, pos * 0.0002).x - 0.5) * 2.0 + 0.5 (texture(t_noise, pos * 0.0002).x - 0.5) * 2.0 + 0.5
); );
vec3 color = mix( vec3 color = mix(
warmth, warmth,
vec3(0.5, 0.5, 0.5), vec3(0.3, 0.3, 0.4),
alt_at(pos) / 1200.0 alt_at(pos) / 1200.0
); );

View File

@ -267,6 +267,8 @@ vec3 get_sky_color(vec3 dir, float time_of_day, vec3 origin, vec3 f_pos, float q
} }
float fog(vec3 f_pos, vec3 focus_pos, uint medium) { float fog(vec3 f_pos, vec3 focus_pos, uint medium) {
return max(1.0 - 10000.0 / (1.0 + distance(f_pos.xy, focus_pos.xy)), 0.0);
float fog_radius = view_distance.x; float fog_radius = view_distance.x;
float mist_radius = 10000000.0; float mist_radius = 10000000.0;

View File

@ -13,6 +13,7 @@ out vec4 tgt_color;
void main() { void main() {
vec3 f_norm = lod_norm(f_pos.xy); vec3 f_norm = lod_norm(f_pos.xy);
vec3 f_col = lod_col(f_pos.xy); vec3 f_col = lod_col(f_pos.xy);
vec3 light, diffuse_light, ambient_light; vec3 light, diffuse_light, ambient_light;
@ -22,7 +23,7 @@ void main() {
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
vec4 clouds; vec4 clouds;
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 1.0, true, clouds); vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 1.0, true, clouds);
vec3 color = mix(mix(surf_color, fog_color, 0.0), clouds.rgb, clouds.a); vec3 color = mix(mix(surf_color, vec3(1), fog_level), clouds.rgb, clouds.a);
tgt_color = vec4(color, 1.0); tgt_color = vec4(color, 1.0);
} }

View File

@ -25,5 +25,5 @@ void main() {
proj_mat * proj_mat *
view_mat * view_mat *
vec4(f_pos, 1); vec4(f_pos, 1);
gl_Position.z = 1.0 / (1.0 - gl_Position.z - 10.0); gl_Position.z = 1.0 / (1.0 - gl_Position.z * 0.001 - 100.0);
} }

View File

@ -36,7 +36,7 @@ void main() {
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
vec4 clouds; vec4 clouds;
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 1.0, true, clouds); vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 1.0, true, clouds);
vec3 color = mix(mix(surf_color, fog_color, 0.0), clouds.rgb, clouds.a); vec3 color = mix(mix(surf_color, vec3(1), fog_level), clouds.rgb, clouds.a);
tgt_color = vec4(color, 1.0); tgt_color = vec4(color, 1.0);
} }

View File

@ -371,7 +371,7 @@ impl<V: RectRasterableVol<Vox = Block> + ReadVol + Debug> Meshable<TerrainPipeli
if block.map_or(false, |vox| vox.is_opaque()) { if block.map_or(false, |vox| vox.is_opaque()) {
vol::push_vox_verts( vol::push_vox_verts(
&mut opaque_mesh, &mut opaque_mesh,
faces_to_make(&blocks, false, |vox| !vox.is_opaque()), faces_to_make(&blocks, true, |vox| !vox.is_opaque()),
offs, offs,
&colors, &colors,
|pos, norm, col, ao, light| { |pos, norm, col, ao, light| {
@ -390,7 +390,7 @@ impl<V: RectRasterableVol<Vox = Block> + ReadVol + Debug> Meshable<TerrainPipeli
} else if block.map_or(false, |vox| vox.is_fluid()) { } else if block.map_or(false, |vox| vox.is_fluid()) {
vol::push_vox_verts( vol::push_vox_verts(
&mut fluid_mesh, &mut fluid_mesh,
faces_to_make(&blocks, false, |vox| vox.is_air()), faces_to_make(&blocks, true, |vox| vox.is_air()),
offs, offs,
&colors, &colors,
|pos, norm, col, _ao, light| { |pos, norm, col, _ao, light| {

View File

@ -13,7 +13,7 @@ impl Lod {
pub fn new(renderer: &mut Renderer) -> Self { pub fn new(renderer: &mut Renderer) -> Self {
Self { Self {
model: renderer model: renderer
.create_model(&create_lod_terrain_mesh(100)) .create_model(&create_lod_terrain_mesh(175))
.unwrap(), .unwrap(),
locals: renderer.create_consts(&[Locals::default()]).unwrap(), locals: renderer.create_consts(&[Locals::default()]).unwrap(),
} }
@ -31,12 +31,14 @@ fn create_lod_terrain_mesh(detail: usize) -> Mesh<LodTerrainPipeline> {
for x in 0..detail { for x in 0..detail {
for y in 0..detail { for y in 0..detail {
mesh.push_quad(Quad::new( if Vec2::new(x, y).map(transform).magnitude() <= 1.0 {
Vertex::new(Vec2::new(x + 0, y + 0).map(transform)), mesh.push_quad(Quad::new(
Vertex::new(Vec2::new(x + 1, y + 0).map(transform)), Vertex::new(Vec2::new(x + 0, y + 0).map(transform)),
Vertex::new(Vec2::new(x + 1, y + 1).map(transform)), Vertex::new(Vec2::new(x + 1, y + 0).map(transform)),
Vertex::new(Vec2::new(x + 0, y + 1).map(transform)), Vertex::new(Vec2::new(x + 1, y + 1).map(transform)),
)); Vertex::new(Vec2::new(x + 0, y + 1).map(transform)),
));
}
} }
} }