UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

52 lines (50 loc) 1.45 kB
var dofBlur_default = ` #if defined(NEAR_BLUR) uniform sampler2D nearTexture; #endif uniform sampler2D farTexture; uniform sampler2D cocTexture; uniform vec2 kernel[{KERNEL_COUNT}]; uniform float blurRadiusNear; uniform float blurRadiusFar; varying vec2 uv0; void main() { vec2 coc = texture2D(cocTexture, uv0).rg; float cocFar = coc.r; vec3 sum = vec3(0.0, 0.0, 0.0); #if defined(NEAR_BLUR) float cocNear = coc.g; if (cocNear > 0.0001) { vec2 nearTextureSize = vec2(textureSize(nearTexture, 0)); vec2 step = cocNear * blurRadiusNear * vec2(nearTextureSize.y / nearTextureSize.x, 1.0); for (int i = 0; i < {KERNEL_COUNT}; i++) { vec2 uv = uv0 + step * kernel[i]; vec3 tap = texture2DLod(nearTexture, uv, 0.0).rgb; sum += tap.rgb; } sum *= float({INV_KERNEL_COUNT}); } else #endif if (cocFar > 0.0001) { vec2 farTextureSize = vec2(textureSize(farTexture, 0)); vec2 step = cocFar * blurRadiusFar * vec2(farTextureSize.y / farTextureSize.x, 1.0); float sumCoC = 0.0; for (int i = 0; i < {KERNEL_COUNT}; i++) { vec2 uv = uv0 + step * kernel[i]; vec3 tap = texture2DLod(farTexture, uv, 0.0).rgb; float cocThis = texture2DLod(cocTexture, uv, 0.0).r; tap *= cocThis; sumCoC += cocThis; sum += tap; } if (sumCoC > 0.0) sum /= sumCoC; sum /= cocFar; } pcFragColor0 = vec4(sum, 1.0); } `; export { dofBlur_default as default };