-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '0cd3bb6672baa96ab1a9a08608d740b3fcb4331d'
- Loading branch information
Showing
138 changed files
with
9,249 additions
and
1,042 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
Currently just has a method `ct.desktop.quit()`, which exits the game when packaged into executables. | ||
Currently just has a method `ct.desktop.quit()`, which exits the game when packaged into executables. | ||
|
||
Also has variables `ct.desktop.isNw` and `ct.desktop.isElectron` to differentiate between these two platforms. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
/* global nw */ | ||
ct.desktop = { | ||
isNw: window.nw && window.nw.App, | ||
isElectron: null, | ||
quit() { | ||
if (window.nw && window.nw.App) { | ||
if (ct.desktop.isNw) { | ||
if (window.iAmInCtIdeDebugger) { | ||
nw.Window.get().close(); | ||
// eslint-disable-next-line no-console | ||
console.warn('We don\'t quit because ct.js would quit as well. Let\'s imagine that the game has exited! :D'); | ||
} else { | ||
nw.App.quit(); | ||
} | ||
return true; | ||
} | ||
try { | ||
} else if (ct.desktop.isElectron) { | ||
require('electron').remote.getCurrentWindow().close(); | ||
return true; | ||
} catch (e) { | ||
console.error('Could not exit the game :c Are we in a browser?'); | ||
return false; | ||
} else { | ||
console.error('[ct.desktop/quit] Unknown environment :c Are we in a browser?'); | ||
} | ||
} | ||
}; | ||
|
||
try { | ||
require('electron'); | ||
ct.desktop.isElectron = true; | ||
} catch (e) { | ||
ct.desktop.isElectron = false; | ||
} | ||
|
||
ct.desktop.isDesktop = ct.desktop.isNw || ct.desktop.isElectron; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Version 1.0.0 | ||
|
||
- Initial release | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# ct.filters | ||
|
||
This module is a collection of shader filters. | ||
It includes [PixiJS built-in filters](https://pixijs.download/dev/docs/PIXI.filters.html) and [additional PixiJS community-authored filters](https://filters.pixijs.download/main/docs/PIXI.filters.html) (version 3.2.2, 30 december 2020). | ||
|
||
For each filter, you can check the PixiJS doc (links above) or use the ct.js autocomplete (to get all filters, all options of each filter, descriptions, types, and default values). | ||
|
||
You can also interactively play with those filters to see how they work [here](https://pixijs.io/pixi-filters/tools/demo/). | ||
|
||
## How it works? | ||
|
||
All PIXI.DisplayObject (stage, room, copy, container, etc.) have a `filters` property. | ||
It's an `array`. | ||
You can add/remove/enable/disable several filters on the same element (beware of performance of course). | ||
|
||
## How to add a filter with default options? | ||
|
||
```js | ||
const fx = ct.filters.addCRT(this); | ||
``` | ||
|
||
## How to add a filter with mandatory params? | ||
|
||
```js | ||
// Replaces pure red with pure blue, and replaces pure green with pure white | ||
const replacements = [ | ||
[0xff0000, 0x0000ff], | ||
[0x00ff00, 0xffffff], | ||
]; | ||
const fx = ct.filters.addMultiColorReplace(this, replacements); | ||
``` | ||
|
||
## How to edit a filter? | ||
|
||
```js | ||
const fx = ct.filters.addGlow(this); | ||
fx.color = 0xff004d; | ||
fx.innerStrength = 1; | ||
``` | ||
|
||
If you type `fx.` the autocomplete will show all the available options (with description, type and default value) for that filter. | ||
|
||
Tip: You can `console.log` your `fx`, unfold the object and live tweak properties. | ||
|
||
## Example of a very interesting filter with presets/methods: | ||
|
||
```js | ||
const fx = ct.filters.addColorMatrix(this); | ||
// You can determine your own color matrix: | ||
fx.matrix = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0.5, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]; | ||
// Or use some nice predefined ones: | ||
fx.night(0.1, true); | ||
fx.polaroid(true); | ||
fx.vintage(true); | ||
``` | ||
|
||
For more (`browni`, `kodachrome`, `predator`, etc.) check the doc: | ||
http://pixijs.download/release/docs/PIXI.filters.ColorMatrixFilter.html | ||
|
||
## How to enable/disable a filter? | ||
|
||
```js | ||
const fx = ct.filters.addGodray(this); | ||
fx.enabled = false; | ||
``` | ||
|
||
If enabled is `true` the filter is applied, if `false` it will not. | ||
|
||
## How to remove a filter? | ||
|
||
```js | ||
const fx = ct.filters.addCRT(this); | ||
ct.filters.removeFilter(this, fx); | ||
``` | ||
|
||
It removes a filter (`fx` in this example) from `this.filters`. | ||
|
||
## How to add a custom filter? | ||
|
||
```js | ||
const fragment = ` | ||
varying vec2 vTextureCoord; | ||
uniform sampler2D uSampler; | ||
uniform float red; | ||
uniform float green; | ||
uniform float blue; | ||
void main(void) | ||
{ | ||
vec4 c = texture2D(uSampler, vTextureCoord); | ||
vec3 rgb = c.rgb; | ||
rgb.r *= red; | ||
rgb.g *= green; | ||
rgb.b *= blue; | ||
c.rgb = rgb; | ||
gl_FragColor = c; | ||
} | ||
`; | ||
|
||
const uniforms = { | ||
red: 1, | ||
green: 0.8, | ||
blue: 0.2} | ||
|
||
const fx = ct.filters.custom(this, undefined, fragment, uniforms); | ||
``` | ||
Mind, PIXI has a default vertex shader and a default fragment shader. | ||
For more info, you can check these links: | ||
|
||
* https://pixijs.download/dev/docs/PIXI.Filter.html | ||
* https://github.com/pixijs/pixi.js/wiki/v5-Creating-filters |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* Based on https://pixijs.io/pixi-filters/docs/PIXI.filters */ | ||
/* Sandbox demo: https://pixijs.io/pixi-filters/tools/demo/ */ | ||
|
||
(() => { | ||
const filters = [ | ||
'Adjustment', | ||
'AdvancedBloom', | ||
'Ascii', | ||
'Bevel', | ||
'Bloom', | ||
'BulgePinch', | ||
'ColorMap', | ||
'ColorOverlay', | ||
'ColorReplace', | ||
'Convolution', | ||
'CrossHatch', | ||
'CRT', | ||
'Dot', | ||
'DropShadow', | ||
'Emboss', | ||
'Glitch', | ||
'Glow', | ||
'Godray', | ||
'KawaseBlur', | ||
'MotionBlur', | ||
'MultiColorReplace', | ||
'OldFilm', | ||
'Outline', | ||
'Pixelate', | ||
'RadialBlur', | ||
'Reflection', | ||
'RGBSplit', | ||
'Shockwave', | ||
'SimpleLightmap', | ||
'TiltShift', | ||
'Twist', | ||
'ZoomBlur', | ||
//Built-in filters | ||
'Alpha', | ||
'Blur', | ||
'BlurPass', | ||
'ColorMatrix', | ||
'Displacement', | ||
'FXAA', | ||
'Noise' | ||
]; | ||
|
||
const addFilter = (target, fx) => { | ||
if (!target.filters) { | ||
target.filters = [fx]; | ||
} else { | ||
target.filters.push(fx); | ||
} | ||
return fx; | ||
}; | ||
|
||
const createFilter = (target, filter, ...args) => { | ||
let fx; | ||
let filterName = filter + 'Filter'; | ||
if (filterName === 'BlurPassFilter') { | ||
filterName = 'BlurFilterPass'; | ||
} | ||
if (args.length > 0) { | ||
fx = new PIXI.filters[filterName](...args); | ||
} else { | ||
fx = new PIXI.filters[filterName](); | ||
} | ||
return addFilter(target, fx); | ||
}; | ||
|
||
ct.filters = {}; | ||
|
||
for (const filter of filters) { | ||
ct.filters['add' + filter] = (target, ...args) => | ||
createFilter(target, filter, ...args); | ||
} | ||
|
||
ct.filters.remove = (target, filter) => { | ||
for (const f in target.filters) { | ||
if (target.filters[f] === filter) { | ||
target.filters.splice(f, 1); | ||
} | ||
} | ||
}; | ||
|
||
ct.filters.custom = (target, vertex, fragment, uniforms) => { | ||
const fx = new PIXI.Filter(vertex, fragment, uniforms); | ||
return addFilter(target, fx); | ||
} | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script type="text/javascript" src="./pixi-filters.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"main": { | ||
"name": "Filters", | ||
"tagline": "Add filters and custom shaders to create special effects on your copies or whole viewport", | ||
"version": "1.0.0", | ||
"packageName": "filters", | ||
"authors": [ | ||
{ | ||
"name": "SN" | ||
} | ||
], | ||
"categories": [ | ||
"FX" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "Filters", | ||
"version": "1.0.0", | ||
"description": "Add shaders filters", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"eslint": "^6.5.1" | ||
} | ||
} |
Oops, something went wrong.