From fa63463310b48a9bcc913a0840d40bfe84f25aa0 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Wed, 27 Aug 2025 01:03:45 -0400 Subject: [PATCH 01/13] Water refraction effect --- data/shader/shader330.frag | 19 +++++++++++++++- data/shader/shader330.vert | 3 +++ src/object/tilemap.cpp | 5 +++- src/video/canvas.cpp | 38 +++++++++++++++++++++++++++++++ src/video/canvas.hpp | 13 +++++++++++ src/video/drawing_request.hpp | 2 ++ src/video/gl/gl20_context.cpp | 6 +++++ src/video/gl/gl20_context.hpp | 2 ++ src/video/gl/gl33core_context.cpp | 6 +++++ src/video/gl/gl33core_context.hpp | 2 ++ src/video/gl/gl_context.hpp | 2 ++ src/video/gl/gl_painter.cpp | 10 +++++++- src/video/gl/gl_painter.hpp | 1 + src/video/gl/gl_program.cpp | 4 +++- src/video/gl/gl_program.hpp | 2 ++ src/video/gl/gl_vertex_arrays.cpp | 18 +++++++++++++++ src/video/gl/gl_vertex_arrays.hpp | 3 +++ 17 files changed, 132 insertions(+), 4 deletions(-) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index 291be7547cd..47227473846 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -12,6 +12,7 @@ uniform bool is_displacement; in vec4 diffuse_var; in vec2 texcoord_var; +flat in uint attrs_var; out vec4 fragColor; @@ -20,7 +21,23 @@ void main(void) if (backbuffer == 0.0 || !is_displacement) { vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time)); - fragColor = color; + if ((attrs_var & 0x0200u) == 0x0200u && (attrs_var & 0x0800u) != 0x0800u) // Water (not lava) + { + vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st); + vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy + vec2(0.0, 0.03); + uv.x = uv.x + 0.003 * sin(game_time + uv.y * 80); + uv.y = 1.0 - uv.y + 0.005 * cos(game_time + uv.y * 140);; + vec4 back_color = texture(framebuffer_texture, uv); + + if (backbuffer == 0.0) + fragColor = color; + else + fragColor = vec4(mix(color.rgb, back_color.rgb, 0.2 * backbuffer), 1.0); + } + else + { + fragColor = color; + } } else if (is_displacement) { diff --git a/data/shader/shader330.vert b/data/shader/shader330.vert index 8a0c413c844..a46fc3a3a88 100644 --- a/data/shader/shader330.vert +++ b/data/shader/shader330.vert @@ -3,9 +3,11 @@ in vec2 texcoord; in vec2 position; in vec4 diffuse; +in uint attrs; out vec2 texcoord_var; out vec4 diffuse_var; +flat out uint attrs_var; uniform mat3 modelviewprojection; @@ -13,6 +15,7 @@ void main(void) { texcoord_var = texcoord; diffuse_var = diffuse; + attrs_var = attrs; gl_Position = vec4(vec3(position, 1) * modelviewprojection, 1.0); } diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index 0b9f8d067ea..8ee2297030c 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -555,7 +555,8 @@ TileMap::draw(DrawingContext& context) std::unordered_map, - std::vector>> batches; + std::vector, + std::vector>> batches; for (pos.x = start.x, tx = t_draw_rect.left; tx < t_draw_rect.right; pos.x += 32, ++tx) { for (pos.y = start.y, ty = t_draw_rect.top; ty < t_draw_rect.bottom; pos.y += 32, ++ty) { @@ -584,6 +585,7 @@ TileMap::draw(DrawingContext& context) std::get<1>(batches[surface]).emplace_back(pos, Sizef(static_cast(surface->get_width()), static_cast(surface->get_height()))); + std::get<2>(batches[surface]).emplace_back(tile.get_attributes()); } } } @@ -597,6 +599,7 @@ TileMap::draw(DrawingContext& context) canvas.draw_surface_batch(surface, std::move(std::get<0>(it.second)), std::move(std::get<1>(it.second)), + std::move(std::get<2>(it.second)), m_current_tint, m_z_pos); } } diff --git a/src/video/canvas.cpp b/src/video/canvas.cpp index 103bdbfb5c1..a6c5b78634a 100644 --- a/src/video/canvas.cpp +++ b/src/video/canvas.cpp @@ -137,6 +137,7 @@ Canvas::draw_surface(const SurfacePtr& surface, request->dstrects.emplace_back(Rectf(apply_translate(position) * scale(), Sizef(static_cast(surface->get_width()) * scale(), static_cast(surface->get_height()) * scale()))); + request->attrs.emplace_back(0); request->angles.emplace_back(angle); request->texture = surface->get_texture().get(); request->displacement_texture = surface->get_displacement_texture().get(); @@ -175,6 +176,7 @@ Canvas::draw_surface_part(const SurfacePtr& surface, const Rectf& srcrect, const request->srcrects.emplace_back(srcrect); request->dstrects.emplace_back(apply_translate(dstrect.p1())*scale(), dstrect.get_size()*scale()); request->angles.emplace_back(0.0f); + request->attrs.emplace_back(0); request->texture = surface->get_texture().get(); request->displacement_texture = surface->get_displacement_texture().get(); request->color = style.get_color(); @@ -188,11 +190,28 @@ Canvas::draw_surface_batch(const SurfacePtr& surface, std::vector dstrects, const Color& color, int layer) +{ + draw_surface_batch(surface, + std::move(srcrects), + std::move(dstrects), + std::vector(srcrects.size(), 0.0f), + std::vector(srcrects.size(), 0.0f), + color, layer); +} + +void +Canvas::draw_surface_batch(const SurfacePtr& surface, + std::vector srcrects, + std::vector dstrects, + std::vector attrs, + const Color& color, + int layer) { const size_t len = srcrects.size(); draw_surface_batch(surface, std::move(srcrects), std::move(dstrects), + std::move(attrs), std::vector(len, 0.0f), color, layer); } @@ -204,6 +223,24 @@ Canvas::draw_surface_batch(const SurfacePtr& surface, std::vector angles, const Color& color, int layer) +{ + const size_t len = srcrects.size(); + draw_surface_batch(surface, + std::move(srcrects), + std::move(dstrects), + std::vector(len, 0), + std::move(angles), + color, layer); +} + +void +Canvas::draw_surface_batch(const SurfacePtr& surface, + std::vector srcrects, + std::vector dstrects, + std::vector attrs, + std::vector angles, + const Color& color, + int layer) { if (!surface) return; @@ -215,6 +252,7 @@ Canvas::draw_surface_batch(const SurfacePtr& surface, request->srcrects = std::move(srcrects); request->dstrects = std::move(dstrects); + request->attrs = std::move(attrs); request->angles = std::move(angles); for (auto& dstrect : request->dstrects) diff --git a/src/video/canvas.hpp b/src/video/canvas.hpp index 0e33019d573..49468add51b 100644 --- a/src/video/canvas.hpp +++ b/src/video/canvas.hpp @@ -66,6 +66,19 @@ class Canvas final std::vector angles, const Color& color, int layer); + void draw_surface_batch(const SurfacePtr& surface, + std::vector srcrects, + std::vector dstrects, + std::vector attrs, + const Color& color, + int layer); + void draw_surface_batch(const SurfacePtr& surface, + std::vector srcrects, + std::vector dstrects, + std::vector attrs, + std::vector angles, + const Color& color, + int layer); Rectf draw_text(const FontPtr& font, const std::string& text, const Vector& position, FontAlignment alignment, int layer, const Color& color = Color(1.0,1.0,1.0)); /** Draw text to the center of the screen */ diff --git a/src/video/drawing_request.hpp b/src/video/drawing_request.hpp index a34aaafa266..4b27bf3b6b8 100644 --- a/src/video/drawing_request.hpp +++ b/src/video/drawing_request.hpp @@ -64,6 +64,7 @@ struct TextureRequest : public DrawingRequest displacement_texture(), srcrects(), dstrects(), + attrs(), angles(), color(1.0f, 1.0f, 1.0f) {} @@ -74,6 +75,7 @@ struct TextureRequest : public DrawingRequest const Texture* displacement_texture; std::vector srcrects; std::vector dstrects; + std::vector attrs; std::vector angles; Color color; diff --git a/src/video/gl/gl20_context.cpp b/src/video/gl/gl20_context.cpp index 11e24c795f1..6e2334a1aca 100644 --- a/src/video/gl/gl20_context.cpp +++ b/src/video/gl/gl20_context.cpp @@ -113,6 +113,12 @@ GL20Context::set_texcoord(float u, float v) assert_gl(); } + +void +GL20Context::set_attrs(const uint32_t* data, size_t size) +{ +} + void GL20Context::set_colors(const float* data, size_t size) { diff --git a/src/video/gl/gl20_context.hpp b/src/video/gl/gl20_context.hpp index d1d7b0909ab..1caf364ea5e 100644 --- a/src/video/gl/gl20_context.hpp +++ b/src/video/gl/gl20_context.hpp @@ -41,6 +41,8 @@ class GL20Context final : public GLContext virtual void set_colors(const float* data, size_t size) override; virtual void set_color(const Color& color) override; + + virtual void set_attrs(const uint32_t* data, size_t size) override; virtual void bind_texture(const Texture& texture, const Texture* displacement_texture) override; virtual void bind_no_texture() override; diff --git a/src/video/gl/gl33core_context.cpp b/src/video/gl/gl33core_context.cpp index 928c917f004..e0060527be6 100644 --- a/src/video/gl/gl33core_context.cpp +++ b/src/video/gl/gl33core_context.cpp @@ -176,6 +176,12 @@ GL33CoreContext::set_color(const Color& color) m_vertex_arrays->set_color(color); } +void +GL33CoreContext::set_attrs(const uint32_t* data, size_t size) +{ + m_vertex_arrays->set_attrs(data, size); +} + void GL33CoreContext::bind_texture(const Texture& texture, const Texture* displacement_texture) { diff --git a/src/video/gl/gl33core_context.hpp b/src/video/gl/gl33core_context.hpp index 529cca8cf15..24040d9e4f6 100644 --- a/src/video/gl/gl33core_context.hpp +++ b/src/video/gl/gl33core_context.hpp @@ -43,6 +43,8 @@ class GL33CoreContext final : public GLContext virtual void set_texcoords(const float* data, size_t size) override; virtual void set_texcoord(float u, float v) override; + + virtual void set_attrs(const uint32_t* data, size_t size) override; virtual void set_colors(const float* data, size_t size) override; virtual void set_color(const Color& color) override; diff --git a/src/video/gl/gl_context.hpp b/src/video/gl/gl_context.hpp index c55bf56ba3b..4c500b9d079 100644 --- a/src/video/gl/gl_context.hpp +++ b/src/video/gl/gl_context.hpp @@ -46,6 +46,8 @@ class GLContext virtual void set_colors(const float* data, size_t size) = 0; virtual void set_color(const Color& color) = 0; + + virtual void set_attrs(const uint32_t* data, size_t size) = 0; virtual void bind_texture(const Texture& texture, const Texture* displacement_texture) = 0; virtual void bind_no_texture() = 0; diff --git a/src/video/gl/gl_painter.cpp b/src/video/gl/gl_painter.cpp index 382606c3cd4..8b3ed977604 100644 --- a/src/video/gl/gl_painter.cpp +++ b/src/video/gl/gl_painter.cpp @@ -17,6 +17,7 @@ #include "video/gl/gl_painter.hpp" #include +#include #include #include "math/util.hpp" @@ -63,7 +64,8 @@ GLPainter::GLPainter(GLVideoSystem& video_system, GLRenderer& renderer) : m_video_system(video_system), m_renderer(renderer), m_vertices(), - m_uvs() + m_uvs(), + m_attrs() { } @@ -76,12 +78,15 @@ GLPainter::draw_texture(const TextureRequest& request) assert(request.srcrects.size() == request.dstrects.size()); assert(request.srcrects.size() == request.angles.size()); + assert(request.attrs.size() == request.attrs.size()); m_vertices.reserve(request.srcrects.size() * 12); m_uvs.reserve(request.srcrects.size() * 12); + m_attrs.reserve(request.attrs.size() * 12); m_vertices.clear(); m_uvs.clear(); + m_attrs.clear(); for (size_t i = 0; i < request.srcrects.size(); ++i) { @@ -94,6 +99,8 @@ GLPainter::draw_texture(const TextureRequest& request) float uv_top = request.srcrects[i].get_top() / static_cast(texture.get_texture_height()); float uv_right = request.srcrects[i].get_right() / static_cast(texture.get_texture_width()); float uv_bottom = request.srcrects[i].get_bottom() / static_cast(texture.get_texture_height()); + + m_attrs.insert(m_attrs.end(), 6, request.attrs[i]); if (request.flip & HORIZONTAL_FLIP) std::swap(uv_left, uv_right); @@ -170,6 +177,7 @@ GLPainter::draw_texture(const TextureRequest& request) context.bind_texture(texture, request.displacement_texture); context.set_texcoords(m_uvs.data(), sizeof(float) * m_uvs.size()); context.set_positions(m_vertices.data(), sizeof(float) * m_vertices.size()); + context.set_attrs(m_attrs.data(), sizeof(uint32_t) * m_attrs.size()); context.set_color(Color(request.color.red, request.color.green, request.color.blue, diff --git a/src/video/gl/gl_painter.hpp b/src/video/gl/gl_painter.hpp index 3d8117698d4..6d33fb6ee98 100644 --- a/src/video/gl/gl_painter.hpp +++ b/src/video/gl/gl_painter.hpp @@ -49,6 +49,7 @@ class GLPainter final : public Painter private: std::vector m_vertices; std::vector m_uvs; + std::vector m_attrs; private: GLPainter(const GLPainter&) = delete; diff --git a/src/video/gl/gl_program.cpp b/src/video/gl/gl_program.cpp index 39ab329b25c..8c00a638851 100644 --- a/src/video/gl/gl_program.cpp +++ b/src/video/gl/gl_program.cpp @@ -37,7 +37,8 @@ GLProgram::GLProgram() : m_position_location(-1), m_texcoord_location(-1), m_diffuse_location(-1), - m_is_displacement_location(-1) + m_is_displacement_location(-1), + m_attrs_location(-1) { assert_gl(); @@ -77,6 +78,7 @@ GLProgram::GLProgram() : m_position_location = glGetAttribLocation(m_program, "position"); m_texcoord_location = glGetAttribLocation(m_program, "texcoord"); m_diffuse_location = glGetAttribLocation(m_program, "diffuse"); + m_attrs_location = glGetAttribLocation(m_program, "attrs"); assert_gl(); } diff --git a/src/video/gl/gl_program.hpp b/src/video/gl/gl_program.hpp index 7fb16163cdc..73cfd8761c1 100644 --- a/src/video/gl/gl_program.hpp +++ b/src/video/gl/gl_program.hpp @@ -46,6 +46,7 @@ class GLProgram final inline GLint get_texcoord_location() const { return check_valid(m_texcoord_location, "texcoord"); } inline GLint get_diffuse_location() const { return check_valid(m_diffuse_location, "diffuse"); } inline GLint get_is_displacement_location() const { return check_valid(m_is_displacement_location, "is_displacement"); } + inline GLint get_attrs_location() const { return check_valid(m_attrs_location, "attrs"); } private: bool get_link_status() const; @@ -72,6 +73,7 @@ class GLProgram final GLint m_texcoord_location; GLint m_diffuse_location; GLint m_is_displacement_location; + GLint m_attrs_location; private: GLProgram(const GLProgram&) = delete; diff --git a/src/video/gl/gl_vertex_arrays.cpp b/src/video/gl/gl_vertex_arrays.cpp index e48eb12a8ce..7016358257e 100644 --- a/src/video/gl/gl_vertex_arrays.cpp +++ b/src/video/gl/gl_vertex_arrays.cpp @@ -27,6 +27,7 @@ GLVertexArrays::GLVertexArrays(GL33CoreContext& context) : m_vao(), m_positions_buffer(), m_texcoords_buffer(), + m_attrs_buffer(), m_color_buffer() { assert_gl(); @@ -34,6 +35,7 @@ GLVertexArrays::GLVertexArrays(GL33CoreContext& context) : glGenVertexArrays(1, &m_vao); glGenBuffers(1, &m_positions_buffer); glGenBuffers(1, &m_texcoords_buffer); + glGenBuffers(1, &m_attrs_buffer); glGenBuffers(1, &m_color_buffer); assert_gl(); @@ -43,6 +45,7 @@ GLVertexArrays::~GLVertexArrays() { glDeleteBuffers(1, &m_positions_buffer); glDeleteBuffers(1, &m_texcoords_buffer); + glDeleteBuffers(1, &m_attrs_buffer); glDeleteBuffers(1, &m_color_buffer); glDeleteVertexArrays(1, &m_vao); } @@ -87,6 +90,21 @@ GLVertexArrays::set_texcoords(const float* data, size_t size) assert_gl(); } +void +GLVertexArrays::set_attrs(const uint32_t* data, size_t size) +{ + assert_gl(); + + glBindBuffer(GL_ARRAY_BUFFER, m_attrs_buffer); + glBufferData(GL_ARRAY_BUFFER, size, data, GL_DYNAMIC_DRAW); + + int loc = m_context.get_program().get_attrs_location(); + glVertexAttribIPointer(loc, 1, GL_UNSIGNED_INT, sizeof(uint32_t), nullptr); + glEnableVertexAttribArray(loc); + + assert_gl(); +} + void GLVertexArrays::set_texcoord(float u, float v) { diff --git a/src/video/gl/gl_vertex_arrays.hpp b/src/video/gl/gl_vertex_arrays.hpp index a3508239d2f..2a6fc6ba48a 100644 --- a/src/video/gl/gl_vertex_arrays.hpp +++ b/src/video/gl/gl_vertex_arrays.hpp @@ -32,6 +32,8 @@ class GLVertexArrays final void bind(); void set_positions(const float* data, size_t size); + + void set_attrs(const uint32_t* data, size_t size); /** size is in bytes */ void set_texcoords(const float* data, size_t size); @@ -46,6 +48,7 @@ class GLVertexArrays final GLuint m_positions_buffer; GLuint m_texcoords_buffer; GLuint m_color_buffer; + GLuint m_attrs_buffer; private: GLVertexArrays(const GLVertexArrays&) = delete; From 2739b1c7f2833bf9e89c75bc8a3ea8ba17aa1cca Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Wed, 27 Aug 2025 17:17:54 -0400 Subject: [PATCH 02/13] Draw objects under water if in water --- data/shader/shader330.frag | 4 ++-- src/badguy/badguy.cpp | 15 ++++++++------- src/object/player.cpp | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index 47227473846..56f84b65a2b 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -24,7 +24,7 @@ void main(void) if ((attrs_var & 0x0200u) == 0x0200u && (attrs_var & 0x0800u) != 0x0800u) // Water (not lava) { vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st); - vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy + vec2(0.0, 0.03); + vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy; uv.x = uv.x + 0.003 * sin(game_time + uv.y * 80); uv.y = 1.0 - uv.y + 0.005 * cos(game_time + uv.y * 140);; vec4 back_color = texture(framebuffer_texture, uv); @@ -32,7 +32,7 @@ void main(void) if (backbuffer == 0.0) fragColor = color; else - fragColor = vec4(mix(color.rgb, back_color.rgb, 0.2 * backbuffer), 1.0); + fragColor = vec4(mix(color.rgb, back_color.rgb, 1.0 * backbuffer), 1.0); } else { diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 6a82c214862..ed6b5447928 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -164,11 +164,12 @@ BadGuy::draw(DrawingContext& context) Vector draw_offset = context.get_time_offset() * m_physic.get_velocity(); Vector draw_pos = get_pos() + draw_offset; + int layer = m_in_water ? -1 : m_layer; if (m_state == STATE_INIT || m_state == STATE_INACTIVE) { if (Editor::is_active()) { - m_sprite->draw(context.color(), draw_pos, m_layer, m_flip); + m_sprite->draw(context.color(), draw_pos, layer, m_flip); } } else @@ -177,30 +178,30 @@ BadGuy::draw(DrawingContext& context) { context.push_transform(); context.set_flip(context.get_flip() ^ VERTICAL_FLIP); - m_sprite->draw(context.color(), draw_pos, m_layer, m_flip); + m_sprite->draw(context.color(), draw_pos, layer, m_flip); context.pop_transform(); } else { if (m_unfreeze_timer.started() && m_unfreeze_timer.get_timeleft() <= 1.f) { - m_sprite->draw(context.color(), draw_pos + Vector(graphicsRandom.randf(-3, 3), 0.f), m_layer - 1, m_flip); + m_sprite->draw(context.color(), draw_pos + Vector(graphicsRandom.randf(-3, 3), 0.f), layer - 1, m_flip); if (is_portable()) - m_freezesprite->draw(context.color(), draw_pos + Vector(graphicsRandom.randf(-3, 3), 0.f), m_layer); + m_freezesprite->draw(context.color(), draw_pos + Vector(graphicsRandom.randf(-3, 3), 0.f), layer); } else { if (m_frozen && is_portable()) { - m_freezesprite->draw(context.color(), draw_pos, m_layer); + m_freezesprite->draw(context.color(), draw_pos, layer); } if (m_state != STATE_BURNING || m_firesprite->get_current_frame() < 5) - m_sprite->draw(context.color(), draw_pos, m_layer - (m_frozen ? 1 : 0), m_flip); + m_sprite->draw(context.color(), draw_pos, layer - (m_frozen ? 1 : 0), m_flip); } if (m_state == STATE_BURNING) { - m_firesprite->draw(context.color(), draw_pos, m_layer); + m_firesprite->draw(context.color(), draw_pos, layer); } if (m_glowing) diff --git a/src/object/player.cpp b/src/object/player.cpp index 91f05c0b3cf..8a95aa0e457 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -2286,7 +2286,7 @@ Player::draw(DrawingContext& context) else if (m_dying) m_sprite->draw(context.color(), draw_pos, Sector::get().get_foremost_opaque_layer() + 1); else - m_sprite->draw(context.color(), draw_pos, LAYER_OBJECTS + 1); + m_sprite->draw(context.color(), draw_pos, m_no_water ? LAYER_OBJECTS + 1 : -1); //TODO: Replace recoloring with proper costumes Color power_color = (get_bonus() == BONUS_FIRE ? Color(1.f, 0.7f, 0.5f) : From 5ec7eb5b4b204af253571e24decd77ad37d3cebd Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Thu, 28 Aug 2025 01:43:02 -0400 Subject: [PATCH 03/13] Make it wateryer --- data/shader/shader330.frag | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index 56f84b65a2b..d02c12a62b1 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -25,8 +25,9 @@ void main(void) { vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st); vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy; - uv.x = uv.x + 0.003 * sin(game_time + uv.y * 80); - uv.y = 1.0 - uv.y + 0.005 * cos(game_time + uv.y * 140);; + uv.x = uv.x + (0.001 + uv.y * 0.001) * sin(game_time + uv.y * (80)); + // Disabled until clamping issue gets fixed + uv.y = 1.0 - uv.y; // + 0.002 * cos(game_time + uv.y * 140);; vec4 back_color = texture(framebuffer_texture, uv); if (backbuffer == 0.0) From 77f591ed5f917ec04a12e89c9b6f08b821dff93d Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Thu, 28 Aug 2025 15:06:23 -0400 Subject: [PATCH 04/13] Fix water surface warping and restore vertical cosine --- data/images/tiles.strf | 24 ++++++------------ data/shader/shader330.frag | 51 +++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/data/images/tiles.strf b/data/images/tiles.strf index 2c92e3fe5a2..c538c9cb5e2 100644 --- a/data/images/tiles.strf +++ b/data/images/tiles.strf @@ -4899,22 +4899,14 @@ 512 512 512 512 ) (images - (surface (diffuse-texture (file "tiles/water/antarctic-1.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-2.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-3.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-4.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-5.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-6.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-7.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-8.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) + "tiles/water/antarctic-1.png" + "tiles/water/antarctic-2.png" + "tiles/water/antarctic-3.png" + "tiles/water/antarctic-4.png" + "tiles/water/antarctic-5.png" + "tiles/water/antarctic-6.png" + "tiles/water/antarctic-7.png" + "tiles/water/antarctic-8.png" ) (fps 16) ) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index d02c12a62b1..32abd5f2c33 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -18,29 +18,9 @@ out vec4 fragColor; void main(void) { - if (backbuffer == 0.0 || !is_displacement) - { - vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time)); - if ((attrs_var & 0x0200u) == 0x0200u && (attrs_var & 0x0800u) != 0x0800u) // Water (not lava) - { - vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st); - vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy; - uv.x = uv.x + (0.001 + uv.y * 0.001) * sin(game_time + uv.y * (80)); - // Disabled until clamping issue gets fixed - uv.y = 1.0 - uv.y; // + 0.002 * cos(game_time + uv.y * 140);; - vec4 back_color = texture(framebuffer_texture, uv); - - if (backbuffer == 0.0) - fragColor = color; - else - fragColor = vec4(mix(color.rgb, back_color.rgb, 1.0 * backbuffer), 1.0); - } - else - { - fragColor = color; - } - } - else if (is_displacement) + vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time)); + + if (is_displacement) { vec4 pixel = texture(displacement_texture, texcoord_var.st + (displacement_animate * game_time)); vec2 displacement = (pixel.rg - vec2(0.5, 0.5)) * 255; @@ -50,8 +30,29 @@ void main(void) uv = vec2(uv.x, 1.0 - uv.y); vec4 back_color = texture(framebuffer_texture, uv); - vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time)); - fragColor = vec4(mix(color.rgb, back_color.rgb, alpha), color.a); + vec4 newcolor = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time)); + color = vec4(mix(newcolor.rgb, back_color.rgb, alpha), newcolor.a); + } + + if ((attrs_var & 0x0200u) == 0x0200u && (attrs_var & 0x0800u) != 0x0800u) // Water (not lava) + { + vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy; + uv.x = uv.x + 0.001 * (sin(game_time + uv.y * (80)) + cos(game_time + uv.y * 30)); + // Disabled until clamping issue gets fixed + uv.y = 1.0 - uv.y + 0.002 * (cos(game_time + uv.y * 140)); + vec4 back_color = texture(framebuffer_texture, uv); + + if (backbuffer == 0.0) + fragColor = color; + else + fragColor = vec4(mix(color.rgb, back_color.rgb, 1.0 * backbuffer), 1.0); + } + else + { + if (backbuffer == 0.0) + { + fragColor = color; + } } } From 94a0a4856d8ab4150acd523bf4f378cc0ebf6807 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Thu, 28 Aug 2025 15:45:20 -0400 Subject: [PATCH 05/13] Only apply shaders if Tile::SHADED --- data/images/tiles.strf | 32 +++++++++++++++++++------------- data/shader/shader330.frag | 3 ++- src/supertux/tile.hpp | 18 ++++++------------ src/supertux/tile_set_parser.cpp | 10 ++-------- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/data/images/tiles.strf b/data/images/tiles.strf index c538c9cb5e2..4ec4ac5eb19 100644 --- a/data/images/tiles.strf +++ b/data/images/tiles.strf @@ -2416,6 +2416,7 @@ (id 75) (images "tiles/water/deprecated/water.png") (water #t) + (shaded #t) (deprecated #t) ) @@ -2427,6 +2428,7 @@ "tiles/water/deprecated/waves-2.png" ) (water #t) + (shaded #t) (fps 10) (deprecated #t) ) @@ -2957,11 +2959,11 @@ 175 176 177 178 ) (attributes - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 ) (images "tiles/waterfall/trans-0.png" @@ -2985,10 +2987,11 @@ "tiles/waterfall/foam-3.png" ) (attributes - 512 0 512 - 512 512 512 + 516 0 516 + 516 516 516 ) (water #t) + (shaded #t) (fps 10) ) @@ -2996,6 +2999,7 @@ (id 200) (images "tiles/water/deprecated/water-trans.png") (water #t) + (shaded #t) (deprecated #t) ) @@ -3007,6 +3011,7 @@ "tiles/water/deprecated/waves-trans-2.png" ) (water #t) + (shaded #t) (fps 10) (deprecated #t) ) @@ -3047,11 +3052,11 @@ 275 276 277 278 ) (attributes - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 ) (images "tiles/waterfall/deprecated/waterfall-0.png" @@ -4896,7 +4901,7 @@ 2019 2140 2141 2142 ) (attributes - 512 512 512 512 + 516 516 516 516 ) (images "tiles/water/antarctic-1.png" @@ -4916,6 +4921,7 @@ (images "tiles/water/antarctic.png") (water #t) + (shaded #t) ) (tiles diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index 32abd5f2c33..a8fb2d3bdcb 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -34,7 +34,8 @@ void main(void) color = vec4(mix(newcolor.rgb, back_color.rgb, alpha), newcolor.a); } - if ((attrs_var & 0x0200u) == 0x0200u && (attrs_var & 0x0800u) != 0x0800u) // Water (not lava) + if ((attrs_var & 0x0004u) == 0x0004u && + (attrs_var & 0x0200u) == 0x0200u && (attrs_var & 0x0800u) != 0x0800u) // Water (not lava) { vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy; uv.x = uv.x + 0.001 * (sin(game_time + uv.y * (80)) + cos(game_time + uv.y * 30)); diff --git a/src/supertux/tile.hpp b/src/supertux/tile.hpp index 24af9992af0..d177f7450c7 100644 --- a/src/supertux/tile.hpp +++ b/src/supertux/tile.hpp @@ -40,19 +40,13 @@ class Tile final SOLID = 0x0001, /** uni-directional solid tile */ UNISOLID = 0x0002, - /** a brick that can be destroyed by jumping under it */ - BRICK = 0x0004, //Marked for removal, DO NOT USE! - /** the level should be finished when touching a goaltile. - * if data is 0 then the endsequence should be triggered, if data is 1 - * then we can finish the level instantly. - */ - GOAL = 0x0008, //Marked for removal, DO NOT USE! + /** Is affected by shader */ + SHADED = 0x0004, + /* 0x0008 reserved */ /** slope tile */ SLOPE = 0x0010, - /** Bonusbox, content is stored in \a data */ - FULLBOX = 0x0020, //Marked for removal, DO NOT USE! - /** Tile is a coin */ - COIN = 0x0040, //Marked for removal, DO NOT USE! + /* 0x0020 reserved */ + /* 0x0040 reserved */ /* interesting flags (the following are passed to gameobjects) */ FIRST_INTERESTING_FLAG = 0x0100, @@ -66,7 +60,7 @@ class Tile final /** for lava: WATER, HURTS, FIRE */ FIRE = 0x0800, /** a walljumping trigger tile */ - WALLJUMP = 0x1000 + WALLJUMP = 0x1000, }; /** worldmap flags */ diff --git a/src/supertux/tile_set_parser.cpp b/src/supertux/tile_set_parser.cpp index 0eb92d2c70f..f0eafbd834f 100644 --- a/src/supertux/tile_set_parser.cpp +++ b/src/supertux/tile_set_parser.cpp @@ -239,8 +239,8 @@ TileSetParser::parse_tile(const ReaderMapping& reader) attributes |= Tile::SOLID; if (reader.get("unisolid", value) && value) attributes |= Tile::UNISOLID | Tile::SOLID; - if (reader.get("brick", value) && value) - attributes |= Tile::BRICK; + if (reader.get("shaded", value) && value) + attributes |= Tile::SHADED; if (reader.get("ice", value) && value) attributes |= Tile::ICE; if (reader.get("water", value) && value) @@ -251,12 +251,6 @@ TileSetParser::parse_tile(const ReaderMapping& reader) attributes |= Tile::FIRE; if (reader.get("walljump", value) && value) attributes |= Tile::WALLJUMP; - if (reader.get("fullbox", value) && value) - attributes |= Tile::FULLBOX; - if (reader.get("coin", value) && value) - attributes |= Tile::COIN; - if (reader.get("goal", value) && value) - attributes |= Tile::GOAL; uint32_t data = 0; From 82d122a5f992c670dbf8e967d22983b91145ece2 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Thu, 28 Aug 2025 15:49:57 -0400 Subject: [PATCH 06/13] Stop using constants in shader --- data/shader/shader330.frag | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index a8fb2d3bdcb..d60d58ae359 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -16,6 +16,17 @@ flat in uint attrs_var; out vec4 fragColor; +const uint TATTR_SOLID = 0x0001u; +const uint TATTR_UNISOLID = 0x0002u; +const uint TATTR_SHADED = 0x0004u; +const uint TATTR_SLOPE = 0x0010u; +const uint TATTR_FIF = 0x0100u; +const uint TATTR_ICE = 0x0100u; +const uint TATTR_WATER = 0x0200u; +const uint TATTR_HURTS = 0x0400u; +const uint TATTR_FIRE = 0x0800u; +const uint TATTR_WALLJUMP = 0x1000u; + void main(void) { vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time)); @@ -34,8 +45,9 @@ void main(void) color = vec4(mix(newcolor.rgb, back_color.rgb, alpha), newcolor.a); } - if ((attrs_var & 0x0004u) == 0x0004u && - (attrs_var & 0x0200u) == 0x0200u && (attrs_var & 0x0800u) != 0x0800u) // Water (not lava) + if ((attrs_var & TATTR_SHADED) == TATTR_SHADED && + (attrs_var & TATTR_WATER) == TATTR_WATER && + (attrs_var & TATTR_FIRE) != TATTR_FIRE) // Water (not lava) { vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy; uv.x = uv.x + 0.001 * (sin(game_time + uv.y * (80)) + cos(game_time + uv.y * 30)); From 905bf28f2b967354f2685c1e5ffcd039e480dcc6 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Thu, 28 Aug 2025 16:26:10 -0400 Subject: [PATCH 07/13] Make water edge blending not include tiles --- data/shader/shader330.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index d60d58ae359..086dfa47d34 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -58,7 +58,7 @@ void main(void) if (backbuffer == 0.0) fragColor = color; else - fragColor = vec4(mix(color.rgb, back_color.rgb, 1.0 * backbuffer), 1.0); + fragColor = vec4(max(color.rgb, back_color.rgb), 1.0); } else { From 3d21134d8eba618b03b2da585ecf0666a7e0dfa1 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Thu, 28 Aug 2025 16:46:30 -0400 Subject: [PATCH 08/13] Make horizontal wave smaller --- data/shader/shader330.frag | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index 086dfa47d34..1ac891f2dcd 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -50,9 +50,8 @@ void main(void) (attrs_var & TATTR_FIRE) != TATTR_FIRE) // Water (not lava) { vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy; - uv.x = uv.x + 0.001 * (sin(game_time + uv.y * (80)) + cos(game_time + uv.y * 30)); - // Disabled until clamping issue gets fixed - uv.y = 1.0 - uv.y + 0.002 * (cos(game_time + uv.y * 140)); + uv.x = uv.x + 0.0005 * (sin(game_time + uv.y * (80)) + cos(game_time + uv.y * 30)); + uv.y = 1.0 - uv.y + 0.003 * (cos(game_time + uv.y * 140)); vec4 back_color = texture(framebuffer_texture, uv); if (backbuffer == 0.0) From f448c259a3aaaecd79eaa6ce1258275a593aa994 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Thu, 28 Aug 2025 16:54:05 -0400 Subject: [PATCH 09/13] Minor touchup --- data/shader/shader330.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index 1ac891f2dcd..28310e74e20 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -50,7 +50,7 @@ void main(void) (attrs_var & TATTR_FIRE) != TATTR_FIRE) // Water (not lava) { vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy; - uv.x = uv.x + 0.0005 * (sin(game_time + uv.y * (80)) + cos(game_time + uv.y * 30)); + uv.x = uv.x + 0.0006 * (sin(game_time + uv.y * (80)) + cos(game_time + uv.y * 30)); uv.y = 1.0 - uv.y + 0.003 * (cos(game_time + uv.y * 140)); vec4 back_color = texture(framebuffer_texture, uv); From 4d689e2f97e3b1329345ef7c6697dff04f1fa75b Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Mon, 1 Sep 2025 03:44:41 -0400 Subject: [PATCH 10/13] GLPainter: Don't add attrs if over the limit --- src/video/gl/gl_painter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/video/gl/gl_painter.cpp b/src/video/gl/gl_painter.cpp index 8b3ed977604..b90a773dbbd 100644 --- a/src/video/gl/gl_painter.cpp +++ b/src/video/gl/gl_painter.cpp @@ -100,7 +100,8 @@ GLPainter::draw_texture(const TextureRequest& request) float uv_right = request.srcrects[i].get_right() / static_cast(texture.get_texture_width()); float uv_bottom = request.srcrects[i].get_bottom() / static_cast(texture.get_texture_height()); - m_attrs.insert(m_attrs.end(), 6, request.attrs[i]); + if (request.attrs.size() > i) + m_attrs.insert(m_attrs.end(), 6, request.attrs[i]); if (request.flip & HORIZONTAL_FLIP) std::swap(uv_left, uv_right); From 6376ddcf6f9f5fc15ceeea5d321344db471b201d Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Mon, 1 Sep 2025 15:38:46 -0400 Subject: [PATCH 11/13] Add missing check --- data/shader/shader330.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index 28310e74e20..c67af067fd3 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -61,7 +61,7 @@ void main(void) } else { - if (backbuffer == 0.0) + if (backbuffer == 0.0 || !is_displacement) { fragColor = color; } From 88c7bffa9e422d6e96b887d6d0d0862d4cfe0f30 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Mon, 1 Sep 2025 15:39:08 -0400 Subject: [PATCH 12/13] Syntrax --- data/shader/shader330.frag | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index c67af067fd3..64428e1429d 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -59,12 +59,9 @@ void main(void) else fragColor = vec4(max(color.rgb, back_color.rgb), 1.0); } - else + else if (backbuffer == 0.0 || !is_displacement) { - if (backbuffer == 0.0 || !is_displacement) - { fragColor = color; - } } } From 7270cb169aebc4a3cdbb6174774c30037eb37785 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Mon, 1 Sep 2025 15:41:28 -0400 Subject: [PATCH 13/13] More syntax --- data/shader/shader330.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index 64428e1429d..819d2dc1781 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -61,7 +61,7 @@ void main(void) } else if (backbuffer == 0.0 || !is_displacement) { - fragColor = color; + fragColor = color; } }