summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main/draw.cpp18
-rw-r--r--main/main-impl.hpp2
-rw-r--r--shaders/tile.hpp2
-rw-r--r--src/camera-offset.cpp5
-rw-r--r--src/chunk-render.cpp2
5 files changed, 15 insertions, 14 deletions
diff --git a/main/draw.cpp b/main/draw.cpp
index 9adb38a2..1a46d4f6 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -22,7 +22,7 @@ void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept
update_window_state();
_shader.set_scale(Vector2{fb_size});
- GL::defaultFramebuffer.bind();
+ GL::Renderer::setDepthMask(true);
#ifdef FM_USE_DEPTH32
{
@@ -40,9 +40,12 @@ void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept
framebuffer.fb.bind();
}
-#endif
-
+#else
GL::defaultFramebuffer.setViewport({{}, fb_size });
+ GL::defaultFramebuffer.clearColor(Color4{0.f, 0.f, 0.f, 1.f});
+ GL::defaultFramebuffer.clearDepth(0);
+ GL::defaultFramebuffer.bind();
+#endif
// -- state ---
using R = GL::Renderer;
@@ -125,10 +128,11 @@ void main_impl::draw_world() noexcept
#else
GL::defaultFramebuffer.clearDepth(0);
#endif
+ GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
- for (int8_t z = z_min; z <= z_max; z++)
+ for (int8_t z = z_max; z >= z_min; z--)
{
- GL::Renderer::setDepthMask(false);
+ GL::Renderer::setDepthMask(true);
for (int16_t y = miny; y <= maxy; y++)
for (int16_t x = minx; x <= maxx; x++)
@@ -145,9 +149,6 @@ void main_impl::draw_world() noexcept
_floor_mesh.draw(_shader, c);
}
- GL::Renderer::setDepthMask(true);
- GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
-
for (int16_t y = miny; y <= maxy; y++)
for (int16_t x = minx; x <= maxx; x++)
{
@@ -178,7 +179,6 @@ void main_impl::draw_world() noexcept
}
GL::Renderer::setDepthMask(true);
-
GL::Renderer::disable(GL::Renderer::Feature::DepthTest);
}
diff --git a/main/main-impl.hpp b/main/main-impl.hpp
index 859f2a8f..2cfeffd4 100644
--- a/main/main-impl.hpp
+++ b/main/main-impl.hpp
@@ -14,7 +14,7 @@
#include <Magnum/GL/DebugOutput.h>
#include <Magnum/Platform/Sdl2Application.h>
-//#define FM_USE_DEPTH32
+#define FM_USE_DEPTH32
#ifdef FM_USE_DEPTH32
#include <Magnum/GL/Framebuffer.h>
diff --git a/shaders/tile.hpp b/shaders/tile.hpp
index 5c3d7a13..4bf78d09 100644
--- a/shaders/tile.hpp
+++ b/shaders/tile.hpp
@@ -38,7 +38,7 @@ struct tile_shader : GL::AbstractShaderProgram
decltype(auto) draw(T&& mesh, Xs&&... xs);
static constexpr float depth_tile_size = 1.f/(256 * TILE_COUNT);
- static constexpr float scenery_depth_offset = .25f, character_depth_offset = .5f;
+ static constexpr float wall_depth_offset = .125f, scenery_depth_offset = .25f, character_depth_offset = .5f;
private:
void _draw();
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp
index 88ebd0e4..f7cf23a4 100644
--- a/src/camera-offset.cpp
+++ b/src/camera-offset.cpp
@@ -14,8 +14,9 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun
const auto offset = _camera + tile_shader::project(Vector3d(c.x, c.y, 0) * chunk_size);
first.x -= 8; first.y -= 8; last.x += 8; last.y += 8; // Z levels
auto len_x = (float)(last.x - first.x), cx = (float)(c.x - first.x), cy = (float)(c.y - first.y);
- cx += c.z; cy += c.z;
- const float depth_offset = shader.depth_tile_size*(cy*TILE_MAX_DIM*len_x*TILE_MAX_DIM + cx*TILE_MAX_DIM);
+ //cx += c.z; cy += c.z;
+ float depth_offset = shader.depth_tile_size*(cy*TILE_MAX_DIM*len_x*TILE_MAX_DIM + cx*TILE_MAX_DIM);
+ depth_offset += tile_shader::depth_value(local_coords{1*c.z, 1*c.z});
_shader.set_camera_offset(offset, depth_offset);
}
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp
index 9e216e8d..8ec10610 100644
--- a/src/chunk-render.cpp
+++ b/src/chunk-render.cpp
@@ -71,7 +71,7 @@ GL::Mesh chunk::make_wall_mesh(size_t count)
const local_coords pos{i / 2u};
const auto center = Vector3(pos) * TILE_SIZE;
const auto quad = i & 1 ? atlas->wall_quad_W(center, TILE_SIZE) : atlas->wall_quad_N(center, TILE_SIZE);
- const float depth = tile_shader::depth_value(pos);
+ const float depth = tile_shader::depth_value(pos, tile_shader::wall_depth_offset);
const auto texcoords = atlas->texcoords_for_id(variant);
auto& v = vertexes[k];
for (auto j = 0uz; j < 4; j++)