This repository has been archived on 2023-05-27. You can view files and clone it, but cannot push or open issues or pull requests.
api8/shaders/twister.fs

34 lines
816 B
Forth
Raw Permalink Normal View History

2023-05-25 10:29:35 +02:00
#version 330
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform float progress;
in vec2 vsoTexCoord;
out vec4 fragColor;
2023-05-25 10:43:26 +02:00
// Fonction de déformation
2023-05-25 16:41:32 +02:00
vec2 deform(float it) {
2023-05-25 10:43:26 +02:00
vec2 center = vec2(0.5);
2023-05-25 10:29:35 +02:00
vec2 offset = vsoTexCoord - center;
2023-05-25 10:43:26 +02:00
// Torsion
2023-05-25 16:41:32 +02:00
float angle = offset.y * it * radians(180) * 2;
2023-05-25 10:29:35 +02:00
float cosTheta = cos(angle);
2023-05-25 10:43:26 +02:00
float sinTheta = sin(angle);
vec2 twistedOffset = vec2(cosTheta * offset.x - sinTheta * offset.y, sinTheta * offset.x + cosTheta * offset.y);
2023-05-25 10:29:35 +02:00
2023-05-25 10:43:26 +02:00
// Vague
float wave = sin(twistedOffset.y * 20);
2023-05-25 16:41:32 +02:00
vec2 deformedUV = twistedOffset + vec2(wave * it, 0);
2023-05-25 10:29:35 +02:00
2023-05-25 10:43:26 +02:00
return center + deformedUV;
}
void main() {
vec4 color1 = texture(tex0, deform(progress));
vec4 color2 = texture(tex1, deform(1. - progress));
2023-05-25 10:29:35 +02:00
fragColor = mix(color1, color2, smoothstep(0., 1., progress));
}