From b25f19d99a78099e10319983cb8230266a2c9870 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 13 Jun 2023 04:30:28 +0200 Subject: shaders: use exact value for foreshortening factor --- shaders/shader.hpp | 6 ++++-- shaders/shader.vert | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'shaders') diff --git a/shaders/shader.hpp b/shaders/shader.hpp index 06bf2928..79ceb940 100644 --- a/shaders/shader.hpp +++ b/shaders/shader.hpp @@ -66,14 +66,16 @@ constexpr Math::Vector2 tile_shader::project(const Math::Vector3& pt) { static_assert(std::is_floating_point_v); const auto x = pt[0], y = pt[1], z = -pt[2]; - return { x-y, (x+y+z*2)*T(.59) }; + return { x-y, (x+y+z*2)*T(foreshortening_factor) }; } template constexpr Math::Vector2 tile_shader::unproject(const Math::Vector2& px) { + static_assert(std::is_floating_point_v); const auto X = px[0], Y = px[1]; - return { X + 100 * Y / 59, 100 * Y / 59 - X }; + const auto Y_ = Y / T(foreshortening_factor); + return { X + Y_, Y_ - X }; } } // namespace floormat diff --git a/shaders/shader.vert b/shaders/shader.vert index a539ed6b..9190fe8d 100644 --- a/shaders/shader.vert +++ b/shaders/shader.vert @@ -10,6 +10,6 @@ noperspective out vec2 frag_texcoords; void main() { float x = -position.y, y = -position.x, z = position.z; - gl_Position = vec4((x-y+offset.x)*scale.x, ((x+y+z*2)*.59-offset.y)*scale.y, offset.z + depth, 1); + gl_Position = vec4((x-y+offset.x)*scale.x, ((x+y+z*2)*0.578125-offset.y)*scale.y, offset.z + depth, 1); frag_texcoords = texcoords; } -- cgit v1.2.3