-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa0869e
commit bc896d2
Showing
6 changed files
with
147 additions
and
85 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
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,56 +1,54 @@ | ||
varying vec2 vTextureCoord; | ||
precision highp float; | ||
in vec2 vTextureCoord; | ||
out vec4 finalColor; | ||
|
||
uniform sampler2D uSampler; | ||
uniform float radius; | ||
uniform float angle; | ||
uniform vec2 offset; | ||
uniform vec4 filterArea; | ||
uniform vec2 uTwist; | ||
uniform vec2 uOffset; | ||
uniform vec4 uInputSize; | ||
|
||
vec2 mapCoord( vec2 coord ) | ||
{ | ||
coord *= filterArea.xy; | ||
coord += filterArea.zw; | ||
coord *= uInputSize.xy; | ||
coord += uInputSize.zw; | ||
|
||
return coord; | ||
} | ||
|
||
vec2 unmapCoord( vec2 coord ) | ||
{ | ||
coord -= filterArea.zw; | ||
coord /= filterArea.xy; | ||
coord -= uInputSize.zw; | ||
coord /= uInputSize.xy; | ||
|
||
return coord; | ||
} | ||
|
||
vec2 twist(vec2 coord) | ||
{ | ||
coord -= offset; | ||
coord -= uOffset; | ||
|
||
float dist = length(coord); | ||
float uRadius = uTwist[0]; | ||
float uAngle = uTwist[1]; | ||
|
||
if (dist < radius) | ||
if (dist < uRadius) | ||
{ | ||
float ratioDist = (radius - dist) / radius; | ||
float angleMod = ratioDist * ratioDist * angle; | ||
float ratioDist = (uRadius - dist) / uRadius; | ||
float angleMod = ratioDist * ratioDist * uAngle; | ||
float s = sin(angleMod); | ||
float c = cos(angleMod); | ||
coord = vec2(coord.x * c - coord.y * s, coord.x * s + coord.y * c); | ||
} | ||
|
||
coord += offset; | ||
coord += uOffset; | ||
|
||
return coord; | ||
} | ||
|
||
void main(void) | ||
{ | ||
|
||
vec2 coord = mapCoord(vTextureCoord); | ||
|
||
coord = twist(coord); | ||
|
||
coord = unmapCoord(coord); | ||
|
||
gl_FragColor = texture2D(uSampler, coord ); | ||
|
||
finalColor = texture(uSampler, coord); | ||
} |
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,47 @@ | ||
struct TwistUniforms { | ||
uTwist:vec2<f32>, | ||
uOffset:vec2<f32>, | ||
}; | ||
|
||
@group(0) @binding(1) var uSampler: texture_2d<f32>; | ||
@group(1) @binding(0) var<uniform> twistUniforms : TwistUniforms; | ||
|
||
@fragment | ||
fn mainFragment( | ||
@location(0) uv: vec2<f32>, | ||
@builtin(position) position: vec4<f32> | ||
) -> @location(0) vec4<f32> { | ||
return textureSample(uSampler, uSampler, unmapCoord(twist(mapCoord(uv)))); | ||
} | ||
|
||
fn unmapCoord(coord: vec2<f32> ) -> vec2<f32> | ||
{ | ||
var mappedCoord: vec2<f32> = coord; | ||
mappedCoord -= gfu.outputFrame.xy; | ||
mappedCoord /= gfu.inputSize.xy; | ||
return mappedCoord; | ||
} | ||
|
||
fn twist(coord: vec2<f32>) -> vec2<f32> | ||
{ | ||
var twistedCoord: vec2<f32> = coord; | ||
let uRadius = twistUniforms.uTwist[0]; | ||
let uAngle = twistUniforms.uTwist[1]; | ||
let uOffset = twistUniforms.uOffset; | ||
|
||
twistedCoord -= uOffset; | ||
|
||
let dist = length(twistedCoord); | ||
|
||
if (dist < uRadius) | ||
{ | ||
let ratioDist: f32 = (uRadius - dist) / uRadius; | ||
let angleMod: f32 = ratioDist * ratioDist * uAngle; | ||
let s: f32 = sin(angleMod); | ||
let c: f32 = cos(angleMod); | ||
twistedCoord = vec2<f32>(twistedCoord.x * c - twistedCoord.y * s, twistedCoord.x * s + twistedCoord.y * c); | ||
} | ||
|
||
twistedCoord += uOffset; | ||
return twistedCoord; | ||
} |
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,15 +1,14 @@ | ||
import { Point } from 'pixi.js'; | ||
|
||
export default function () | ||
{ | ||
const app = this; | ||
|
||
this.addFilter('TwistFilter', function (folder) | ||
{ | ||
this.offset = new Point(app.initWidth / 2, app.initHeight / 2); | ||
this.offsetX = app.initWidth / 2; | ||
this.offsetY = app.initHeight / 2; | ||
folder.add(this, 'angle', -10, 10); | ||
folder.add(this, 'radius', 0, app.initWidth); | ||
folder.add(this.offset, 'x', 0, app.initWidth); | ||
folder.add(this.offset, 'y', 0, app.initHeight); | ||
folder.add(this, 'offsetX', 0, app.initWidth); | ||
folder.add(this, 'offsetY', 0, app.initHeight); | ||
}); | ||
} |
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