summaryrefslogtreecommitdiffhomepage
path: root/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'shaders')
-rw-r--r--shaders/lightmap.cpp11
-rw-r--r--shaders/lightmap.frag3
-rw-r--r--shaders/lightmap.hpp2
-rw-r--r--shaders/lightmap.vert2
-rw-r--r--shaders/shader.hpp1
5 files changed, 12 insertions, 7 deletions
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
index a599cfc9..3a2d339a 100644
--- a/shaders/lightmap.cpp
+++ b/shaders/lightmap.cpp
@@ -109,8 +109,8 @@ void lightmap_shader::add_light(Vector2i neighbor_offset, const light_s& light)
constexpr auto tile_size = TILE_SIZE2.sum()/2;
constexpr auto scale = 2/chunk_size;
- auto dist = std::fmax(0.f, light.dist * tile_size);
- auto dist_clip = dist * tile_size;
+ auto dist = std::fmax(0.f, light.dist/* * tile_size*/);
+ auto dist_clip = dist/* * tile_size*/;
auto center = light.center + chunk_offset + Vector2(neighbor_offset)*chunk_size;
auto center_clip = Vector2{center} * scale; // clip coordinate
constexpr auto image_size_factor = Vector2(image_size) / Vector2(chunk_size);
@@ -126,7 +126,10 @@ void lightmap_shader::add_light(Vector2i neighbor_offset, const light_s& light)
_count++;
- setUniform(ColorIntensityUniform, Vector4{Vector3{light.color}, dist});
+ float alpha = light.color.a() / 255.f;
+ auto color = Vector3{light.color.rgb()} / 255.f;
+
+ setUniform(ColorIntensityUniform, Vector4{Vector3{color} * alpha, dist});
setUniform(CenterUniform, center_fragcoord);
setUniform(FalloffUniform, (uint32_t)light.falloff);
setUniform(SizeUniform, chunk_size);
@@ -136,7 +139,7 @@ lightmap_shader::~lightmap_shader() = default;
void lightmap_shader::clear()
{
- framebuffer.fb.clearColor(0, Color4{1.f, 0.f, 1.f, 1.f});
+ framebuffer.fb.clearColor(0, Vector4ui{0});
//framebuffer.fb.clearDepth(0);
}
diff --git a/shaders/lightmap.frag b/shaders/lightmap.frag
index 748be244..eb7ed789 100644
--- a/shaders/lightmap.frag
+++ b/shaders/lightmap.frag
@@ -11,7 +11,8 @@ void main() {
vec2 pos = gl_FragCoord.xy;
float I = color_intensity.w;
vec2 tmp = pos - center;
+ //float dist = sqrt(tmp.x*tmp.x + tmp.y*tmp.y);
float dist = sqrt(tmp.x*tmp.x + tmp.y*tmp.y);
float alpha = 1 - min(1, dist / I);
- color = vec4(alpha * color_intensity.xyz, 1);
+ color = vec4(color_intensity.xyz, alpha);
}
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp
index a7204723..e458cadc 100644
--- a/shaders/lightmap.hpp
+++ b/shaders/lightmap.hpp
@@ -20,7 +20,7 @@ struct light_s final
Vector2 center;
float dist = 1;
//float depth = -1 + 1e-4f;
- Math::Color3<uint8_t> color {255, 255, 255};
+ Math::Color4<uint8_t> color;
light_falloff falloff = light_falloff::linear;
bool operator==(const light_s&) const noexcept;
diff --git a/shaders/lightmap.vert b/shaders/lightmap.vert
index a044a141..7b1ca696 100644
--- a/shaders/lightmap.vert
+++ b/shaders/lightmap.vert
@@ -8,5 +8,5 @@ layout (location = 3) uniform vec2 size;
layout (location = 0) in vec4 position;
void main() {
- gl_Position = vec4(position.x, -position.y, 0, 1);
+ gl_Position = vec4(position.x, position.y, 0, 1);
}
diff --git a/shaders/shader.hpp b/shaders/shader.hpp
index 7e73974b..0f7100e0 100644
--- a/shaders/shader.hpp
+++ b/shaders/shader.hpp
@@ -37,6 +37,7 @@ struct tile_shader final : GL::AbstractShaderProgram
static constexpr Vector2s max_screen_tiles = {8, 8};
static constexpr float character_depth_offset = 1 + 1./64;
static constexpr float scenery_depth_offset = 1 + 1./64;
+ static constexpr float ground_depth_offset = 0; // todo scenery cut off at chunk boundary
static constexpr float wall_depth_offset = 1;
static constexpr float z_depth_offset = 1 + 2./64;
static constexpr float depth_tile_size = 1/(double)(TILE_MAX_DIM * 2 * max_screen_tiles.product());