Game Development Reference
In-Depth Information
pixel. It then blends the near-field buffer over that result with premultiplied alpha
blending. Near-field pixels exhibit inpainted detail from the far-field buffer and
existing detail from the input buffer, both of which then receive the significantly
blurred near-field content over them. Far-field pixels are blurry from the far-field
image, the focus field is sharp and from the original image, and all transition
regions are smooth because of the lerp.
uniform sampler2D packedBuffer;
uniform sampler2D blurBuffer;
uniform sampler2D nearBuffer;
out vec3 result;
const float coverageBoost = 1.5;
float grayscale(float3 c) {
return (c.r + c.g + c.b) / 3.0;
}
void main() {
int2 A = int2(gl_FragCoord.xy);
float4 pack = texelFetch(packedBuffer , A, 0);
float3 sharp = pack.rgb;
float3 blurred = texture(blurBuffer,
gl_FragCoord.xy / textureSize(packedBuffer , 0));
float4 near = texture(nearBuffer,
gl_FragCoord.xy / textureSize(packedBuffer , 0));
// Normalize radius.
float normRadius = (pack.a * 2.0 - 1.0);
if (coverageBoost != 1.0) {\{}
float a = saturate(coverageBoost * near.a);
near.rgb = near.rgb * (a / max(near.a, 0.001f));
near.a = a;
}
// Decrease sharp image's contribution rapidly in the near field.
if (normRadius > 0.1) {\{}
normRadius = min(normRadius * 1.5, 1.0);
}
result = lerp(sharp, blurred, abs(normRadius)) * (1.0 - near.a)
+ near.rgb;
}
The effect is extremely robust to camera and object movement and varying blur
radii, independent of the scene. It should be tuned for two application-specific
cases: transitions from mid to near depending on the field of view, and objects
that don't write the depth buffer.
A compile-time constant, coverageBoost , allows increasing the partial coverage
(alpha) of the near field to make it feel more substantial. This should always be
greater than or equal to 1. If the near-field objects seem too transparent, then
 
Search Nedrilad ::




Custom Search