summaryrefslogtreecommitdiffhomepage
path: root/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'shaders')
-rw-r--r--shaders/lightmap.cpp32
-rw-r--r--shaders/lightmap.frag25
-rw-r--r--shaders/lightmap.hpp18
-rw-r--r--shaders/lightmap.vert16
4 files changed, 45 insertions, 46 deletions
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
index 5a93721d..7fb3f198 100644
--- a/shaders/lightmap.cpp
+++ b/shaders/lightmap.cpp
@@ -10,14 +10,12 @@
#include <Corrade/Containers/PairStl.h>
#include <Corrade/Containers/Iterable.h>
#include <Corrade/Containers/ArrayViewStl.h>
-#include <Magnum/Magnum.h>
#include <Magnum/GL/Context.h>
#include <Magnum/GL/MeshView.h>
#include <Magnum/GL/Shader.h>
#include <Magnum/GL/Version.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/TextureFormat.h>
-#include <Magnum/DebugTools/Screenshot.h>
#if defined __CLION_IDE__ || defined __clang__
#pragma GCC diagnostic ignored "-Wfloat-equal"
@@ -76,12 +74,12 @@ 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, 1, 0, 1});
- //framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{0});
+ .clearColor(1, Color4{0, 0, 0, 1});
- using BF = Magnum::GL::Renderer::BlendFunction;
- GL::Renderer::setBlendFunction(0, BF::One, BF::Zero, BF::One, BF::Zero);
- GL::Renderer::setBlendFunction(1, BF::One, BF::One, BF::One, BF::One);
+ framebuffer.fb.mapForDraw({
+ { 0u, GL::Framebuffer::ColorAttachment{0} },
+ { 1u, GL::Framebuffer::ColorAttachment{1} },
+ });
return framebuffer;
}
@@ -118,8 +116,6 @@ 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()
@@ -259,11 +255,13 @@ void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light)
{ -size.x() + center_clip.x(), size.y() + center_clip.y(), 0 },
}};
light_vertex_buf.setSubData(0, light_vertexes);
+
AbstractShaderProgram::draw(light_mesh);
setUniform(ModeUniform, DrawShadowsMode);
setUniform(LightColorUniform, Color3{0, 0, 0});
setUniform(RangeUniform, I);
+
fm_assert(occlusion_mesh.id());
auto mesh_view = GL::MeshView{occlusion_mesh};
mesh_view.setCount((int32_t)count*6);
@@ -271,10 +269,7 @@ void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light)
AbstractShaderProgram::draw(mesh_view);
setUniform(ModeUniform, BlendLightmapMode);
- framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{1});
AbstractShaderProgram::draw(light_mesh);
-
- //DebugTools::screenshot(framebuffer.fb, "../../../screenshot.bmp");
}
void lightmap_shader::add_rect(Vector2 neighbor_offset, Vector2 min, Vector2 max)
@@ -380,15 +375,18 @@ void lightmap_shader::add_entities(Vector2 neighbor_offset, chunk& c)
void lightmap_shader::bind()
{
- framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{0});
framebuffer.fb.bind();
- GL::Renderer::setScissor({{}, {(int)1e6, (int)1e6}});
+ GL::Renderer::setScissor({{}, image_size});
+ framebuffer.fb.clearColor(1, Color4{0, 0, 0, 1});
+ using BlendFunction = Magnum::GL::Renderer::BlendFunction;
+ GL::Renderer::setBlendFunction(0, BlendFunction::One, BlendFunction::Zero);
+ GL::Renderer::setBlendFunction(1, BlendFunction::One, BlendFunction::One);
}
-GL::Texture2D& lightmap_shader::scratch_texture()
+void lightmap_shader::finish() // NOLINT(*-convert-member-functions-to-static)
{
- fm_debug_assert(framebuffer.scratch.id());
- return framebuffer.scratch;
+ using BlendFunction = Magnum::GL::Renderer::BlendFunction;
+ GL::Renderer::setBlendFunction(BlendFunction::SourceAlpha, BlendFunction::OneMinusSourceAlpha);
}
GL::Texture2D& lightmap_shader::accum_texture()
diff --git a/shaders/lightmap.frag b/shaders/lightmap.frag
index 91467907..deaaa894 100644
--- a/shaders/lightmap.frag
+++ b/shaders/lightmap.frag
@@ -1,15 +1,16 @@
precision mediump float;
-layout (location = 0) uniform sampler2D sampler;
-layout (location = 1) uniform vec3 light_color;
-layout (location = 2) uniform vec2 size;
-layout (location = 3) uniform vec2 center_fragcoord;
-layout (location = 4) uniform vec2 center_clip;
-layout (location = 5) uniform float range;
-layout (location = 6) uniform uint mode;
-layout (location = 7) uniform uint falloff;
+layout (location = 2) uniform sampler2D sampler0;
+layout (location = 3) uniform vec3 light_color;
+layout (location = 4) uniform vec2 size;
+layout (location = 5) uniform vec2 center_fragcoord;
+layout (location = 6) uniform vec2 center_clip;
+layout (location = 7) uniform float range;
+layout (location = 8) uniform uint mode;
+layout (location = 9) uniform uint falloff;
-out vec4 color;
+layout (location = 0) out vec4 color0;
+layout (location = 1) out vec4 color1;
//layout(origin_upper_left, pixel_center_integer) in vec4 gl_FragCoord;
@@ -27,14 +28,14 @@ void main() {
float tmp = max(0, L - dist);
A = tmp*tmp / (L*L);
}
- color = vec4(light_color.rgb, A);
+ color0 = vec4(light_color.rgb * A, 1);
}
else if (mode == 2) // blend
{
- color = texture(sampler, gl_FragCoord.xy * size);
+ color1 = texture(sampler0, gl_FragCoord.xy * size);
}
else if (mode == 0) // shadows
{
- color = vec4(0, 0, 0, 1);
+ color0 = vec4(0, 0, 0, 1);
}
}
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp
index 22748d16..22a94af0 100644
--- a/shaders/lightmap.hpp
+++ b/shaders/lightmap.hpp
@@ -45,8 +45,8 @@ struct lightmap_shader final : GL::AbstractShaderProgram
void add_chunk(Vector2 neighbor_offset, chunk& c);
void add_light(Vector2 neighbor_offset, const light_s& light);
void bind();
+ void finish();
- GL::Texture2D& scratch_texture();
GL::Texture2D& accum_texture();
// todo allow 16 neighbors on new gpu's
@@ -57,14 +57,14 @@ struct lightmap_shader final : GL::AbstractShaderProgram
private:
enum : Int {
- SamplerUniform = 0,
- LightColorUniform = 1,
- SizeUniform = 2,
- CenterFragcoordUniform = 3,
- CenterClipUniform = 4,
- RangeUniform = 5,
- ModeUniform = 6,
- FalloffUniform = 7,
+ SamplerUniform = 2,
+ LightColorUniform = 3,
+ SizeUniform = 4,
+ CenterFragcoordUniform = 5,
+ CenterClipUniform = 6,
+ RangeUniform = 7,
+ ModeUniform = 8,
+ FalloffUniform = 9,
};
enum : Int {
diff --git a/shaders/lightmap.vert b/shaders/lightmap.vert
index 90c5bc9c..aceaf4d5 100644
--- a/shaders/lightmap.vert
+++ b/shaders/lightmap.vert
@@ -1,13 +1,13 @@
precision mediump float;
-layout (location = 0) uniform sampler2D sampler;
-layout (location = 1) uniform vec3 light_color;
-layout (location = 2) uniform vec2 size;
-layout (location = 3) uniform vec2 center_fragcoord;
-layout (location = 4) uniform vec2 center_clip;
-layout (location = 5) uniform float range;
-layout (location = 6) uniform uint mode;
-layout (location = 7) uniform uint falloff;
+layout (location = 2) uniform sampler2D sampler0;
+layout (location = 3) uniform vec3 light_color;
+layout (location = 4) uniform vec2 size;
+layout (location = 5) uniform vec2 center_fragcoord;
+layout (location = 6) uniform vec2 center_clip;
+layout (location = 7) uniform float range;
+layout (location = 8) uniform uint mode;
+layout (location = 9) uniform uint falloff;
//layout (location = 0) out vec2 frag_texcoords;
//layout (location = 1) flat out vec2 frag_light_coord;