UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

3 lines (2 loc) 1.94 kB
declare const _default: "\n #ifdef DOF\n uniform sampler2D cocTexture;\n uniform sampler2D blurTexture;\n \n // Global variables for debug\n vec2 dCoc;\n vec3 dBlur;\n\n // Samples the DOF blur and CoC textures\n vec3 getDofBlur(vec2 uv) {\n dCoc = texture2DLod(cocTexture, uv, 0.0).rg;\n\n #if DOF_UPSCALE\n vec2 blurTexelSize = 1.0 / vec2(textureSize(blurTexture, 0));\n vec3 bilinearBlur = vec3(0.0);\n float totalWeight = 0.0;\n\n // 3x3 grid of neighboring texels\n for (int i = -1; i <= 1; i++) {\n for (int j = -1; j <= 1; j++) {\n vec2 offset = vec2(i, j) * blurTexelSize;\n vec2 cocSample = texture2DLod(cocTexture, uv + offset, 0.0).rg;\n vec3 blurSample = texture2DLod(blurTexture, uv + offset, 0.0).rgb;\n\n // Accumulate the weighted blur sample\n float cocWeight = clamp(cocSample.r + cocSample.g, 0.0, 1.0);\n bilinearBlur += blurSample * cocWeight;\n totalWeight += cocWeight;\n }\n }\n\n // normalize the accumulated color\n if (totalWeight > 0.0) {\n bilinearBlur /= totalWeight;\n }\n\n dBlur = bilinearBlur;\n return bilinearBlur;\n #else\n // when blurTexture is full resolution, just sample it, no upsampling\n dBlur = texture2DLod(blurTexture, uv, 0.0).rgb;\n return dBlur;\n #endif\n }\n\n vec3 applyDof(vec3 color, vec2 uv) {\n vec3 blur = getDofBlur(uv);\n return mix(color, blur, dCoc.r + dCoc.g);\n }\n #endif\n"; export default _default;