summit/frontend/node_modules/three-stdlib/shaders/DepthLimitedBlurShader.cjs.map

1 line
6.5 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"DepthLimitedBlurShader.cjs","sources":["../../src/shaders/DepthLimitedBlurShader.ts"],"sourcesContent":["import { Vector2 } from 'three'\nimport type { IUniform, Texture } from 'three'\nimport type { IShader } from './types'\n\nexport type DepthLimitedBlurShaderDefines = {\n DEPTH_PACKING: number\n KERNEL_RADIUS: number\n PERSPECTIVE_CAMERA: number\n}\n\nexport type DepthLimitedBlurShaderUniforms = {\n cameraFar: IUniform<number>\n cameraNear: IUniform<number>\n depthCutoff: IUniform<number>\n sampleUvOffsets: IUniform<Vector2[]>\n sampleWeights: IUniform<number[]>\n size: IUniform<Vector2>\n tDepth: IUniform<Texture | null>\n tDiffuse: IUniform<Texture | null>\n}\n\nexport interface IDepthLimitedBlurShader\n extends IShader<DepthLimitedBlurShaderUniforms, DepthLimitedBlurShaderDefines> {\n defines: DepthLimitedBlurShaderDefines\n needsUpdate?: boolean\n}\n\nexport const DepthLimitedBlurShader: IDepthLimitedBlurShader = {\n defines: {\n KERNEL_RADIUS: 4,\n DEPTH_PACKING: 1,\n PERSPECTIVE_CAMERA: 1,\n },\n uniforms: {\n tDiffuse: { value: null },\n size: { value: /* @__PURE__ */ new Vector2(512, 512) },\n sampleUvOffsets: { value: [/* @__PURE__ */ new Vector2(0, 0)] },\n sampleWeights: { value: [1.0] },\n tDepth: { value: null },\n cameraNear: { value: 10 },\n cameraFar: { value: 1000 },\n depthCutoff: { value: 10 },\n },\n vertexShader: /* glsl */ `\n #include <common>\n\n uniform vec2 size;\n\n varying vec2 vUv;\n varying vec2 vInvSize;\n\n void main() {\n \tvUv = uv;\n \tvInvSize = 1.0 / size;\n\n \tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n `,\n fragmentShader: /* glsl */ `\n #include <common>\n #include <packing>\n\n uniform sampler2D tDiffuse;\n uniform sampler2D tDepth;\n\n uniform float cameraNear;\n uniform float cameraFar;\n uniform float depthCutoff;\n\n uniform vec2 sampleUvOffsets[ KERNEL_RADIUS + 1 ];\n uniform float sampleWeights[ KERNEL_RADIUS + 1 ];\n\n varying vec2 vUv;\n varying vec2 vInvSize;\n\n float getDepth( const in vec2 screenPosition ) {\n \t#if DEPTH_PACKING == 1\n \treturn unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );\n \t#else\n \treturn texture2D( tDepth, screenPosition ).x;\n \t#endif\n }\n\n float getViewZ( const in float depth ) {\n \t#if PERSPECTIVE_CAMERA == 1\n \treturn perspectiveDepthToViewZ( depth, cameraNear, cameraFar );\n \t#else\n \treturn orthographicDepthToViewZ( depth, cameraNear, cameraFar );\n \t#endif\n }\n\n void main() {\n \tfloat depth = getDepth( vUv );\n \tif( depth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = -getViewZ( depth );\n \tbool rBreak = false, lBreak = false;\n\n \tfloat weightSum = sampleWeights[0];\n \tvec4 diffuseSum = texture2D( tDiffuse, vUv ) * weightSum;\n\n \tfor( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n \t\tfloat sampleWeight = sampleWeights[i];\n \t\tvec2 sampleUvOffset = sampleUvOffsets[i] * vInvSize;\n\n \t\tvec2 sampleUv = vUv + sampleUvOffset;\n \t\tfloat viewZ = -getViewZ( getDepth( sampleUv ) );\n\n \t\tif( abs( viewZ - centerViewZ ) > depthCutoff ) rBreak = true;\n\n \t\tif( ! rBreak ) {\n \t\t\tdiffuseSum += texture2D( tDiffuse, sampleUv ) * sampleWeight;\n \t\t\tweightSum += sampleWeight;\n \t\t}\n\n \t\tsampleUv = vUv - sampleUvOffset;\n \t\tviewZ = -getViewZ( getDepth( sampleUv ) );\n\n \t\tif( abs( viewZ - centerViewZ ) > depthCutoff ) lBreak = true;\n\n \t\tif( ! lBreak ) {\n \t\t\tdiffuseSum += texture2D( tDiffuse, sampleUv ) * sampleWeight;\n \t\t\tweightSum += sampleWeight;\n \t\t}\n\n \t}\n\n \tgl_FragColor = diffuseSum / weightSum;\n }\n `,\n}\n\nexport const BlurShaderUtils = {\n createSampleWeights: (kernelRadius: number, stdDev: number): number[] => {\n const gaussian = (x: number, stdDev: number): number => {\n return Math.exp(-(x * x) / (2.0 * (stdDev * stdDev))) / (Math.sqrt(2