UNPKG

@luma.gl/effects

Version:

Post-processing effects for luma.gl

58 lines 4.15 kB
/** * @filter Triangle Blur * @description This is the most basic blur filter, which convolves the image with a * pyramid filter. The pyramid filter is separable and is applied as two * perpendicular triangle filters. */ export type TriangleBlurProps = { /** The radius of the pyramid convolved with the image. */ radius?: number; /** @deprecated internal property */ delta?: [number, number]; }; export type TriangleBlurUniforms = TriangleBlurProps; /** * @filter Triangle Blur * @description This is the most basic blur filter, which convolves the image with a * pyramid filter. The pyramid filter is separable and is applied as two * perpendicular triangle filters. */ export declare const triangleBlur: { readonly name: "triangleBlur"; readonly dependencies: [{ readonly name: "random"; readonly source: "fn random(scale: vec3f, seed: float) -> f32 {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n}\n"; readonly fs: "float random(vec3 scale, float seed) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n}\n"; }]; readonly source: "uniform triangleBlurUniforms {\n radius: f32,\n delta: vec2f,\n}\n\n@group(0) @binding(1) var<uniform> triangleBlur: triangleBlurUniforms;\n\nvec4 triangleBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {\n vec2 adjustedDelta = triangleBlur.delta * triangleBlur.radius / texSize;\n\n vec4 color = vec4(0.0);\n float total = 0.0;\n\n /* randomize the lookup values to hide the fixed number of samples */\n float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);\n\n for (float t = -30.0; t <= 30.0; t++) {\n float percent = (t + offset - 0.5) / 30.0;\n float weight = 1.0 - abs(percent);\n vec4 offsetColor = texture(source, texCoord + adjustedDelta * percent);\n\n /* switch to pre-multiplied alpha to correctly blur transparent images */\n offsetColor.rgb *= offsetColor.a;\n\n color += offsetColor * weight;\n total += weight;\n }\n\n color = color / total;\n\n /* switch back from pre-multiplied alpha */\n color.rgb /= color.a + 0.00001;\n\n return color;\n}\n"; readonly fs: "uniform triangleBlurUniforms {\n float radius;\n vec2 delta;\n} triangleBlur;\n\nvec4 triangleBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {\n vec2 adjustedDelta = triangleBlur.delta * triangleBlur.radius / texSize;\n\n vec4 color = vec4(0.0);\n float total = 0.0;\n\n /* randomize the lookup values to hide the fixed number of samples */\n float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);\n\n for (float t = -30.0; t <= 30.0; t++) {\n float percent = (t + offset - 0.5) / 30.0;\n float weight = 1.0 - abs(percent);\n vec4 offsetColor = texture(source, texCoord + adjustedDelta * percent);\n\n /* switch to pre-multiplied alpha to correctly blur transparent images */\n offsetColor.rgb *= offsetColor.a;\n\n color += offsetColor * weight;\n total += weight;\n }\n\n color = color / total;\n\n /* switch back from pre-multiplied alpha */\n color.rgb /= color.a + 0.00001;\n\n return color;\n}\n"; readonly props: TriangleBlurProps; readonly uniforms: TriangleBlurUniforms; readonly uniformTypes: { readonly radius: "f32"; readonly delta: "vec2<f32>"; }; readonly propTypes: { readonly radius: { readonly value: 20; readonly min: 0; readonly softMax: 100; }; readonly delta: { readonly value: readonly [1, 0]; readonly private: true; }; }; readonly passes: [{ readonly sampler: true; readonly uniforms: { readonly delta: [1, 0]; }; }, { readonly sampler: true; readonly uniforms: { readonly delta: [0, 1]; }; }]; }; //# sourceMappingURL=triangleblur.d.ts.map