UNPKG

playcanvas

Version:

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

43 lines (41 loc) 1.17 kB
var compose_dof_default = ` #ifdef DOF uniform sampler2D cocTexture; uniform sampler2D blurTexture; vec2 dCoc; vec3 dBlur; vec3 getDofBlur(vec2 uv) { dCoc = texture2DLod(cocTexture, uv, 0.0).rg; #if DOF_UPSCALE vec2 blurTexelSize = 1.0 / vec2(textureSize(blurTexture, 0)); vec3 bilinearBlur = vec3(0.0); float totalWeight = 0.0; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { vec2 offset = vec2(i, j) * blurTexelSize; vec2 cocSample = texture2DLod(cocTexture, uv + offset, 0.0).rg; vec3 blurSample = texture2DLod(blurTexture, uv + offset, 0.0).rgb; float cocWeight = clamp(cocSample.r + cocSample.g, 0.0, 1.0); bilinearBlur += blurSample * cocWeight; totalWeight += cocWeight; } } if (totalWeight > 0.0) { bilinearBlur /= totalWeight; } dBlur = bilinearBlur; return bilinearBlur; #else dBlur = texture2DLod(blurTexture, uv, 0.0).rgb; return dBlur; #endif } vec3 applyDof(vec3 color, vec2 uv) { vec3 blur = getDofBlur(uv); return mix(color, blur, dCoc.r + dCoc.g); } #endif `; export { compose_dof_default as default };