summaryrefslogtreecommitdiffhomepage
path: root/shaders
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-08-23 03:37:35 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-08-23 03:37:35 +0200
commit95115d88ffeadd734048129525c14632f089aaa5 (patch)
tree9e662dd7bc209365b140631d57f3ad4acf343e14 /shaders
parente9f5c273128e553a6ebc9d15f3a9a820faf2bbb4 (diff)
wip
Diffstat (limited to 'shaders')
-rw-r--r--shaders/lightmap.cpp56
-rw-r--r--shaders/lightmap.frag4
-rw-r--r--shaders/lightmap.hpp5
-rw-r--r--shaders/lightmap.vert2
4 files changed, 40 insertions, 27 deletions
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
index a022544a..77c5bd6c 100644
--- a/shaders/lightmap.cpp
+++ b/shaders/lightmap.cpp
@@ -23,14 +23,12 @@ namespace floormat {
namespace {
-constexpr auto max_neighbors = 8;
-
constexpr auto chunk_size = TILE_SIZE2 * TILE_MAX_DIM;
constexpr auto chunk_offset = TILE_SIZE2/2;
-constexpr auto image_size = max_neighbors * iTILE_SIZE2 * TILE_MAX_DIM;
+constexpr auto image_size = iTILE_SIZE2 * TILE_MAX_DIM;
-constexpr auto clip_start = Vector2{-1, 1};
-constexpr auto clip_scale = 2/(chunk_size * max_neighbors);
+constexpr auto clip_start = Vector2{-1, -1};
+constexpr auto clip_scale = 2/chunk_size;
//constexpr auto shadow_length = chunk_size * 2 * max_neighbors;
constexpr auto shadow_color = Vector4{0, 0, 0, 1};
@@ -39,7 +37,7 @@ constexpr auto shadow_wall_depth = 4.f;
using Utility::forward;
template<typename T>
-GL::Mesh make_light_mesh(T&& vert, T&& index)
+GL::Mesh make_light_mesh(T vert, T index)
{
GL::Mesh mesh{GL::MeshPrimitive::Triangles};
mesh.addVertexBuffer(forward<T>(vert), 0, lightmap_shader::Position{})
@@ -195,7 +193,7 @@ lightmap_shader::lightmap_shader()
setUniform(SamplerUniform, TextureSampler);
setUniform(LightColorUniform, Color3{1, 1, 1});
- setUniform(SizeUniform, Vector2(1 / (chunk_size * max_neighbors)));
+ setUniform(SizeUniform, Vector2(1 / chunk_size));
setUniform(CenterFragcoordUniform, Vector2(0, 0));
setUniform(CenterClipUniform, Vector2(-1, -1));
setUniform(IntensityUniform, 1.f);
@@ -233,35 +231,41 @@ std::array<UnsignedShort, 6> lightmap_shader::quad_indexes(size_t N)
}; /* 2 2--0 */
}
-void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light)
+void lightmap_shader::add_light(const light_s& light)
{
- Vector2 I_clip;
+ constexpr auto tile_size = TILE_SIZE2.sum()/2;
+ float I = tile_size;
switch (light.falloff)
{
default:
+ case light_falloff::constant:
+ I = TILE_MAX_DIM * 3;
break;
case light_falloff::linear:
case light_falloff::quadratic:
- I_clip = light.dist * TILE_SIZE2;
+ I = light.dist;
break;
}
- I_clip = { std::fmax(1.f, I_clip.x()), std::fmax(1.f, I_clip.y()) };
+ I *= tile_size;
+ I = std::fmax(0.f, I);
+ //I_clip = { std::fmax(1.f, I_clip.x()), std::fmax(1.f, I_clip.y()) };
- // window-relative coordinates
- auto center_fragcoord = light.center + chunk_offset + neighbor_offset*chunk_size;
+ auto center_fragcoord = light.center + 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;
setUniform(SamplerUniform, TextureSampler);
- setUniform(LightColorUniform, color);
- setUniform(SizeUniform, 1 / (chunk_size * max_neighbors));
- setUniform(CenterFragcoordUniform, center_fragcoord);
+ //setUniform(LightColorUniform, color * alpha);
+ setUniform(LightColorUniform, Vector3{1});
+ setUniform(SizeUniform, 1 / chunk_size);
+ //setUniform(CenterFragcoordUniform, center_fragcoord);
+ setUniform(CenterFragcoordUniform, Vector2{512});
setUniform(CenterClipUniform, center_clip);
- setUniform(IntensityUniform, alpha);
+ setUniform(IntensityUniform, I);
setUniform(FalloffUniform, (uint32_t)light.falloff);
framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{0});
@@ -270,25 +274,31 @@ void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light)
fm_debug_assert(light_vertex_buf.id());
fm_debug_assert(light_mesh.id());
setUniform(ModeUniform, DrawLightmapMode);
+#if 0
auto quad = std::array<Vector3, 4>{{
- { I_clip.x() + center_clip.x(), -I_clip.y() + center_clip.y(), 0 },
- { I_clip.x() + center_clip.x(), I_clip.y() + center_clip.y(), 0 },
- { -I_clip.x() + center_clip.x(), -I_clip.y() + center_clip.y(), 0 },
- { -I_clip.x() + center_clip.x(), I_clip.y() + center_clip.y(), 0 },
+ { I_clip + center_clip.x(), -I_clip + center_clip.y(), 0 },
+ { I_clip + center_clip.x(), I_clip + center_clip.y(), 0 },
+ { -I_clip + center_clip.x(), -I_clip + center_clip.y(), 0 },
+ { -I_clip + center_clip.x(), I_clip + center_clip.y(), 0 },
}};
light_vertex_buf.setSubData(0, quad);
- AbstractShaderProgram::draw(light_mesh);
+#endif
+ AbstractShaderProgram::draw(blend_mesh);
+#if 0
setUniform(LightColorUniform, Color3{0, 0, 0});
fm_assert(occlusion_mesh.id());
auto mesh_view = GL::MeshView{occlusion_mesh};
mesh_view.setCount((int32_t)count*6);
AbstractShaderProgram::draw(mesh_view);
- //mesh_view.setIndexRange(0, 0, uint32_t(count*6 - 1));
+ mesh_view.setIndexRange(0, 0, uint32_t(count*6 - 1));
+#endif
+#if 0
setUniform(ModeUniform, BlendLightmapMode);
framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{1});
AbstractShaderProgram::draw(blend_mesh);
+#endif
}
void lightmap_shader::add_rect(Vector2 neighbor_offset, Vector2 min, Vector2 max)
diff --git a/shaders/lightmap.frag b/shaders/lightmap.frag
index 8865e48e..6cf1d841 100644
--- a/shaders/lightmap.frag
+++ b/shaders/lightmap.frag
@@ -27,7 +27,9 @@ void main() {
float tmp = max(0, L - dist);
A = tmp*tmp / (L*L);
}
- color = vec4(light_color, A);
+ color = vec4(light_color.rgb, A);
+ //A += 0.2;
+ //color = vec4(vec3(A), 1);
}
else if (mode == 2) // blend
{
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp
index 8e9b77e2..b885501a 100644
--- a/shaders/lightmap.hpp
+++ b/shaders/lightmap.hpp
@@ -67,7 +67,7 @@ const blend_shadow = {
void add_rect(Vector2 neighbor_offset, Pair<Vector2, Vector2> minmax);
//void finish_light_only();
//void finish_and_blend_light();
- void add_light(Vector2 neighbor_offset, const light_s& light);
+ void add_light(const light_s& light);
void bind();
GL::Texture2D& scratch_texture();
@@ -75,7 +75,7 @@ const blend_shadow = {
static constexpr auto max_chunks = Vector2s(8, 8);
- using Position = GL::Attribute<0, Vector2>;
+ using Position = GL::Attribute<0, Vector3>;
private:
enum : Int {
@@ -117,7 +117,6 @@ private:
GL::Mesh occlusion_mesh{NoCreate};
static constexpr auto starting_capacity = 1; // todo
- std::array<Vector3, 4> light_vertexes;
GL::Buffer light_vertex_buf{NoCreate};
GL::Mesh light_mesh{NoCreate};
diff --git a/shaders/lightmap.vert b/shaders/lightmap.vert
index 900038c4..6c1e3d73 100644
--- a/shaders/lightmap.vert
+++ b/shaders/lightmap.vert
@@ -16,6 +16,7 @@ layout (location = 0) in vec3 position;
void main() {
vec2 pos = position.xy;
+ /*
if (mode == 0)
{
vec2 dir = pos - center_clip;
@@ -26,5 +27,6 @@ void main() {
pos += dir_norm * position.z * 4;
}
}
+ */
gl_Position = vec4(pos, 0, 1);
}