summaryrefslogtreecommitdiffhomepage
path: root/shaders
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-08 21:52:49 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-08 21:52:49 +0200
commit4c151b5d580e6c855f05583a04fbf5e4220e11cf (patch)
treeaea029a944df3ab6c404bb48472bd9498210116b /shaders
parent4a21f53f53f6982b0aec725bd9ae4eebfb1ce39c (diff)
a
Diffstat (limited to 'shaders')
-rw-r--r--shaders/tile-shader.cpp15
-rw-r--r--shaders/tile-shader.frag3
-rw-r--r--shaders/tile-shader.hpp6
3 files changed, 18 insertions, 6 deletions
diff --git a/shaders/tile-shader.cpp b/shaders/tile-shader.cpp
index 733cdd8b..aeba4929 100644
--- a/shaders/tile-shader.cpp
+++ b/shaders/tile-shader.cpp
@@ -29,8 +29,8 @@ tile_shader::tile_shader()
tile_shader& tile_shader::set_scale(const Vector2& scale)
{
- scale_ = scale;
- setUniform(ScaleUniform, scale);
+ if (scale != scale_)
+ setUniform(ScaleUniform, scale_ = scale);
return *this;
}
@@ -38,8 +38,15 @@ tile_shader& tile_shader::set_camera_offset(Vector2 camera_offset)
{
CORRADE_INTERNAL_ASSERT(std::fabs(camera_offset[0]) <= std::scalbn(1.f, std::numeric_limits<float>::digits));
CORRADE_INTERNAL_ASSERT(std::fabs(camera_offset[1]) <= std::scalbn(1.f, std::numeric_limits<float>::digits));
- camera_offset_ = camera_offset;
- setUniform(OffsetUniform, camera_offset);
+ if (camera_offset != camera_offset_)
+ setUniform(OffsetUniform, camera_offset_ = camera_offset);
+ return *this;
+}
+
+tile_shader& tile_shader::set_tint(const Color4& tint)
+{
+ if (tint != tint_)
+ setUniform(TintUniform, tint_ = tint);
return *this;
}
diff --git a/shaders/tile-shader.frag b/shaders/tile-shader.frag
index 84bcac45..13bc462c 100644
--- a/shaders/tile-shader.frag
+++ b/shaders/tile-shader.frag
@@ -1,10 +1,11 @@
precision highp float;
uniform sampler2DRect sampler;
+layout (location = 2) uniform vec4 tint = vec4(1, 1, 1, 1);
noperspective in vec2 frag_texcoords;
out vec4 color;
void main() {
- color = vec4(texture(sampler, frag_texcoords).rgb, 1);
+ color = vec4(texture(sampler, frag_texcoords).rgb, 1) * tint;
}
diff --git a/shaders/tile-shader.hpp b/shaders/tile-shader.hpp
index fd865208..2dd7e607 100644
--- a/shaders/tile-shader.hpp
+++ b/shaders/tile-shader.hpp
@@ -2,6 +2,7 @@
#include <Magnum/GL/AbstractShaderProgram.h>
#include <Magnum/Math/Vector2.h>
#include <Magnum/Math/Vector3.h>
+#include <Magnum/Math/Color.h>
namespace Magnum::Examples {
@@ -16,13 +17,16 @@ struct tile_shader : GL::AbstractShaderProgram
tile_shader& set_scale(const Vector2& scale);
Vector2 camera_offset() const { return camera_offset_; }
tile_shader& set_camera_offset(Vector2 camera_offset);
+ Color4 tint () const { return tint_; }
+ tile_shader& set_tint(const Color4& tint);
static constexpr Vector2 project(Vector3 pt);
private:
Vector2 scale_, camera_offset_;
+ Color4 tint_;
- enum { ScaleUniform = 0, OffsetUniform = 1, };
+ enum { ScaleUniform = 0, OffsetUniform = 1, TintUniform = 2, };
};
constexpr Vector2 tile_shader::project(const Vector3 pt)