summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-04-12 18:58:52 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-04-12 19:08:03 +0200
commit38efeacfd21be1c44d51b18fe9a11b0624a77cda (patch)
treead6b8632d302836e968db0115a3357694c948d5c
parentee38547c4f22ed48572a605ca71f26bd374a90ba (diff)
aaaa
-rw-r--r--main/draw.cpp11
-rw-r--r--shaders/tile.hpp5
-rw-r--r--src/camera-offset.cpp43
-rw-r--r--src/character.cpp2
4 files changed, 29 insertions, 32 deletions
diff --git a/main/draw.cpp b/main/draw.cpp
index db3bbd0c..a4291b7d 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -126,10 +126,9 @@ void main_impl::draw_world() noexcept
#endif
GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
- for (int8_t z = z_max; z >= z_min; z--)
- {
- GL::Renderer::setDepthMask(true);
+ GL::Renderer::setDepthMask(true);
+ for (int8_t z = z_max; z >= z_min; z--)
for (int16_t y = maxy; y >= miny; y--)
for (int16_t x = maxx; x >= minx; x--)
{
@@ -141,13 +140,15 @@ void main_impl::draw_world() noexcept
const with_shifted_camera_offset o{_shader, pos, {minx, miny}, {maxx, maxy}};
if (check_chunk_visible(_shader.camera_offset(), sz))
{
+
_wall_mesh.draw(_shader, c);
_floor_mesh.draw(_shader, c);
}
}
- GL::Renderer::setDepthMask(false);
+ GL::Renderer::setDepthMask(false);
+ for (int8_t z = z_max; z >= z_min; z--)
for (int16_t y = maxy; y >= miny; y--)
for (int16_t x = maxx; x >= minx; x--)
{
@@ -160,9 +161,9 @@ void main_impl::draw_world() noexcept
if (check_chunk_visible(_shader.camera_offset(), sz))
_anim_mesh.draw(_shader, sz, c, _clickable_scenery);
}
- }
GL::Renderer::setDepthMask(true);
+
GL::Renderer::disable(GL::Renderer::Feature::DepthTest);
}
diff --git a/shaders/tile.hpp b/shaders/tile.hpp
index 8415d836..f1e14c9e 100644
--- a/shaders/tile.hpp
+++ b/shaders/tile.hpp
@@ -37,9 +37,8 @@ struct tile_shader : GL::AbstractShaderProgram
template<typename T, typename... Xs>
decltype(auto) draw(T&& mesh, Xs&&... xs);
- static constexpr double depth_tile_size = 1/(double)(TILE_COUNT * 16 * 16);
- static constexpr double depth_chunk_size = 1/(double)(16 * 16);
- static constexpr float scenery_depth_offset = 0.5f, character_depth_offset = 0.5f, wall_depth_offset = 0.25f;
+ static constexpr float depth_tile_size = 1/(double)(TILE_COUNT * 16 * 16);
+ static constexpr float scenery_depth_offset = 0.25f, character_depth_offset = 0.25f, wall_depth_offset = 0.125f;
private:
void _draw();
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp
index de6f584d..ab547387 100644
--- a/src/camera-offset.cpp
+++ b/src/camera-offset.cpp
@@ -12,29 +12,26 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun
constexpr auto chunk_size = TILE_MAX_DIM20d*dTILE_SIZE;
auto offset = _camera + tile_shader::project(Vector3d(c_.x, c_.y, 0) * chunk_size);
- auto pos = Vector2d(chunk_coords(c_) - first_);
- auto len = Vector2d(last_ - first_) + Vector2d(1, 1);
- auto pos1 = pos.y() * len.x() + pos.x();
- auto z = c_.z - chunk_z_min;
- constexpr auto depth_start = -1 + 1.111e-16;
-
- double chunk_offset, tile_offset;
-
- if (c_.z < chunk_z_max)
- {
- chunk_offset = depth_start + tile_shader::depth_chunk_size * pos1;
- tile_offset = (double)tile_shader::depth_value({z, z});
- }
- else
- {
- chunk_offset = 1;
- tile_offset = 0;
- }
-
- double depth_offset_ = chunk_offset + tile_offset;
- auto depth_offset = (float)depth_offset_;
-
- _shader.set_camera_offset(offset, depth_offset);
+ auto z = (int)(c_.z - chunk_z_min);
+ auto pos = chunk_coords(c_) - first_;
+ auto len = (last_ - first_) + Vector2i(1, 1);
+ constexpr auto depth_start = -1 + 1.111e-16f;
+
+ int depth = TILE_MAX_DIM * pos.x() +
+ (int)TILE_COUNT * len.x() * pos.y() +
+ z * (TILE_MAX_DIM+1);
+
+#if 1
+ if (c_.z == 0)
+ printf("c=(%2hd %2hd %2hhd) pos=(%2d %2d) len=(%d %d) --> %d\n", c_.x, c_.y, c_.z, pos.x(), pos.y(), len.x(), len.y(), depth);
+#endif
+
+ float d = depth * tile_shader::depth_tile_size + depth_start;
+
+ if (c_.z == chunk_z_max)
+ d = 1;
+
+ _shader.set_camera_offset(offset, d);
}
with_shifted_camera_offset::~with_shifted_camera_offset()
diff --git a/src/character.cpp b/src/character.cpp
index a2098788..88b55d45 100644
--- a/src/character.cpp
+++ b/src/character.cpp
@@ -17,7 +17,7 @@ namespace {
template <typename T> constexpr T sgn(T val) { return T(T(0) < val) - T(val < T(0)); }
constexpr int tile_size_1 = iTILE_SIZE2.sum()/2,
- framerate = 96, move_speed = tile_size_1 * 2;
+ framerate = 96 * 3, move_speed = tile_size_1 * 2 * 3;
constexpr float frame_time = 1.f/framerate;
constexpr auto arrows_to_dir(bool left, bool right, bool up, bool down)