summaryrefslogtreecommitdiffhomepage
path: root/shaders
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-05-17 17:06:16 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-05-17 17:08:52 +0200
commit8138cc9a269844b6c0a84c193a7a43aec7010592 (patch)
tree1d7c1f1b37c7f714fd0976bfa839e0b18ca2385d /shaders
parent08b89c6575947e8fdcba9b6c329c25aa8472e52b (diff)
wip vobj
Diffstat (limited to 'shaders')
-rw-r--r--shaders/lightmap.cpp20
-rw-r--r--shaders/lightmap.frag18
-rw-r--r--shaders/lightmap.hpp49
-rw-r--r--shaders/lightmap.vert0
4 files changed, 87 insertions, 0 deletions
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
new file mode 100644
index 00000000..3575e424
--- /dev/null
+++ b/shaders/lightmap.cpp
@@ -0,0 +1,20 @@
+#include "lightmap.hpp"
+#include "src/local-coords.hpp"
+
+#ifdef __clang__
+#pragma clang diagnostic ignored "-Wfloat-equal"
+#endif
+
+namespace floormat {
+
+lightmap_shader::~lightmap_shader() = default;
+bool lightmap_shader::light_s::operator==(const light_s&) const noexcept = default;
+
+static constexpr Vector2 output_size = TILE_MAX_DIM * TILE_SIZE2 * 3;
+
+lightmap_shader::lightmap_shader()
+{
+
+}
+
+} // namespace floormat
diff --git a/shaders/lightmap.frag b/shaders/lightmap.frag
new file mode 100644
index 00000000..2179160c
--- /dev/null
+++ b/shaders/lightmap.frag
@@ -0,0 +1,18 @@
+precision mediump float;
+
+struct light_u
+{
+ vec4 color_and_intensity;
+ vec2 center;
+ uint mode;
+};
+
+#define TILE_MAX_DIM 16
+#define TILE_SIZE_X 64
+#define TILE_SIZE_Y 64
+
+#define CHUNK_SIZE_X (TILE_SIZE_X * TILE_MAX_DIM)
+#define CHUNK_SIZE_Y (TILE_SIZE_Y * TILE_MAX_DIM)
+
+layout (location = 0) uniform vec4 color_intensity;
+layout (location = 1) uniform vec2 px;
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp
new file mode 100644
index 00000000..a2d566e6
--- /dev/null
+++ b/shaders/lightmap.hpp
@@ -0,0 +1,49 @@
+#pragma once
+
+#include "light-falloff.hpp"
+#include <Magnum/GL/AbstractShaderProgram.h>
+#include <Magnum/Math/Vector2.h>
+#include <Magnum/Math/Vector3.h>
+#include <Magnum/Math/Vector4.h>
+#include <Magnum/Math/Color.h>
+
+namespace floormat {
+
+struct local_coords;
+
+struct lightmap_shader final : GL::AbstractShaderProgram
+{
+ using Position = GL::Attribute<0, Vector2>;
+
+ explicit lightmap_shader();
+ ~lightmap_shader() override;
+
+ void set_light(Vector2i neighbor_offset, local_coords pos, Vector2b offset);
+ struct light light() const; // is a reader accessor needed?
+
+private:
+ static Vector2i get_px_pos(Vector2i neighbor_offset, local_coords pos, Vector2b offset);
+
+ struct light_u final
+ {
+ Vector4 color_and_intensity;
+ Vector2 center;
+ uint32_t mode;
+ };
+
+ struct light_s final
+ {
+ float intensity = 1;
+ Color3ub color {255, 255, 255};
+ Vector2i center;
+ light_falloff falloff;
+
+ bool operator==(const light_s&) const noexcept;
+ };
+
+ enum { ColorUniform = 0, CenterUniform = 1, FalloffUniform = 2, DepthUniform = 3, };
+
+ light_s _light;
+};
+
+} // namespace floormat
diff --git a/shaders/lightmap.vert b/shaders/lightmap.vert
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/shaders/lightmap.vert