Toonify

Introduction

Draw outlines and quantize color in HSV domain, post processing filter. Reference

  • Author: Rex
  • A camera filter

Source code

Plugin, minify

Usage

Sample code

User could import class directly, or install it by global plugin.

Import class

import rexToonifyPipeline from './plugins/toonifypipeline.js';

Install global plugin

Install plugin in configuration of game

import ToonifyPipelinePlugin from './plugins/toonifypipeline-plugin.js';

var config = {
    // ...
    plugins: {
        global: [{
            key: 'rexToonifyPipeline',
            plugin: ToonifyPipelinePlugin,
            start: true
        },
        // ...
        ]
    }
    // ...
};
var game = new Phaser.Game(config);

Apply filter

  1. Create pipeline instance
    var customPipeline = scene.plugins.get('rexToonifyPipeline').add(scene, key, {
        // edgeThreshold: 0.2,
        // hueLevels: 0,
        // sLevels: 0,
        // vLevels: 0,
        // edgeColor: 0
    });
    
    • edgeThreshold : Threshold of edge. Set 1.1 (or any number larger then 1) to disable this feature.
    • hueLevels : Amount of hue levels. Set 0 to disable this feature.
    • sLevels : Amount of saturation levels. Set 0 to disable this feature.
    • vLevels : Amount of value levels. Set 0 to disable this feature.
    • edgeColor : Color of edge, could be a number 0xRRGGBB, or a JSON object {r:255, g:255, b:255}
  2. Add pipeline to camera
    // var camera = scene.cameras.main;
    camera.setRenderToTexture(customPipeline);
    

Edge threshold

  • Get
    var edgeThreshold = customPipeline.edgeThreshold;
    
  • Set
    customPipeline.edgeThreshold = edgeThreshold;
    
    or
    customPipeline.setEdgeThreshold(value);
    
    • Set 1.1 (or any number larger then 1) to disable this feature.

Hue levels

  • Get
    var hueLevels = customPipeline.hueLevels;
    
  • Set
    customPipeline.hueLevels = hueLevels;
    
    or
    customPipeline.setHueLevels(value);
    
    • Set 0 to disable this feature.

Saturation levels

  • Get
    var satLevels = customPipeline.satLevels;
    
  • Set
    customPipeline.satLevels = satLevels;
    
    or
    customPipeline.setSatLevels(value);
    
    • Set 0 to disable this feature.

Value levels

  • Get
    var valLevels = customPipeline.valLevels;
    
  • Set
    customPipeline.valLevels = valLevels;
    
    or
    customPipeline.setValLevels(value);
    
    • Set 0 to disable this feature.

Edge color

  • Get
    var color = customPipeline.edgeColor;
    
    • color : Color object.
      • Red: color.red, 0~255.
      • Green: color.green, 0~255.
      • Blue: color.blue, 0~255.
  • Set
    customPipeline.edgeColor = value;
    
    • value : A number 0xRRGGBB, or a JSON object {r:255, g:255, b:255}