diff options
-rw-r--r-- | draw/anim.cpp | 3 | ||||
-rw-r--r-- | main/draw.cpp | 7 | ||||
-rw-r--r-- | shaders/tile.cpp | 4 | ||||
-rw-r--r-- | shaders/tile.hpp | 4 | ||||
-rw-r--r-- | src/camera-offset.cpp | 6 | ||||
-rw-r--r-- | src/character.cpp | 4 | ||||
-rw-r--r-- | src/character.hpp | 2 | ||||
-rw-r--r-- | src/chunk-render.cpp | 2 | ||||
-rw-r--r-- | src/chunk-scenery.cpp | 3 | ||||
-rw-r--r-- | src/entity.hpp | 2 | ||||
-rw-r--r-- | src/scenery.cpp | 14 | ||||
-rw-r--r-- | src/scenery.hpp | 2 |
12 files changed, 31 insertions, 22 deletions
diff --git a/draw/anim.cpp b/draw/anim.cpp index b24dffa7..8ca03b87 100644 --- a/draw/anim.cpp +++ b/draw/anim.cpp @@ -89,8 +89,7 @@ void anim_mesh::draw(tile_shader& shader, const Vector2i& win_size, chunk& c, st else { const auto depth0 = e.depth_offset(); - const auto depth1 = depth0[1]*TILE_MAX_DIM + depth0[0]; - const auto depth = tile_shader::depth_value(e.coord.local(), depth1); + const auto depth = tile_shader::depth_value(e.coord.local(), depth0); draw(shader, atlas, e.r, e.frame, e.coord.local(), e.offset, depth); } } diff --git a/main/draw.cpp b/main/draw.cpp index 51031427..0e4ecc9f 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -127,7 +127,6 @@ void main_impl::draw_world() noexcept GL::defaultFramebuffer.clearDepth(0); #endif GL::Renderer::enable(GL::Renderer::Feature::DepthTest); - GL::Renderer::setDepthMask(true); for (int8_t z = z_max; z >= z_min; z--) @@ -160,6 +159,11 @@ void main_impl::draw_world() noexcept for (int16_t y = miny; y <= maxy; y++) for (int16_t x = minx; x <= maxx; x++) { + if (only && z != z_cur) + _shader.set_tint({1, 1, 1, 0.75}); + else + _shader.set_tint({1, 1, 1, 1}); + const chunk_coords_ pos{x, y, z}; auto* c_ = _world.at(pos); if (!c_) @@ -170,6 +174,7 @@ void main_impl::draw_world() noexcept _anim_mesh.draw(_shader, sz, c, _clickable_scenery); } + _shader.set_tint({1, 1, 1, 1}); GL::Renderer::setDepthMask(true); GL::Renderer::disable(GL::Renderer::Feature::DepthTest); diff --git a/shaders/tile.cpp b/shaders/tile.cpp index 9725c974..9c347021 100644 --- a/shaders/tile.cpp +++ b/shaders/tile.cpp @@ -78,4 +78,8 @@ float tile_shader::depth_value(const local_coords& xy, float offset) noexcept return ((float)xy.x + (float)xy.y + offset) * depth_tile_size; } +const float tile_shader::scenery_depth_offset = 1./64; +const float tile_shader::wall_depth_offset = 0; +const float tile_shader::z_depth_offset = 1e-4f; + } // namespace floormat diff --git a/shaders/tile.hpp b/shaders/tile.hpp index 47ec2f35..19d2d552 100644 --- a/shaders/tile.hpp +++ b/shaders/tile.hpp @@ -37,9 +37,9 @@ struct tile_shader : GL::AbstractShaderProgram template<typename T, typename... Xs> decltype(auto) draw(T&& mesh, Xs&&... xs); - static constexpr Vector2s max_screen_tiles{32, 32}; + static constexpr Vector2s max_screen_tiles{8, 8}; static constexpr float depth_tile_size = 1/(double)(TILE_MAX_DIM * 2 * max_screen_tiles.product()); - static constexpr float scenery_depth_offset = 0.25f, character_depth_offset = 0.25f, wall_depth_offset = 0; + static const float scenery_depth_offset, wall_depth_offset, z_depth_offset; private: void _draw(); diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp index 95933316..d662803a 100644 --- a/src/camera-offset.cpp +++ b/src/camera-offset.cpp @@ -19,11 +19,11 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun int depth = TILE_MAX_DIM*2 * pos.sum(); #if 0 - if (c_ == chunk_coords_{} || c_ == chunk_coords_{0, -1, 1}) - 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); + 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; + auto z_offset = (z-chunk_z_min) * tile_shader::depth_value({}, tile_shader::z_depth_offset); + auto d = depth * tile_shader::depth_tile_size + depth_start + z_offset; if (c_.z == chunk_z_max) d = 1; diff --git a/src/character.cpp b/src/character.cpp index 88b55d45..b00ba73a 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -130,9 +130,9 @@ void character::set_keys(bool L, bool R, bool U, bool D) b_D = D; } -Vector2 character::depth_offset() const +float character::depth_offset() const { - return Vector2(tile_shader::character_depth_offset, 0); + return tile_shader::scenery_depth_offset; } Vector2 character::ordinal_offset(Vector2b offset) const diff --git a/src/character.hpp b/src/character.hpp index db17131d..8a45ce10 100644 --- a/src/character.hpp +++ b/src/character.hpp @@ -29,7 +29,7 @@ struct character final : entity bool update(size_t i, float dt) override; void set_keys(bool L, bool R, bool U, bool D); Vector2 ordinal_offset(Vector2b offset) const override; - Vector2 depth_offset() const override; + float depth_offset() const override; String name; Vector2s offset_frac; diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp index 28bdc759..8ec10610 100644 --- a/src/chunk-render.cpp +++ b/src/chunk-render.cpp @@ -40,7 +40,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple const local_coords pos{i}; const auto quad = atlas->floor_quad(Vector3(pos) * TILE_SIZE, TILE_SIZE2); const auto texcoords = atlas->texcoords_for_id(_ground_variants[i]); - const float depth = tile_shader::depth_value(local_coords{0}); + const float depth = tile_shader::depth_value(pos); auto& v = vertexes[k]; for (auto j = 0uz; j < 4; j++) v[j] = { quad[j], texcoords[j], depth }; diff --git a/src/chunk-scenery.cpp b/src/chunk-scenery.cpp index ad29a3d7..c8dad93e 100644 --- a/src/chunk-scenery.cpp +++ b/src/chunk-scenery.cpp @@ -158,8 +158,7 @@ auto chunk::ensure_scenery_mesh(scenery_scratch_buffers buffers) noexcept -> sce const auto quad = atlas->frame_quad(coord, fr.r, fr.frame); const auto& group = atlas->group(fr.r); const auto texcoords = atlas->texcoords_for_frame(fr.r, fr.frame, !group.mirror_from.isEmpty()); - const auto depth2 = e->depth_offset(); - const auto d = depth2.y() * TILE_MAX_DIM + depth2.x(); + const auto d = e->depth_offset(); const float depth = tile_shader::depth_value(pos, d); for (auto j = 0uz; j < 4; j++) diff --git a/src/entity.hpp b/src/entity.hpp index c6ceabaf..183892d5 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -52,7 +52,7 @@ struct entity virtual ~entity() noexcept; virtual Vector2 ordinal_offset(Vector2b offset) const = 0; - virtual Vector2 depth_offset() const = 0; + virtual float depth_offset() const = 0; float ordinal() const; float ordinal(local_coords xy, Vector2b offset, Vector2s z_offset) const; struct chunk& chunk() const; diff --git a/src/scenery.cpp b/src/scenery.cpp index 1696f248..778c274b 100644 --- a/src/scenery.cpp +++ b/src/scenery.cpp @@ -88,21 +88,23 @@ Vector2 scenery::ordinal_offset(Vector2b offset) const return Vector2(offset); } -Vector2 scenery::depth_offset() const +float scenery::depth_offset() const { constexpr auto inv_tile_size = 1.f/TILE_SIZE2; - Vector2 ret; - ret += Vector2(atlas->group(r).depth_offset) * inv_tile_size; + Vector2 offset; + offset += Vector2(atlas->group(r).depth_offset) * inv_tile_size; if (sc_type == scenery_type::door) { const bool is_open = frame != atlas->info().nframes-1; constexpr auto off_opened = Vector2(-1, 0); constexpr auto off_closed = Vector2(-1, 0); const auto vec = is_open ? off_opened : off_closed; - const auto offset = rotate_point(vec, rotation::N, r); - ret += offset; + const auto pt = rotate_point(vec, rotation::N, r); + offset += pt; } - ret += Vector2(tile_shader::scenery_depth_offset, 0); + float ret = 0; + ret += offset[1]*TILE_MAX_DIM + offset[0]; + ret += tile_shader::scenery_depth_offset; return ret; } diff --git a/src/scenery.hpp b/src/scenery.hpp index 00ae28f9..a3ba7934 100644 --- a/src/scenery.hpp +++ b/src/scenery.hpp @@ -43,7 +43,7 @@ struct scenery final : entity bool update(size_t i, float dt) override; Vector2 ordinal_offset(Vector2b offset) const override; - Vector2 depth_offset() const override; + float depth_offset() const override; bool can_activate(size_t i) const override; bool activate(size_t i) override; |