24 lines
1.3 KiB
Plaintext
24 lines
1.3 KiB
Plaintext
#version 450
|
|
#extension GL_GOOGLE_include_directive : require
|
|
layout(local_size_x = 8, local_size_y = 8) in;
|
|
#include "common.glsl"
|
|
|
|
// The light of the entities (LightComponent, up to 128 near the window) at every cell of the window, once per frame: render.comp's lighting() reads it.
|
|
// (render.comp summed every light for every output pixel - some 36 pixels per cell in a large window - and grew slow with the lanterns and fires of a
|
|
// long session.)
|
|
layout(std430, set = 0, binding = 45) readonly buffer Lit { uvec4 lhead; vec4 lent[]; }; // count, then (x, y, radius, strength), (r, g, b, 0) per light
|
|
layout(std430, set = 0, binding = 57) buffer LitCells { uvec2 litc[]; }; // per cell: the summed light, half floats (r g, b)
|
|
|
|
void main() {
|
|
const ivec2 cp = ivec2(gl_GlobalInvocationID.xy);
|
|
if (cp.x >= pc.gw || cp.y >= pc.gh) return;
|
|
const vec2 w = vec2(cp + ivec2(pc.view_x, pc.view_y)) + 0.5;
|
|
vec3 L = vec3(0.0);
|
|
for (uint i = 0u; i < min(lhead.x, 128u); ++i) {
|
|
const vec4 a = lent[2u * i], b = lent[2u * i + 1u];
|
|
const float d = distance(w, a.xy) / a.z;
|
|
if (d < 1.0) L += b.rgb * (1.0 - d) * (1.0 - d) * (1.0 - d) * 1.1 * a.w;
|
|
}
|
|
litc[cp.y * pc.gw + cp.x] = uvec2(packHalf2x16(L.rg), packHalf2x16(vec2(L.b, 0.0)));
|
|
}
|