HSL adjust

Introduction

Adjust color in HSL domain, post processing filter.

  • 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('rexhsladjustpipelineplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexhsladjustpipelineplugin.min.js', true);
    
  • Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexhsladjustpipelineplugin').add(scene, key, config);
    

Import plugin

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

Import class

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

Apply filter

  1. Create pipeline instance
    var pipelineInstance = scene.plugins.get('rexHslAdjustPipeline').add(scene, key, {
        // hueRotate: 0,
        // satAdjust: 1,
        // lumAdjust: 0.5,
    });
    
    • hueRotate : Hue rotation
      • 0 : Rotate 0 degrees, original color (Default value)
      • 0.5 : Rotate 180 degrees
      • 1 : Rotate 360 degrees
    • satAdjust : Saturation adjustment
      • 0 : Gray
      • 1 : Original color (Default value)
      • 1 :

    • lumAdjust : Lumen adjustment
      • 0 : Dark
      • 0.5 : Original color (Default value)
      • 1 : White
  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.

Hue rotation

  • Get
    var hueRotate = pipelineInstance.hueRotate;
    
  • Set
    pipelineInstance.hueRotate = hueRotate;
    // pipelineInstance.hueRotate += value;
    
    or
    pipelineInstance.setHueRotate(value);
    
    • 0 : Rotate 0 degrees, original color
    • 0.5 : Rotate 180 degrees
    • 1 : Rotate 360 degrees

Saturation adjustment

  • Get
    var satAdjust = pipelineInstance.satAdjust;
    
  • Set
    pipelineInstance.satAdjust = satAdjust;
    // pipelineInstance.satAdjust += value;
    
    or
    pipelineInstance.setSatAdjust(value);
    
    • 0 : Gray
    • 1 : Original color
    • 1 :

Lumen adjustment

  • Get
    var lumAdjust = pipelineInstance.lumAdjust;
    
  • Set
    pipelineInstance.lumAdjust = lumAdjust;
    // pipelineInstance.lumAdjust += value;
    
    or
    pipelineInstance.setLumAdjust(value);
    
    • 0 : Dark
    • 0.5 : Original color
    • 1 : White