import type { Texture, TextureFormatColor } from '@luma.gl/core'; import type { ShaderPassPipeline } from '@luma.gl/shadertools'; import type { BloomProps, BloomUniforms } from "./bloom.js"; import { type BloomLensEffectsOptions } from "./bloom-lens-effects.js"; export type { BloomLensEffectsOptions } from "./bloom-lens-effects.js"; declare const BLOOM_QUALITY_LEVELS: { readonly low: 2; readonly medium: 3; readonly high: 4; readonly ultra: 5; }; /** Construction options for HDR-capable multiscale bloom. */ export type BloomShaderPassPipelineOptions = BloomProps & { /** Controls the number of bloom pyramid levels: low=2, medium=3, high=4, ultra=5. */ quality?: keyof typeof BLOOM_QUALITY_LEVELS; /** Normalized contribution from progressively wider bloom levels. Defaults to 0.55. */ scatter?: number; /** Width of the soft highlight threshold relative to the threshold. Defaults to 0.5. */ softKnee?: number; /** Camera exposure used to move the scene-referred highlight threshold. Defaults to one. */ exposure?: number; /** Additional exposure compensation, measured in photographic stops. Defaults to zero. */ exposureCompensation?: number; /** Luminance-weighted suppression of isolated bright samples. Defaults to 0. */ fireflyReduction?: number; /** Negative values stretch vertically; positive values stretch horizontally. */ anamorphicRatio?: number; /** RGB multiplier applied to the reconstructed bloom before composition. */ tint?: [number, number, number]; /** Optional photographic diffraction, spectral ghosts, lens halo, and sampled dirt mask. */ lens?: BloomLensEffectsOptions; /** Neighborhood-clamped history contribution for stable highlights. Defaults to zero. */ temporalStability?: number; /** Reproject temporal history with externally supplied velocityTexture and depthTexture. */ temporalReprojection?: boolean; /** Maximum encoded scene-depth change accepted by motion-aware temporal history. */ temporalDepthThreshold?: number; /** Previous adapted exposure used to rescale glow history when camera exposure changes. */ previousExposure?: number; /** Separable Gaussian filtering or a lower-cost downsample/reconstruction-only pyramid. */ blurAlgorithm?: 'gaussian' | 'dual-kawase'; /** Scatter every source pixel and blend normalized glow without duplicating scene energy. */ energyConserving?: boolean; /** Normalized tent reconstruction or four-fetch bicubic B-spline filtering. */ reconstruction?: 'tent' | 'bicubic'; /** Select fragment downsampling or the fused WebGPU compute pyramid when available. */ downsample?: 'auto' | 'render' | 'compute'; /** Reuse expired extraction textures during reconstruction. Defaults to true. */ reuseRenderTargets?: boolean; /** * Positive fractional size multiplier applied to every pyramid level. The extraction filter * adapts its source footprint to the resulting target size. */ resolutionScale?: number; /** Filterable color intermediate format. Defaults to rgba16float for HDR highlight energy. */ colorFormat?: TextureFormatColor; }; type BloomCompositeBindings = { glowHalf?: Texture; glowQuarter?: Texture; glowEighth?: Texture; }; /** * BloomShaderPassPipeline * Extracts bright pixels at half resolution, successively downsamples and blurs them, and * composites the multiscale glow over the preceding effect output. */ export declare const bloomShaderPassPipeline: { readonly name: "bloomShaderPassPipeline"; readonly renderTargets: { readonly extractHalf: { readonly scale: [0.5, 0.5]; readonly sampler: { readonly minFilter: "linear"; readonly magFilter: "linear"; }; }; readonly blurHalfScratch: { readonly scale: [0.5, 0.5]; readonly sampler: { readonly minFilter: "linear"; readonly magFilter: "linear"; }; }; readonly blurHalf: { readonly scale: [0.5, 0.5]; readonly sampler: { readonly minFilter: "linear"; readonly magFilter: "linear"; }; }; readonly extractQuarter: { readonly scale: [0.25, 0.25]; readonly sampler: { readonly minFilter: "linear"; readonly magFilter: "linear"; }; }; readonly blurQuarterScratch: { readonly scale: [0.25, 0.25]; readonly sampler: { readonly minFilter: "linear"; readonly magFilter: "linear"; }; }; readonly blurQuarter: { readonly scale: [0.25, 0.25]; readonly sampler: { readonly minFilter: "linear"; readonly magFilter: "linear"; }; }; readonly extractEighth: { readonly scale: [0.125, 0.125]; readonly sampler: { readonly minFilter: "linear"; readonly magFilter: "linear"; }; }; readonly blurEighthScratch: { readonly scale: [0.125, 0.125]; readonly sampler: { readonly minFilter: "linear"; readonly magFilter: "linear"; }; }; readonly blurEighth: { readonly scale: [0.125, 0.125]; readonly sampler: { readonly minFilter: "linear"; readonly magFilter: "linear"; }; }; }; readonly steps: [{ readonly shaderPass: { readonly name: "bloomExtract"; readonly source: "\nstruct bloomExtractUniforms {\n threshold: f32,\n softKnee: f32,\n fireflyReduction: f32,\n exposure: f32,\n exposureCompensation: f32,\n};\n\n@group(0) @binding(auto) var bloomExtract: bloomExtractUniforms;\n\nfn bloomExtract_applyThreshold(sourceColor: vec4f) -> vec4f {\n let luminance = dot(sourceColor.rgb, vec3f(0.2126, 0.7152, 0.0722));\n let exposure = max(bloomExtract.exposure * exp2(bloomExtract.exposureCompensation), 0.0001);\n let threshold = bloomExtract.threshold / exposure;\n let knee = max(threshold * bloomExtract.softKnee, 0.00001);\n let soft = clamp((luminance - threshold + knee) / (2.0 * knee), 0.0, 1.0);\n let softContribution = soft * soft * knee;\n let hardContribution = max(luminance - threshold, 0.0);\n let bloomContribution = max(hardContribution, softContribution) / max(luminance, 0.00001);\n return vec4f(sourceColor.rgb * bloomContribution, sourceColor.a * bloomContribution);\n}\n\nfn bloomExtract_loadColor(sourceTexture: texture_2d, coordinate: vec2i) -> vec4f {\n let maximumCoordinate = vec2i(textureDimensions(sourceTexture)) - vec2i(1);\n return textureLoad(sourceTexture, clamp(coordinate, vec2i(0), maximumCoordinate), 0);\n}\n\nfn bloomExtract_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let sourceDimensions = vec2i(textureDimensions(sourceTexture));\n let sourceCenter = texCoord * vec2f(sourceDimensions) - vec2f(0.5);\n let sourceFootprint = max(\n (abs(dpdx(texCoord)) + abs(dpdy(texCoord))) * vec2f(sourceDimensions),\n vec2f(1.0)\n );\n let filterRadius = max(sourceFootprint, vec2f(2.0));\n let minimumCoordinate = vec2i(floor(sourceCenter - filterRadius)) + vec2i(1);\n let maximumCoordinate = vec2i(ceil(sourceCenter + filterRadius)) - vec2i(1);\n var color = vec4f(0.0);\n var totalWeight = 0.0;\n\n // The tent radius follows the actual source-to-target ratio so reduced-resolution pyramids do\n // not leave unsampled bands. At the default half resolution this is the original 4x4 tent.\n for (var sourceY = minimumCoordinate.y; sourceY <= maximumCoordinate.y; sourceY += 1) {\n let weightY = max(1.0 - abs(f32(sourceY) - sourceCenter.y) / filterRadius.y, 0.0);\n for (var sourceX = minimumCoordinate.x; sourceX <= maximumCoordinate.x; sourceX += 1) {\n let weightX = max(1.0 - abs(f32(sourceX) - sourceCenter.x) / filterRadius.x, 0.0);\n let sourceColor = bloomExtract_loadColor(\n sourceTexture,\n vec2i(sourceX, sourceY)\n );\n let luminance = dot(sourceColor.rgb, vec3f(0.2126, 0.7152, 0.0722));\n let fireflyWeight = mix(\n 1.0,\n 1.0 / (1.0 + max(luminance, 0.0)),\n clamp(bloomExtract.fireflyReduction, 0.0, 1.0)\n );\n let weight = weightX * weightY * fireflyWeight;\n color += bloomExtract_applyThreshold(sourceColor) * weight;\n totalWeight += weight;\n }\n }\n\n return color / max(totalWeight, 0.00001);\n}\n"; readonly fs: "\nlayout(std140) uniform bloomExtractUniforms {\n float threshold;\n float softKnee;\n float fireflyReduction;\n float exposure;\n float exposureCompensation;\n} bloomExtract;\n\nvec4 bloomExtract_applyThreshold(vec4 sourceColor) {\n float luminance = dot(sourceColor.rgb, vec3(0.2126, 0.7152, 0.0722));\n float exposure = max(bloomExtract.exposure * exp2(bloomExtract.exposureCompensation), 0.0001);\n float threshold = bloomExtract.threshold / exposure;\n float knee = max(threshold * bloomExtract.softKnee, 0.00001);\n float soft = clamp((luminance - threshold + knee) / (2.0 * knee), 0.0, 1.0);\n float softContribution = soft * soft * knee;\n float hardContribution = max(luminance - threshold, 0.0);\n float bloomContribution = max(hardContribution, softContribution) / max(luminance, 0.00001);\n return vec4(sourceColor.rgb * bloomContribution, sourceColor.a * bloomContribution);\n}\n\nvec4 bloomExtract_loadColor(sampler2D sourceTexture, ivec2 coordinate) {\n ivec2 maximumCoordinate = textureSize(sourceTexture, 0) - ivec2(1);\n return texelFetch(sourceTexture, clamp(coordinate, ivec2(0), maximumCoordinate), 0);\n}\n\nvec4 bloomExtract_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) {\n ivec2 sourceDimensions = textureSize(sourceTexture, 0);\n vec2 sourceCenter = texCoord * vec2(sourceDimensions) - vec2(0.5);\n vec2 sourceFootprint = max(\n (abs(dFdx(texCoord)) + abs(dFdy(texCoord))) * vec2(sourceDimensions),\n vec2(1.0)\n );\n vec2 filterRadius = max(sourceFootprint, vec2(2.0));\n ivec2 minimumCoordinate = ivec2(floor(sourceCenter - filterRadius)) + ivec2(1);\n ivec2 maximumCoordinate = ivec2(ceil(sourceCenter + filterRadius)) - ivec2(1);\n vec4 color = vec4(0.0);\n float totalWeight = 0.0;\n\n // Keep this kernel identical to the WGSL path so WebGL and WebGPU conserve the same energy.\n for (int sourceY = minimumCoordinate.y; sourceY <= maximumCoordinate.y; sourceY++) {\n float weightY = max(1.0 - abs(float(sourceY) - sourceCenter.y) / filterRadius.y, 0.0);\n for (int sourceX = minimumCoordinate.x; sourceX <= maximumCoordinate.x; sourceX++) {\n float weightX = max(1.0 - abs(float(sourceX) - sourceCenter.x) / filterRadius.x, 0.0);\n vec4 sourceColor = bloomExtract_loadColor(\n sourceTexture,\n ivec2(sourceX, sourceY)\n );\n float luminance = dot(sourceColor.rgb, vec3(0.2126, 0.7152, 0.0722));\n float fireflyWeight = mix(\n 1.0,\n 1.0 / (1.0 + max(luminance, 0.0)),\n clamp(bloomExtract.fireflyReduction, 0.0, 1.0)\n );\n float weight = weightX * weightY * fireflyWeight;\n color += bloomExtract_applyThreshold(sourceColor) * weight;\n totalWeight += weight;\n }\n }\n\n return color / max(totalWeight, 0.00001);\n}\n"; readonly uniformTypes: { readonly threshold: "f32"; readonly softKnee: "f32"; readonly fireflyReduction: "f32"; readonly exposure: "f32"; readonly exposureCompensation: "f32"; }; readonly defaultUniforms: { readonly threshold: 0.8; readonly softKnee: 0.5; readonly fireflyReduction: 0; readonly exposure: 1; readonly exposureCompensation: 0; }; readonly propTypes: { readonly threshold: { readonly value: 0.8; readonly min: 0; readonly max: 1; }; readonly softKnee: { readonly value: 0.5; readonly min: 0; readonly max: 1; }; readonly fireflyReduction: { readonly value: 0; readonly min: 0; readonly max: 1; }; readonly exposure: { readonly value: 1; readonly min: 0.0001; readonly softMax: 8; }; readonly exposureCompensation: { readonly value: 0; readonly min: -8; readonly max: 8; }; }; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "previous"; }; readonly output: "extractHalf"; readonly uniforms: { readonly threshold: 0.8; }; }, { readonly shaderPass: { readonly name: "bloomBlur"; readonly source: ` const BLOOM_BLUR_MAX_RADIUS = 24.0; const BLOOM_BLUR_MAX_PAIRS = ${number}; struct bloomBlurUniforms { radius: f32, delta: vec2f, }; @group(0) @binding(auto) var bloomBlur: bloomBlurUniforms; fn bloomBlur_applySample(color: vec4f) -> vec4f { return color; } fn bloomBlur_getEffectiveRadius() -> f32 { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } fn bloomBlur_getSigma(radius: f32) -> f32 { return max(radius / 3.0, 0.00001); } fn bloomBlur_getWeight(offset: f32, sigma: f32) -> f32 { let normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } fn bloomBlur_sampleColor( sourceTexture: texture_2d, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f ) -> vec4f { let effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return textureSample(sourceTexture, sourceTextureSampler, texCoord); } let adjustedDelta = bloomBlur.delta / texSize; let sigma = bloomBlur_getSigma(effectiveRadius); let centerWeight = bloomBlur_getWeight(0.0, sigma); var color = vec4f(0.0); var totalWeight = centerWeight; let centerColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord) ); color += centerColor * centerWeight; for (var pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex += 1) { let firstOffset = f32(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } let secondOffset = firstOffset + 1.0; let firstWeight = bloomBlur_getWeight(firstOffset, sigma); let secondWeight = select(0.0, bloomBlur_getWeight(secondOffset, sigma), secondOffset <= effectiveRadius); let combinedWeight = firstWeight + secondWeight; let combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); let positiveColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord + adjustedDelta * combinedOffset) ); let negativeColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord - adjustedDelta * combinedOffset) ); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } return color / totalWeight; } `; readonly fs: ` #define BLOOM_BLUR_MAX_RADIUS 24.0 #define BLOOM_BLUR_MAX_PAIRS ${number} layout(std140) uniform bloomBlurUniforms { float radius; vec2 delta; } bloomBlur; vec4 bloomBlur_applySample(vec4 color) { return color; } float bloomBlur_getEffectiveRadius() { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } float bloomBlur_getSigma(float radius) { return max(radius / 3.0, 0.00001); } float bloomBlur_getWeight(float offset, float sigma) { float normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } vec4 bloomBlur_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) { float effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return texture(sourceTexture, texCoord); } vec2 adjustedDelta = bloomBlur.delta / texSize; float sigma = bloomBlur_getSigma(effectiveRadius); float centerWeight = bloomBlur_getWeight(0.0, sigma); vec4 color = vec4(0.0); float totalWeight = centerWeight; vec4 centerColor = bloomBlur_applySample(texture(sourceTexture, texCoord)); color += centerColor * centerWeight; for (int pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex++) { float firstOffset = float(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } float secondOffset = firstOffset + 1.0; float firstWeight = bloomBlur_getWeight(firstOffset, sigma); float secondWeight = secondOffset <= effectiveRadius ? bloomBlur_getWeight(secondOffset, sigma) : 0.0; float combinedWeight = firstWeight + secondWeight; float combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); vec4 positiveColor = bloomBlur_applySample(texture(sourceTexture, texCoord + adjustedDelta * combinedOffset)); vec4 negativeColor = bloomBlur_applySample(texture(sourceTexture, texCoord - adjustedDelta * combinedOffset)); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } color /= totalWeight; return color; } `; readonly uniformTypes: { readonly radius: "f32"; readonly delta: "vec2"; }; readonly propTypes: { readonly radius: { readonly value: 8; readonly min: 0; readonly max: 24; readonly softMax: 24; }; readonly delta: { readonly value: readonly [1, 0]; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "extractHalf"; }; readonly output: "blurHalfScratch"; readonly uniforms: { readonly radius: 8; readonly delta: [1, 0]; }; }, { readonly shaderPass: { readonly name: "bloomBlur"; readonly source: ` const BLOOM_BLUR_MAX_RADIUS = 24.0; const BLOOM_BLUR_MAX_PAIRS = ${number}; struct bloomBlurUniforms { radius: f32, delta: vec2f, }; @group(0) @binding(auto) var bloomBlur: bloomBlurUniforms; fn bloomBlur_applySample(color: vec4f) -> vec4f { return color; } fn bloomBlur_getEffectiveRadius() -> f32 { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } fn bloomBlur_getSigma(radius: f32) -> f32 { return max(radius / 3.0, 0.00001); } fn bloomBlur_getWeight(offset: f32, sigma: f32) -> f32 { let normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } fn bloomBlur_sampleColor( sourceTexture: texture_2d, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f ) -> vec4f { let effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return textureSample(sourceTexture, sourceTextureSampler, texCoord); } let adjustedDelta = bloomBlur.delta / texSize; let sigma = bloomBlur_getSigma(effectiveRadius); let centerWeight = bloomBlur_getWeight(0.0, sigma); var color = vec4f(0.0); var totalWeight = centerWeight; let centerColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord) ); color += centerColor * centerWeight; for (var pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex += 1) { let firstOffset = f32(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } let secondOffset = firstOffset + 1.0; let firstWeight = bloomBlur_getWeight(firstOffset, sigma); let secondWeight = select(0.0, bloomBlur_getWeight(secondOffset, sigma), secondOffset <= effectiveRadius); let combinedWeight = firstWeight + secondWeight; let combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); let positiveColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord + adjustedDelta * combinedOffset) ); let negativeColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord - adjustedDelta * combinedOffset) ); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } return color / totalWeight; } `; readonly fs: ` #define BLOOM_BLUR_MAX_RADIUS 24.0 #define BLOOM_BLUR_MAX_PAIRS ${number} layout(std140) uniform bloomBlurUniforms { float radius; vec2 delta; } bloomBlur; vec4 bloomBlur_applySample(vec4 color) { return color; } float bloomBlur_getEffectiveRadius() { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } float bloomBlur_getSigma(float radius) { return max(radius / 3.0, 0.00001); } float bloomBlur_getWeight(float offset, float sigma) { float normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } vec4 bloomBlur_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) { float effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return texture(sourceTexture, texCoord); } vec2 adjustedDelta = bloomBlur.delta / texSize; float sigma = bloomBlur_getSigma(effectiveRadius); float centerWeight = bloomBlur_getWeight(0.0, sigma); vec4 color = vec4(0.0); float totalWeight = centerWeight; vec4 centerColor = bloomBlur_applySample(texture(sourceTexture, texCoord)); color += centerColor * centerWeight; for (int pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex++) { float firstOffset = float(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } float secondOffset = firstOffset + 1.0; float firstWeight = bloomBlur_getWeight(firstOffset, sigma); float secondWeight = secondOffset <= effectiveRadius ? bloomBlur_getWeight(secondOffset, sigma) : 0.0; float combinedWeight = firstWeight + secondWeight; float combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); vec4 positiveColor = bloomBlur_applySample(texture(sourceTexture, texCoord + adjustedDelta * combinedOffset)); vec4 negativeColor = bloomBlur_applySample(texture(sourceTexture, texCoord - adjustedDelta * combinedOffset)); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } color /= totalWeight; return color; } `; readonly uniformTypes: { readonly radius: "f32"; readonly delta: "vec2"; }; readonly propTypes: { readonly radius: { readonly value: 8; readonly min: 0; readonly max: 24; readonly softMax: 24; }; readonly delta: { readonly value: readonly [1, 0]; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "blurHalfScratch"; }; readonly output: "blurHalf"; readonly uniforms: { readonly radius: 8; readonly delta: [0, 1]; }; }, { readonly shaderPass: { readonly name: "bloomDownsample"; readonly source: "\nfn bloomDownsample_loadColor(sourceTexture: texture_2d, coordinate: vec2i) -> vec4f {\n let maximumCoordinate = vec2i(textureDimensions(sourceTexture)) - vec2i(1);\n return textureLoad(sourceTexture, clamp(coordinate, vec2i(0), maximumCoordinate), 0);\n}\n\nfn bloomDownsample_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let sourceDimensions = vec2i(textureDimensions(sourceTexture));\n let sourceCenter = texCoord * vec2f(sourceDimensions) - vec2f(0.5);\n let sourceFootprint = max(\n (abs(dpdx(texCoord)) + abs(dpdy(texCoord))) * vec2f(sourceDimensions),\n vec2f(1.0)\n );\n let filterRadius = max(sourceFootprint, vec2f(2.0));\n let minimumCoordinate = vec2i(floor(sourceCenter - filterRadius)) + vec2i(1);\n let maximumCoordinate = vec2i(ceil(sourceCenter + filterRadius)) - vec2i(1);\n var color = vec4f(0.0);\n var totalWeight = 0.0;\n\n for (var sourceY = minimumCoordinate.y; sourceY <= maximumCoordinate.y; sourceY += 1) {\n let weightY = max(1.0 - abs(f32(sourceY) - sourceCenter.y) / filterRadius.y, 0.0);\n for (var sourceX = minimumCoordinate.x; sourceX <= maximumCoordinate.x; sourceX += 1) {\n let weightX = max(1.0 - abs(f32(sourceX) - sourceCenter.x) / filterRadius.x, 0.0);\n let weight = weightX * weightY;\n color += bloomDownsample_loadColor(\n sourceTexture,\n vec2i(sourceX, sourceY)\n ) * weight;\n totalWeight += weight;\n }\n }\n\n return color / max(totalWeight, 0.00001);\n}\n"; readonly fs: "\nvec4 bloomDownsample_loadColor(sampler2D sourceTexture, ivec2 coordinate) {\n ivec2 maximumCoordinate = textureSize(sourceTexture, 0) - ivec2(1);\n return texelFetch(sourceTexture, clamp(coordinate, ivec2(0), maximumCoordinate), 0);\n}\n\nvec4 bloomDownsample_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) {\n ivec2 sourceDimensions = textureSize(sourceTexture, 0);\n vec2 sourceCenter = texCoord * vec2(sourceDimensions) - vec2(0.5);\n vec2 sourceFootprint = max(\n (abs(dFdx(texCoord)) + abs(dFdy(texCoord))) * vec2(sourceDimensions),\n vec2(1.0)\n );\n vec2 filterRadius = max(sourceFootprint, vec2(2.0));\n ivec2 minimumCoordinate = ivec2(floor(sourceCenter - filterRadius)) + ivec2(1);\n ivec2 maximumCoordinate = ivec2(ceil(sourceCenter + filterRadius)) - ivec2(1);\n vec4 color = vec4(0.0);\n float totalWeight = 0.0;\n\n for (int sourceY = minimumCoordinate.y; sourceY <= maximumCoordinate.y; sourceY++) {\n float weightY = max(1.0 - abs(float(sourceY) - sourceCenter.y) / filterRadius.y, 0.0);\n for (int sourceX = minimumCoordinate.x; sourceX <= maximumCoordinate.x; sourceX++) {\n float weightX = max(1.0 - abs(float(sourceX) - sourceCenter.x) / filterRadius.x, 0.0);\n float weight = weightX * weightY;\n color += bloomDownsample_loadColor(\n sourceTexture,\n ivec2(sourceX, sourceY)\n ) * weight;\n totalWeight += weight;\n }\n }\n\n return color / max(totalWeight, 0.00001);\n}\n"; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "extractHalf"; }; readonly output: "extractQuarter"; }, { readonly shaderPass: { readonly name: "bloomBlur"; readonly source: ` const BLOOM_BLUR_MAX_RADIUS = 24.0; const BLOOM_BLUR_MAX_PAIRS = ${number}; struct bloomBlurUniforms { radius: f32, delta: vec2f, }; @group(0) @binding(auto) var bloomBlur: bloomBlurUniforms; fn bloomBlur_applySample(color: vec4f) -> vec4f { return color; } fn bloomBlur_getEffectiveRadius() -> f32 { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } fn bloomBlur_getSigma(radius: f32) -> f32 { return max(radius / 3.0, 0.00001); } fn bloomBlur_getWeight(offset: f32, sigma: f32) -> f32 { let normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } fn bloomBlur_sampleColor( sourceTexture: texture_2d, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f ) -> vec4f { let effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return textureSample(sourceTexture, sourceTextureSampler, texCoord); } let adjustedDelta = bloomBlur.delta / texSize; let sigma = bloomBlur_getSigma(effectiveRadius); let centerWeight = bloomBlur_getWeight(0.0, sigma); var color = vec4f(0.0); var totalWeight = centerWeight; let centerColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord) ); color += centerColor * centerWeight; for (var pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex += 1) { let firstOffset = f32(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } let secondOffset = firstOffset + 1.0; let firstWeight = bloomBlur_getWeight(firstOffset, sigma); let secondWeight = select(0.0, bloomBlur_getWeight(secondOffset, sigma), secondOffset <= effectiveRadius); let combinedWeight = firstWeight + secondWeight; let combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); let positiveColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord + adjustedDelta * combinedOffset) ); let negativeColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord - adjustedDelta * combinedOffset) ); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } return color / totalWeight; } `; readonly fs: ` #define BLOOM_BLUR_MAX_RADIUS 24.0 #define BLOOM_BLUR_MAX_PAIRS ${number} layout(std140) uniform bloomBlurUniforms { float radius; vec2 delta; } bloomBlur; vec4 bloomBlur_applySample(vec4 color) { return color; } float bloomBlur_getEffectiveRadius() { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } float bloomBlur_getSigma(float radius) { return max(radius / 3.0, 0.00001); } float bloomBlur_getWeight(float offset, float sigma) { float normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } vec4 bloomBlur_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) { float effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return texture(sourceTexture, texCoord); } vec2 adjustedDelta = bloomBlur.delta / texSize; float sigma = bloomBlur_getSigma(effectiveRadius); float centerWeight = bloomBlur_getWeight(0.0, sigma); vec4 color = vec4(0.0); float totalWeight = centerWeight; vec4 centerColor = bloomBlur_applySample(texture(sourceTexture, texCoord)); color += centerColor * centerWeight; for (int pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex++) { float firstOffset = float(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } float secondOffset = firstOffset + 1.0; float firstWeight = bloomBlur_getWeight(firstOffset, sigma); float secondWeight = secondOffset <= effectiveRadius ? bloomBlur_getWeight(secondOffset, sigma) : 0.0; float combinedWeight = firstWeight + secondWeight; float combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); vec4 positiveColor = bloomBlur_applySample(texture(sourceTexture, texCoord + adjustedDelta * combinedOffset)); vec4 negativeColor = bloomBlur_applySample(texture(sourceTexture, texCoord - adjustedDelta * combinedOffset)); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } color /= totalWeight; return color; } `; readonly uniformTypes: { readonly radius: "f32"; readonly delta: "vec2"; }; readonly propTypes: { readonly radius: { readonly value: 8; readonly min: 0; readonly max: 24; readonly softMax: 24; }; readonly delta: { readonly value: readonly [1, 0]; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "extractQuarter"; }; readonly output: "blurQuarterScratch"; readonly uniforms: { readonly radius: 8; readonly delta: [1, 0]; }; }, { readonly shaderPass: { readonly name: "bloomBlur"; readonly source: ` const BLOOM_BLUR_MAX_RADIUS = 24.0; const BLOOM_BLUR_MAX_PAIRS = ${number}; struct bloomBlurUniforms { radius: f32, delta: vec2f, }; @group(0) @binding(auto) var bloomBlur: bloomBlurUniforms; fn bloomBlur_applySample(color: vec4f) -> vec4f { return color; } fn bloomBlur_getEffectiveRadius() -> f32 { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } fn bloomBlur_getSigma(radius: f32) -> f32 { return max(radius / 3.0, 0.00001); } fn bloomBlur_getWeight(offset: f32, sigma: f32) -> f32 { let normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } fn bloomBlur_sampleColor( sourceTexture: texture_2d, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f ) -> vec4f { let effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return textureSample(sourceTexture, sourceTextureSampler, texCoord); } let adjustedDelta = bloomBlur.delta / texSize; let sigma = bloomBlur_getSigma(effectiveRadius); let centerWeight = bloomBlur_getWeight(0.0, sigma); var color = vec4f(0.0); var totalWeight = centerWeight; let centerColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord) ); color += centerColor * centerWeight; for (var pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex += 1) { let firstOffset = f32(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } let secondOffset = firstOffset + 1.0; let firstWeight = bloomBlur_getWeight(firstOffset, sigma); let secondWeight = select(0.0, bloomBlur_getWeight(secondOffset, sigma), secondOffset <= effectiveRadius); let combinedWeight = firstWeight + secondWeight; let combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); let positiveColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord + adjustedDelta * combinedOffset) ); let negativeColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord - adjustedDelta * combinedOffset) ); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } return color / totalWeight; } `; readonly fs: ` #define BLOOM_BLUR_MAX_RADIUS 24.0 #define BLOOM_BLUR_MAX_PAIRS ${number} layout(std140) uniform bloomBlurUniforms { float radius; vec2 delta; } bloomBlur; vec4 bloomBlur_applySample(vec4 color) { return color; } float bloomBlur_getEffectiveRadius() { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } float bloomBlur_getSigma(float radius) { return max(radius / 3.0, 0.00001); } float bloomBlur_getWeight(float offset, float sigma) { float normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } vec4 bloomBlur_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) { float effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return texture(sourceTexture, texCoord); } vec2 adjustedDelta = bloomBlur.delta / texSize; float sigma = bloomBlur_getSigma(effectiveRadius); float centerWeight = bloomBlur_getWeight(0.0, sigma); vec4 color = vec4(0.0); float totalWeight = centerWeight; vec4 centerColor = bloomBlur_applySample(texture(sourceTexture, texCoord)); color += centerColor * centerWeight; for (int pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex++) { float firstOffset = float(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } float secondOffset = firstOffset + 1.0; float firstWeight = bloomBlur_getWeight(firstOffset, sigma); float secondWeight = secondOffset <= effectiveRadius ? bloomBlur_getWeight(secondOffset, sigma) : 0.0; float combinedWeight = firstWeight + secondWeight; float combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); vec4 positiveColor = bloomBlur_applySample(texture(sourceTexture, texCoord + adjustedDelta * combinedOffset)); vec4 negativeColor = bloomBlur_applySample(texture(sourceTexture, texCoord - adjustedDelta * combinedOffset)); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } color /= totalWeight; return color; } `; readonly uniformTypes: { readonly radius: "f32"; readonly delta: "vec2"; }; readonly propTypes: { readonly radius: { readonly value: 8; readonly min: 0; readonly max: 24; readonly softMax: 24; }; readonly delta: { readonly value: readonly [1, 0]; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "blurQuarterScratch"; }; readonly output: "blurQuarter"; readonly uniforms: { readonly radius: 8; readonly delta: [0, 1]; }; }, { readonly shaderPass: { readonly name: "bloomDownsample"; readonly source: "\nfn bloomDownsample_loadColor(sourceTexture: texture_2d, coordinate: vec2i) -> vec4f {\n let maximumCoordinate = vec2i(textureDimensions(sourceTexture)) - vec2i(1);\n return textureLoad(sourceTexture, clamp(coordinate, vec2i(0), maximumCoordinate), 0);\n}\n\nfn bloomDownsample_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let sourceDimensions = vec2i(textureDimensions(sourceTexture));\n let sourceCenter = texCoord * vec2f(sourceDimensions) - vec2f(0.5);\n let sourceFootprint = max(\n (abs(dpdx(texCoord)) + abs(dpdy(texCoord))) * vec2f(sourceDimensions),\n vec2f(1.0)\n );\n let filterRadius = max(sourceFootprint, vec2f(2.0));\n let minimumCoordinate = vec2i(floor(sourceCenter - filterRadius)) + vec2i(1);\n let maximumCoordinate = vec2i(ceil(sourceCenter + filterRadius)) - vec2i(1);\n var color = vec4f(0.0);\n var totalWeight = 0.0;\n\n for (var sourceY = minimumCoordinate.y; sourceY <= maximumCoordinate.y; sourceY += 1) {\n let weightY = max(1.0 - abs(f32(sourceY) - sourceCenter.y) / filterRadius.y, 0.0);\n for (var sourceX = minimumCoordinate.x; sourceX <= maximumCoordinate.x; sourceX += 1) {\n let weightX = max(1.0 - abs(f32(sourceX) - sourceCenter.x) / filterRadius.x, 0.0);\n let weight = weightX * weightY;\n color += bloomDownsample_loadColor(\n sourceTexture,\n vec2i(sourceX, sourceY)\n ) * weight;\n totalWeight += weight;\n }\n }\n\n return color / max(totalWeight, 0.00001);\n}\n"; readonly fs: "\nvec4 bloomDownsample_loadColor(sampler2D sourceTexture, ivec2 coordinate) {\n ivec2 maximumCoordinate = textureSize(sourceTexture, 0) - ivec2(1);\n return texelFetch(sourceTexture, clamp(coordinate, ivec2(0), maximumCoordinate), 0);\n}\n\nvec4 bloomDownsample_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) {\n ivec2 sourceDimensions = textureSize(sourceTexture, 0);\n vec2 sourceCenter = texCoord * vec2(sourceDimensions) - vec2(0.5);\n vec2 sourceFootprint = max(\n (abs(dFdx(texCoord)) + abs(dFdy(texCoord))) * vec2(sourceDimensions),\n vec2(1.0)\n );\n vec2 filterRadius = max(sourceFootprint, vec2(2.0));\n ivec2 minimumCoordinate = ivec2(floor(sourceCenter - filterRadius)) + ivec2(1);\n ivec2 maximumCoordinate = ivec2(ceil(sourceCenter + filterRadius)) - ivec2(1);\n vec4 color = vec4(0.0);\n float totalWeight = 0.0;\n\n for (int sourceY = minimumCoordinate.y; sourceY <= maximumCoordinate.y; sourceY++) {\n float weightY = max(1.0 - abs(float(sourceY) - sourceCenter.y) / filterRadius.y, 0.0);\n for (int sourceX = minimumCoordinate.x; sourceX <= maximumCoordinate.x; sourceX++) {\n float weightX = max(1.0 - abs(float(sourceX) - sourceCenter.x) / filterRadius.x, 0.0);\n float weight = weightX * weightY;\n color += bloomDownsample_loadColor(\n sourceTexture,\n ivec2(sourceX, sourceY)\n ) * weight;\n totalWeight += weight;\n }\n }\n\n return color / max(totalWeight, 0.00001);\n}\n"; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "extractQuarter"; }; readonly output: "extractEighth"; }, { readonly shaderPass: { readonly name: "bloomBlur"; readonly source: ` const BLOOM_BLUR_MAX_RADIUS = 24.0; const BLOOM_BLUR_MAX_PAIRS = ${number}; struct bloomBlurUniforms { radius: f32, delta: vec2f, }; @group(0) @binding(auto) var bloomBlur: bloomBlurUniforms; fn bloomBlur_applySample(color: vec4f) -> vec4f { return color; } fn bloomBlur_getEffectiveRadius() -> f32 { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } fn bloomBlur_getSigma(radius: f32) -> f32 { return max(radius / 3.0, 0.00001); } fn bloomBlur_getWeight(offset: f32, sigma: f32) -> f32 { let normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } fn bloomBlur_sampleColor( sourceTexture: texture_2d, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f ) -> vec4f { let effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return textureSample(sourceTexture, sourceTextureSampler, texCoord); } let adjustedDelta = bloomBlur.delta / texSize; let sigma = bloomBlur_getSigma(effectiveRadius); let centerWeight = bloomBlur_getWeight(0.0, sigma); var color = vec4f(0.0); var totalWeight = centerWeight; let centerColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord) ); color += centerColor * centerWeight; for (var pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex += 1) { let firstOffset = f32(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } let secondOffset = firstOffset + 1.0; let firstWeight = bloomBlur_getWeight(firstOffset, sigma); let secondWeight = select(0.0, bloomBlur_getWeight(secondOffset, sigma), secondOffset <= effectiveRadius); let combinedWeight = firstWeight + secondWeight; let combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); let positiveColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord + adjustedDelta * combinedOffset) ); let negativeColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord - adjustedDelta * combinedOffset) ); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } return color / totalWeight; } `; readonly fs: ` #define BLOOM_BLUR_MAX_RADIUS 24.0 #define BLOOM_BLUR_MAX_PAIRS ${number} layout(std140) uniform bloomBlurUniforms { float radius; vec2 delta; } bloomBlur; vec4 bloomBlur_applySample(vec4 color) { return color; } float bloomBlur_getEffectiveRadius() { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } float bloomBlur_getSigma(float radius) { return max(radius / 3.0, 0.00001); } float bloomBlur_getWeight(float offset, float sigma) { float normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } vec4 bloomBlur_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) { float effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return texture(sourceTexture, texCoord); } vec2 adjustedDelta = bloomBlur.delta / texSize; float sigma = bloomBlur_getSigma(effectiveRadius); float centerWeight = bloomBlur_getWeight(0.0, sigma); vec4 color = vec4(0.0); float totalWeight = centerWeight; vec4 centerColor = bloomBlur_applySample(texture(sourceTexture, texCoord)); color += centerColor * centerWeight; for (int pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex++) { float firstOffset = float(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } float secondOffset = firstOffset + 1.0; float firstWeight = bloomBlur_getWeight(firstOffset, sigma); float secondWeight = secondOffset <= effectiveRadius ? bloomBlur_getWeight(secondOffset, sigma) : 0.0; float combinedWeight = firstWeight + secondWeight; float combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); vec4 positiveColor = bloomBlur_applySample(texture(sourceTexture, texCoord + adjustedDelta * combinedOffset)); vec4 negativeColor = bloomBlur_applySample(texture(sourceTexture, texCoord - adjustedDelta * combinedOffset)); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } color /= totalWeight; return color; } `; readonly uniformTypes: { readonly radius: "f32"; readonly delta: "vec2"; }; readonly propTypes: { readonly radius: { readonly value: 8; readonly min: 0; readonly max: 24; readonly softMax: 24; }; readonly delta: { readonly value: readonly [1, 0]; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "extractEighth"; }; readonly output: "blurEighthScratch"; readonly uniforms: { readonly radius: 8; readonly delta: [1, 0]; }; }, { readonly shaderPass: { readonly name: "bloomBlur"; readonly source: ` const BLOOM_BLUR_MAX_RADIUS = 24.0; const BLOOM_BLUR_MAX_PAIRS = ${number}; struct bloomBlurUniforms { radius: f32, delta: vec2f, }; @group(0) @binding(auto) var bloomBlur: bloomBlurUniforms; fn bloomBlur_applySample(color: vec4f) -> vec4f { return color; } fn bloomBlur_getEffectiveRadius() -> f32 { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } fn bloomBlur_getSigma(radius: f32) -> f32 { return max(radius / 3.0, 0.00001); } fn bloomBlur_getWeight(offset: f32, sigma: f32) -> f32 { let normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } fn bloomBlur_sampleColor( sourceTexture: texture_2d, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f ) -> vec4f { let effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return textureSample(sourceTexture, sourceTextureSampler, texCoord); } let adjustedDelta = bloomBlur.delta / texSize; let sigma = bloomBlur_getSigma(effectiveRadius); let centerWeight = bloomBlur_getWeight(0.0, sigma); var color = vec4f(0.0); var totalWeight = centerWeight; let centerColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord) ); color += centerColor * centerWeight; for (var pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex += 1) { let firstOffset = f32(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } let secondOffset = firstOffset + 1.0; let firstWeight = bloomBlur_getWeight(firstOffset, sigma); let secondWeight = select(0.0, bloomBlur_getWeight(secondOffset, sigma), secondOffset <= effectiveRadius); let combinedWeight = firstWeight + secondWeight; let combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); let positiveColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord + adjustedDelta * combinedOffset) ); let negativeColor = bloomBlur_applySample( textureSample(sourceTexture, sourceTextureSampler, texCoord - adjustedDelta * combinedOffset) ); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } return color / totalWeight; } `; readonly fs: ` #define BLOOM_BLUR_MAX_RADIUS 24.0 #define BLOOM_BLUR_MAX_PAIRS ${number} layout(std140) uniform bloomBlurUniforms { float radius; vec2 delta; } bloomBlur; vec4 bloomBlur_applySample(vec4 color) { return color; } float bloomBlur_getEffectiveRadius() { return clamp(bloomBlur.radius, 0.0, BLOOM_BLUR_MAX_RADIUS); } float bloomBlur_getSigma(float radius) { return max(radius / 3.0, 0.00001); } float bloomBlur_getWeight(float offset, float sigma) { float normalizedOffset = offset / sigma; return exp(-0.5 * normalizedOffset * normalizedOffset); } vec4 bloomBlur_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) { float effectiveRadius = bloomBlur_getEffectiveRadius(); if (effectiveRadius <= 0.0) { return texture(sourceTexture, texCoord); } vec2 adjustedDelta = bloomBlur.delta / texSize; float sigma = bloomBlur_getSigma(effectiveRadius); float centerWeight = bloomBlur_getWeight(0.0, sigma); vec4 color = vec4(0.0); float totalWeight = centerWeight; vec4 centerColor = bloomBlur_applySample(texture(sourceTexture, texCoord)); color += centerColor * centerWeight; for (int pairIndex = 0; pairIndex < BLOOM_BLUR_MAX_PAIRS; pairIndex++) { float firstOffset = float(pairIndex * 2 + 1); if (firstOffset > effectiveRadius) { continue; } float secondOffset = firstOffset + 1.0; float firstWeight = bloomBlur_getWeight(firstOffset, sigma); float secondWeight = secondOffset <= effectiveRadius ? bloomBlur_getWeight(secondOffset, sigma) : 0.0; float combinedWeight = firstWeight + secondWeight; float combinedOffset = (firstOffset * firstWeight + secondOffset * secondWeight) / max(combinedWeight, 0.00001); vec4 positiveColor = bloomBlur_applySample(texture(sourceTexture, texCoord + adjustedDelta * combinedOffset)); vec4 negativeColor = bloomBlur_applySample(texture(sourceTexture, texCoord - adjustedDelta * combinedOffset)); color += (positiveColor + negativeColor) * combinedWeight; totalWeight += combinedWeight * 2.0; } color /= totalWeight; return color; } `; readonly uniformTypes: { readonly radius: "f32"; readonly delta: "vec2"; }; readonly propTypes: { readonly radius: { readonly value: 8; readonly min: 0; readonly max: 24; readonly softMax: 24; }; readonly delta: { readonly value: readonly [1, 0]; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "blurEighthScratch"; }; readonly output: "blurEighth"; readonly uniforms: { readonly radius: 8; readonly delta: [0, 1]; }; }, { readonly shaderPass: { readonly name: "bloomComposite"; readonly source: "\nstruct bloomCompositeUniforms {\n intensity: f32,\n};\n\n@group(0) @binding(auto) var bloomComposite: bloomCompositeUniforms;\n@group(0) @binding(auto) var glowHalf: texture_2d;\n@group(0) @binding(auto) var glowHalfSampler: sampler;\n@group(0) @binding(auto) var glowQuarter: texture_2d;\n@group(0) @binding(auto) var glowQuarterSampler: sampler;\n@group(0) @binding(auto) var glowEighth: texture_2d;\n@group(0) @binding(auto) var glowEighthSampler: sampler;\n\nfn bloomComposite_sampleColor(\n sourceTexture: texture_2d,\n sourceTextureSampler: sampler,\n texSize: vec2f,\n texCoord: vec2f\n) -> vec4f {\n let sourceColor = textureSample(sourceTexture, sourceTextureSampler, texCoord);\n let halfGlow = textureSample(glowHalf, glowHalfSampler, texCoord).rgb;\n let quarterGlow = textureSample(glowQuarter, glowQuarterSampler, texCoord).rgb;\n let eighthGlow = textureSample(glowEighth, glowEighthSampler, texCoord).rgb;\n let glowColor = halfGlow * 0.50 + quarterGlow * 0.32 + eighthGlow * 0.18;\n return vec4f(sourceColor.rgb + glowColor * bloomComposite.intensity, sourceColor.a);\n}\n"; readonly fs: "\nlayout(std140) uniform bloomCompositeUniforms {\n float intensity;\n} bloomComposite;\n\nuniform sampler2D glowHalf;\nuniform sampler2D glowQuarter;\nuniform sampler2D glowEighth;\n\nvec4 bloomComposite_sampleColor(sampler2D sourceTexture, vec2 texSize, vec2 texCoord) {\n vec4 sourceColor = texture(sourceTexture, texCoord);\n vec3 halfGlow = texture(glowHalf, texCoord).rgb;\n vec3 quarterGlow = texture(glowQuarter, texCoord).rgb;\n vec3 eighthGlow = texture(glowEighth, texCoord).rgb;\n vec3 glowColor = halfGlow * 0.50 + quarterGlow * 0.32 + eighthGlow * 0.18;\n return vec4(sourceColor.rgb + glowColor * bloomComposite.intensity, sourceColor.a);\n}\n"; readonly bindingLayout: readonly [{ readonly name: "glowHalf"; readonly group: 0; }, { readonly name: "glowQuarter"; readonly group: 0; }, { readonly name: "glowEighth"; readonly group: 0; }]; readonly uniforms: Pick; readonly bindings: BloomCompositeBindings; readonly uniformTypes: { readonly intensity: "f32"; }; readonly propTypes: { readonly intensity: { readonly value: 1; readonly min: 0; readonly softMax: 3; }; }; readonly passes: [{ readonly sampler: true; }]; }; readonly inputs: { readonly sourceTexture: "previous"; readonly glowHalf: "blurHalf"; readonly glowQuarter: "blurQuarter"; readonly glowEighth: "blurEighth"; }; readonly output: "previous"; readonly uniforms: { readonly intensity: 1; }; }]; }; /** Creates configurable multiscale bloom that preserves high-dynamic-range radiance. */ export declare function createBloomShaderPassPipeline(options?: BloomShaderPassPipelineOptions): ShaderPassPipeline; //# sourceMappingURL=bloom-shader-pass-pipeline.d.ts.map