diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-06-10 06:46:49 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-06-10 06:46:49 +0200 |
commit | f7898053802ea38630f93034d0cd1555492fbc56 (patch) | |
tree | f81955574f7ecc24ff26ee770c45768a366d0202 /shaders/lightmap.hpp | |
parent | dc913f11422e002059029cac8da2d6b9a725656a (diff) |
wip
Diffstat (limited to 'shaders/lightmap.hpp')
-rw-r--r-- | shaders/lightmap.hpp | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp index a2d566e6..a7204723 100644 --- a/shaders/lightmap.hpp +++ b/shaders/lightmap.hpp @@ -1,15 +1,32 @@ #pragma once #include "light-falloff.hpp" -#include <Magnum/GL/AbstractShaderProgram.h> +#include <array> +#include <Corrade/Containers/Array.h> #include <Magnum/Math/Vector2.h> -#include <Magnum/Math/Vector3.h> #include <Magnum/Math/Vector4.h> #include <Magnum/Math/Color.h> +#include <Magnum/GL/AbstractShaderProgram.h> +#include <Magnum/GL/Buffer.h> +#include <Magnum/GL/Framebuffer.h> +#include <Magnum/GL/Mesh.h> +//#include <Magnum/GL/Renderbuffer.h> +#include <Magnum/GL/Texture.h> namespace floormat { -struct local_coords; +struct light_s final +{ + Vector2 center; + float dist = 1; + //float depth = -1 + 1e-4f; + Math::Color3<uint8_t> color {255, 255, 255}; + light_falloff falloff = light_falloff::linear; + + bool operator==(const light_s&) const noexcept; +}; + +struct chunk; struct lightmap_shader final : GL::AbstractShaderProgram { @@ -18,32 +35,43 @@ struct lightmap_shader final : GL::AbstractShaderProgram explicit lightmap_shader(); ~lightmap_shader() override; - void set_light(Vector2i neighbor_offset, local_coords pos, Vector2b offset); - struct light light() const; // is a reader accessor needed? - -private: - static Vector2i get_px_pos(Vector2i neighbor_offset, local_coords pos, Vector2b offset); - - struct light_u final - { - Vector4 color_and_intensity; - Vector2 center; - uint32_t mode; + struct Framebuffer final { + GL::Framebuffer fb{NoCreate}; + //GL::Renderbuffer depth{NoCreate}; + GL::Texture2D color{NoCreate}; }; - struct light_s final - { - float intensity = 1; - Color3ub color {255, 255, 255}; - Vector2i center; - light_falloff falloff; + void begin(Vector2i neighbor_offset, const light_s& light); + void add_chunk(Vector2i neighbor_offset, const chunk& ch); + void add_vertex(Vector2i neighbor_offset, const std::array<Vector2, 4>& obj); + void end(); + GL::Texture2D& texture(); - bool operator==(const light_s&) const noexcept; - }; +private: + static Framebuffer make_framebuffer(); + GL::Mesh make_mesh(); + void add_light(Vector2i neighbor_offset, const light_s& light); + void flush_vertexes(); + void bind(); + void clear(); + static std::array<UnsignedShort, 6> quad_indexes(size_t N); - enum { ColorUniform = 0, CenterUniform = 1, FalloffUniform = 2, DepthUniform = 3, }; + enum : int { + ColorIntensityUniform = 0, + CenterUniform = 1, + FalloffUniform = 2, + SizeUniform = 3, + //DepthUniform = 4, + }; - light_s _light; + Framebuffer framebuffer; + Array<std::array<Vector2, 4>> _quads; + Array<std::array<UnsignedShort, 6>> _indexes; + size_t _count = 0; + //light_u _light_uniform; + //light_s _light; + GL::Buffer _vertex_buf{NoCreate}, _index_buf{NoCreate}; + GL::Mesh _mesh{NoCreate}; }; } // namespace floormat |