🚚 Move whirl code to common.glsl
This commit is contained in:
@@ -23,8 +23,6 @@ uniform float uRandomness;
|
|||||||
const float ACTOR_SCALE = 2.0;
|
const float ACTOR_SCALE = 2.0;
|
||||||
const float PADDING = ACTOR_SCALE / 2.0 - 0.5;
|
const float PADDING = ACTOR_SCALE / 2.0 - 0.5;
|
||||||
|
|
||||||
// The math for the whirling is inspired by this post:
|
|
||||||
// http://www.geeks3d.com/20110428/shader-library-swirl-post-processing-filter-in-glsl
|
|
||||||
void main() {
|
void main() {
|
||||||
// We simply inverse the progress for opening windows.
|
// We simply inverse the progress for opening windows.
|
||||||
float progress = uForOpening ? 1.0 - uProgress : uProgress;
|
float progress = uForOpening ? 1.0 - uProgress : uProgress;
|
||||||
@@ -44,10 +42,7 @@ void main() {
|
|||||||
coords += progress * coords / dist * 0.5 * uSuction;
|
coords += progress * coords / dist * 0.5 * uSuction;
|
||||||
|
|
||||||
// Apply some whirling.
|
// Apply some whirling.
|
||||||
float angle = pow(1.0 - dist, 2.0) * uTwirl * progress;
|
coords = whirl(coords, uTwirl * progress, 0.0);
|
||||||
float s = sin(angle);
|
|
||||||
float c = cos(angle);
|
|
||||||
coords = vec2(dot(coords, vec2(c, -s)), dot(coords, vec2(s, c)));
|
|
||||||
|
|
||||||
// Fade out the window texture.
|
// Fade out the window texture.
|
||||||
vec4 oColor = getInputColor(coords + center);
|
vec4 oColor = getInputColor(coords + center);
|
||||||
|
|||||||
@@ -183,6 +183,15 @@ float getRelativeEdgeMask(float fadeAmount) {
|
|||||||
|
|
||||||
// ------------------------------------------------------------------------------- 2D math
|
// ------------------------------------------------------------------------------- 2D math
|
||||||
|
|
||||||
|
// The math for the whirling is inspired by this post:
|
||||||
|
// http://www.geeks3d.com/20110428/shader-library-swirl-post-processing-filter-in-glsl
|
||||||
|
vec2 whirl(vec2 coords, float warping, float rotation) {
|
||||||
|
float angle = pow(1.0 - length(coords), 2.0) * warping + rotation;
|
||||||
|
float s = sin(angle);
|
||||||
|
float c = cos(angle);
|
||||||
|
return vec2(dot(coords, vec2(c, -s)), dot(coords, vec2(s, c)));
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the shortest distance between the given point and the line defined by "origin"
|
// Returns the shortest distance between the given point and the line defined by "origin"
|
||||||
// and "direction".
|
// and "direction".
|
||||||
float distToLine(vec2 origin, vec2 direction, vec2 point) {
|
float distToLine(vec2 origin, vec2 direction, vec2 point) {
|
||||||
|
|||||||
Reference in New Issue
Block a user