diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-08-24 10:16:38 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-08-24 10:16:38 +0200 |
commit | f57dfc925bfeaec772c4eac88995e87262fe357f (patch) | |
tree | 183764be6e7ed6c5809d6a365f87070b17f5d910 /shaders | |
parent | 0635b7f5e8902856a86517aa921ac9f05e295917 (diff) |
wip
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/lightmap.cpp | 14 | ||||
-rw-r--r-- | shaders/lightmap.hpp | 17 |
2 files changed, 19 insertions, 12 deletions
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp index 6b09c5f8..10d8fd9e 100644 --- a/shaders/lightmap.cpp +++ b/shaders/lightmap.cpp @@ -27,7 +27,8 @@ namespace floormat { namespace { -constexpr auto neighbor_count = 8; +constexpr auto neighbor_count = lightmap_shader::neighbor_count; + constexpr auto chunk_size = TILE_SIZE2 * TILE_MAX_DIM; constexpr auto chunk_offset = TILE_SIZE2/2; constexpr auto image_size = iTILE_SIZE2 * TILE_MAX_DIM * neighbor_count; @@ -75,7 +76,7 @@ auto lightmap_shader::make_framebuffer(Vector2i size) -> Framebuffer .attachTexture(GL::Framebuffer::ColorAttachment{1}, framebuffer.accum, 0) //.clearDepth(0); .clearColor(0, Color4{1, 0, 1, 1}) - .clearColor(1, Color4{0, 0, 0, 1}); + .clearColor(1, Color4{0, 1, 0, 1}); //framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{0}); using BF = Magnum::GL::Renderer::BlendFunction; @@ -117,6 +118,8 @@ void lightmap_shader::end_occlusion() vertex_buf.setSubData(0, vertexes.prefix(count)); index_buf.setSubData(0, indexes.prefix(count)); } + + framebuffer.fb.clearColor(1, Color4{0, 0, 1, 1}); } std::array<Vector3, 4>& lightmap_shader::alloc_rect() @@ -212,6 +215,8 @@ std::array<UnsignedShort, 6> lightmap_shader::quad_indexes(size_t N) void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light) { + neighbor_offset += half_neighbors; + constexpr auto tile_size = TILE_SIZE2.sum()/2; float I; @@ -236,11 +241,10 @@ void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light) float alpha = light.color.a() / 255.f; auto color = (Vector3{light.color.rgb()} / 255.f) * alpha; - framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{0}); framebuffer.fb.clearColor(0, Color4{0, 0, 0, 1}); setUniform(LightColorUniform, color * alpha); - setUniform(SizeUniform, 1 / chunk_size); + setUniform(SizeUniform, 1 / (chunk_size * neighbor_count)); setUniform(CenterFragcoordUniform, center_fragcoord); setUniform(CenterClipUniform, center_clip); setUniform(RangeUniform, I); @@ -323,6 +327,8 @@ void lightmap_shader::add_rect(Vector2 neighbor_offset, Pair<Vector2, Vector2> m void lightmap_shader::add_chunk(Vector2 neighbor_offset, chunk& c) { + neighbor_offset += half_neighbors; + add_geometry(neighbor_offset, c); add_entities(neighbor_offset, c); } diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp index 76ef081a..22748d16 100644 --- a/shaders/lightmap.hpp +++ b/shaders/lightmap.hpp @@ -43,17 +43,15 @@ struct lightmap_shader final : GL::AbstractShaderProgram void begin_occlusion(); void end_occlusion(); void add_chunk(Vector2 neighbor_offset, chunk& c); - void add_entities(Vector2 neighbor_offset, chunk& c); - void add_geometry(Vector2 neighbor_offset, chunk& c); - void add_rect(Vector2 neighbor_offset, Vector2 min, Vector2 max); - void add_rect(Vector2 neighbor_offset, Pair<Vector2, Vector2> minmax); void add_light(Vector2 neighbor_offset, const light_s& light); void bind(); GL::Texture2D& scratch_texture(); GL::Texture2D& accum_texture(); - static constexpr auto max_chunks = Vector2s(8, 8); + // todo allow 16 neighbors on new gpu's + static constexpr auto neighbor_count = 8; + static constexpr auto half_neighbors = Vector2(neighbor_count)/2; using Position = GL::Attribute<0, Vector3>; @@ -84,7 +82,12 @@ private: GL::Mesh make_occlusion_mesh(); static std::array<UnsignedShort, 6> quad_indexes(size_t N); - // todo use setData() and a boolean flag on capacity change + void add_entities(Vector2 neighbor_offset, chunk& c); + void add_geometry(Vector2 neighbor_offset, chunk& c); + void add_rect(Vector2 neighbor_offset, Vector2 min, Vector2 max); + void add_rect(Vector2 neighbor_offset, Pair<Vector2, Vector2> minmax); + [[nodiscard]] std::array<Vector3, 4>& alloc_rect(); + GL::Buffer vertex_buf{NoCreate}, index_buf{NoCreate}; Array<std::array<Vector3, 4>> vertexes; // todo make a contiguous allocation Array<std::array<UnsignedShort, 6>> indexes; @@ -96,8 +99,6 @@ private: std::array<Vector3, 4> light_vertexes; GL::Buffer light_vertex_buf{NoCreate}; GL::Mesh light_mesh{NoCreate}; - - [[nodiscard]] std::array<Vector3, 4>& alloc_rect(); }; } // namespace floormat |