// MinecraftPT — Depth of Field // Circle of confusion computation and bokeh blur. #ifndef DOF_GLSL #define DOF_GLSL // Compute CoC (circle of confusion) for a fragment float GetCoC(float depth, float focalDepth){ float focus = focalDepth; float aperture = DOF_BLUR; float coc = abs(depth - focus) / focus * aperture * DOF_MAX_COC; return clamp(coc, 0.0, DOF_MAX_COC); } // Simple bokeh blur (gather) vec3 DofBlur(vec2 texelCoord, float coc){ vec3 color = vec3(0.0); float weight = 0.0; int radius = int(min(coc, 8.0)) + 1; for (int i = -radius; i <= radius; i++){ for (int j = -radius; j <= radius; j++){ float dist = length(vec2(i, j)); if (dist > coc) continue; vec2 coord = texelCoord + vec2(i, j); vec3 sampleColor = texelFetch(colortex12, ivec2(coord), 0).rgb; float w = max(0.0, 1.0 - dist / coc); color += sampleColor * w; weight += w; }} return weight > 0.0 ? color / weight : color; } #endif