import type { Texture } from '@luma.gl/core'; import type { ShaderPassPipeline } from '@luma.gl/shadertools'; import { Matrix4 } from '@math.gl/core'; /** Construction options for the horizon-based GTAO pipeline. */ export type GTAOShaderPassPipelineOptions = { /** Fractional AO evaluation, history, and denoising resolution. Defaults to full resolution. */ resolutionScale?: number; /** Apply visibility to the full image or only to a separately supplied ambient-light texture. */ composition?: 'color' | 'ambient-only'; }; type GTAOEvaluateUniforms = { projectionMatrix: Matrix4; inverseProjectionMatrix: Matrix4; radius: number; bias: number; intensity: number; frameIndex: number; }; type GTAOTemporalUniforms = { inverseProjectionMatrix: Matrix4; historyWeight: number; depthThreshold: number; }; type GTAOCompositeUniforms = { strength: number; debugMode: number; }; type GTAOAmbientCompositeBindings = { ambientLightingTexture?: Texture; }; type GTAOBindings = { depthTexture?: Texture; normalTexture?: Texture; }; type GTAOTemporalBindings = { depthTexture?: Texture; velocityTexture?: Texture; historyTexture?: Texture; previousDepthTexture?: Texture; }; /** Configurable-resolution horizon search over G-buffer depth and view normals. */ export declare const gtaoEvaluate: { readonly name: "gtaoEvaluate"; readonly source: "const GTAO_PI: f32 = 3.141592653589793;\nconst GTAO_SLICE_COUNT: i32 = 4;\nconst GTAO_STEPS_PER_SIDE: i32 = 6;\n\nstruct GTAOEvaluateUniforms {\n projectionMatrix: mat4x4f,\n inverseProjectionMatrix: mat4x4f,\n radius: f32,\n bias: f32,\n intensity: f32,\n frameIndex: f32,\n};\n\n@group(0) @binding(auto) var gtaoEvaluate: GTAOEvaluateUniforms;\n@group(0) @binding(auto) var depthTexture: texture_depth_2d;\n@group(0) @binding(auto) var depthTextureSampler: sampler;\n@group(0) @binding(auto) var normalTexture: texture_2d;\n@group(0) @binding(auto) var normalTextureSampler: sampler;\n\nfn gtaoEvaluate_reconstructViewPosition(uv: vec2f, depth: f32) -> vec3f {\n let clip = vec4f(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0, depth, 1.0);\n let viewPosition = gtaoEvaluate.inverseProjectionMatrix * clip;\n return viewPosition.xyz / max(viewPosition.w, 0.00001);\n}\n\nfn gtaoEvaluate_hash(value: vec2f) -> f32 {\n return fract(sin(dot(value, vec2f(12.9898, 78.233))) * 43758.5453);\n}\n\nfn gtaoEvaluate_sampleHorizon(\n centerPosition: vec3f,\n viewDirection: vec3f,\n sliceDirection: vec3f,\n sceneCoord: vec2f,\n direction: vec2f,\n side: f32,\n radiusPixels: f32,\n depthDimensions: vec2f,\n radialJitter: f32\n) -> f32 {\n let hemisphereEdge = side * GTAO_PI * 0.5;\n var horizon = hemisphereEdge;\n for (var stepIndex: i32 = 1; stepIndex <= GTAO_STEPS_PER_SIDE; stepIndex++) {\n let fraction = f32(stepIndex) / f32(GTAO_STEPS_PER_SIDE);\n let jitteredFraction =\n (f32(stepIndex) - 1.0 + radialJitter) / f32(GTAO_STEPS_PER_SIDE);\n let sampleOffset = direction * side * radiusPixels * jitteredFraction / depthDimensions;\n let sampleCoord = sceneCoord + sampleOffset;\n if (any(sampleCoord < vec2f(0.0)) || any(sampleCoord > vec2f(1.0))) {\n continue;\n }\n let sampleDepth = textureSampleLevel(depthTexture, depthTextureSampler, sampleCoord, 0);\n if (sampleDepth >= 0.99999) {\n continue;\n }\n let samplePosition = gtaoEvaluate_reconstructViewPosition(sampleCoord, sampleDepth);\n let delta = samplePosition - centerPosition;\n let distanceToSample = length(delta);\n if (distanceToSample <= 0.0001 || distanceToSample >= gtaoEvaluate.radius) {\n continue;\n }\n let sampleDirection = delta / distanceToSample;\n let sliceProjection = dot(sampleDirection, sliceDirection);\n if (sliceProjection * side <= 0.0) {\n continue;\n }\n let sampleAngle = atan2(sliceProjection, dot(sampleDirection, viewDirection));\n let biasedAngle = sampleAngle + side * gtaoEvaluate.bias;\n let boundedAngle = select(\n clamp(biasedAngle, -GTAO_PI * 0.5, 0.0),\n clamp(biasedAngle, 0.0, GTAO_PI * 0.5),\n side > 0.0\n );\n let distanceFalloff = 1.0 - smoothstep(gtaoEvaluate.radius * 0.35, gtaoEvaluate.radius, distanceToSample);\n let stepFalloff = 1.0 - fraction * 0.15;\n let weightedAngle = mix(hemisphereEdge, boundedAngle, distanceFalloff * stepFalloff);\n horizon = select(max(horizon, weightedAngle), min(horizon, weightedAngle), side > 0.0);\n }\n return horizon;\n}\n\nfn gtaoEvaluate_integrateSlice(\n negativeHorizon: f32,\n positiveHorizon: f32,\n normalAngle: f32\n) -> f32 {\n let lowerHemisphere = normalAngle - GTAO_PI * 0.5;\n let upperHemisphere = normalAngle + GTAO_PI * 0.5;\n let visibleLower = clamp(negativeHorizon, lowerHemisphere, upperHemisphere);\n let visibleUpper = clamp(positiveHorizon, lowerHemisphere, upperHemisphere);\n let unoccludedLower = clamp(-GTAO_PI * 0.5, lowerHemisphere, upperHemisphere);\n let unoccludedUpper = clamp(GTAO_PI * 0.5, lowerHemisphere, upperHemisphere);\n let visibilityIntegral = max(\n sin(visibleUpper - normalAngle) - sin(visibleLower - normalAngle),\n 0.0\n );\n let hemisphereIntegral = max(\n sin(unoccludedUpper - normalAngle) - sin(unoccludedLower - normalAngle),\n 0.0001\n );\n return clamp(visibilityIntegral / hemisphereIntegral, 0.0, 1.0);\n}\n\nfn gtaoEvaluate_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let sceneCoord = texCoord;\n let depth = textureSampleLevel(depthTexture, depthTextureSampler, sceneCoord, 0);\n if (depth >= 0.99999) {\n return vec4f(1.0);\n }\n\n let centerPosition = gtaoEvaluate_reconstructViewPosition(sceneCoord, depth);\n let normalSample = textureSampleLevel(normalTexture, normalTextureSampler, sceneCoord, 0);\n let normal = normalize(normalSample.xyz * 2.0 - 1.0);\n let depthDimensions = vec2f(textureDimensions(depthTexture));\n let focalLength = abs(gtaoEvaluate.projectionMatrix[1][1]);\n let projectedRadius = gtaoEvaluate.radius * focalLength /\n max(-centerPosition.z, 0.0001) * depthDimensions.y * 0.5;\n let radiusPixels = clamp(projectedRadius, 2.0, 72.0);\n let pixelCoordinate = sceneCoord * depthDimensions;\n let frameOffset = vec2f(gtaoEvaluate.frameIndex * 0.754877666, gtaoEvaluate.frameIndex * 0.569840291);\n let rotation = gtaoEvaluate_hash(floor(pixelCoordinate) + frameOffset) * GTAO_PI;\n let radialJitter = 0.25 + gtaoEvaluate_hash(floor(pixelCoordinate) + frameOffset.yx + 17.0) * 0.75;\n let viewDirection = normalize(-centerPosition);\n\n var accumulatedVisibility = 0.0;\n var accumulatedWeight = 0.0;\n for (var sliceIndex: i32 = 0; sliceIndex < GTAO_SLICE_COUNT; sliceIndex++) {\n let angle = rotation + f32(sliceIndex) * GTAO_PI / f32(GTAO_SLICE_COUNT);\n let direction = vec2f(cos(angle), sin(angle));\n let sliceSampleCoord = clamp(sceneCoord + direction / depthDimensions, vec2f(0.0), vec2f(1.0));\n let slicePosition = gtaoEvaluate_reconstructViewPosition(sliceSampleCoord, depth);\n let sliceDelta = slicePosition - centerPosition;\n if (length(sliceDelta) <= 0.00001) {\n continue;\n }\n let slicePlaneNormal = normalize(cross(sliceDelta, viewDirection));\n let sliceDirection = normalize(cross(viewDirection, slicePlaneNormal));\n let projectedNormal = normal - slicePlaneNormal * dot(normal, slicePlaneNormal);\n let projectedNormalLength = length(projectedNormal);\n if (projectedNormalLength <= 0.00001) {\n continue;\n }\n let normalizedProjectedNormal = projectedNormal / projectedNormalLength;\n let normalAngle = atan2(\n dot(normalizedProjectedNormal, sliceDirection),\n dot(normalizedProjectedNormal, viewDirection)\n );\n let positiveHorizon = gtaoEvaluate_sampleHorizon(\n centerPosition,\n viewDirection,\n sliceDirection,\n sceneCoord,\n direction,\n 1.0,\n radiusPixels,\n depthDimensions,\n radialJitter\n );\n let negativeHorizon = gtaoEvaluate_sampleHorizon(\n centerPosition,\n viewDirection,\n sliceDirection,\n sceneCoord,\n direction,\n -1.0,\n radiusPixels,\n depthDimensions,\n radialJitter\n );\n let sliceVisibility = gtaoEvaluate_integrateSlice(\n negativeHorizon,\n positiveHorizon,\n normalAngle\n );\n accumulatedVisibility += sliceVisibility * projectedNormalLength;\n accumulatedWeight += projectedNormalLength;\n }\n\n let integratedVisibility = accumulatedVisibility / max(accumulatedWeight, 0.0001);\n let visibility = clamp(\n 1.0 - (1.0 - integratedVisibility) * gtaoEvaluate.intensity,\n 0.0,\n 1.0\n );\n return vec4f(vec3f(visibility), 1.0);\n}"; readonly bindingLayout: readonly [{ readonly name: "depthTexture"; readonly group: 0; }, { readonly name: "normalTexture"; readonly group: 0; }]; readonly props: Partial & GTAOBindings; readonly uniforms: GTAOEvaluateUniforms; readonly bindings: GTAOBindings; readonly uniformTypes: { readonly projectionMatrix: "mat4x4"; readonly inverseProjectionMatrix: "mat4x4"; readonly radius: "f32"; readonly bias: "f32"; readonly intensity: "f32"; readonly frameIndex: "f32"; }; readonly propTypes: { readonly projectionMatrix: { readonly value: Matrix4; readonly private: true; }; readonly inverseProjectionMatrix: { readonly value: Matrix4; readonly private: true; }; readonly radius: { readonly value: 2.2; readonly min: 0.1; readonly softMax: 8; }; readonly bias: { readonly value: 0.04; readonly min: 0; readonly softMax: 0.25; }; readonly intensity: { readonly value: 3.2; readonly min: 0; readonly softMax: 8; }; readonly frameIndex: { readonly value: 0; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; /** Reprojects the previous AO result with G-buffer velocity and rejects disocclusions by depth. */ export declare const gtaoTemporal: { readonly name: "gtaoTemporal"; readonly source: "struct GTAOTemporalUniforms {\n inverseProjectionMatrix: mat4x4f,\n historyWeight: f32,\n depthThreshold: f32,\n};\n\n@group(0) @binding(auto) var gtaoTemporal: GTAOTemporalUniforms;\n@group(0) @binding(auto) var historyTexture: texture_2d;\n@group(0) @binding(auto) var historyTextureSampler: sampler;\n@group(0) @binding(auto) var velocityTexture: texture_2d;\n@group(0) @binding(auto) var velocityTextureSampler: sampler;\n@group(0) @binding(auto) var depthTexture: texture_depth_2d;\n@group(0) @binding(auto) var depthTextureSampler: sampler;\n@group(0) @binding(auto) var previousDepthTexture: texture_2d;\n@group(0) @binding(auto) var previousDepthTextureSampler: sampler;\n\nfn gtaoTemporal_reconstructViewDepth(texCoord: vec2f, depth: f32) -> f32 {\n let clip = vec4f(texCoord.x * 2.0 - 1.0, 1.0 - texCoord.y * 2.0, depth, 1.0);\n let viewPosition = gtaoTemporal.inverseProjectionMatrix * clip;\n return abs(viewPosition.z / max(abs(viewPosition.w), 0.00001));\n}\n\nfn gtaoTemporal_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let current = textureSample(sourceTexture, sourceTextureSampler, texCoord);\n let velocity = textureSample(velocityTexture, velocityTextureSampler, texCoord).xy;\n let previousCoord = texCoord - velocity;\n let validCoord = all(previousCoord >= vec2f(0.0)) && all(previousCoord <= vec2f(1.0));\n let clampedPreviousCoord = clamp(previousCoord, vec2f(0.0), vec2f(1.0));\n let currentDepth = textureSample(depthTexture, depthTextureSampler, texCoord);\n let previousDepth = textureSample(\n previousDepthTexture,\n previousDepthTextureSampler,\n clampedPreviousCoord\n ).r;\n let currentViewDepth = gtaoTemporal_reconstructViewDepth(texCoord, currentDepth);\n let previousViewDepth = gtaoTemporal_reconstructViewDepth(\n clampedPreviousCoord,\n previousDepth\n );\n let relativeDepthDifference = abs(previousViewDepth - currentViewDepth) /\n max(currentViewDepth, 0.0001);\n let validDepth = relativeDepthDifference < gtaoTemporal.depthThreshold;\n\n let texel = 1.0 / vec2f(textureDimensions(sourceTexture));\n var minimumVisibility = current.r;\n var maximumVisibility = current.r;\n for (var y: i32 = -1; y <= 1; y++) {\n for (var x: i32 = -1; x <= 1; x++) {\n let sampleVisibility = textureSample(\n sourceTexture,\n sourceTextureSampler,\n texCoord + vec2f(f32(x), f32(y)) * texel\n ).r;\n minimumVisibility = min(minimumVisibility, sampleVisibility);\n maximumVisibility = max(maximumVisibility, sampleVisibility);\n }\n }\n let historyVisibility = clamp(\n textureSample(historyTexture, historyTextureSampler, clampedPreviousCoord).r,\n minimumVisibility,\n maximumVisibility\n );\n let historyWeight = select(0.0, gtaoTemporal.historyWeight, validCoord && validDepth);\n let visibility = mix(current.r, historyVisibility, historyWeight);\n return vec4f(vec3f(visibility), 1.0);\n}"; readonly bindingLayout: readonly [{ readonly name: "historyTexture"; readonly group: 0; }, { readonly name: "velocityTexture"; readonly group: 0; }, { readonly name: "depthTexture"; readonly group: 0; }, { readonly name: "previousDepthTexture"; readonly group: 0; }]; readonly props: Partial & GTAOTemporalBindings; readonly uniforms: GTAOTemporalUniforms; readonly bindings: GTAOTemporalBindings; readonly uniformTypes: { readonly inverseProjectionMatrix: "mat4x4"; readonly historyWeight: "f32"; readonly depthThreshold: "f32"; }; readonly propTypes: { readonly inverseProjectionMatrix: { readonly value: Matrix4; readonly private: true; }; readonly historyWeight: { readonly value: 0.88; readonly min: 0; readonly max: 0.97; }; readonly depthThreshold: { readonly value: 0.015; readonly min: 0.0001; readonly softMax: 0.1; }; }; readonly passes: [{ readonly sampler: true; }]; }; /** Stores the current hardware depth for next-frame temporal disocclusion rejection. */ export declare const gtaoDepthHistoryCopy: { readonly name: "gtaoDepthHistoryCopy"; readonly source: "@group(0) @binding(auto) var depthTexture: texture_depth_2d;\n@group(0) @binding(auto) var depthTextureSampler: sampler;\n\nfn gtaoDepthHistoryCopy_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let depth = textureSample(depthTexture, depthTextureSampler, texCoord);\n return vec4f(depth, 0.0, 0.0, 1.0);\n}"; readonly bindingLayout: readonly [{ readonly name: "depthTexture"; readonly group: 0; }]; readonly passes: [{ readonly sampler: true; }]; }; /** Multiplies the lit color by denoised ambient visibility, or exposes it as a debug view. */ export declare const gtaoComposite: { readonly name: "gtaoComposite"; readonly source: "struct GTAOCompositeUniforms {\n strength: f32,\n debugMode: f32,\n};\n\n@group(0) @binding(auto) var gtaoComposite: GTAOCompositeUniforms;\n@group(0) @binding(auto) var ambientOcclusionTexture: texture_2d;\n@group(0) @binding(auto) var ambientOcclusionTextureSampler: sampler;\n\nfn gtaoComposite_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let color = textureSample(sourceTexture, sourceTextureSampler, texCoord);\n let visibility = textureSample(\n ambientOcclusionTexture,\n ambientOcclusionTextureSampler,\n texCoord\n ).r;\n if (gtaoComposite.debugMode > 0.5) {\n return vec4f(vec3f(visibility), 1.0);\n }\n let ambientVisibility = mix(1.0, visibility, clamp(gtaoComposite.strength, 0.0, 1.0));\n return vec4f(color.rgb * ambientVisibility, color.a);\n}"; readonly bindingLayout: readonly [{ readonly name: "ambientOcclusionTexture"; readonly group: 0; }]; readonly props: Partial; readonly uniforms: GTAOCompositeUniforms; readonly uniformTypes: { readonly strength: "f32"; readonly debugMode: "f32"; }; readonly propTypes: { readonly strength: { readonly value: 0.68; readonly min: 0; readonly max: 1; }; readonly debugMode: { readonly value: 0; readonly min: 0; readonly max: 1; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; /** Applies ambient visibility without darkening direct lighting or emissive scene color. */ export declare const gtaoAmbientComposite: { readonly name: "gtaoAmbientComposite"; readonly source: "struct GTAOAmbientCompositeUniforms {\n strength: f32,\n debugMode: f32,\n};\n\n@group(0) @binding(auto) var gtaoAmbientComposite: GTAOAmbientCompositeUniforms;\n@group(0) @binding(auto) var ambientOcclusionTexture: texture_2d;\n@group(0) @binding(auto) var ambientOcclusionTextureSampler: sampler;\n@group(0) @binding(auto) var ambientLightingTexture: texture_2d;\n@group(0) @binding(auto) var ambientLightingTextureSampler: sampler;\n\nfn gtaoAmbientComposite_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let color = textureSample(sourceTexture, sourceTextureSampler, texCoord);\n let visibility = textureSample(\n ambientOcclusionTexture,\n ambientOcclusionTextureSampler,\n texCoord\n ).r;\n if (gtaoAmbientComposite.debugMode > 0.5) {\n return vec4f(vec3f(visibility), 1.0);\n }\n let ambientLighting = textureSample(\n ambientLightingTexture,\n ambientLightingTextureSampler,\n texCoord\n ).rgb;\n let ambientVisibility = mix(\n 1.0,\n visibility,\n clamp(gtaoAmbientComposite.strength, 0.0, 1.0)\n );\n return vec4f(color.rgb + ambientLighting * (ambientVisibility - 1.0), color.a);\n}"; readonly bindingLayout: readonly [{ readonly name: "ambientOcclusionTexture"; readonly group: 0; }, { readonly name: "ambientLightingTexture"; readonly group: 0; }]; readonly props: Partial & GTAOAmbientCompositeBindings; readonly uniforms: GTAOCompositeUniforms; readonly bindings: GTAOAmbientCompositeBindings; readonly uniformTypes: { readonly strength: "f32"; readonly debugMode: "f32"; }; readonly propTypes: { readonly strength: { readonly value: 0.68; readonly min: 0; readonly max: 1; }; readonly debugMode: { readonly value: 0; readonly min: 0; readonly max: 1; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; /** Creates a temporally stabilized horizon-based ambient-occlusion pipeline. */ export declare function createGTAOShaderPassPipeline(options?: GTAOShaderPassPipelineOptions): ShaderPassPipeline<'gtaoRaw' | 'gtaoHistory' | 'gtaoHistoryDepth' | 'gtaoScratch' | 'gtaoBlurred'>; export {}; //# sourceMappingURL=gtao.d.ts.map