import type { Texture } from '@luma.gl/core'; /** Bindings consumed by {@link dof}. */ type DofBindings = { /** Depth texture sampled to reconstruct per-pixel view-space depth. */ depthTexture?: Texture; }; /** Internal uniforms consumed by the shader implementation. */ type InternalDofUniforms = { depthRange?: [number, number]; focusDistance?: number; blurCoefficient?: number; pixelsPerMillimeter?: number; texelOffset?: [number, number]; }; /** * Depth of field * Applies a depth-driven blur using the provided scene depth texture. */ export type DofProps = { /** Near and far clip distances used to reconstruct linear depth. */ depthRange?: [number, number]; /** View-space focal-plane distance that should stay sharp. */ focusDistance?: number; /** Lens blur coefficient derived from focal length and aperture. */ blurCoefficient?: number; /** Pixel density factor used to convert millimeters to texels. */ pixelsPerMillimeter?: number; }; /** * Public uniforms exposed by {@link dof}. * * `texelOffset` is intentionally excluded because the reusable pipeline controls the blur axis. */ export type DofUniforms = DofProps; /** * Depth-of-field postprocessing pass. * * This pass samples scene color from `sourceTexture` and scene depth from `depthTexture`, then * computes a blur radius from reconstructed linear depth. It is designed to be driven by * {@link dofShaderPassPipeline}, which runs the pass twice with different internal * `texelOffset` values for horizontal and vertical blur. * * Callers are expected to provide: * - `sourceTexture`: the resolved scene color texture * - `depthTexture`: a matching sampled depth texture * - uniforms describing the camera or lens state used to derive the circle of confusion */ export declare const dof: { readonly name: "dof"; readonly source: "const DEPTH_OF_FIELD_MAX_BLUR: i32 = 20;\n\nstruct dofUniforms {\n depthRange: vec2,\n focusDistance: f32,\n blurCoefficient: f32,\n pixelsPerMillimeter: f32,\n texelOffset: vec2,\n};\n\n@group(0) @binding(auto) var dof: dofUniforms;\n@group(0) @binding(auto) var depthTexture: texture_depth_2d;\n@group(0) @binding(auto) var depthTextureSampler: sampler;\n\nfn dof_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let resolution = vec2(textureDimensions(sourceTexture, 0));\n let maxCoordinate = resolution - vec2(1, 1);\n let fragmentCoordinate = min(vec2(vec2(resolution) * texCoord), maxCoordinate);\n\n let depthSample = textureSample(depthTexture, depthTextureSampler, texCoord);\n let linearDepth =\n (dof.depthRange.x * dof.depthRange.y) /\n (dof.depthRange.y -\n depthSample * (dof.depthRange.y - dof.depthRange.x));\n\n let deltaDepth = abs(dof.focusDistance - linearDepth);\n let foregroundCompensation = select(\n abs(dof.focusDistance + deltaDepth),\n abs(dof.focusDistance - deltaDepth),\n linearDepth < dof.focusDistance\n );\n let blurRadius = min(\n floor(\n dof.blurCoefficient *\n (deltaDepth / max(foregroundCompensation, 0.0001)) *\n dof.pixelsPerMillimeter\n ),\n f32(DEPTH_OF_FIELD_MAX_BLUR)\n );\n\n var color = vec4f(0.0);\n\n if (blurRadius > 1.0) {\n let halfBlur = blurRadius * 0.5;\n var sampleCount = 0.0;\n\n for (var sampleIndex: i32 = 0; sampleIndex <= DEPTH_OF_FIELD_MAX_BLUR; sampleIndex++) {\n if (f32(sampleIndex) > blurRadius) {\n break;\n }\n\n let sampleOffset = round((f32(sampleIndex) - halfBlur) * dof.texelOffset);\n let sampleCoordinate = clamp(\n fragmentCoordinate + vec2(sampleOffset),\n vec2(0, 0),\n maxCoordinate\n );\n color += textureLoad(sourceTexture, sampleCoordinate, 0);\n sampleCount += 1.0;\n }\n\n color /= sampleCount;\n } else {\n color = textureLoad(sourceTexture, fragmentCoordinate, 0);\n }\n\n return color;\n}\n"; readonly fs: "#define DEPTH_OF_FIELD_MAX_BLUR 20.0\n\nuniform sampler2D depthTexture;\n\nlayout(std140) uniform dofUniforms {\n vec2 depthRange;\n float focusDistance;\n float blurCoefficient;\n float pixelsPerMillimeter;\n vec2 texelOffset;\n} dof;\n\nvec4 dof_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) {\n ivec2 resolution = textureSize(sourceTexture, 0);\n ivec2 maxCoordinate = resolution - 1;\n ivec2 fragmentCoordinate = min(ivec2(texCoord * vec2(resolution)), maxCoordinate);\n\n float depthSample = texelFetch(depthTexture, fragmentCoordinate, 0).r;\n float ndcDepth = depthSample * 2.0 - 1.0;\n float linearDepth = -(2.0 * dof.depthRange.y * dof.depthRange.x) /\n (ndcDepth * (dof.depthRange.y - dof.depthRange.x) -\n dof.depthRange.y -\n dof.depthRange.x);\n\n float deltaDepth = abs(dof.focusDistance - linearDepth);\n float foregroundCompensation =\n linearDepth < dof.focusDistance\n ? abs(dof.focusDistance - deltaDepth)\n : abs(dof.focusDistance + deltaDepth);\n float blurRadius = min(\n floor(\n dof.blurCoefficient *\n (deltaDepth / max(foregroundCompensation, 0.0001)) *\n dof.pixelsPerMillimeter\n ),\n DEPTH_OF_FIELD_MAX_BLUR\n );\n\n vec4 color = vec4(0.0);\n\n if (blurRadius > 1.0) {\n float halfBlur = blurRadius * 0.5;\n float sampleCount = 0.0;\n\n for (float sampleIndex = 0.0; sampleIndex <= DEPTH_OF_FIELD_MAX_BLUR; sampleIndex++) {\n if (sampleIndex > blurRadius) {\n break;\n }\n\n ivec2 sampleCoordinate = clamp(\n fragmentCoordinate + ivec2((sampleIndex - halfBlur) * dof.texelOffset),\n ivec2(0),\n maxCoordinate\n );\n color += texelFetch(sourceTexture, sampleCoordinate, 0);\n sampleCount += 1.0;\n }\n\n color /= sampleCount;\n } else {\n color = texelFetch(sourceTexture, fragmentCoordinate, 0);\n }\n\n return color;\n}\n"; readonly bindingLayout: readonly [{ readonly name: "depthTexture"; readonly group: 0; }]; readonly props: DofProps & DofBindings; readonly uniforms: InternalDofUniforms; readonly bindings: DofBindings; readonly uniformTypes: { readonly depthRange: "vec2"; readonly focusDistance: "f32"; readonly blurCoefficient: "f32"; readonly pixelsPerMillimeter: "f32"; readonly texelOffset: "vec2"; }; readonly propTypes: { readonly depthRange: { readonly value: readonly [0.1, 100]; }; readonly focusDistance: { readonly value: 1; readonly min: 0.0001; }; readonly blurCoefficient: { readonly value: 1; readonly min: 0; }; readonly pixelsPerMillimeter: { readonly value: 1; readonly min: 0; }; readonly texelOffset: { readonly value: readonly [1, 0]; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; /** Separable depth-of-field pipeline with horizontal and vertical blur passes. */ export declare const dofShaderPassPipeline: { readonly name: "dofShaderPassPipeline"; readonly renderTargets: { readonly blurScratch: {}; }; readonly steps: [{ readonly shaderPass: { readonly name: "dof"; readonly source: "const DEPTH_OF_FIELD_MAX_BLUR: i32 = 20;\n\nstruct dofUniforms {\n depthRange: vec2,\n focusDistance: f32,\n blurCoefficient: f32,\n pixelsPerMillimeter: f32,\n texelOffset: vec2,\n};\n\n@group(0) @binding(auto) var dof: dofUniforms;\n@group(0) @binding(auto) var depthTexture: texture_depth_2d;\n@group(0) @binding(auto) var depthTextureSampler: sampler;\n\nfn dof_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let resolution = vec2(textureDimensions(sourceTexture, 0));\n let maxCoordinate = resolution - vec2(1, 1);\n let fragmentCoordinate = min(vec2(vec2(resolution) * texCoord), maxCoordinate);\n\n let depthSample = textureSample(depthTexture, depthTextureSampler, texCoord);\n let linearDepth =\n (dof.depthRange.x * dof.depthRange.y) /\n (dof.depthRange.y -\n depthSample * (dof.depthRange.y - dof.depthRange.x));\n\n let deltaDepth = abs(dof.focusDistance - linearDepth);\n let foregroundCompensation = select(\n abs(dof.focusDistance + deltaDepth),\n abs(dof.focusDistance - deltaDepth),\n linearDepth < dof.focusDistance\n );\n let blurRadius = min(\n floor(\n dof.blurCoefficient *\n (deltaDepth / max(foregroundCompensation, 0.0001)) *\n dof.pixelsPerMillimeter\n ),\n f32(DEPTH_OF_FIELD_MAX_BLUR)\n );\n\n var color = vec4f(0.0);\n\n if (blurRadius > 1.0) {\n let halfBlur = blurRadius * 0.5;\n var sampleCount = 0.0;\n\n for (var sampleIndex: i32 = 0; sampleIndex <= DEPTH_OF_FIELD_MAX_BLUR; sampleIndex++) {\n if (f32(sampleIndex) > blurRadius) {\n break;\n }\n\n let sampleOffset = round((f32(sampleIndex) - halfBlur) * dof.texelOffset);\n let sampleCoordinate = clamp(\n fragmentCoordinate + vec2(sampleOffset),\n vec2(0, 0),\n maxCoordinate\n );\n color += textureLoad(sourceTexture, sampleCoordinate, 0);\n sampleCount += 1.0;\n }\n\n color /= sampleCount;\n } else {\n color = textureLoad(sourceTexture, fragmentCoordinate, 0);\n }\n\n return color;\n}\n"; readonly fs: "#define DEPTH_OF_FIELD_MAX_BLUR 20.0\n\nuniform sampler2D depthTexture;\n\nlayout(std140) uniform dofUniforms {\n vec2 depthRange;\n float focusDistance;\n float blurCoefficient;\n float pixelsPerMillimeter;\n vec2 texelOffset;\n} dof;\n\nvec4 dof_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) {\n ivec2 resolution = textureSize(sourceTexture, 0);\n ivec2 maxCoordinate = resolution - 1;\n ivec2 fragmentCoordinate = min(ivec2(texCoord * vec2(resolution)), maxCoordinate);\n\n float depthSample = texelFetch(depthTexture, fragmentCoordinate, 0).r;\n float ndcDepth = depthSample * 2.0 - 1.0;\n float linearDepth = -(2.0 * dof.depthRange.y * dof.depthRange.x) /\n (ndcDepth * (dof.depthRange.y - dof.depthRange.x) -\n dof.depthRange.y -\n dof.depthRange.x);\n\n float deltaDepth = abs(dof.focusDistance - linearDepth);\n float foregroundCompensation =\n linearDepth < dof.focusDistance\n ? abs(dof.focusDistance - deltaDepth)\n : abs(dof.focusDistance + deltaDepth);\n float blurRadius = min(\n floor(\n dof.blurCoefficient *\n (deltaDepth / max(foregroundCompensation, 0.0001)) *\n dof.pixelsPerMillimeter\n ),\n DEPTH_OF_FIELD_MAX_BLUR\n );\n\n vec4 color = vec4(0.0);\n\n if (blurRadius > 1.0) {\n float halfBlur = blurRadius * 0.5;\n float sampleCount = 0.0;\n\n for (float sampleIndex = 0.0; sampleIndex <= DEPTH_OF_FIELD_MAX_BLUR; sampleIndex++) {\n if (sampleIndex > blurRadius) {\n break;\n }\n\n ivec2 sampleCoordinate = clamp(\n fragmentCoordinate + ivec2((sampleIndex - halfBlur) * dof.texelOffset),\n ivec2(0),\n maxCoordinate\n );\n color += texelFetch(sourceTexture, sampleCoordinate, 0);\n sampleCount += 1.0;\n }\n\n color /= sampleCount;\n } else {\n color = texelFetch(sourceTexture, fragmentCoordinate, 0);\n }\n\n return color;\n}\n"; readonly bindingLayout: readonly [{ readonly name: "depthTexture"; readonly group: 0; }]; readonly props: DofProps & DofBindings; readonly uniforms: InternalDofUniforms; readonly bindings: DofBindings; readonly uniformTypes: { readonly depthRange: "vec2"; readonly focusDistance: "f32"; readonly blurCoefficient: "f32"; readonly pixelsPerMillimeter: "f32"; readonly texelOffset: "vec2"; }; readonly propTypes: { readonly depthRange: { readonly value: readonly [0.1, 100]; }; readonly focusDistance: { readonly value: 1; readonly min: 0.0001; }; readonly blurCoefficient: { readonly value: 1; readonly min: 0; }; readonly pixelsPerMillimeter: { readonly value: 1; readonly min: 0; }; readonly texelOffset: { readonly value: readonly [1, 0]; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "previous"; }; readonly output: "blurScratch"; readonly uniforms: { readonly texelOffset: [1, 0]; }; }, { readonly shaderPass: { readonly name: "dof"; readonly source: "const DEPTH_OF_FIELD_MAX_BLUR: i32 = 20;\n\nstruct dofUniforms {\n depthRange: vec2,\n focusDistance: f32,\n blurCoefficient: f32,\n pixelsPerMillimeter: f32,\n texelOffset: vec2,\n};\n\n@group(0) @binding(auto) var dof: dofUniforms;\n@group(0) @binding(auto) var depthTexture: texture_depth_2d;\n@group(0) @binding(auto) var depthTextureSampler: sampler;\n\nfn dof_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let resolution = vec2(textureDimensions(sourceTexture, 0));\n let maxCoordinate = resolution - vec2(1, 1);\n let fragmentCoordinate = min(vec2(vec2(resolution) * texCoord), maxCoordinate);\n\n let depthSample = textureSample(depthTexture, depthTextureSampler, texCoord);\n let linearDepth =\n (dof.depthRange.x * dof.depthRange.y) /\n (dof.depthRange.y -\n depthSample * (dof.depthRange.y - dof.depthRange.x));\n\n let deltaDepth = abs(dof.focusDistance - linearDepth);\n let foregroundCompensation = select(\n abs(dof.focusDistance + deltaDepth),\n abs(dof.focusDistance - deltaDepth),\n linearDepth < dof.focusDistance\n );\n let blurRadius = min(\n floor(\n dof.blurCoefficient *\n (deltaDepth / max(foregroundCompensation, 0.0001)) *\n dof.pixelsPerMillimeter\n ),\n f32(DEPTH_OF_FIELD_MAX_BLUR)\n );\n\n var color = vec4f(0.0);\n\n if (blurRadius > 1.0) {\n let halfBlur = blurRadius * 0.5;\n var sampleCount = 0.0;\n\n for (var sampleIndex: i32 = 0; sampleIndex <= DEPTH_OF_FIELD_MAX_BLUR; sampleIndex++) {\n if (f32(sampleIndex) > blurRadius) {\n break;\n }\n\n let sampleOffset = round((f32(sampleIndex) - halfBlur) * dof.texelOffset);\n let sampleCoordinate = clamp(\n fragmentCoordinate + vec2(sampleOffset),\n vec2(0, 0),\n maxCoordinate\n );\n color += textureLoad(sourceTexture, sampleCoordinate, 0);\n sampleCount += 1.0;\n }\n\n color /= sampleCount;\n } else {\n color = textureLoad(sourceTexture, fragmentCoordinate, 0);\n }\n\n return color;\n}\n"; readonly fs: "#define DEPTH_OF_FIELD_MAX_BLUR 20.0\n\nuniform sampler2D depthTexture;\n\nlayout(std140) uniform dofUniforms {\n vec2 depthRange;\n float focusDistance;\n float blurCoefficient;\n float pixelsPerMillimeter;\n vec2 texelOffset;\n} dof;\n\nvec4 dof_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) {\n ivec2 resolution = textureSize(sourceTexture, 0);\n ivec2 maxCoordinate = resolution - 1;\n ivec2 fragmentCoordinate = min(ivec2(texCoord * vec2(resolution)), maxCoordinate);\n\n float depthSample = texelFetch(depthTexture, fragmentCoordinate, 0).r;\n float ndcDepth = depthSample * 2.0 - 1.0;\n float linearDepth = -(2.0 * dof.depthRange.y * dof.depthRange.x) /\n (ndcDepth * (dof.depthRange.y - dof.depthRange.x) -\n dof.depthRange.y -\n dof.depthRange.x);\n\n float deltaDepth = abs(dof.focusDistance - linearDepth);\n float foregroundCompensation =\n linearDepth < dof.focusDistance\n ? abs(dof.focusDistance - deltaDepth)\n : abs(dof.focusDistance + deltaDepth);\n float blurRadius = min(\n floor(\n dof.blurCoefficient *\n (deltaDepth / max(foregroundCompensation, 0.0001)) *\n dof.pixelsPerMillimeter\n ),\n DEPTH_OF_FIELD_MAX_BLUR\n );\n\n vec4 color = vec4(0.0);\n\n if (blurRadius > 1.0) {\n float halfBlur = blurRadius * 0.5;\n float sampleCount = 0.0;\n\n for (float sampleIndex = 0.0; sampleIndex <= DEPTH_OF_FIELD_MAX_BLUR; sampleIndex++) {\n if (sampleIndex > blurRadius) {\n break;\n }\n\n ivec2 sampleCoordinate = clamp(\n fragmentCoordinate + ivec2((sampleIndex - halfBlur) * dof.texelOffset),\n ivec2(0),\n maxCoordinate\n );\n color += texelFetch(sourceTexture, sampleCoordinate, 0);\n sampleCount += 1.0;\n }\n\n color /= sampleCount;\n } else {\n color = texelFetch(sourceTexture, fragmentCoordinate, 0);\n }\n\n return color;\n}\n"; readonly bindingLayout: readonly [{ readonly name: "depthTexture"; readonly group: 0; }]; readonly props: DofProps & DofBindings; readonly uniforms: InternalDofUniforms; readonly bindings: DofBindings; readonly uniformTypes: { readonly depthRange: "vec2"; readonly focusDistance: "f32"; readonly blurCoefficient: "f32"; readonly pixelsPerMillimeter: "f32"; readonly texelOffset: "vec2"; }; readonly propTypes: { readonly depthRange: { readonly value: readonly [0.1, 100]; }; readonly focusDistance: { readonly value: 1; readonly min: 0.0001; }; readonly blurCoefficient: { readonly value: 1; readonly min: 0; }; readonly pixelsPerMillimeter: { readonly value: 1; readonly min: 0; }; readonly texelOffset: { readonly value: readonly [1, 0]; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "blurScratch"; }; readonly output: "previous"; readonly uniforms: { readonly texelOffset: [0, 1]; }; }]; }; export {}; //# sourceMappingURL=dof.d.ts.map