Fry3DX/engine/shaders/ssao_blur.frag
Nexoniarz f3e8eca87b Fry3DX 0.4: an easy 3D modeller
Shapes with live settings, shape editing, knife and hole tools, drawing
shapes onto other objects, combining objects (add / subtract / overlap),
copies, thickness, painting with stickers and layers, a Layout tab, a
Print tab with checks, packed .fry files with autosave, export to GLB,
glTF, FBX, OBJ, 3MF, STL and PLY, folders in Layers, its own crash
screen, and a website for GitHub Pages in docs/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NMSrd5oe1GpUD7E6d825KP
2026-10-19 21:18:35 +02:00

34 lines
1.2 KiB
GLSL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#version 460
// Smooths the occlusion (4×4, weighted by how close each sample's depth is to this pixel's).
#define KEEL_POST // screen-space: render targets, sampled clamped
#include "backend.glsl"
PUSH_BLOCK {
uint ao, depth;
uint w, h; // depth size
uint outW, outH; // this target's (= the occlusion's)
float pad0, pad1;
vec4 proj;
} pc;
layout(location = 0) out vec4 o_ao;
float linearDepth(vec2 uv) {
ivec2 p = clamp(ivec2(uv * vec2(pc.w, pc.h)), ivec2(0), ivec2(pc.w - 1, pc.h - 1));
float d = fetchTex(pc.depth, p).r;
return pc.proj.z * pc.proj.w / (pc.proj.w - d * (pc.proj.w - pc.proj.z));
}
void main() {
ivec2 o = ivec2(gl_FragCoord.xy);
vec2 uv = gl_FragCoord.xy / vec2(pc.outW, pc.outH);
float z = linearDepth(uv);
float sum = 0.0, weight = 0.0;
for (int y = -2; y < 2; ++y)
for (int x = -2; x < 2; ++x) {
ivec2 q = clamp(o + ivec2(x, y), ivec2(0), ivec2(pc.outW - 1, pc.outH - 1));
float zq = linearDepth((vec2(q) + 0.5) / vec2(pc.outW, pc.outH));
float wgt = max(0.0, 1.0 - abs(zq - z) / (0.05 * z + 1.0));
sum += fetchTex(pc.ao, q).r * wgt;
weight += wgt;
}
o_ao = vec4(weight > 0.0 ? sum / weight : 1.0);
}