2024-04-14 13:28:52 -04:00
|
|
|
|
|
|
|
//#define dof
|
2024-04-14 13:59:53 -04:00
|
|
|
#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;
|
2024-04-18 17:02:53 -04:00
|
|
|
int stops = max(min(int(sqrt(distance * 256)), 5), 0);
|
2024-04-14 13:28:52 -04:00
|
|
|
|
2024-04-14 18:48:16 -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;
|
2024-04-14 13:59:53 -04:00
|
|
|
|
|
|
|
#ifdef dofRes
|
|
|
|
renderRes = virtualSize;
|
|
|
|
#endif
|
2024-04-14 13:28:52 -04:00
|
|
|
return (floor(texcoord * view) + offset) / view;
|
|
|
|
}
|
|
|
|
|