aeon-199x/shaders/module/dof.frag

29 lines
664 B
GLSL
Raw Normal View History

2024-04-14 13:28:52 -04:00
//#define dof
#define dofRes
2024-04-14 13:28:52 -04:00
uniform float centerDepthSmooth;
uniform sampler2D depthtex1;
const float centerDepthSmoothHalfLife = 16f;
vec2 depthOfField() {
float depth = texture2D(depthtex1, texcoord).x;
float distance = depth - centerDepthSmooth;
int stops = max(min(int(sqrt(distance * 256)), 5), 0);
2024-04-14 13:28:52 -04:00
#if pixelSize > 1
float virtualSize = pow(float(pixelSize), 1 + stops);
#else
float virtualSize = pow(2f, stops);
#endif
2024-04-14 13:28:52 -04:00
vec2 view = vec2(viewWidth, viewHeight) / virtualSize;
float offset = (ceil(virtualSize * 0.5) - 0.5) / virtualSize;
#ifdef dofRes
renderRes = virtualSize;
#endif
2024-04-14 13:28:52 -04:00
return (floor(texcoord * view) + offset) / view;
}