summaryrefslogtreecommitdiffhomepage
path: root/shaders
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-06-11 02:40:06 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-06-11 02:40:06 +0200
commit04b9df316971e0cb897605fdabb16da712f3f791 (patch)
tree3c54c390ec3f42fc8d66d6f3f9bb7b36b2feeb08 /shaders
parentd63ae5ac3af050be4439b8d9f9d0c06f94058b7c (diff)
wip
Diffstat (limited to 'shaders')
-rw-r--r--shaders/lightmap.cpp13
-rw-r--r--shaders/lightmap.frag10
-rw-r--r--shaders/lightmap.hpp7
3 files changed, 15 insertions, 15 deletions
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
index bc61a434..7c955e1f 100644
--- a/shaders/lightmap.cpp
+++ b/shaders/lightmap.cpp
@@ -24,14 +24,14 @@ constexpr auto buffer_size = 256uz;
} // namespace
-auto lightmap_shader::make_framebuffer() -> Framebuffer
+auto lightmap_shader::make_framebuffer(Vector2i size) -> Framebuffer
{
Framebuffer framebuffer;
- framebuffer.fb = GL::Framebuffer{{ {}, image_size }};
+ framebuffer.fb = GL::Framebuffer{{ {}, size }};
framebuffer.color = GL::Texture2D{};
- framebuffer.color.setStorage(1, GL::TextureFormat::RGB8, image_size);
+ framebuffer.color.setStorage(1, GL::TextureFormat::RGB8, size);
//framebuffer.depth = GL::Renderbuffer{};
//framebuffer.depth.setStorage(GL::RenderbufferFormat::DepthComponent32F, fb_size);
@@ -53,7 +53,8 @@ GL::Mesh lightmap_shader::make_mesh()
}
lightmap_shader::lightmap_shader() :
- framebuffer { make_framebuffer() },
+ framebuffer { make_framebuffer(image_size) },
+ accum { make_framebuffer(image_size) },
_quads { ValueInit, buffer_size },
_indexes { ValueInit, buffer_size },
_vertex_buf { _quads },
@@ -116,10 +117,8 @@ void lightmap_shader::add_light(Vector2i neighbor_offset, const light_s& light)
I = 1;
break;
case light_falloff::linear:
- I = light.dist * tile_size / 5;
- break;
case light_falloff::quadratic:
- I = light.dist * tile_size * 100;
+ I = light.dist * tile_size;
break;
}
diff --git a/shaders/lightmap.frag b/shaders/lightmap.frag
index db1cf895..61bf10ff 100644
--- a/shaders/lightmap.frag
+++ b/shaders/lightmap.frag
@@ -9,14 +9,18 @@ out vec4 color;
void main() {
vec2 pos = gl_FragCoord.xy;
- float I = color_intensity.w;
+ float L = color_intensity.w;
float dist = distance(pos, center);
//float dist = sqrt(tmp.x*tmp.x + tmp.y*tmp.y);
float A = 1;
+ //attenuation = ((light_dist - dist)**exponent) / (light_dist**exponent)
if (falloff == 0) // linear
- A = I/(I + dist);
+ A = max(0, (L - dist) / L);
else if (falloff == 2) // quadratic
- A = I/(I + dist*dist);
+ {
+ float tmp = max(0, L - dist);
+ A = max(0, tmp*tmp / (L*L));
+ }
//I = sqrt(color_intensity.w*1.5)*16;
//dist = sqrt(tmp.x*tmp.x + tmp.y*tmp.y);
//float alpha = 1 - min(1, dist / I);
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp
index e458cadc..4ae6cb5c 100644
--- a/shaders/lightmap.hpp
+++ b/shaders/lightmap.hpp
@@ -43,12 +43,11 @@ struct lightmap_shader final : GL::AbstractShaderProgram
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();
private:
- static Framebuffer make_framebuffer();
+ static Framebuffer make_framebuffer(Vector2i size);
GL::Mesh make_mesh();
void add_light(Vector2i neighbor_offset, const light_s& light);
void flush_vertexes();
@@ -64,12 +63,10 @@ private:
//DepthUniform = 4,
};
- Framebuffer framebuffer;
+ Framebuffer framebuffer, accum;
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};
};