From 8138cc9a269844b6c0a84c193a7a43aec7010592 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 17 May 2023 17:06:16 +0200 Subject: wip vobj --- shaders/lightmap.cpp | 20 ++++++++++++++++++++ shaders/lightmap.frag | 18 ++++++++++++++++++ shaders/lightmap.hpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ shaders/lightmap.vert | 0 4 files changed, 87 insertions(+) create mode 100644 shaders/lightmap.cpp create mode 100644 shaders/lightmap.frag create mode 100644 shaders/lightmap.hpp create mode 100644 shaders/lightmap.vert (limited to 'shaders') 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 +#include +#include +#include +#include + +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 -- cgit v1.2.3