playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
3 lines (2 loc) • 1.55 kB
TypeScript
declare const _default: "\n #include \"screenDepthPS\"\n\n varying vec2 uv0;\n\n uniform sampler2D uFogTexture;\n uniform vec4 uFogTextureSize; // xy: fog texture resolution, zw: inverse resolution\n\n void main() {\n float depth = getLinearScreenDepth(uv0);\n\n // 4 nearest texel centers of the low resolution fog texture\n vec2 texel = uv0 * uFogTextureSize.xy - 0.5;\n vec2 base = (floor(texel) + 0.5) * uFogTextureSize.zw;\n vec2 f = fract(texel);\n\n vec2 uvs[4];\n uvs[0] = base;\n uvs[1] = base + vec2(uFogTextureSize.z, 0.0);\n uvs[2] = base + vec2(0.0, uFogTextureSize.w);\n uvs[3] = base + uFogTextureSize.zw;\n\n vec4 bilinear = vec4((1.0 - f.x) * (1.0 - f.y), f.x * (1.0 - f.y), (1.0 - f.x) * f.y, f.x * f.y);\n\n // depth-aware upsample - weight the low resolution fog samples by depth similarity to\n // avoid fog leaking across geometry edges\n vec4 sum = vec4(0.0);\n float sumWeight = 0.0;\n for (int i = 0; i < 4; i++) {\n float sampleDepth = getLinearScreenDepth(uvs[i]);\n float w = bilinear[i] / (1.0 + 16.0 * abs(sampleDepth - depth) / max(depth, 0.001));\n sum += texture2D(uFogTexture, uvs[i]) * w;\n sumWeight += w;\n }\n\n // rgb: in-scattered light, a: transmittance. Blended over the scene using\n // scene * transmittance + inscatter.\n gl_FragColor = sum / max(sumWeight, 0.0001);\n }\n";
export default _default;