-
Notifications
You must be signed in to change notification settings - Fork 1
/
ShapeMorph.glsl
68 lines (46 loc) · 1.84 KB
/
ShapeMorph.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#version 150
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
uniform vec3 spectrum;
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D prevFrame;
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
void main(void)
{
float speed = 1;
float adjustedTime = time * speed;
vec2 coord = gl_FragCoord.xy; // screen coord
vec2 screenUV = coord / resolution.x; // UV coord using height
vec2 screenUVCentered = (screenUV + vec2(-.5, -.5)) * 2; // UVs based around center -1 - 1
float normSin = (sin(adjustedTime) + 1) / 2; // normalized sin value
float normCos = (cos(adjustedTime) + 1) / 2; // normalized cos value
float stepCutoff = .8;
/// ------------- SHAPES
float circle = length(screenUVCentered);
float diamond = abs(screenUVCentered.x) + abs(screenUVCentered.y);
float square = max(abs(screenUVCentered.x), abs(screenUVCentered.y));
float tri = abs(screenUVCentered.x*1.7) + screenUVCentered.y;
tri = clamp(tri,0,1);
float tribottomCutoff = 1-step(-stepCutoff, screenUVCentered.y); // kinda haxy triangle not a proper tringle gradient
tri += tribottomCutoff;
/// ------------- MIXING
float mixValue = mod(adjustedTime , 4);
// Mix square to tri
float mixedShapes = mix(tri, diamond, smoothstep(0,1,mixValue));
mixedShapes = mix(mixedShapes, square, smoothstep(1,2,mixValue));
mixedShapes = mix(mixedShapes, circle, smoothstep(2,3,mixValue));
mixedShapes = mix(mixedShapes, tri, smoothstep(3,4,mixValue));
mixedShapes = step(mixedShapes, stepCutoff);
fragColor = vec4(mixedShapes);
}
//float square = abs(screenUVCentered.x) + screenUVCentered.y; // makes cool trianle shape