UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

3 lines (2 loc) 2.19 kB
declare const _default: "\n #ifdef DOF\n var cocTexture: texture_2d<f32>;\n var cocTextureSampler: sampler;\n var blurTexture: texture_2d<f32>;\n var blurTextureSampler: sampler;\n \n // Global variables for debug\n var<private> dCoc: vec2f;\n var<private> dBlur: vec3f;\n\n // Samples the DOF blur and CoC textures\n fn getDofBlur(uv: vec2f) -> vec3f {\n dCoc = textureSampleLevel(cocTexture, cocTextureSampler, uv, 0.0).rg;\n\n #if DOF_UPSCALE\n let blurTexelSize = 1.0 / vec2f(textureDimensions(blurTexture, 0));\n var bilinearBlur = vec3f(0.0);\n var totalWeight = 0.0;\n\n // 3x3 grid of neighboring texels\n for (var i = -1; i <= 1; i++) {\n for (var j = -1; j <= 1; j++) {\n let offset = vec2f(f32(i), f32(j)) * blurTexelSize;\n let cocSample = textureSampleLevel(cocTexture, cocTextureSampler, uv + offset, 0.0).rg;\n let blurSample = textureSampleLevel(blurTexture, blurTextureSampler, uv + offset, 0.0).rgb;\n\n // Accumulate the weighted blur sample\n let 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 = textureSampleLevel(blurTexture, blurTextureSampler, uv, 0.0).rgb;\n return dBlur;\n #endif\n }\n\n fn applyDof(color: vec3f, uv: vec2f) -> vec3f {\n let blur = getDofBlur(uv);\n return mix(color, blur, dCoc.r + dCoc.g);\n }\n #endif\n"; export default _default;