17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-02 09:19:12 +01:00

Even out the fog cells with their neighbours and stagger the points next to lamps

This commit is contained in:
2026-10-17 00:37:58 +02:00
parent d07204db5c
commit 8dd80c4d2e
2 changed files with 12 additions and 3 deletions

View File

@@ -1,7 +1,9 @@
// the fog volume of the main view, second pass: the light and extinction of the cells (fog_inject.comp) added up along the rays
// of the view, front to back, into what the fog adds and lets through from the camera to the far side of every slice
// (apply_fog.glsl). the light of a cell is integrated over its length as Hillaire (2015) does it, so it doesn't grow with
// the size of the cell
// the size of the cell. the light of the cells is taken with the light of their neighbours across the view, a 3x3 tent filter
// (four fetches of the linear filter): every cell is sampled at a point of its own in a frame, and what is left of that after
// the blending over frames differs from cell to cell, which the filter evens out. the history keeps the cells unfiltered
#include <common>
@@ -35,6 +37,12 @@ void main()
float span = (back - front) * stretch;
front = back;
vec4 cell = texelFetch(fog_scattering, ivec3(column, slice), 0);
float depthcoord = (float(slice) + 0.5) / float(grid.z);
vec2 texel = 1.0 / vec2(grid.xy);
cell.rgb = 0.25 * (textureLod(fog_scattering, vec3(coords + vec2(-0.5, -0.5) * texel, depthcoord), 0.0).rgb
+ textureLod(fog_scattering, vec3(coords + vec2(0.5, -0.5) * texel, depthcoord), 0.0).rgb
+ textureLod(fog_scattering, vec3(coords + vec2(-0.5, 0.5) * texel, depthcoord), 0.0).rgb
+ textureLod(fog_scattering, vec3(coords + vec2(0.5, 0.5) * texel, depthcoord), 0.0).rgb);
float extinction = max(cell.a, 1e-7);
float through = exp(-extinction * span);
light += transmittance * cell.rgb * ((1.0 - through) / extinction);