Skip to content

Commit

Permalink
Merge pull request #554 from excaliburjs/release-prep
Browse files Browse the repository at this point in the history
Update post processor documentation
  • Loading branch information
eonarheim committed Jan 3, 2016
2 parents 4d4d34c + 7f90159 commit b7da9d7
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* - [[Sound|Working with Sounds]]
* - [[SpriteSheet|Working with SpriteSheets]]
* - [[Animation|Working with Animations]]
* - [[TileMap|Working with TileMaps]]
*
* ## Effects and Particles
*
Expand All @@ -88,6 +89,7 @@
*
* - [[Effects|Sprite Effects]]
* - [[ParticleEmitter|Particle Emitters]]
* - [[IPostProcessor|Post Processors]]
*
* ## Math
*
Expand Down
24 changes: 23 additions & 1 deletion src/engine/PostProcessing/ColorBlindCorrector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,29 @@ module ex {
Tritanope
}

// Color correction algorithm originally sourced from http://www.daltonize.org/

/**
* This post processor can correct colors and simulate color blindness.
* It is possible to use this on every game, but the game's performance
* will suffer measurably. It's better to use it as a helpful tool while developing your game.
* Remember, the best practice is to design with color blindness in mind.
*
* Color correction algorithm originally sourced from http://www.daltonize.org/
*
* Example:
* ```typescript
*
* var game = new ex.Engine();
*
* var colorBlindPostProcessor = new ex.ColorBlindCorrector(game, false, ColorBlindness.Protanope);
*
* // post processors evaluate left to right
* game.postProcessors.push(colorBlindPostProcessor);
* game.start();
*
* ```
*
*/
export class ColorBlindCorrector implements IPostProcessor {

private _vertexShader =
Expand Down
68 changes: 68 additions & 0 deletions src/engine/PostProcessing/IPostProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,72 @@
 module ex {

/**
* Post Processors
*
* Sometimes it is necessary to apply an effect to the canvas after the engine has completed its drawing pass. A few reasons to do
* this might be creating a blur effect, adding a lighting effect, or changing how colors and pixels look.
*
* ## Basic post procesors
*
* To create and use a post processor you just need to implement a class that implements [[IPostProcessor]], which has one method
* [[IPostProcessor.process]]. Set the `out` canvas parameter to the final result, using the `image` pixel data.
*
* Click to read more about [[https://developer.mozilla.org/en-US/docs/Web/API/ImageData|ImageData]] on MDN.
*
* For example:
* ```typescript
* // simple way to grayscale, a faster way would be to implement using a webgl fragment shader
* class GrayscalePostProcessor implements IPostProcessor {
* process(image: ImageData, out: CanvasRenderingContext2D) {
* for(var i = 0; i < (image.height * image.width), i+=4){
* // for pixel "i""
* var r = image.data[i+0]; //0-255
* var g = image.data[i+1]; //g
* var b = image.data[i+2]; //b
* image.data[i+3]; //a
* var result = Math.floor((r + g + b) / 3.0) | 0; // only valid on 0-255 integers `| 0` forces int
* image.data[i+0] = result;
* image.data[i+1] = result;
* image.data[i+2] = result;
* }
* // finish processing and write result
* out.putImageData(image, 0, 0);
* }
* }
*
* ```
*
* ## Color Blind Corrector Post Processor
*
* Choosing colors that are friendly to players with color blindness is an important consideration when making a game.
* There is a significant portion of the population that has some form of color blindness,
* and choosing bad colors can make your game unplayable. We have built
* a post procesors that can shift your colors into as more visible range for the 3 most common types of
* [[https://en.wikipedia.org/wiki/Color_blindness|color blindness]].
*
* - [[ColorBlindness.Protanope|Protanope]]
* - [[ColorBlindness.Deuteranope|Deuteranope]]
* - [[ColorBlindness.Tritanope|Tritanope]]
*
* This post processor can correct colors, and simulate color blindness.
* It is possible to use this on every game, but the game's performance
* will suffer measurably. It's better to use it as a helpful tool while developing your game.
* Remember, the best practice is to design with color blindness in mind.
*
* Example:
* ```typescript
*
* var game = new ex.Engine();
*
* var colorBlindPostProcessor = new ex.ColorBlindCorrector(game, false, ColorBlindness.Protanope);
*
* // post processors evaluate left to right
* game.postProcessors.push(colorBlindPostProcessor);
* game.start();
*
* ```
*
*/
export interface IPostProcessor {
process(image: ImageData, out: CanvasRenderingContext2D): void;
}
Expand Down

0 comments on commit b7da9d7

Please sign in to comment.