Glow

Introduction

Glow post processing filter. Reference

  • Author: Rex
  • A camera filter

Live demos

Usage

Sample code

Install plugin

Load minify file

  • Load plugin (minify file) in preload stage
    scene.load.plugin('rexglowfilterpipelineplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexglowfilterpipelineplugin.min.js', true);
    
  • Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexglowfilterpipelineplugin').add(scene, key, config);
    

Import plugin

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Install plugin in configuration of game
    import GlowFilterPipelinePlugin from 'phaser3-rex-plugins/plugins/glowfilterpipeline-plugin.js';
    var config = {
        // ...
        plugins: {
            global: [{
                key: 'rexGlowFilterPipeline',
                plugin: GlowFilterPipelinePlugin,
                start: true
            },
            // ...
            ]
        }
        // ...
    };
    var game = new Phaser.Game(config);
    
  • Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexGlowFilterPipeline').add(scene, key, config);
    

Import class

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Import class
    import GlowFilterPipeline from 'phaser3-rex-plugins/plugins/glowfilterpipeline.js';
    
  • Create pipeline instance
    var pipelineInstance = new GlowFilterPipeline(scene, key, config);
    

Apply filter

  1. Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexGlowFilterPipeline').add(scene, key, {
        // intensity: 0
    });
    
    • intensity : 0(original color) ~ 1(white color)
      • Suggestion value : 0 ~ 0.02
  2. Add to render pipeline
    scene.game.renderer.addPipeline(pipelineName, pipelineInstance);
    
  3. Apply filter
    • To camera
      // var camera = scene.cameras.main;
      camera.setRenderToTexture(pipelineName);
      
    • To game object
      gameObject.setPipeline(pipelineName);
      
      • pipelineName : Name of this render pipeline, a string.

Intensity

  • Get
    var intensity = pipelineInstance.intensity;
    
  • Set
    pipelineInstance.intensity = intensity;
    // pipelineInstance.intensity += value;
    
    or
    pipelineInstance.setIntensity(radius);
    
    • intensity : 0(original color) ~ 1(white color)
      • Suggestion value : 0 ~ 0.02