PixiJS Filters

repository·main·Indexed 22 days ago

https://github.com/pixijs/filters

A collection of specialized shaders and filters for the PixiJS rendering engine, providing effects such as bloom, blur, color adjustments, and stylized distortions. Includes a wide range of built-in filters like AdjustmentFilter, AdvancedBloomFilter, AsciiFilter, and ColorGradientFilter. Version 6.1.5 is compatible with PixiJS v8.x.

Tokens
15.7K
Snippets
69
Records
84
Agent score
76%

What's inside pixi-filters

  1. Build the pixi-filters project

    main

    If you are developing or contributing to the pixi-filters repository, you can manage the project using the following commands:

    1. Install dependencies: Run npm install to set up the environment.
    2. Build project: Run npm run build to compile all filters, the demo site, and generate screenshots.
    3. Watch mode: Run npm run watch to automatically rebuild the filters and demo whenever source files are changed.
    npm install
    npm run build
    npm run watch
  2. Install pixi-filters via CDN

    main

    For browser-based projects without a build step, you can include the minified bundle directly via JSDelivr.

    <script src="https://cdn.jsdelivr.net/npm/pixi-filters@latest/dist/browser/pixi-filters.min.js"></script>
  3. Advanced GlitchFilter manipulation

    main

    For fine-grained control over the glitch effect, you can manually manipulate the internal displacement map components:

    • sizes: A Float32Array representing the height of each slice. Setting this manually allows for custom band thickness.
    • offsets: A Float32Array of values between -1 and 1 representing the displacement for each slice.
    • redraw(): Forces the internal canvas (displacement map) to update based on current sizes and offsets.
    • texture: The GlitchFilter uses an internal Texture as a displacement map. If you provide your own texture, the slices property will be ignored.
    // Manually setting slice sizes and offsets
    const customSizes = new Float32Array([0.1, 0.5, 0.4]);
    const customOffsets = new Float32Array([0.5, -0.2, 0.8]);
    
    glitchFilter.sizes = customSizes;
    glitchFilter.offsets = customOffsets;
    
    // Apply the changes to the displacement map
    glitchFilter.redraw();
  4. Configure AdvancedBloomFilter options

    main

    When creating an AdvancedBloomFilter, you can pass an AdvancedBloomFilterOptions object. The following properties are available:

    PropertyTypeDefaultDescription
    thresholdnumber0.5Defines how bright a color needs to be to affect bloom.
    bloomScalenumber1Adjusts the strength of the bloom. Higher values increase intensity.
    brightnessnumber1Controls the overall brightness of the bloom effect.
    blurnumber8The strength of the blur properties.
    kernelsnumber[]undefinedSpecific kernel sizes for the blur.
    qualitynumber4The quality of the blur filter.
    pixelSizePointData | number[] | number{x:1, y:1}The pixel size of the blur filter. Larger values result in a blurrier effect.
    const options: AdvancedBloomFilterOptions = {
        threshold: 0.6,
        bloomScale: 2,
        brightness: 1,
        blur: 10,
        quality: 5,
        pixelSize: { x: 2, y: 2 }
    };
    const filter = new AdvancedBloomFilter(options);
  5. Configure SimplexNoiseFilter options

    main

    When creating a SimplexNoiseFilter, you can pass the following options in the constructor:

    OptionTypeDefaultDescription
    strengthnumber0.5Noise map strength. Formula: (noiseMap + strength) * texture
    noiseScalenumber10.0The scale of the noise map
    offsetXnumber0Horizontal offset for the noise map
    offsetYnumber0Vertical offset for the noise map
    offsetZnumber0Depth offset for the noise map
    stepnumber-1Threshold for the step function. If > 0, creates a blocky effect by comparing noise value to this threshold.
  6. Configure ReflectionFilterOptions

    main

    When instantiating ReflectionFilter, you can provide an options object with the following properties:

    PropertyTypeDefaultDescription
    mirrorbooleantrueIf true, the image is reflected. If false, only waves are applied.
    boundarynumber0.5Vertical position of the reflection point. Smaller numbers produce a larger reflection; larger numbers produce a smaller reflection.
    amplitudeRange[0, 20]Starting and ending amplitude of waves.
    waveLengthRange[30, 100]Starting and ending length of waves.
    alphaRange[1, 1]Starting and ending alpha values.
    timenumber0Time for animating the position of waves.

    Note: Range is defined as [number, number] | Float32Array.

    const options: ReflectionFilterOptions = {
        mirror: true,
        boundary: 0.5,
        amplitude: [0, 20],
        waveLength: [30, 100],
        alpha: [1, 1],
        time: 0
    };
  7. Configure TiltShiftFilterOptions

    main

    When constructing a TiltShiftFilter, you can provide a TiltShiftFilterOptions object to configure the initial state of the effect:

    PropertyTypeDescription
    blurnumberThe strength of the blur.
    gradientBlurnumberThe strength of the blur gradient.
    startPointDataThe position to start the effect at (e.g., { x: 0.5, y: 0.5 }).
    endPointDataThe position to end the effect at (e.g., { x: 0.5, y: 0.5 }).
    export interface TiltShiftFilterOptions
    {
        blur?: number;
        gradientBlur?: number;
        start?: PointData;
        end?: PointData;
    }
  8. Configure OldFilmFilter options

    main

    When instantiating OldFilmFilter, you can provide an OldFilmFilterOptions object. The following properties are available (defaults are provided if omitted):

    PropertyTypeDefaultDescription
    sepianumber0.3Saturation of sepia effect (1 is high, 0 is none).
    noisenumber0.3Opacity/intensity of the noise effect (0 to 1).
    noiseSizenumber1The size of the noise particles.
    scratchnumber0.5How often scratches appear.
    scratchDensitynumber0.3The density of the number of scratches.
    scratchWidthnumber1The width of the scratches.
    vignettingnumber0.3Radius of the vignette effect (smaller is smaller).
    vignettingAlphanumber1Opacity of the vignette.
    vignettingBlurnumber1Blur intensity of the vignette.
    seednumber0A seed value for random noise generation.
  9. Configure GlitchFilterOptions

    main

    When instantiating GlitchFilter, you can pass a GlitchFilterOptions object to define the initial state of the effect.

    OptionTypeDefaultDescription
    slicesnumber5The count of glitch slices.
    offsetnumber100The maximum offset amount of slices.
    directionnumber0The angle in degrees of the offset of slices.
    fillModenumber0 (TRANSPARENT)The fill mode of the space after the offset.
    seednumber0A seed value for randomizing glitch effect.
    averagebooleanfalseIf true, divides bands roughly equally; if false, varies band sizes dramatically.
    minSizenumber8Minimum size of slices as a portion of the sampleSize.
    sampleSizenumber512Height of the displacement map canvas.
    redPointData | number[]{x:0, y:0}Red channel offset.
    greenPointData | number[]{x:0, y:0}Green channel offset.
    bluePointData | number[]{x:0, y:0}Blue channel offset.
  10. Configure ShockwaveFilterOptions

    main

    When instantiating a ShockwaveFilter, you can provide a ShockwaveFilterOptions object to configure the following properties:

    PropertyTypeDefaultDescription
    centerPointData{x:0, y:0}The x and y center coordinates of the effect.
    speednumber500The speed the shockwave ripples out in pixels-per-second.
    amplitudenumber30The amplitude of the shockwave.
    wavelengthnumber160The wavelength of the shockwave.
    brightnessnumber1The brightness of the shockwave.
    radiusnumber-1The maximum radius. A value < 0 results in an infinite distance.
    timenumber0The elapsed time of the shockwave.
    export interface ShockwaveFilterOptions
    {
        center?: PointData;
        speed?: number;
        amplitude?: number;
        wavelength?: number;
        brightness?: number;
        radius?: number;
        time?: number;
    }
  11. Configure CRTFilterOptions

    main

    When instantiating CRTFilter, you can pass a CRTFilterOptions object. The following options are available (defaults are provided if omitted):

    OptionTypeDefaultDescription
    curvaturenumber1Bend of interlaced lines; higher values increase bend.
    lineWidthnumber1Width of the interlaced lines.
    lineContrastnumber0.25Contrast of the interlaced lines.
    verticalLinebooleanfalsetrue for vertical lines, false for horizontal lines.
    timenumber0Used for animating interlaced lines.
    noisenumber0.3Opacity/intensity of the noise effect (range 0 to 1).
    noiseSizenumber1The size of the noise particles.
    seednumber0A seed value for random noise generation.
    vignettingnumber0.3Radius of the vignette effect; smaller values produce a smaller vignette.
    vignettingAlphanumber1Amount of opacity on the vignette.
    vignettingBlurnumber0.3Blur intensity of the vignette.
    const options: CRTFilterOptions = {
        curvature: 1.0,
        lineWidth: 1.0,
        lineContrast: 0.25,
        verticalLine: false,
        noise: 0.0,
        noiseSize: 1.0,
        vignetting: 0.3,
        vignettingAlpha: 1.0,
        vignettingBlur: 0.3,
        time: 0.0,
        seed: 0.0,
    };
    
    const filter = new CRTFilter(options);