UNPKG

@luma.gl/effects

Version:

Post-processing effects for luma.gl

43 lines 2.84 kB
/** * Denoise - * Smooths over grainy noise in dark images using an 9x9 box filter * weighted by color intensity, similar to a bilateral filter. */ export type DenoiseProps = { /** * The exponent of the color intensity difference, should be greater * than zero. A value of zero just gives an 9x9 box blur and high values * give the original image, but ideal values are usually around 10-20. */ strength?: number; }; export type DenoiseUniforms = DenoiseProps; /** * Denoise - * Smooths over grainy noise in dark images using an 9x9 box filter * weighted by color intensity, similar to a bilateral filter. */ export declare const denoise: { readonly props: DenoiseProps; readonly uniforms: DenoiseUniforms; readonly name: "denoise"; readonly uniformTypes: { readonly strength: "f32"; }; readonly propTypes: { readonly strength: { readonly format: "f32"; readonly value: 0.5; readonly min: 0; readonly max: 1; }; }; readonly source: "\nstruct denoiseUniforms {\n strength: f32\n};\n\n@group(0), @binding(1) var<uniform> denoise: denoiseUniforms;\n\nfn denoise_sampleColor(source: sampler2D, texSize: vec2<f32>, texCoord: vec2<f32>) -> vec4<f32> {\n\tlet adjustedExponent: f32 = 3. + 200. * pow(1. - denoise.strength, 4.);\n\tlet center: vec4<f32> = sample_texture(BUFFER_source, texCoord);\n\tvar color: vec4<f32> = vec4<f32>(0.);\n\tvar total: f32 = 0.;\n\n\tfor (var x: f32 = -4.; x <= 4.; x = x + (1.)) {\n\n\t\tfor (var y: f32 = -4.; y <= 4.; y = y + (1.)) {\n\t\t\tlet offsetColor: vec4<f32> = sample_texture(BUFFER_source, texCoord + vec2<f32>(x, y) / texSize);\n\t\t\tvar weight: f32 = 1. - abs(dot(offsetColor.rgb - center.rgb, vec3<f32>(0.25)));\n\t\t\tweight = pow(weight, adjustedExponent);\n\t\t\tcolor = color + (offsetColor * weight);\n\t\t\ttotal = total + (weight);\n\t\t}\n\n\t}\n\n\treturn color / total;\n} \n"; readonly fs: "uniform dedenoiseUniforms {\n float strength;\n} denoise;\n\nvec4 dedenoise_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {\n float adjustedExponent = 3. + 200. * pow(1. - noise.strength, 4.);\n\n vec4 center = texture(source, texCoord);\n vec4 color = vec4(0.0);\n float total = 0.0;\n for (float x = -4.0; x <= 4.0; x += 1.0) {\n for (float y = -4.0; y <= 4.0; y += 1.0) {\n vec4 offsetColor = texture(source, texCoord + vec2(x, y) / texSize);\n float weight = 1.0 - abs(dot(offsetColor.rgb - center.rgb, vec3(0.25)));\n weight = pow(weight, adjustedExponent);\n color += offsetColor * weight;\n total += weight;\n }\n }\n\n return color / total;\n}\n"; readonly passes: [{ readonly sampler: true; }, { readonly sampler: true; }]; }; //# sourceMappingURL=denoise.d.ts.map