mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-21 15:34:58 +01:00
feat(render): ambient occlusion with bent normals darkens only the light of the surroundings instead of the whole image, so the sun and headlights keep their full strength; the occlusion and the bent normal of the previous frame are reprojected into the lighting of the scene, with the motion of the camera and of every vehicle and cab taken into account and with depth checks against disocclusion, the ambient light follows how much of the sky the bent normal sees, and reflections of the environment are occluded where the cone of visible directions around the bent normal cuts off the reflected lobe, only where the occlusion is clear enough that open flat panels and windows keep their grazing reflections
This commit is contained in:
@@ -2,44 +2,37 @@ in vec2 f_coords;
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
#texture (ao_tex, 0, R)
|
||||
#texture (ao_tex, 0, RGBA)
|
||||
uniform sampler2D ao_tex;
|
||||
|
||||
#texture (depth_tex, 1, R)
|
||||
uniform sampler2D depth_tex;
|
||||
|
||||
#include <common>
|
||||
|
||||
float view_distance(vec2 uv)
|
||||
{
|
||||
ivec2 size = textureSize(depth_tex, 0);
|
||||
float depth = texelFetch(depth_tex, clamp(ivec2(uv * vec2(size)), ivec2(0), size - 1), 0).r;
|
||||
if (depth <= 0.0)
|
||||
return 1e6;
|
||||
float ndcz = (param[1].x > 0.5 ? depth : depth * 2.0 - 1.0);
|
||||
return projection[3][2] / (ndcz + projection[2][2]);
|
||||
}
|
||||
#include <gtao_common.glsl>
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texel = 1.0 / vec2(textureSize(ao_tex, 0));
|
||||
float center = view_distance(f_coords);
|
||||
if (center >= 1e6) {
|
||||
out_color = vec4(1.0);
|
||||
ivec2 size = textureSize(ao_tex, 0);
|
||||
ivec2 center = ivec2(f_coords * vec2(size));
|
||||
vec4 centersample = texelFetch(ao_tex, center, 0);
|
||||
float centerdistance = centersample.g;
|
||||
if (centerdistance >= 60000.0) {
|
||||
out_color = centersample;
|
||||
return;
|
||||
}
|
||||
float sum = 0.0;
|
||||
float visibility = 0.0;
|
||||
vec3 bent = vec3(0.0);
|
||||
float weights = 0.0;
|
||||
for (int y = -2; y <= 2; ++y)
|
||||
{
|
||||
for (int x = -2; x <= 2; ++x)
|
||||
{
|
||||
vec2 uv = f_coords + vec2(float(x), float(y)) * texel;
|
||||
float difference = (view_distance(uv) - center) / (center * 0.02 + 0.01);
|
||||
vec4 tap = texelFetch(ao_tex, clamp(center + ivec2(x, y), ivec2(0), size - 1), 0);
|
||||
float difference = (tap.g - centerdistance) / (centerdistance * 0.02 + 0.01);
|
||||
float weight = exp(-float(x * x + y * y) / 4.5 - difference * difference);
|
||||
sum += texture(ao_tex, uv).r * weight;
|
||||
visibility += tap.r * weight;
|
||||
bent += octahedral_decode(tap.ba) * weight;
|
||||
weights += weight;
|
||||
}
|
||||
}
|
||||
out_color = vec4(sum / max(weights, 1e-4));
|
||||
bent = (dot(bent, bent) > 1e-8 ? normalize(bent) : octahedral_decode(centersample.ba));
|
||||
out_color = vec4(visibility / max(weights, 1e-4), centerdistance, octahedral_encode(bent));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user