diff options
Diffstat (limited to 'shaders')
| -rw-r--r-- | shaders/tile.cpp | 10 | ||||
| -rw-r--r-- | shaders/tile.frag | 1 | ||||
| -rw-r--r-- | shaders/tile.hpp | 8 | ||||
| -rw-r--r-- | shaders/tile.vert | 3 |
4 files changed, 19 insertions, 3 deletions
diff --git a/shaders/tile.cpp b/shaders/tile.cpp index 2fb37cd8..c8261acd 100644 --- a/shaders/tile.cpp +++ b/shaders/tile.cpp @@ -1,6 +1,7 @@ #include "shaders/tile.hpp" #include "loader.hpp" #include "compat/assert.hpp" +#include "local-coords.hpp" #include <Magnum/Math/Vector4.h> #include <Magnum/GL/Context.h> #include <Magnum/GL/Shader.h> @@ -65,4 +66,13 @@ void tile_shader::_draw() } } +float tile_shader::depth_value(const local_coords& xy) noexcept +{ + constexpr float max = (TILE_MAX_DIM+1)*(TILE_MAX_DIM+1) * .5f; + constexpr float min = -1 + 1.f/256; + float value = min + xy.to_index()/max; + fm_assert(value > -1 && value < 1); + return value; +} + } // namespace floormat diff --git a/shaders/tile.frag b/shaders/tile.frag index 64372b7b..a233825e 100644 --- a/shaders/tile.frag +++ b/shaders/tile.frag @@ -5,6 +5,7 @@ layout (location = 2) uniform vec4 tint = vec4(1, 1, 1, 1); noperspective in vec2 frag_texcoords; out vec4 color; +//layout (depth_greater) out float gl_FragDepth; void main() { color = texture(sampler, frag_texcoords) * tint; diff --git a/shaders/tile.hpp b/shaders/tile.hpp index 2be1414a..8a45e1e7 100644 --- a/shaders/tile.hpp +++ b/shaders/tile.hpp @@ -7,10 +7,13 @@ namespace floormat { +struct local_coords; + struct tile_shader : GL::AbstractShaderProgram { - typedef GL::Attribute<0, Vector3> Position; - typedef GL::Attribute<1, Vector2> TextureCoordinates; + using Position = GL::Attribute<0, Vector3>; + using TextureCoordinates = GL::Attribute<1, Vector2>; + using Depth = GL::Attribute<2, float>; fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(tile_shader); fm_DECLARE_DELETED_COPY_ASSIGNMENT(tile_shader); @@ -24,6 +27,7 @@ struct tile_shader : GL::AbstractShaderProgram tile_shader& set_camera_offset(Vector2d camera_offset); Vector4 tint() const { return _tint; } tile_shader& set_tint(const Vector4& tint); + static float depth_value(const local_coords& xy) noexcept; template<typename T = float> static constexpr Math::Vector2<T> project(const Math::Vector3<T>& pt); template<typename T = float> static constexpr Math::Vector2<T> unproject(const Math::Vector2<T>& px); diff --git a/shaders/tile.vert b/shaders/tile.vert index b512b7ac..ad038e6d 100644 --- a/shaders/tile.vert +++ b/shaders/tile.vert @@ -5,10 +5,11 @@ layout (location = 1) uniform vec2 offset; layout (location = 0) in vec4 position; layout (location = 1) in vec2 texcoords; +layout (location = 2) in float depth; 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, 0, 1); + gl_Position = vec4((x-y+offset.x)*scale.x, ((x+y+z*2)*.59-offset.y)*scale.y, depth, 1); frag_texcoords = texcoords; } |
