-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fog filter (experimental, might change at any time, use at …
…your own risk) Closes #67
- Loading branch information
Showing
11 changed files
with
302 additions
and
158 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,45 +1,139 @@ | ||
import { fog } from "./shaders/fog.js"; | ||
import { customVertex2D } from "./shaders/customvertex2D.js"; | ||
import { FXMasterFilterEffectMixin } from "./mixins/filter.js"; | ||
import fog from "./shaders/fog.frag"; | ||
import customVertex2D from "./shaders/custom-vertex-2d.vert"; | ||
import { FadingFilterMixin } from "./mixins/fading-filter.js"; | ||
|
||
export class FogFilter extends FXMasterFilterEffectMixin(PIXI.Filter) { | ||
export class FogFilter extends FadingFilterMixin(PIXI.Filter) { | ||
constructor(options, id) { | ||
super(options, id, customVertex2D, fog); | ||
this.color = new Float32Array([1.0, 0.4, 0.1, 0.55]); | ||
this.dimensions = new Float32Array([1.0, 1.0]); | ||
this.time = 0.0; | ||
this.density = 0.65; | ||
this.uniforms.time = 0.0; | ||
this.uniforms.dimensions = new Float32Array([0.0, 0.0]); | ||
this.uniforms.color = new Float32Array([0.0, 0.0, 0.0, 1.0]); | ||
} | ||
|
||
/** @type {number} */ | ||
lastTick; | ||
|
||
/** @override */ | ||
static label = "FXMASTER.FilterEffectFog"; | ||
|
||
/** @override */ | ||
static icon = "fas fa-cloud"; | ||
|
||
apply(filterManager, input, output, clear) { | ||
this.uniforms.color = this.color; | ||
this.uniforms.dimensions = this.dimensions; | ||
this.uniforms.time = this.time; | ||
this.uniforms.density = this.density; | ||
this.uniforms.dimensions = this.dimensions; | ||
/** @override */ | ||
static get parameters() { | ||
return { | ||
dimensions: { | ||
label: "FXMASTER.Scale", | ||
type: "range", | ||
max: 5, | ||
min: 0, | ||
step: 0.1, | ||
value: 1, | ||
skipInitialAnimation: true, | ||
}, | ||
speed: { | ||
label: "FXMASTER.Speed", | ||
type: "range", | ||
max: 5, | ||
min: 0, | ||
step: 0.1, | ||
value: 1, | ||
skipInitialAnimation: true, | ||
}, | ||
density: { | ||
label: "FXMASTER.Density", | ||
type: "range", | ||
max: 1, | ||
min: 0, | ||
step: 0.05, | ||
value: 0.65, | ||
}, | ||
color: { | ||
label: "FXMASTER.Tint", | ||
type: "color", | ||
value: { | ||
value: "#000000", | ||
apply: false, | ||
}, | ||
skipInitialAnimation: true, | ||
}, | ||
}; | ||
} | ||
|
||
filterManager.applyFilter(this, input, output, clear); | ||
/** @override */ | ||
static get neutral() { | ||
return { | ||
density: 0, | ||
}; | ||
} | ||
|
||
/** @type {number} */ | ||
get r() { | ||
return this.uniforms.color[0]; | ||
} | ||
set r(value) { | ||
this.uniforms.color[0] = value; | ||
} | ||
|
||
/** @type {number} */ | ||
get g() { | ||
return this.uniforms.color[1]; | ||
} | ||
set g(value) { | ||
this.uniforms.color[1] = value; | ||
} | ||
|
||
/** @type {number} */ | ||
get b() { | ||
return this.uniforms.color[2]; | ||
} | ||
set b(value) { | ||
this.uniforms.color[2] = value; | ||
} | ||
|
||
/** @type {number} */ | ||
get density() { | ||
return this.uniforms.density; | ||
} | ||
set density(value) { | ||
this.uniforms.density = value; | ||
} | ||
|
||
/** @type {number} */ | ||
get dimensions() { | ||
return this.uniforms.dimensions[0]; | ||
} | ||
set dimensions(value) { | ||
this.uniforms.dimensions[0] = this.uniforms.dimensions[1] = (value * 100) / (canvas?.dimensions?.size ?? 100); | ||
} | ||
|
||
/** @override */ | ||
static get parameters() { | ||
return {}; | ||
configure(options) { | ||
if (!options) { | ||
return; | ||
} | ||
const { color, ...otherOptions } = options; | ||
const { r, g, b } = foundry.utils.Color.from(color.apply ? color.value : 0x000000); | ||
super.configure({ ...otherOptions, r, g, b }); | ||
} | ||
|
||
/** @override */ | ||
static get neutral() { | ||
return {}; | ||
play(options) { | ||
this.lastTick = canvas.app.ticker.lastTime; | ||
super.play(options); | ||
} | ||
|
||
/** @override */ | ||
async step() { | ||
this.time = canvas.app.ticker.lastTime; | ||
const delta = canvas.app.ticker.lastTime - this.lastTick; | ||
this.lastTick = canvas.app.ticker.lastTime; | ||
this.uniforms.time += delta * this.speed * 0.1; | ||
await super.step(); | ||
} | ||
|
||
apply(filterManager, input, output, clear, currentState) { | ||
this.uniforms.filterMatrix ??= new PIXI.Matrix(); | ||
this.uniforms.filterMatrix.copyFrom(currentState.target.worldTransform).invert(); | ||
return super.apply(filterManager, input, output, clear, currentState); | ||
} | ||
} |
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
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,22 @@ | ||
// SPDX-FileCopyrightText: 2022 Johannes Loher | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
precision mediump float; | ||
|
||
attribute vec2 aVertexPosition; | ||
|
||
uniform mat3 projectionMatrix; | ||
uniform mat3 filterMatrix; | ||
uniform vec4 inputSize; | ||
uniform vec4 outputFrame; | ||
|
||
varying vec2 vTextureCoord; | ||
varying vec2 vFilterCoord; | ||
|
||
void main(void) { | ||
vTextureCoord = aVertexPosition * (outputFrame.zw * inputSize.zw); | ||
vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy; | ||
vFilterCoord = (filterMatrix * vec3(position, 1.0)).xy; | ||
gl_Position = vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0); | ||
} |
Oops, something went wrong.