summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-04-12 00:08:56 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-04-12 00:08:56 +0200
commit903e1644fce5652a621803a6eb3617d605d22434 (patch)
treece088b04f92ffc8bdb5e6c1d31e3981e20a5b2bb
parent993d828c3c2cdab6174e460c39a605dbd31d192c (diff)
wip
-rw-r--r--main/draw.cpp28
-rw-r--r--main/main-impl.hpp2
-rw-r--r--shaders/tile.cpp2
-rw-r--r--shaders/tile.hpp5
-rw-r--r--src/camera-offset.cpp2
-rw-r--r--src/chunk-render.cpp2
-rw-r--r--src/chunk-scenery.cpp4
-rw-r--r--src/entity-type.hpp2
-rw-r--r--src/scenery.cpp7
9 files changed, 22 insertions, 32 deletions
diff --git a/main/draw.cpp b/main/draw.cpp
index 732c9cee..2c9d6964 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -31,19 +31,19 @@ void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept
framebuffer.color = GL::Texture2D{};
framebuffer.color.setStorage(1, GL::TextureFormat::RGBA8, fb_size);
framebuffer.depth = GL::Renderbuffer{};
- framebuffer.depth.setStorage(GL::RenderbufferFormat::DepthComponent32F, fb_size);
+ framebuffer.depth.setStorage(GL::RenderbufferFormat::Depth32FStencil8, fb_size);
framebuffer.fb.attachTexture(GL::Framebuffer::ColorAttachment{0}, framebuffer.color, 0);
- framebuffer.fb.attachRenderbuffer(GL::Framebuffer::BufferAttachment::Depth, framebuffer.depth);
+ framebuffer.fb.attachRenderbuffer(GL::Framebuffer::BufferAttachment::DepthStencil, framebuffer.depth);
framebuffer.fb.clearColor(0, Color4{0.f, 0.f, 0.f, 1.f});
- framebuffer.fb.clearDepth(0);
+ framebuffer.fb.clearDepthStencil(0, 0);
framebuffer.fb.bind();
}
#else
GL::defaultFramebuffer.setViewport({{}, fb_size });
GL::defaultFramebuffer.clearColor(Color4{0.f, 0.f, 0.f, 1.f});
- GL::defaultFramebuffer.clearDepth(0);
+ GL::defaultFramebuffer.clearDepthStencil(0, 0);
GL::defaultFramebuffer.bind();
#endif
@@ -113,7 +113,7 @@ void main_impl::draw_world() noexcept
_clickable_scenery.clear();
#ifdef FM_USE_DEPTH32
- framebuffer.fb.clearDepth(0);
+ framebuffer.fb.clearDepthStencil(0, 0);
#else
GL::defaultFramebuffer.clearDepth(0);
#endif
@@ -127,28 +127,16 @@ void main_impl::draw_world() noexcept
for (int16_t x = minx; x <= maxx; x++)
{
const chunk_coords_ pos{x, y, z};
- if (pos == chunk_coords_{} && !_world.contains(pos))
- app.maybe_initialize_chunk(pos, _world[pos]);
- auto* c_ = _world.at(pos);
- if (!c_)
- continue;
- auto& c = *c_;
- const with_shifted_camera_offset o{_shader, pos, {minx, miny}, {maxx, maxy}};
- if (check_chunk_visible(_shader.camera_offset(), sz))
- _floor_mesh.draw(_shader, c);
- }
-
- for (int16_t y = miny; y <= maxy; y++)
- for (int16_t x = minx; x <= maxx; x++)
- {
- const chunk_coords_ pos{x, y, z};
auto* c_ = _world.at(pos);
if (!c_)
continue;
auto& c = *c_;
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);
diff --git a/main/main-impl.hpp b/main/main-impl.hpp
index fc20c947..63d18b72 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.cpp b/shaders/tile.cpp
index 8d859ff3..d5f6b7d3 100644
--- a/shaders/tile.cpp
+++ b/shaders/tile.cpp
@@ -74,7 +74,7 @@ void tile_shader::_draw()
float tile_shader::depth_value(const local_coords& xy, float offset) noexcept
{
- return (xy.to_index() + offset)*depth_tile_size;
+ return depth_tile_size + (xy.to_index() + offset)*depth_tile_size;
}
} // namespace floormat
diff --git a/shaders/tile.hpp b/shaders/tile.hpp
index 4bf78d09..fd3788f3 100644
--- a/shaders/tile.hpp
+++ b/shaders/tile.hpp
@@ -37,8 +37,9 @@ struct tile_shader : GL::AbstractShaderProgram
template<typename T, typename... Xs>
decltype(auto) draw(T&& mesh, Xs&&... xs);
- static constexpr float depth_tile_size = 1.f/(256 * TILE_COUNT);
- static constexpr float wall_depth_offset = .125f, scenery_depth_offset = .25f, character_depth_offset = .5f;
+ static constexpr float depth_tile_size = 3.56e-15; // 1 - nextafter(1, 0) * TILE_MAX_DIM / 2
+ static constexpr float depth_start = -1 + depth_tile_size;
+ static constexpr float scenery_depth_offset = .5f, character_depth_offset = .5f;
private:
void _draw();
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp
index e8c80861..0aab5ea1 100644
--- a/src/camera-offset.cpp
+++ b/src/camera-offset.cpp
@@ -19,6 +19,8 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun
const int z = c.z - chunk_z_min;
depth_offset += tile_shader::depth_value(local_coords{z, z});
+ // wip
+
if (c.z == chunk_z_max)
depth_offset = 1;
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp
index 28bdc759..802cb11a 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, tile_shader::wall_depth_offset);
+ const float depth = tile_shader::depth_value(pos);
const auto texcoords = atlas->texcoords_for_id(variant);
auto& v = vertexes[k];
for (auto j = 0uz; j < 4; j++)
diff --git a/src/chunk-scenery.cpp b/src/chunk-scenery.cpp
index 6c4a1b7c..b17b2e2a 100644
--- a/src/chunk-scenery.cpp
+++ b/src/chunk-scenery.cpp
@@ -159,7 +159,9 @@ 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 float depth = tile_shader::depth_value(pos, tile_shader::scenery_depth_offset);
+ const auto depth2 = e->depth_offset();
+ const auto d = depth2.y() * TILE_MAX_DIM + depth2.x();
+ const float depth = tile_shader::depth_value(pos, d);
for (auto j = 0uz; j < 4; j++)
scenery_vertexes[i][j] = { quad[j], texcoords[j], depth };
diff --git a/src/entity-type.hpp b/src/entity-type.hpp
index 70490645..308bc8a6 100644
--- a/src/entity-type.hpp
+++ b/src/entity-type.hpp
@@ -3,7 +3,7 @@
namespace floormat {
enum class entity_type : unsigned char {
- none, character, scenery,
+ none, character, scenery, light,
};
constexpr inline size_t entity_type_BITS = 3;
diff --git a/src/scenery.cpp b/src/scenery.cpp
index fadc0471..a07a69a5 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -90,22 +90,19 @@ Vector2 scenery::ordinal_offset(Vector2b offset) const
Vector2 scenery::depth_offset() const
{
- constexpr auto sc_offset = tile_shader::scenery_depth_offset;
constexpr auto inv_tile_size = 1.f/TILE_SIZE2;
Vector2 ret;
ret += Vector2(atlas->group(r).depth_offset) * inv_tile_size;
if (sc_type == scenery_type::door)
{
const bool is_open = frame != atlas->info().nframes-1;
- ret += Vector2(sc_offset * is_open, 0);
- constexpr auto off_opened = Vector2(-1, 0);
+ constexpr auto off_opened = Vector2(-1, 0) + Vector2();
constexpr auto off_closed = Vector2(0, 0);
const auto vec = is_open ? off_opened : off_closed;
const auto offset = rotate_point(vec, rotation::N, r);
ret += offset;
}
- else
- ret += Vector2(sc_offset, 0);
+ ret += Vector2(tile_shader::scenery_depth_offset, 0);
return ret;
}