Toonify
Introduction¶
Draw outlines and quantize color in HSV domain, post processing filter. Reference
- Author: Rex
- A post-fx shader effect
WebGL only
Only work in WebGL render mode.
Live demos¶
Usage¶
Install plugin¶
Load minify file¶
- Load plugin (minify file) in preload stage
scene.load.plugin('rextoonifypipelineplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rextoonifypipelineplugin.min.js', true);
- Apply effect
- Apply effect to game object
var pipelineInstance = scene.plugins.get('rextoonifypipelineplugin').add(gameObject, config);
- Apply effect to camera
var pipelineInstance = scene.plugins.get('rextoonifypipelineplugin').add(camera, config);
- Apply effect to game object
Import plugin¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Install plugin in configuration of game
import ToonifyPipelinePlugin from 'phaser3-rex-plugins/plugins/toonifypipeline-plugin.js'; var config = { // ... plugins: { global: [{ key: 'rexToonifyPipeline', plugin: ToonifyPipelinePlugin, start: true }, // ... ] } // ... }; var game = new Phaser.Game(config);
- Apply effect
- Apply effect to game object
var pipelineInstance = scene.plugins.get('rexToonifyPipeline').add(gameObject, config);
- Apply effect to camera
var pipelineInstance = scene.plugins.get('rexToonifyPipeline').add(camera, config);
- Apply effect to game object
Import class¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Add to game config
import ToonifyPostFx from 'phaser3-rex-plugins/plugins/toonifypipeline.js'; var config = { // ... pipeline: [ToonifyPostFx] // ... }; var game = new Phaser.Game(config);
- Apply effect
- Apply effect to game object
gameObject.setPostPipeline(ToonifyPostFx);
- Apply effect to camera
camera.setPostPipeline(ToonifyPostFx);
- Apply effect to game object
Apply effect¶
- Apply effect to game object. A game object only can add 1 toonify effect.
var pipelineInstance = scene.plugins.get('rexToonifyPipeline').add(gameObject, { // edgeThreshold: 0.2, // hueLevels: 0, // sLevels: 0, // vLevels: 0, // edgeColor: 0, // name: 'rexToonifyPostFx' });
edgeThreshold
: Threshold of edge. Set1.1
(or any number larger then1
) to disable this feature.hueLevels
: Amount of hue levels. Set0
to disable this feature.sLevels
: Amount of saturation levels. Set0
to disable this feature.vLevels
: Amount of value levels. Set0
to disable this feature.edgeColor
: Color of edge, could be a number0xRRGGBB
, or a JSON object{r:255, g:255, b:255}
- Apply effect to camera. A camera only can add 1 toonify effect.
var pipelineInstance = scene.plugins.get('rexToonifyPipeline').add(camera, config);
Remove effect¶
- Remove effect from game object
scene.plugins.get('rexToonifyPipeline').remove(gameObject);
- Remove effect from camera
scene.plugins.get('rexToonifyPipeline').remove(camera);
Get effect¶
- Get effect from game object
var pipelineInstance = scene.plugins.get('rexToonifyPipeline').get(gameObject)[0]; // var pipelineInstances = scene.plugins.get('rexToonifyPipeline').get(gameObject);
- Get effect from camera
var pipelineInstance = scene.plugins.get('rexToonifyPipeline').get(camera)[0]; // var pipelineInstances = scene.plugins.get('rexToonifyPipeline').get(camera);
Edge threshold¶
- Get
var edgeThreshold = pipelineInstance.edgeThreshold;
- Set
or
pipelineInstance.edgeThreshold = edgeThreshold;
pipelineInstance.setEdgeThreshold(value);
- Set
1.1
(or any number larger then1
) to disable this feature.
- Set
Hue levels¶
- Get
var hueLevels = pipelineInstance.hueLevels;
- Set
or
pipelineInstance.hueLevels = hueLevels;
pipelineInstance.setHueLevels(value);
- Set
0
to disable this feature.
- Set
Saturation levels¶
- Get
var satLevels = pipelineInstance.satLevels;
- Set
or
pipelineInstance.satLevels = satLevels;
pipelineInstance.setSatLevels(value);
- Set
0
to disable this feature.
- Set
Value levels¶
- Get
var valLevels = pipelineInstance.valLevels;
- Set
or
pipelineInstance.valLevels = valLevels;
pipelineInstance.setValLevels(value);
- Set
0
to disable this feature.
- Set
Edge color¶
- Get
var color = pipelineInstance.edgeColor;
color
: Color object.- Red:
color.red
, 0~255. - Green:
color.green
, 0~255. - Blue:
color.blue
, 0~255.
- Red:
- Set
or
pipelineInstance.setEdgeColor(value);
pipelineInstance.edgeColor = value;
value
: A number0xRRGGBB
, or a JSON object{r:255, g:255, b:255}