summaryrefslogtreecommitdiffhomepage
path: root/shaders
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-08-23 04:07:38 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-08-23 04:07:38 +0200
commit4019ab7a0dfb771e02d07a70c56c64703a053315 (patch)
tree950ab6c4d690b7af0d4d3a09a17fd23fbf3e8c05 /shaders
parent8e4781b3103f68965b2aba4e914f7c3281ccbc59 (diff)
shaders: clean up a bit
Diffstat (limited to 'shaders')
-rw-r--r--shaders/lightmap.cpp31
-rw-r--r--shaders/lightmap.frag4
-rw-r--r--shaders/lightmap.hpp26
-rw-r--r--shaders/lightmap.vert2
4 files changed, 8 insertions, 55 deletions
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
index 2f61e846..bafda3d8 100644
--- a/shaders/lightmap.cpp
+++ b/shaders/lightmap.cpp
@@ -191,32 +191,11 @@ lightmap_shader::lightmap_shader()
setUniform(SizeUniform, Vector2(1 / chunk_size));
setUniform(CenterFragcoordUniform, Vector2(0, 0));
setUniform(CenterClipUniform, Vector2(-1, -1));
- setUniform(IntensityUniform, 1.f);
+ setUniform(RangeUniform, 1.f);
setUniform(ModeUniform, DrawLightmapMode);
setUniform(FalloffUniform, (uint32_t)light_falloff::constant);
}
-#if 0
-void lightmap_shader::flush_vertexes(ShaderMode mode)
-{
- fm_assert(_count != (size_t)-1);
-
- if (_count > 0)
- {
- setUniform(ModeUniform, mode);
-
- _index_buf.setSubData(0, ArrayView<std::array<UnsignedShort, 6>>{_indexes, _count});
- _vertex_buf.setSubData(0, ArrayView<std::array<Vector2, 4>>{_quads, _count});
-
- GL::MeshView mesh{_mesh};
- mesh.setCount((int)(6 * _count));
- mesh.setIndexRange(0, 0, (uint32_t)(_count * 6 - 1));
- AbstractShaderProgram::draw(mesh);
- }
- _count = 0;
-}
-#endif
-
std::array<UnsignedShort, 6> lightmap_shader::quad_indexes(size_t N)
{
using u16 = UnsignedShort;
@@ -229,7 +208,7 @@ std::array<UnsignedShort, 6> lightmap_shader::quad_indexes(size_t N)
void lightmap_shader::add_light(const light_s& light)
{
constexpr auto tile_size = TILE_SIZE2.sum()/2;
- float I = tile_size;
+ float I;
switch (light.falloff)
{
@@ -257,7 +236,7 @@ void lightmap_shader::add_light(const light_s& light)
setUniform(SizeUniform, 1 / chunk_size);
setUniform(CenterFragcoordUniform, center_fragcoord);
setUniform(CenterClipUniform, center_clip);
- setUniform(IntensityUniform, I);
+ setUniform(RangeUniform, I);
setUniform(FalloffUniform, (uint32_t)light.falloff);
framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{0});
@@ -269,7 +248,7 @@ void lightmap_shader::add_light(const light_s& light)
#if 1
setUniform(ModeUniform, DrawShadowsMode);
setUniform(LightColorUniform, Color3{0, 0, 0});
- setUniform(IntensityUniform, 1 );
+ setUniform(RangeUniform, 1 );
fm_assert(occlusion_mesh.id());
auto mesh_view = GL::MeshView{occlusion_mesh};
mesh_view.setCount((int32_t)count*6);
@@ -349,7 +328,6 @@ void lightmap_shader::add_geometry(Vector2 neighbor_offset, chunk& c)
if (auto atlas = t.wall_north_atlas())
if (atlas->pass_mode(pass_mode::blocked) == pass_mode::blocked)
{
- // todo check backface
auto start = tile_start(i);
auto min = start - Vector2(0, shadow_wall_depth),
max = start + Vector2(TILE_SIZE2[0], 0);
@@ -358,7 +336,6 @@ void lightmap_shader::add_geometry(Vector2 neighbor_offset, chunk& c)
if (auto atlas = t.wall_west_atlas())
if (atlas->pass_mode(pass_mode::blocked) == pass_mode::blocked)
{
- // todo check backface
auto start = tile_start(i);
auto min = start - Vector2(shadow_wall_depth, 0),
max = start + Vector2(0, TILE_SIZE[1]);
diff --git a/shaders/lightmap.frag b/shaders/lightmap.frag
index 4922db8e..91467907 100644
--- a/shaders/lightmap.frag
+++ b/shaders/lightmap.frag
@@ -5,7 +5,7 @@ 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 intensity;
+layout (location = 5) uniform float range;
layout (location = 6) uniform uint mode;
layout (location = 7) uniform uint falloff;
@@ -16,7 +16,7 @@ out vec4 color;
void main() {
if (mode == 1)
{
- float L = intensity;
+ float L = range;
vec2 pos = gl_FragCoord.xy;
float dist = distance(pos, center_fragcoord);
float A = 1;
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp
index 4c9e4b7b..d555dfc5 100644
--- a/shaders/lightmap.hpp
+++ b/shaders/lightmap.hpp
@@ -40,24 +40,6 @@ struct lightmap_shader final : GL::AbstractShaderProgram
GL::Texture2D scratch{NoCreate}, accum{NoCreate};
};
-#if 0
-const blend_light = {
- equation: {color: gl.FUNC_ADD, alpha: gl.FUNC_ADD},
- function: {color_src:gl.DST_ALPHA, alpha_src:gl.ONE,
- color_dst:gl.ONE, alpha_dst:gl.ZERO},
-};
-
-// Shadows should only be drawn into the alpha channel and should leave color untouched.
-// You could also do this with a write mask if that's supported.
-const blend_shadow = {
- equation: {color: gl.FUNC_ADD, alpha: gl.FUNC_ADD},
- function: {color_src:gl.ZERO, alpha_src:gl.ZERO,
- color_dst:gl.ONE_MINUS_SRC_COLOR, alpha_dst:GL_ONE},
-};
-#endif
-
- //void begin_light(Vector2 neighbor_offset, const light_s& light);
-
void begin_occlusion();
void end_occlusion();
void add_chunk(Vector2 neighbor_offset, chunk& c);
@@ -65,8 +47,6 @@ const blend_shadow = {
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 finish_light_only();
- //void finish_and_blend_light();
void add_light(const light_s& light);
void bind();
@@ -84,7 +64,7 @@ private:
SizeUniform = 2,
CenterFragcoordUniform = 3,
CenterClipUniform = 4,
- IntensityUniform = 5,
+ RangeUniform = 5,
ModeUniform = 6,
FalloffUniform = 7,
};
@@ -102,10 +82,6 @@ private:
static Framebuffer make_framebuffer(Vector2i size);
GL::Mesh make_occlusion_mesh();
- //void flush_vertexes(ShaderMode mode);
- //void add_quad(const std::array<Vector2, 4>& quad);
- //void clear_scratch();
- //void clear_accum();
static std::array<UnsignedShort, 6> quad_indexes(size_t N);
// todo use setData() and a boolean flag on capacity change
diff --git a/shaders/lightmap.vert b/shaders/lightmap.vert
index 1f49404f..7acd83ce 100644
--- a/shaders/lightmap.vert
+++ b/shaders/lightmap.vert
@@ -5,7 +5,7 @@ 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 intensity;
+layout (location = 5) uniform float range;
layout (location = 6) uniform uint mode;
layout (location = 7) uniform uint falloff;