import type { Texture } from '@luma.gl/core'; import type { ShaderPassPipeline } from '@luma.gl/shadertools'; import type { NumberArray16 } from '@math.gl/core'; /** Construction options for temporally stabilized diffuse screen-space global illumination. */ export type SSGIShaderPassPipelineOptions = { /** Fractional tracing, history, and denoising resolution. Defaults to full resolution. */ resolutionScale?: number; }; type SSGITraceUniforms = { projectionMatrix: Readonly; inverseProjectionMatrix: Readonly; radius: number; thickness: number; intensity: number; rayCount: number; stepCount: number; frameIndex: number; }; type SSGITemporalUniforms = { inverseProjectionMatrix: Readonly; historyWeight: number; depthThreshold: number; }; type SSGISpatialUniforms = { direction: [number, number]; radius: number; depthSigma: number; }; type SSGICompositeUniforms = { strength: number; debugMode: number; }; type SSGITraceBindings = { depthTexture?: Texture; normalTexture?: Texture; }; type SSGITemporalBindings = { depthTexture?: Texture; velocityTexture?: Texture; historyTexture?: Texture; previousDepthTexture?: Texture; }; type SSGISpatialBindings = { depthTexture?: Texture; normalTexture?: Texture; }; /** Traces cosine-weighted hemisphere rays through lit scene color and G-buffer depth. */ export declare const ssgiTrace: { readonly name: "ssgiTrace"; readonly source: "const SSGI_TWO_PI: f32 = 6.283185307179586;\nconst SSGI_GOLDEN_ANGLE: f32 = 2.399963229728653;\nconst SSGI_MAX_RAYS: i32 = 12;\nconst SSGI_MAX_STEPS: i32 = 12;\n\nstruct SSGITraceUniforms {\n projectionMatrix: mat4x4f,\n inverseProjectionMatrix: mat4x4f,\n radius: f32,\n thickness: f32,\n intensity: f32,\n rayCount: f32,\n stepCount: f32,\n frameIndex: f32,\n};\n\n@group(0) @binding(auto) var ssgiTrace: SSGITraceUniforms;\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 ssgiTrace_reconstructViewPosition(texCoord: vec2f, depth: f32) -> vec3f {\n let clip = vec4f(texCoord.x * 2.0 - 1.0, 1.0 - texCoord.y * 2.0, depth, 1.0);\n let viewPosition = ssgiTrace.inverseProjectionMatrix * clip;\n return viewPosition.xyz / max(viewPosition.w, 0.00001);\n}\n\nfn ssgiTrace_projectViewPosition(viewPosition: vec3f) -> vec2f {\n let clip = ssgiTrace.projectionMatrix * vec4f(viewPosition, 1.0);\n let normalizedDeviceCoordinate = clip.xy / max(clip.w, 0.00001);\n return normalizedDeviceCoordinate * vec2f(0.5, -0.5) + vec2f(0.5);\n}\n\nfn ssgiTrace_hash(value: vec2f) -> f32 {\n return fract(sin(dot(value, vec2f(12.9898, 78.233))) * 43758.5453);\n}\n\nfn ssgiTrace_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let centerDepth = textureSampleLevel(depthTexture, depthTextureSampler, texCoord, 0);\n if (centerDepth >= 0.99999 || ssgiTrace.intensity <= 0.0001) {\n return vec4f(0.0);\n }\n\n let centerPosition = ssgiTrace_reconstructViewPosition(texCoord, centerDepth);\n let centerNormalSample = textureSampleLevel(normalTexture, normalTextureSampler, texCoord, 0);\n let centerNormal = normalize(centerNormalSample.rgb * 2.0 - 1.0);\n let roughness = clamp(centerNormalSample.a, 0.0, 1.0);\n let referenceAxis = select(\n vec3f(0.0, 1.0, 0.0),\n vec3f(1.0, 0.0, 0.0),\n abs(centerNormal.y) > 0.9\n );\n let tangent = normalize(cross(referenceAxis, centerNormal));\n let bitangent = normalize(cross(centerNormal, tangent));\n let pixelCoordinate = floor(texCoord * vec2f(textureDimensions(depthTexture)));\n let rotation = ssgiTrace_hash(pixelCoordinate) * SSGI_TWO_PI;\n let activeRayCount = clamp(i32(ssgiTrace.rayCount), 1, SSGI_MAX_RAYS);\n let activeStepCount = clamp(i32(ssgiTrace.stepCount), 2, SSGI_MAX_STEPS);\n\n var indirectRadiance = vec3f(0.0);\n var accumulatedWeight = 0.0;\n var hitCount = 0.0;\n for (var rayIndex: i32 = 0; rayIndex < SSGI_MAX_RAYS; rayIndex++) {\n if (rayIndex >= activeRayCount) {\n break;\n }\n\n let distribution = (f32(rayIndex) + 0.5) / f32(activeRayCount);\n let cosine = sqrt(1.0 - distribution * 0.82);\n let sine = sqrt(max(1.0 - cosine * cosine, 0.0));\n let angle = rotation + f32(rayIndex) * SSGI_GOLDEN_ANGLE;\n let rayDirection = normalize(\n centerNormal * cosine +\n (tangent * cos(angle) + bitangent * sin(angle)) * sine\n );\n let rayOrigin = centerPosition + centerNormal * max(ssgiTrace.thickness * 0.2, 0.025);\n var previousDepthDelta = -ssgiTrace.thickness;\n\n for (var stepIndex: i32 = 1; stepIndex <= SSGI_MAX_STEPS; stepIndex++) {\n if (stepIndex > activeStepCount) {\n break;\n }\n\n let stepFraction = f32(stepIndex) / f32(activeStepCount);\n let travel = max(ssgiTrace.radius * pow(stepFraction, 1.35), 0.04);\n let rayPosition = rayOrigin + rayDirection * travel;\n if (rayPosition.z >= -0.04) {\n break;\n }\n\n let sampleCoord = ssgiTrace_projectViewPosition(rayPosition);\n if (any(sampleCoord <= vec2f(0.0)) || any(sampleCoord >= vec2f(1.0))) {\n break;\n }\n\n let sampleDepth = textureSampleLevel(depthTexture, depthTextureSampler, sampleCoord, 0);\n if (sampleDepth >= 0.99999) {\n previousDepthDelta = -ssgiTrace.thickness;\n continue;\n }\n\n let samplePosition = ssgiTrace_reconstructViewPosition(sampleCoord, sampleDepth);\n let depthDelta = (-rayPosition.z) - (-samplePosition.z);\n let stepDistance = ssgiTrace.radius / f32(activeStepCount);\n let hitThickness = max(ssgiTrace.thickness, stepDistance * 1.25);\n let screenDistance = length((sampleCoord - texCoord) * texSize);\n if (previousDepthDelta <= 0.0 && depthDelta >= 0.0 &&\n depthDelta <= hitThickness && screenDistance > 1.5) {\n let sampleNormal = normalize(\n textureSampleLevel(normalTexture, normalTextureSampler, sampleCoord, 0).rgb * 2.0 - 1.0\n );\n let emitterFacing = max(dot(sampleNormal, -rayDirection), 0.0);\n let receiverFacing = max(dot(centerNormal, rayDirection), 0.0);\n let distanceFalloff = 1.0 - smoothstep(\n ssgiTrace.radius * 0.28,\n ssgiTrace.radius,\n travel\n );\n let edgeDistance = min(\n min(sampleCoord.x, sampleCoord.y),\n min(1.0 - sampleCoord.x, 1.0 - sampleCoord.y)\n );\n let edgeWeight = smoothstep(0.0, 0.075, edgeDistance);\n let sampleWeight = receiverFacing * (0.2 + emitterFacing * 0.8) *\n distanceFalloff * edgeWeight;\n let sourceRadiance = textureSampleLevel(\n sourceTexture,\n sourceTextureSampler,\n sampleCoord,\n 0\n ).rgb;\n indirectRadiance += sourceRadiance * sampleWeight;\n accumulatedWeight += sampleWeight;\n hitCount += select(0.0, 1.0, sampleWeight > 0.0001);\n break;\n }\n previousDepthDelta = depthDelta;\n }\n }\n\n let diffuseResponse = mix(0.18, 1.0, roughness);\n let radiance = indirectRadiance /\n max(f32(activeRayCount), 1.0) * ssgiTrace.intensity * diffuseResponse;\n let confidence = clamp(hitCount / max(f32(activeRayCount), 1.0), 0.0, 1.0);\n return vec4f(radiance, confidence);\n}"; readonly bindingLayout: readonly [{ readonly name: "depthTexture"; readonly group: 0; }, { readonly name: "normalTexture"; readonly group: 0; }]; readonly props: Partial & SSGITraceBindings; readonly uniforms: SSGITraceUniforms; readonly bindings: SSGITraceBindings; readonly uniformTypes: { readonly projectionMatrix: "mat4x4"; readonly inverseProjectionMatrix: "mat4x4"; readonly radius: "f32"; readonly thickness: "f32"; readonly intensity: "f32"; readonly rayCount: "f32"; readonly stepCount: "f32"; readonly frameIndex: "f32"; }; readonly propTypes: { readonly projectionMatrix: { readonly value: NumberArray16; readonly private: true; }; readonly inverseProjectionMatrix: { readonly value: NumberArray16; readonly private: true; }; readonly radius: { readonly value: 4.5; readonly min: 0.2; readonly softMax: 12; }; readonly thickness: { readonly value: 0.32; readonly min: 0.02; readonly softMax: 2; }; readonly intensity: { readonly value: 2.2; readonly min: 0; readonly softMax: 6; }; readonly rayCount: { readonly value: 7; readonly min: 1; readonly max: 12; }; readonly stepCount: { readonly value: 8; readonly min: 2; readonly max: 12; }; readonly frameIndex: { readonly value: 0; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; /** Reprojects diffuse bounce history with velocity and relative linear-depth rejection. */ export declare const ssgiTemporal: { readonly name: "ssgiTemporal"; readonly source: "struct SSGITemporalUniforms {\n inverseProjectionMatrix: mat4x4f,\n historyWeight: f32,\n depthThreshold: f32,\n};\n\n@group(0) @binding(auto) var ssgiTemporal: SSGITemporalUniforms;\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 ssgiTemporal_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 = ssgiTemporal.inverseProjectionMatrix * clip;\n return abs(viewPosition.z / max(abs(viewPosition.w), 0.00001));\n}\n\nfn ssgiTemporal_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let current = textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0);\n let currentDepth = textureSampleLevel(depthTexture, depthTextureSampler, texCoord, 0);\n if (currentDepth >= 0.99999) {\n return vec4f(0.0);\n }\n\n let velocity = textureSampleLevel(velocityTexture, velocityTextureSampler, texCoord, 0).xy;\n let previousCoord = texCoord - velocity;\n let validCoordinate = all(previousCoord >= vec2f(0.0)) &&\n all(previousCoord <= vec2f(1.0));\n let clampedPreviousCoord = clamp(previousCoord, vec2f(0.0), vec2f(1.0));\n let previousDepth = textureSampleLevel(\n previousDepthTexture,\n previousDepthTextureSampler,\n clampedPreviousCoord,\n 0\n ).r;\n let currentViewDepth = ssgiTemporal_reconstructViewDepth(texCoord, currentDepth);\n let previousViewDepth = ssgiTemporal_reconstructViewDepth(clampedPreviousCoord, previousDepth);\n let relativeDepthDifference = abs(previousViewDepth - currentViewDepth) /\n max(currentViewDepth, 0.0001);\n let validDepth = relativeDepthDifference < ssgiTemporal.depthThreshold;\n\n let texel = 1.0 / vec2f(textureDimensions(sourceTexture));\n var minimumRadiance = current;\n var maximumRadiance = current;\n for (var sampleY: i32 = -1; sampleY <= 1; sampleY++) {\n for (var sampleX: i32 = -1; sampleX <= 1; sampleX++) {\n let sampleCoord = clamp(\n texCoord + vec2f(f32(sampleX), f32(sampleY)) * texel,\n vec2f(0.0),\n vec2f(1.0)\n );\n let neighborhoodRadiance = textureSampleLevel(\n sourceTexture,\n sourceTextureSampler,\n sampleCoord,\n 0\n );\n minimumRadiance = min(minimumRadiance, neighborhoodRadiance);\n maximumRadiance = max(maximumRadiance, neighborhoodRadiance);\n }\n }\n\n let historyRadiance = clamp(\n textureSampleLevel(historyTexture, historyTextureSampler, clampedPreviousCoord, 0),\n minimumRadiance,\n maximumRadiance\n );\n let historyWeight = select(\n 0.0,\n ssgiTemporal.historyWeight,\n validCoordinate && validDepth\n );\n return mix(current, historyRadiance, historyWeight);\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 & SSGITemporalBindings; readonly uniforms: SSGITemporalUniforms; readonly bindings: SSGITemporalBindings; readonly uniformTypes: { readonly inverseProjectionMatrix: "mat4x4"; readonly historyWeight: "f32"; readonly depthThreshold: "f32"; }; readonly propTypes: { readonly inverseProjectionMatrix: { readonly value: NumberArray16; readonly private: true; }; readonly historyWeight: { readonly value: 0.89; readonly min: 0; readonly max: 0.97; }; readonly depthThreshold: { readonly value: 0.022; readonly min: 0.0001; readonly softMax: 0.1; }; }; readonly passes: [{ readonly sampler: true; }]; }; /** Stores scene depth for diffuse-bounce temporal disocclusion rejection. */ export declare const ssgiDepthHistoryCopy: { readonly name: "ssgiDepthHistoryCopy"; readonly source: "@group(0) @binding(auto) var depthTexture: texture_depth_2d;\n@group(0) @binding(auto) var depthTextureSampler: sampler;\n\nfn ssgiDepthHistoryCopy_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let depth = textureSampleLevel(depthTexture, depthTextureSampler, texCoord, 0);\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; }]; }; /** Applies depth/normal-aware separable diffuse-irradiance denoising. */ export declare const ssgiSpatial: { readonly name: "ssgiSpatial"; readonly source: "struct SSGISpatialUniforms {\n direction: vec2f,\n radius: f32,\n depthSigma: f32,\n};\n\n@group(0) @binding(auto) var ssgiSpatial: SSGISpatialUniforms;\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 ssgiSpatial_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let centerRadiance = textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0);\n let centerDepth = textureSampleLevel(depthTexture, depthTextureSampler, texCoord, 0);\n if (centerDepth >= 0.99999) {\n return vec4f(0.0);\n }\n\n let centerNormal = normalize(\n textureSampleLevel(normalTexture, normalTextureSampler, texCoord, 0).rgb * 2.0 - 1.0\n );\n let texel = ssgiSpatial.direction / vec2f(textureDimensions(sourceTexture));\n var radiance = centerRadiance;\n var accumulatedWeight = 1.0;\n for (var sampleIndex: i32 = 1; sampleIndex <= 5; sampleIndex++) {\n if (f32(sampleIndex) > ssgiSpatial.radius) {\n break;\n }\n for (var side: i32 = -1; side <= 1; side += 2) {\n let sampleCoord = clamp(\n texCoord + texel * f32(sampleIndex * side),\n vec2f(0.0),\n vec2f(1.0)\n );\n let sampleDepth = textureSampleLevel(depthTexture, depthTextureSampler, sampleCoord, 0);\n let sampleNormal = normalize(\n textureSampleLevel(normalTexture, normalTextureSampler, sampleCoord, 0).rgb * 2.0 - 1.0\n );\n let depthDelta = abs(sampleDepth - centerDepth);\n let depthWeight = exp(\n -(depthDelta * depthDelta) /\n max(2.0 * ssgiSpatial.depthSigma * ssgiSpatial.depthSigma, 0.000001)\n );\n let normalWeight = pow(max(dot(centerNormal, sampleNormal), 0.0), 12.0);\n let distanceWeight = exp(\n -f32(sampleIndex * sampleIndex) /\n max(2.0 * ssgiSpatial.radius * ssgiSpatial.radius, 0.1)\n );\n let weight = depthWeight * normalWeight * distanceWeight;\n radiance += textureSampleLevel(sourceTexture, sourceTextureSampler, sampleCoord, 0) * weight;\n accumulatedWeight += weight;\n }\n }\n\n return radiance / max(accumulatedWeight, 0.0001);\n}"; readonly bindingLayout: readonly [{ readonly name: "depthTexture"; readonly group: 0; }, { readonly name: "normalTexture"; readonly group: 0; }]; readonly props: Partial & SSGISpatialBindings; readonly uniforms: SSGISpatialUniforms; readonly bindings: SSGISpatialBindings; readonly uniformTypes: { readonly direction: "vec2"; readonly radius: "f32"; readonly depthSigma: "f32"; }; readonly propTypes: { readonly direction: { readonly value: readonly [1, 0]; }; readonly radius: { readonly value: 3; readonly min: 0; readonly max: 5; }; readonly depthSigma: { readonly value: 0.012; readonly min: 0.0001; readonly softMax: 0.1; }; }; readonly passes: [{ readonly sampler: true; }]; }; /** Adds diffuse bounced radiance or exposes indirect-lighting/confidence debug views. */ export declare const ssgiComposite: { readonly name: "ssgiComposite"; readonly source: "struct SSGICompositeUniforms {\n strength: f32,\n debugMode: f32,\n};\n\n@group(0) @binding(auto) var ssgiComposite: SSGICompositeUniforms;\n@group(0) @binding(auto) var indirectLightingTexture: texture_2d;\n@group(0) @binding(auto) var indirectLightingTextureSampler: sampler;\n\nfn ssgiComposite_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let color = textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0);\n let indirect = textureSampleLevel(\n indirectLightingTexture,\n indirectLightingTextureSampler,\n texCoord,\n 0\n );\n if (ssgiComposite.debugMode > 1.5) {\n let confidence = clamp(indirect.a, 0.0, 1.0);\n return vec4f(\n mix(vec3f(0.025, 0.05, 0.18), vec3f(1.0, 0.72, 0.18), confidence),\n 1.0\n );\n }\n if (ssgiComposite.debugMode > 0.5) {\n return vec4f(indirect.rgb * 2.2, 1.0);\n }\n return vec4f(color.rgb + indirect.rgb * ssgiComposite.strength, color.a);\n}"; readonly bindingLayout: readonly [{ readonly name: "indirectLightingTexture"; readonly group: 0; }]; readonly props: Partial; readonly uniforms: SSGICompositeUniforms; readonly uniformTypes: { readonly strength: "f32"; readonly debugMode: "f32"; }; readonly propTypes: { readonly strength: { readonly value: 1; readonly min: 0; readonly softMax: 3; }; readonly debugMode: { readonly value: 0; readonly min: 0; readonly max: 2; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; /** Creates a hemisphere-traced, temporally stabilized screen-space diffuse GI pipeline. */ export declare function createSSGIShaderPassPipeline(options?: SSGIShaderPassPipelineOptions): ShaderPassPipeline<'ssgiRaw' | 'ssgiHistory' | 'ssgiHistoryDepth' | 'ssgiScratch' | 'ssgiIndirect'>; export {}; //# sourceMappingURL=screen-space-global-illumination.d.ts.map