diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-08-29 23:38:40 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-08-30 18:22:56 +0200 |
commit | af6ca21ed0f2715aad0b2ae80d200589b5e31089 (patch) | |
tree | 51a51a4f4a487d29439be597e674d6c8ac58c498 /shaders | |
parent | dbffcdc7db183ae3f1c938e8d84f4a0a11c6c122 (diff) |
wip
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/lightmap.cpp | 10 | ||||
-rw-r--r-- | shaders/lightmap.frag | 4 | ||||
-rw-r--r-- | shaders/lightmap.vert | 3 | ||||
-rw-r--r-- | shaders/texture-unit-cache.cpp | 9 | ||||
-rw-r--r-- | shaders/texture-unit-cache.hpp | 2 |
5 files changed, 17 insertions, 11 deletions
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp index 44df7500..7c943686 100644 --- a/shaders/lightmap.cpp +++ b/shaders/lightmap.cpp @@ -217,6 +217,9 @@ std::array<UnsignedShort, 6> lightmap_shader::quad_indexes(size_t N) void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light) { + // todo finish uniform interface block + // NOTE, go benchjmark case where the main inteface block doesn't need to be uploaded ijn given frame. + neighbor_offset += Vector2((float)half_neighbors); constexpr auto tile_size = TILE_SIZE2.sum()/2; @@ -240,14 +243,11 @@ void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light) auto center_fragcoord = light.center + neighbor_offset * chunk_size + chunk_offset; // window-relative coordinates auto center_clip = clip_start + center_fragcoord * clip_scale; // clip coordinates - float alpha = light.color.a() / 255.f; - auto color = (Vector3{light.color.rgb()} / 255.f) * alpha; - framebuffer.fb.mapForDraw({ { 0u, GL::Framebuffer::ColorAttachment{0} }, }); - setUniform(LightColorUniform, color * alpha); + setUniform(LightColorUniform, Vector4(light.color) / 255.f); setUniform(SizeUniform, Vector2(1) / real_image_size); setUniform(CenterFragcoordUniform, center_fragcoord * image_size_ratio); setUniform(CenterClipUniform, center_clip); @@ -264,7 +264,6 @@ void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light) mesh_view.setCount((int32_t)count*6); AbstractShaderProgram::draw(mesh_view); - setUniform(SamplerUniform, tuc.bind(framebuffer.scratch)); framebuffer.fb.mapForDraw({ { 1u, GL::Framebuffer::ColorAttachment{1} }, }); @@ -280,6 +279,7 @@ void lightmap_shader::bind() using BlendFunction = Magnum::GL::Renderer::BlendFunction; GL::Renderer::setBlendFunction(0, BlendFunction::One, BlendFunction::Zero); GL::Renderer::setBlendFunction(1, BlendFunction::One, BlendFunction::One); + setUniform(SamplerUniform, tuc.bind(framebuffer.scratch)); } void lightmap_shader::finish() // NOLINT(*-convert-member-functions-to-static) diff --git a/shaders/lightmap.frag b/shaders/lightmap.frag index f6ca40a2..9136a4a5 100644 --- a/shaders/lightmap.frag +++ b/shaders/lightmap.frag @@ -1,7 +1,7 @@ precision mediump float; layout (location = 2) uniform sampler2D sampler0; -layout (location = 3) uniform vec3 light_color; +layout (location = 3) uniform vec4 light_color; layout (location = 4) uniform vec2 scale; layout (location = 5) uniform vec2 center_fragcoord; layout (location = 6) uniform vec2 center_clip; @@ -28,7 +28,7 @@ void main() { float tmp = max(0, L - dist); A = tmp*tmp / (L*L); } - color0 = vec4(light_color.rgb * A, 1); + color0 = vec4(light_color.rgb * light_color.a * A, 1); } else if (mode == 2) // blend { diff --git a/shaders/lightmap.vert b/shaders/lightmap.vert index 7aba6feb..2ed69f8b 100644 --- a/shaders/lightmap.vert +++ b/shaders/lightmap.vert @@ -1,7 +1,7 @@ precision mediump float; layout (location = 2) uniform sampler2D sampler0; -layout (location = 3) uniform vec3 light_color; +layout (location = 3) uniform vec4 light_color; layout (location = 4) uniform vec2 scale; layout (location = 5) uniform vec2 center_fragcoord; layout (location = 6) uniform vec2 center_clip; @@ -15,6 +15,7 @@ layout (location = 9) uniform uint falloff; layout (location = 0) in vec3 position; void main() { + // todo add interface blocks vec2 pos = position.xy; if (mode == 0) { diff --git a/shaders/texture-unit-cache.cpp b/shaders/texture-unit-cache.cpp index 71d21a8f..2c415c80 100644 --- a/shaders/texture-unit-cache.cpp +++ b/shaders/texture-unit-cache.cpp @@ -91,7 +91,7 @@ void texture_unit_cache::unlock(size_t i, bool reuse_immediately) units[i] = { .ptr = units[i].ptr, .lru_val = reuse_immediately ? 0 : ++lru_counter }; } -void texture_unit_cache::output_stats() const +void texture_unit_cache::output_stats() { auto total = cache_hit_count + cache_miss_count; @@ -100,6 +100,11 @@ void texture_unit_cache::output_stats() const auto ratio = (double)cache_hit_count/(double)(cache_hit_count+cache_miss_count); printf("texture-binding: hit rate %.2f%% (%zu binds total)\n", ratio*100, (size_t)total); std::fflush(stdout); } + if (total > (size_t)10'000) + { + cache_hit_count /= 5; + cache_miss_count /= 5; + } } size_t texture_unit_cache::get_unit_count() @@ -108,7 +113,7 @@ size_t texture_unit_cache::get_unit_count() GLint value = 0; glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &value); fm_assert(value >= /*GL 3.3*/ 16); - //value = 16; // for performance testing + value = 1; // limit for performance testing return value; }(); return (size_t)ret; diff --git a/shaders/texture-unit-cache.hpp b/shaders/texture-unit-cache.hpp index 5f09ecb9..a6252bec 100644 --- a/shaders/texture-unit-cache.hpp +++ b/shaders/texture-unit-cache.hpp @@ -25,7 +25,7 @@ struct texture_unit_cache final size_t reuse_count() const { return cache_hit_count; } size_t bind_count() const { return cache_miss_count; } - void output_stats() const; + void output_stats(); statistics stats() const { return statistics { cache_hit_count, cache_miss_count }; } void reset_stats() { cache_miss_count = cache_hit_count = 0; } |