Inverse

Introduction

Inverse color post processing filter.

  • Author: Rex
  • A camera filter

Usage

Sample code

Install plugin

Load minify file

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

Import plugin

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

Import class

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

Apply filter

  1. Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexInversePipeline').add(scene, key, {
        // intensity: 0
    });
    
    • intensity : 0(original color) ~ 1(gray scale)
  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(inverse color)