{"version":3,"file":"NoiseFilter.mjs","sources":["../../../../src/filters/defaults/noise/NoiseFilter.ts"],"sourcesContent":["import { GlProgram } from '../../../rendering/renderers/gl/shader/GlProgram';\nimport { GpuProgram } from '../../../rendering/renderers/gpu/shader/GpuProgram';\nimport { UniformGroup } from '../../../rendering/renderers/shared/shader/UniformGroup';\nimport { Filter } from '../../Filter';\nimport vertex from '../defaultFilter.vert';\nimport fragment from './noise.frag';\nimport source from './noise.wgsl';\n\nimport type { FilterOptions } from '../../Filter';\n\n/**\n * Configuration options for the NoiseFilter.\n *\n * The NoiseFilter adds random noise to the rendered content. The noise effect can be\n * controlled through the noise intensity and an optional seed value for reproducible results.\n * @example\n * ```ts\n * // Basic noise effect\n * const options: NoiseFilterOptions = {\n *     noise: 0.5,\n *     seed: Math.random()\n * };\n *\n * // Create filter with options\n * const noiseFilter = new NoiseFilter(options);\n * ```\n * @category filters\n * @standard\n */\nexport interface NoiseFilterOptions extends FilterOptions\n{\n    /**\n     * The amount of noise to apply. Should be in range (0, 1]:\n     * - 0.1 = subtle noise\n     * - 0.5 = moderate noise (default)\n     * - 1.0 = maximum noise\n     * @default 0.5\n     * @example\n     * ```ts\n     * // Moderate noise effect\n     * const noiseFilter = new NoiseFilter({ noise: 0.5 });\n     * ```\n     */\n    noise?: number;\n    /**\n     * A seed value to apply to the random noise generation.\n     * Using the same seed will generate the same noise pattern.\n     * @default Math.random()\n     * @example\n     * ```ts\n     * // Using a fixed seed for reproducible noise\n     * const noiseFilter = new NoiseFilter({ seed: 12345 });\n     * ```\n     */\n    seed?: number;\n}\n\n/**\n * A filter that adds configurable random noise to rendered content.\n *\n * This filter generates pixel noise based on a noise intensity value and an optional seed.\n * It can be used to create various effects like film grain, static, or texture variation.\n *\n * Based on: https://github.com/evanw/glfx.js/blob/master/src/filters/adjust/noise.js\n * @example\n * ```ts\n * import { NoiseFilter } from 'pixi.js';\n *\n * // Create with options\n * const filter = new NoiseFilter({\n *     noise: 0.5,    // 50% noise intensity\n *     seed: 12345    // Fixed seed for consistent noise\n * });\n *\n * // Apply to a display object\n * sprite.filters = [filter];\n *\n * // Adjust noise dynamically\n * filter.noise = 0.8;    // Increase noise\n * filter.seed = Math.random(); // New random pattern\n * ```\n * @category filters\n * @author Vico: vicocotea\n * @standard\n * @noInheritDoc\n */\nexport class NoiseFilter extends Filter\n{\n    /**\n     * The default configuration options for the NoiseFilter.\n     *\n     * These values will be used when no specific options are provided to the constructor.\n     * You can override any of these values by passing your own options object.\n     * @example\n     * ```ts\n     * NoiseFilter.defaultOptions.noise = 0.7; // Change default noise to 0.7\n     * const filter = new NoiseFilter(); // Will use noise 0.7 by default\n     * ```\n     */\n    public static defaultOptions: NoiseFilterOptions = {\n        noise: 0.5,\n    };\n\n    /**\n     * @param options - The options of the noise filter.\n     */\n    constructor(options: NoiseFilterOptions = {})\n    {\n        options = { ...NoiseFilter.defaultOptions, ...options };\n\n        const gpuProgram = GpuProgram.from({\n            vertex: {\n                source,\n                entryPoint: 'mainVertex',\n            },\n            fragment: {\n                source,\n                entryPoint: 'mainFragment',\n            },\n        });\n\n        const glProgram = GlProgram.from({\n            vertex,\n            fragment,\n            name: 'noise-filter'\n        });\n\n        const { noise, seed, ...rest } = options;\n\n        super({\n            ...rest,\n            gpuProgram,\n            glProgram,\n            resources: {\n                noiseUniforms: new UniformGroup({\n                    uNoise: { value: 1, type: 'f32' },\n                    uSeed: { value: 1, type: 'f32' },\n                })\n            },\n        });\n\n        this.noise = noise;\n        this.seed = seed ?? Math.random();\n    }\n\n    /**\n     * The amount of noise to apply to the filtered content.\n     *\n     * This value controls the intensity of the random noise effect:\n     * - Values close to 0 produce subtle noise\n     * - Values around 0.5 produce moderate noise\n     * - Values close to 1 produce strong noise\n     * @default 0.5\n     * @example\n     * ```ts\n     * const noiseFilter = new NoiseFilter();\n     *\n     * // Set to subtle noise\n     * noiseFilter.noise = 0.2;\n     *\n     * // Set to maximum noise\n     * noiseFilter.noise = 1.0;\n     * ```\n     */\n    get noise(): number\n    {\n        return this.resources.noiseUniforms.uniforms.uNoise;\n    }\n\n    set noise(value: number)\n    {\n        this.resources.noiseUniforms.uniforms.uNoise = value;\n    }\n\n    /**\n     * The seed value used for random noise generation.\n     *\n     * This value determines the noise pattern:\n     * - Using the same seed will generate identical noise patterns\n     * - Different seeds produce different but consistent patterns\n     * - `Math.random()` can be used for random patterns\n     * @default Math.random()\n     * @example\n     * ```ts\n     * const noiseFilter = new NoiseFilter();\n     *\n     * // Use a fixed seed for consistent noise\n     * noiseFilter.seed = 12345;\n     *\n     * // Generate new random pattern\n     * noiseFilter.seed = Math.random();\n     * ```\n     */\n    get seed(): number\n    {\n        return this.resources.noiseUniforms.uniforms.uSeed;\n    }\n\n    set seed(value: number)\n    {\n        this.resources.noiseUniforms.uniforms.uSeed = value;\n    }\n}\n"],"names":[],"mappings":";;;;;;;;;AAsFO,MAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,MAAA,CACjC;AAAA;AAAA;AAAA;AAAA,EAmBI,WAAA,CAAY,OAAA,GAA8B,EAAC,EAC3C;AACI,IAAA,OAAA,GAAU,EAAE,GAAG,YAAA,CAAY,cAAA,EAAgB,GAAG,OAAA,EAAQ;AAEtD,IAAA,MAAM,UAAA,GAAa,WAAW,IAAA,CAAK;AAAA,MAC/B,MAAA,EAAQ;AAAA,QACJ,MAAA;AAAA,QACA,UAAA,EAAY;AAAA,OAChB;AAAA,MACA,QAAA,EAAU;AAAA,QACN,MAAA;AAAA,QACA,UAAA,EAAY;AAAA;AAChB,KACH,CAAA;AAED,IAAA,MAAM,SAAA,GAAY,UAAU,IAAA,CAAK;AAAA,MAC7B,MAAA;AAAA,MACA,QAAA;AAAA,MACA,IAAA,EAAM;AAAA,KACT,CAAA;AAED,IAAA,MAAM,EAAE,KAAA,EAAO,IAAA,EAAM,GAAG,MAAK,GAAI,OAAA;AAEjC,IAAA,KAAA,CAAM;AAAA,MACF,GAAG,IAAA;AAAA,MACH,UAAA;AAAA,MACA,SAAA;AAAA,MACA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