shaderflow 0.4.0.dev1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of shaderflow might be problematic. Click here for more details.

Files changed (51) hide show
  1. ShaderFlow/Common/Imgui.py +0 -0
  2. ShaderFlow/Common/Notes.py +134 -0
  3. ShaderFlow/Common/__init__.py +0 -0
  4. ShaderFlow/Message.py +147 -0
  5. ShaderFlow/Module.py +162 -0
  6. ShaderFlow/Modules/Audio.py +431 -0
  7. ShaderFlow/Modules/Bouncing.py +94 -0
  8. ShaderFlow/Modules/Camera.py +451 -0
  9. ShaderFlow/Modules/Depth.py +0 -0
  10. ShaderFlow/Modules/Dynamics.py +288 -0
  11. ShaderFlow/Modules/Frametimer.py +79 -0
  12. ShaderFlow/Modules/Keyboard.py +43 -0
  13. ShaderFlow/Modules/Noise.py +80 -0
  14. ShaderFlow/Modules/OpticalFlow.py +1 -0
  15. ShaderFlow/Modules/Piano.py +362 -0
  16. ShaderFlow/Modules/Spectrogram.py +315 -0
  17. ShaderFlow/Modules/Video.py +234 -0
  18. ShaderFlow/Modules/Waveform.py +100 -0
  19. ShaderFlow/Modules/__init__.py +0 -0
  20. ShaderFlow/Resources/Images/ShaderFlow.png +0 -0
  21. ShaderFlow/Resources/Images/ShaderFlow.svg +1 -0
  22. ShaderFlow/Resources/Scenes/Examples/Demo.py +284 -0
  23. ShaderFlow/Resources/Scenes/Examples/GLSL/Bars.frag +20 -0
  24. ShaderFlow/Resources/Scenes/Examples/GLSL/Bouncing.frag +50 -0
  25. ShaderFlow/Resources/Scenes/Examples/GLSL/Life/Simulation.glsl +49 -0
  26. ShaderFlow/Resources/Scenes/Examples/GLSL/Life/Visuals.glsl +31 -0
  27. ShaderFlow/Resources/Scenes/Examples/GLSL/MotionBlur.frag +20 -0
  28. ShaderFlow/Resources/Scenes/Examples/GLSL/Multipass.frag +43 -0
  29. ShaderFlow/Resources/Scenes/Examples/GLSL/RayMarch.frag +59 -0
  30. ShaderFlow/Resources/Scenes/Examples/GLSL/ShaderToy.frag +65 -0
  31. ShaderFlow/Resources/Scenes/Examples/GLSL/Video.frag +5 -0
  32. ShaderFlow/Resources/Scenes/Examples/GLSL/Visualizer.frag +75 -0
  33. ShaderFlow/Resources/Scenes/Examples/GLSL/Waveform.frag +18 -0
  34. ShaderFlow/Resources/Shaders/Fragment/Default.glsl +65 -0
  35. ShaderFlow/Resources/Shaders/Fragment/Final.glsl +7 -0
  36. ShaderFlow/Resources/Shaders/Fragment/Loading.frag +40 -0
  37. ShaderFlow/Resources/Shaders/Fragment/Missing.glsl +23 -0
  38. ShaderFlow/Resources/Shaders/Include/Camera.glsl +166 -0
  39. ShaderFlow/Resources/Shaders/Include/Complex.glsl +0 -0
  40. ShaderFlow/Resources/Shaders/Include/ShaderFlow.glsl +444 -0
  41. ShaderFlow/Resources/Shaders/Vertex/Default.glsl +21 -0
  42. ShaderFlow/Scene.py +1124 -0
  43. ShaderFlow/Shader.py +391 -0
  44. ShaderFlow/Texture.py +528 -0
  45. ShaderFlow/Variable.py +128 -0
  46. ShaderFlow/__init__.py +11 -0
  47. ShaderFlow/__main__.py +22 -0
  48. shaderflow-0.4.0.dev1.dist-info/METADATA +79 -0
  49. shaderflow-0.4.0.dev1.dist-info/RECORD +51 -0
  50. shaderflow-0.4.0.dev1.dist-info/WHEEL +5 -0
  51. shaderflow-0.4.0.dev1.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,166 @@
1
+ #ifndef SHADERFLOW_CAMERA
2
+ #define SHADERFLOW_CAMERA
3
+
4
+ // Camera Mode Enum
5
+ #define CameraModeFreeCamera 0
6
+ #define CameraMode2D 1
7
+ #define CameraModeSpherical 2
8
+
9
+ // Camera Projection Enum
10
+ #define CameraProjectionPerspective 0
11
+ #define CameraProjectionVirtualReality 1
12
+ #define CameraProjectionEquirectangular 2
13
+
14
+ struct Camera {
15
+
16
+ //// Basic
17
+
18
+ int mode; // Camera mode, defined on by the CameraMode enum
19
+ int projection; // Camera projection, defined on by the CameraProjection enum
20
+
21
+ //// Position
22
+
23
+ vec3 position; // Camera position in world coordinates
24
+ vec3 UP; // Camera up vector
25
+ vec3 X; // Camera X axis
26
+ vec3 Y; // Camera Y axis
27
+ vec3 Z; // Camera Z axis
28
+
29
+ //// Rays 3D
30
+
31
+ vec3 origin; // Origin of the camera ray
32
+ vec3 target; // Target of the camera ray
33
+ vec3 ray; // Camera ray normalized vector
34
+ float orbital; // Displacement of origin and target from the position
35
+ float dolly; // Displacement of the origin from the position
36
+
37
+ //// Rays 2D
38
+
39
+ vec3 plane_point;
40
+ vec3 plane_normal;
41
+ vec2 screen;
42
+ vec2 gluv;
43
+ vec2 agluv;
44
+ vec2 stuv;
45
+ vec2 astuv;
46
+ vec2 glxy;
47
+ vec2 stxy;
48
+ bool out_of_bounds;
49
+
50
+ //// Virtual Reality
51
+ float separation;
52
+
53
+ //// Parameters
54
+ float isometric;
55
+ float zoom;
56
+ };
57
+
58
+ /* Builds a rectangle where the camera is looking at centered on the origin */
59
+ vec3 CameraRectangle(Camera camera, float size) {
60
+ return size*(camera.screen.x*camera.X + camera.screen.y*camera.Y);
61
+ }
62
+
63
+ vec3 CameraRayOrigin(Camera camera) {
64
+ return camera.position
65
+ + CameraRectangle(camera, (1/camera.zoom)*camera.isometric)
66
+ - (camera.Z*camera.orbital)
67
+ - (camera.Z*camera.dolly);
68
+ }
69
+
70
+ vec3 CameraRayTarget(Camera camera) {
71
+ return camera.position
72
+ + CameraRectangle(camera, (1/camera.zoom))
73
+ - (camera.Z*camera.orbital)
74
+ + camera.Z;
75
+ }
76
+
77
+ Camera CameraRay2D(Camera camera) {
78
+
79
+ // Calculate the interstion with the plane define by a point and norm
80
+ // https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection
81
+ float num = dot(camera.plane_point - camera.origin, camera.plane_normal);
82
+ float den = dot(camera.ray, camera.plane_normal);
83
+ float t = num/den;
84
+
85
+ // The ray intersects the plane behind the camera
86
+ if (t < 0) {
87
+ camera.out_of_bounds = true;
88
+ return camera;
89
+ }
90
+
91
+ // Calculate the intersection point
92
+ camera.gluv = (camera.origin + (t*camera.ray)).xy;
93
+ camera.stuv = gluv2stuv(camera.gluv);
94
+ camera.agluv = vec2(camera.gluv.x/iAspectRatio, camera.gluv.y);
95
+ camera.astuv = gluv2stuv(camera.agluv);
96
+ camera.stxy = (iResolution * camera.astuv);
97
+ camera.glxy = (camera.stxy - iResolution/2.0);
98
+ return camera;
99
+ }
100
+
101
+ Camera iProjectCamera(Camera camera) {
102
+
103
+ // Perspective - Simple origin and target
104
+ if (camera.projection == CameraProjectionPerspective) {
105
+ camera.origin = CameraRayOrigin(camera);
106
+ camera.target = CameraRayTarget(camera);
107
+
108
+ // Virtual Reality - Emulate two cameras, same as perspective
109
+ } else if (camera.projection == CameraProjectionVirtualReality) {
110
+
111
+ // Make both sides of the uv a new GLUV
112
+ int side = (agluv.x <= 0 ? 1 : -1);
113
+ camera.screen += side*vec2(iAspectRatio/2, 0);
114
+
115
+ // Get the VR Horizontal Separation and add to the new own projections
116
+ vec3 separation = camera.X * side*(camera.separation/2.0);
117
+ camera.origin = CameraRayOrigin(camera) - separation;
118
+ camera.target = CameraRayTarget(camera) - separation;
119
+
120
+ // Equirectangular
121
+ } else if (camera.projection == CameraProjectionEquirectangular) {
122
+ camera.origin = camera.position;
123
+
124
+ float phi = (1/camera.zoom) * (PI*camera.screen.y/2);
125
+ float theta = (1/camera.zoom) * (PI*camera.screen.x/iAspectRatio);
126
+ vec3 target = camera.Z;
127
+
128
+ target = rotate3d(target, camera.X, -phi);
129
+ target = rotate3d(target, camera.Y, theta);
130
+
131
+ camera.target = camera.position + target;
132
+ }
133
+
134
+ // Origin and target rays projections
135
+ camera.ray = normalize(camera.target - camera.origin);
136
+
137
+ return CameraRay2D(camera);
138
+ }
139
+
140
+ #endif
141
+
142
+ // Initialization
143
+
144
+ Camera iInitCamera(vec2 gluv) {
145
+ Camera camera;
146
+ camera.plane_point = vec3(0, 0, 1);
147
+ camera.plane_normal = vec3(0, 0, 1);
148
+ camera.screen = gluv;
149
+ camera.mode = iCameraMode;
150
+ camera.projection = iCameraProjection;
151
+ camera.position = iCameraPosition;
152
+ camera.orbital = iCameraOrbital;
153
+ camera.dolly = iCameraDolly;
154
+ camera.UP = iCameraUP;
155
+ camera.X = iCameraX;
156
+ camera.Y = iCameraY;
157
+ camera.Z = iCameraZ;
158
+ camera.isometric = iCameraIsometric;
159
+ camera.zoom = iCameraZoom;
160
+ camera.separation = iCameraVRSeparation;
161
+ camera.out_of_bounds = false;
162
+ return camera;
163
+ }
164
+
165
+ Camera iCamera = iProjectCamera(iInitCamera(gluv));
166
+
File without changes
@@ -0,0 +1,444 @@
1
+ #ifndef ShaderFlowSpecification
2
+ #define ShaderFlowSpecification
3
+
4
+ // ------------------------------------------------------------------------------------------------|
5
+ // The Good Code - A Sane Attempt
6
+
7
+ #define iFrameTime (1.0/iFrameRate)
8
+ #define iDeltaTime (iFrameTime)
9
+ #define iTau (iTime/min(iDuration, iTime))
10
+ #define iAspectRatio (float(iResolution.x)/iResolution.y)
11
+ #define iWidth (iResolution.x)
12
+ #define iHeight (iResolution.y)
13
+ #define iRendering (!iRealtime)
14
+
15
+ const float PI = 3.1415926535897932;
16
+ const float TAU = 6.2831853071795864;
17
+ const float SQRT2 = 1.4142135623730951;
18
+ const float SQRT3 = 1.7320508075688772;
19
+
20
+ // // Interpolation
21
+
22
+ // Interpolate between two points (x0, y0) and (x1, y1) at x
23
+ float lerp(float x0, float y0, float x1, float y1, float x) {
24
+ return y0 + (x - x0)*(y1 - y0)/(x1 - x0);
25
+ }
26
+
27
+ // Your standard "Cross Multiplication", (a/c) = (b/?), returns '?'
28
+ float proportion(float a, float b, float c) {
29
+ return (b*c)/a;
30
+ }
31
+
32
+ // Smooth relative interpolation between two values given a magnitude difference factor
33
+ // • Applied whenever |b - a| > difference
34
+ // • Positive difference gives min(a, b) else max(a, b)
35
+ float smoothlerp(float a, float b, float difference) {
36
+ float t = clamp((a - b)/difference + 0.5, 0, 1);
37
+ float offset = difference*t*(1 - t)/2;
38
+ return mix(a, b, t) - offset;
39
+ }
40
+
41
+ // Aliases to smoothlerp, smooth versions of min and max
42
+ float smin(float a, float b, float k) {return smoothlerp(a, b, k);}
43
+ float smax(float a, float b, float k) {return smoothlerp(a, b, -k);}
44
+ float smin(float a, float b) {return smoothlerp(a, b, 1);}
45
+ float smax(float a, float b) {return smoothlerp(a, b, -1);}
46
+
47
+ // Smoothstep linear interpolation between two values
48
+ // • Useful when a=f(x), b=f(x) and the transition is [x0, x1]
49
+ float smoothmix(float a, float b, float x0, float x1, float x) {
50
+ return mix(a, b, smoothstep(x0, x1, x));
51
+ }
52
+
53
+ // Aliases to smoothmix, smooth versions of mix
54
+ float smix(float a, float b, float x0, float x1, float x) {
55
+ return smoothmix(a, b, x0, x1, x);
56
+ }
57
+
58
+ // // Waveforms
59
+
60
+ // Triangle wave that starts in zero, amplitude 1, range (-1, 1)
61
+ float triangle_wave(float x, float period) {
62
+ return 2*abs(mod(2*x/period - 0.5, 2) - 1) - 1;
63
+ // return asin(cos(2*PI*x/period - PI/2)) * (2/PI);
64
+ }
65
+
66
+ // // Angles and Rotations
67
+
68
+ // Angle between two vectors for any dimensions
69
+ float angle(vec4 A, vec4 B) {return acos(dot(A, B) / (length(A)*length(B)));}
70
+ float angle(vec3 A, vec3 B) {return acos(dot(A, B) / (length(A)*length(B)));}
71
+ float angle(vec2 A, vec2 B) {return acos(dot(A, B) / (length(A)*length(B)));}
72
+
73
+ // Trivial 2D rotation matrix, doesn't consider aspect ratio
74
+ mat2 rotate2d(float angle) {
75
+ return mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
76
+ }
77
+
78
+ #define rotate2deg(angle) rotate2d(radians(angle))
79
+
80
+ // Rotate a vector around an axis, right-handed
81
+ vec3 rotate3d(vec3 vector, vec3 axis, float angle) {
82
+ return mix(dot(axis, vector)*axis, vector, cos(angle)) + cross(axis, vector)*sin(angle);
83
+ }
84
+
85
+ #define rotate3deg(vector, axis, angle) rotate3d(vector, axis, radians(angle))
86
+
87
+ // // Coordinates conversion
88
+
89
+ // Converts a (0, 0) - (1, 1) coordinate to a (-1, -1) - (1, 1) coordinate
90
+ vec2 stuv2gluv(vec2 stuv) {return (stuv*2) - 1;}
91
+ vec2 s2g(vec2 stuv) {return stuv2gluv(stuv);}
92
+
93
+ // Converts a (-1, -1) - (1, 1) coordinate to a (0, 0) - (1, 1) coordinate
94
+ vec2 gluv2stuv(vec2 gluv) {return (gluv + 1)/2;}
95
+ vec2 g2s(vec2 gluv) {return gluv2stuv(gluv);}
96
+
97
+ // Applies or reverts Aspect Ratio to a (-1, -1) - (1, 1) coordinate
98
+ vec2 agluv2gluv(vec2 agluv) {return agluv * vec2(iAspectRatio, 1);}
99
+ vec2 gluv2agluv(vec2 gluv) {return gluv / vec2(iAspectRatio, 1);}
100
+
101
+ // Converts a (0, 0) - (1, 1) coordinate to a (0, 0) - (width, height) coordinate
102
+ vec2 stuv2stxy(vec2 stuv, vec2 resolution) {return resolution*stuv;}
103
+ vec2 stuv2stxy(vec2 stuv) {return stuv2stxy(stuv, iResolution);}
104
+
105
+ // Converts a (0, 0) - (width, height) coordinate to a (0, 0) - (1, 1) coordinate
106
+ vec2 stxy2stuv(vec2 stxy, vec2 resolution) {return stxy/resolution;}
107
+ vec2 stxy2stuv(vec2 stxy) {return stxy2stuv(stxy, iResolution);}
108
+
109
+ // Applies or reverts Aspect Ratio to a (0, 0) - (1, 1) coordinate
110
+ vec2 astuv2stuv(vec2 astuv) {
111
+ return vec2(astuv.x*iAspectRatio + (1 - iAspectRatio)/2, astuv.y);
112
+ }
113
+ vec2 stuv2astuv(vec2 stuv) {
114
+ return vec2((stuv.x - (1 - iAspectRatio)/2)/iAspectRatio, stuv.y);
115
+ }
116
+
117
+ // Apply a virtual GL_MIRRORED_REPEAT to a AGLUV coordinate
118
+ vec2 agluv_mirrored_repeat(vec2 agluv) {
119
+ return vec2(
120
+ triangle_wave(agluv.x, 4),
121
+ triangle_wave(agluv.y, 4)
122
+ );
123
+ }
124
+
125
+ // Apply a virtual GL_MIRRORED_REPEAT to a GLUV coordinate
126
+ vec2 gluv_mirrored_repeat(vec2 gluv) {
127
+ return vec2(
128
+ iAspectRatio * triangle_wave(gluv.x, 4*iAspectRatio),
129
+ triangle_wave(gluv.y, 4)
130
+ );
131
+ }
132
+
133
+ // Out of Bounds checks
134
+ bool astuv_oob(vec2 astuv) {
135
+ return (astuv.x<0)||(astuv.x>1)||(astuv.y<0)||(astuv.y>1);
136
+ }
137
+ bool stuv_oob(vec2 stuv) {
138
+ return astuv_oob(stuv2astuv(stuv));
139
+ }
140
+ bool agluv_oob(vec2 agluv) {
141
+ return (agluv.x<-1)||(agluv.x>1)||(agluv.y<-1)||(agluv.y>1);
142
+ }
143
+ bool gluv_oob(vec2 gluv) {
144
+ return agluv_oob(gluv2agluv(gluv));
145
+ }
146
+
147
+ // Get a polar coordinate from (r, θ)
148
+ vec2 polar2rect(float radius, float angle) {
149
+ return radius * vec2(cos(angle), sin(angle));
150
+ }
151
+
152
+ // Get a Rectangular coordinate from a Spherical coordinate (radius, θ, φ)
153
+ vec3 sphere2rect(float radius, float theta, float phi) {
154
+ return vec3(
155
+ radius*sin(theta)*cos(phi),
156
+ radius*sin(theta)*sin(phi),
157
+ radius*cos(theta)
158
+ );
159
+ }
160
+
161
+ // // Textures
162
+
163
+ // GLUV Coordinate texture
164
+ vec4 gtexture(sampler2D image, vec2 gluv) {
165
+ vec2 resolution = textureSize(image, 0);
166
+ vec2 scale = vec2(resolution.y/resolution.x, 1);
167
+ return texture(image, gluv2stuv(gluv*scale));
168
+ }
169
+
170
+ // GLUV Coordinate + Mirrored Repeat texture
171
+ // Note: Have .repeat(False) (CLAMP_TO_EDGE) on the sampler
172
+ vec4 gmtexture(sampler2D image, vec2 gluv) {
173
+ return gtexture(image, gluv_mirrored_repeat(gluv));
174
+ }
175
+
176
+ // Function overloading to call gmtexture on gtexture(_, _, true)
177
+ vec4 gtexture(sampler2D image, vec2 gluv, bool mirror) {
178
+ if (mirror)
179
+ return gmtexture(image, gluv);
180
+ return gtexture(image, gluv);
181
+ }
182
+
183
+ // AGLUV Coordinate texture
184
+ vec4 agtexture(sampler2D image, vec2 agluv) {
185
+ return gtexture(image, agluv2gluv(agluv));
186
+ }
187
+
188
+ // AGLUV Coordinate + Mirrored Repeat texture
189
+ // Note: Have .repeat(False) (CLAMP_TO_EDGE) on the sampler
190
+ vec4 agmtexture(sampler2D image, vec2 agluv) {
191
+ return agtexture(image, agluv_mirrored_repeat(agluv));
192
+ }
193
+
194
+ // Function overloading to call agmtexture on agtexture(_, _, true)
195
+ vec4 agtexture(sampler2D image, vec2 agluv, bool mirror) {
196
+ if (mirror)
197
+ return agmtexture(image, agluv);
198
+ return agtexture(image, agluv);
199
+ }
200
+
201
+ vec4 stexture(sampler2D image, vec2 stuv) {
202
+ return gtexture(image, stuv2gluv(stuv));
203
+ }
204
+
205
+ vec4 astexture(sampler2D image, vec2 astuv) {
206
+ return agtexture(image, stuv2gluv(astuv));
207
+ }
208
+
209
+ // // Palettes
210
+
211
+ vec3 palette(float t, vec3 A, vec3 B, vec3 C, vec3 D) {
212
+ if (t < 0.25) {
213
+ return mix(A, B, t*4);
214
+ } else if (t < 0.5) {
215
+ return mix(B, C, (t - 0.25)*4);
216
+ } else {
217
+ return mix(C, D, (t - 0.5)*4);
218
+ }
219
+ }
220
+
221
+ #define PALETTE_MAGMA_1 vec3(0.01060815, 0.01808215, 0.10018654)
222
+ #define PALETTE_MAGMA_2 vec3(0.38092887, 0.12061482, 0.32506528)
223
+ #define PALETTE_MAGMA_3 vec3(0.79650140, 0.10506637, 0.31063031)
224
+ #define PALETTE_MAGMA_4 vec3(0.95922872, 0.53307513, 0.37488950)
225
+ #define palette_magma(x) palette(x, PALETTE_MAGMA_1, PALETTE_MAGMA_2, PALETTE_MAGMA_3, PALETTE_MAGMA_4)
226
+
227
+ // // Piano and Midi Keys
228
+
229
+ // Black keys have a constant index relative to the octave
230
+ bool isBlackKey(int index) {
231
+ int key = index % 12;
232
+ return key==1||key==3||key==6||key==8||key==10;
233
+ }
234
+ bool isBlackKey(float key) {
235
+ return isBlackKey(int(key));
236
+ }
237
+
238
+ // Can only be black or white
239
+ bool isWhiteKey(int index) {
240
+ return !isBlackKey(index);
241
+ }
242
+ bool isWhiteKey(float key) {
243
+ return isWhiteKey(int(key));
244
+ }
245
+
246
+ // // Ray Marching
247
+
248
+ // Note: SDF: Signed Distance Function
249
+
250
+ // SDF to a infinite line defined by two points
251
+ // • Define the line's direction D as (B - A)
252
+ // • Define a point P on the line P = (A + D*t)
253
+ // • Find a value for t that dot(P-A, P-O) = 0
254
+ float _sdLine(vec3 origin, vec3 A, vec3 B, bool segment) {
255
+ vec3 direction = (B - A);
256
+ vec3 shortest = (origin - A);
257
+ float t = dot(shortest, direction) / dot(direction, direction);
258
+ if (segment) t = clamp(t, 0, 1);
259
+ return length(shortest - direction*t);
260
+ }
261
+
262
+ float sdLine(vec2 origin, vec2 p1, vec2 p2) {
263
+ return _sdLine(vec3(origin, 0), vec3(p1, 0), vec3(p2, 0), false);}
264
+ float sdLine(vec3 origin, vec3 p1, vec3 p2) {
265
+ return _sdLine(origin, p1, p2, false);}
266
+
267
+ float sdLineSegment(vec3 origin, vec3 p1, vec3 p2) {
268
+ return _sdLine(origin, p1, p2, true);}
269
+ float sdLineSegment(vec2 origin, vec2 p1, vec2 p2) {
270
+ return _sdLine(vec3(origin, 0), vec3(p1, 0), vec3(p2, 0), true);}
271
+
272
+
273
+ // SDF to a sphere at some position and radius
274
+ float sdSphere(vec3 origin, vec3 position, float radius) {
275
+ return length(position - origin) - radius;
276
+ }
277
+
278
+ // SDF to a plane defined by a point and a normal
279
+ float sdPlane(vec3 origin, vec3 point, vec3 normal) {
280
+ return dot(origin - point, normalize(normal));
281
+ }
282
+
283
+ // SDF to a box defined by a point and a size
284
+ float sdBox(vec3 origin, vec3 point, vec3 size) {
285
+ vec3 d = abs(origin - point) - size/2;
286
+ return min(max(d.x, max(d.y, d.z)), 0) + length(max(d, 0));
287
+ }
288
+
289
+ // SDF to a Octahedron defined by a point and a size
290
+ float sdOctahedron(vec3 origin, vec3 point, float size) {
291
+ vec3 p = abs(origin - point);
292
+ return SQRT3 * (p.x + p.y + p.z - size);
293
+ }
294
+
295
+ // Operators
296
+
297
+ // Union of two SDFs: Join two SDFs into one
298
+ float sdUnion(float a, float b) {
299
+ return min(a, b);
300
+ }
301
+
302
+ // Smooth union of two SDFs: "Simple relative interpolation"
303
+ // • width defines the relative value range of the transition
304
+ float sdSmoothUnion(float a, float b, float width) {
305
+ float k = clamp(0.5 + 0.5*(b-a)/width, 0, 1);
306
+ return mix(b, a, k) - width*k*(1 - k);
307
+ }
308
+
309
+ // Subtraction of two SDFs: Get the difference between A and B
310
+ float sdSubtraction(float a, float b) {
311
+ return max(b, -a);
312
+ }
313
+
314
+ // Smooth subtraction of two SDFs: "
315
+ // • width defines the relative value range of the transition
316
+ float sdSmoothSubtraction(float a, float b, float width) {
317
+ float k = clamp(0.5 - 0.5*(b+a)/width, 0, 1);
318
+ return mix(b, -a, k) + width*k*(1 - k);
319
+ }
320
+
321
+ // Intersection of two SDFs: Get where two SDFs meet
322
+ float sdIntersection(float a, float b) {
323
+ return max(a, b);
324
+ }
325
+
326
+ // Smooth intersection of two SDFs: "Opposite of union, so k' = 1 - k"
327
+ // • width defines the relative value range of the transition
328
+ float sdSmoothIntersection(float a, float b, float width) {
329
+ float k = clamp(0.5 - 0.5*(b-a)/width, 0, 1);
330
+ return mix(b, a, k) + width*k*(1 - k);
331
+ }
332
+
333
+ // // Compositing
334
+
335
+ vec4 blend(vec4 a, vec4 b) {
336
+ return mix(a, b, b.a);
337
+ }
338
+
339
+
340
+
341
+ // ------------------------------------------------------------------------------------------------|
342
+ // The Bad Code - Accumulated Tech Debt
343
+
344
+ // // Utils
345
+
346
+ vec4 alpha_composite(vec4 a, vec4 b) {
347
+ return a*(1 - b.a) + (b * b.a);
348
+ }
349
+
350
+ // Saturation
351
+ vec4 saturate(vec4 color, float amount) {return clamp(color * amount, 0, 1);}
352
+ vec3 saturate(vec3 color, float amount) {return clamp(color * amount, 0, 1);}
353
+ vec2 saturate(vec2 color, float amount) {return clamp(color * amount, 0, 1);}
354
+
355
+ // // Zoom
356
+
357
+ // Zoom into some point on an STUV coordinates
358
+ vec2 zoom(vec2 uv, float zoom, vec2 anchor) {
359
+ return (uv - anchor) * (zoom*zoom) + anchor;
360
+ }
361
+
362
+ vec2 zoom(vec2 uv, float zoom) {
363
+ return uv * (zoom*zoom);
364
+ }
365
+
366
+ // // Math
367
+ float atan_normalized(float x) {
368
+ return 2 * atan(x) / PI;
369
+ }
370
+
371
+ float atan1(vec2 point) {
372
+ return atan(point.y, point.x);
373
+ }
374
+
375
+ float atan1n(vec2 point) {
376
+ return atan(point.y, point.x) / PI;
377
+ }
378
+
379
+ float atan2(float y, float x) {
380
+ if (y < 0) {
381
+ return TAU - atan(-y, x);
382
+ } else {
383
+ return atan(y, x);
384
+ }
385
+ }
386
+
387
+ float atan2(vec2 point) {
388
+ return atan2(point.y, point.x);
389
+ }
390
+
391
+ float atan2n(float y, float x) {
392
+ return atan2(y, x) / TAU;
393
+ }
394
+
395
+ float atan2n(vec2 point) {
396
+ return atan2n(point.y, point.x);
397
+ }
398
+
399
+ // // Colors
400
+
401
+ // https://www.rapidtables.com/convert/color/hsv-to-rgb.html
402
+ // "Assume 0 <= H < 2pi, 0 <= S <= 1, 0 <= V <= 1"
403
+ vec3 hsv2rgb(vec3 hsv) {
404
+ float h = hsv.x;
405
+ float s = hsv.y;
406
+ float v = hsv.z;
407
+ h = mod(h, 2*PI);
408
+ float c = v * s;
409
+ float x = c * (1 - abs(mod(h / (PI/3), 2) - 1));
410
+ float m = v - c;
411
+ vec3 rgb = vec3(0.5);
412
+ switch (int(floor(6*(h/(2*PI))))) {
413
+ case 0: rgb = vec3(c, x, 0); break;
414
+ case 1: rgb = vec3(x, c, 0); break;
415
+ case 2: rgb = vec3(0, c, x); break;
416
+ case 3: rgb = vec3(0, x, c); break;
417
+ case 4: rgb = vec3(x, 0, c); break;
418
+ case 5: rgb = vec3(c, 0, x); break;
419
+ default: rgb = vec3(0);
420
+ }
421
+ return rgb + vec3(m);
422
+ }
423
+
424
+ vec4 hsv2rgb(vec4 hsv) {
425
+ return vec4(hsv2rgb(hsv.rgb), hsv.a);
426
+ }
427
+
428
+
429
+ // // Noise
430
+
431
+ float noise21(vec2 coords) {
432
+ return fract(sin(dot(coords.xy, vec2(18.4835183, 59.583596))) * 39758.381532);
433
+ }
434
+
435
+ vec2 noise22(vec2 coords) {
436
+ float x = noise21(coords);
437
+ return vec2(x, noise21(coords + x));
438
+ }
439
+
440
+ float noise11(float f) {
441
+ return fract(sin(f) * 39758.381532);
442
+ }
443
+
444
+ #endif
@@ -0,0 +1,21 @@
1
+ void main() {
2
+
3
+ // Fullscreen Rectangle
4
+ gl_Position = vec4(vertex_position, 0.0, 1.0);
5
+ instance = gl_InstanceID;
6
+
7
+ // // Coordinates Recap:
8
+ // ST = 'ShaderToy', (0, 0) to (1, 1), center half
9
+ // GL = 'OpenGL', (-1, -1) to (1, 1), center zero
10
+
11
+ // Continuous coordinates
12
+ agluv = vertex_gluv;
13
+ gluv = agluv2gluv(agluv);
14
+ astuv = gluv2stuv(agluv);
15
+ stuv = gluv2stuv(gluv);
16
+
17
+ // Pixel coordinates
18
+ stxy = (iResolution*astuv) + 1;
19
+ glxy = (stxy - iResolution/2);
20
+ fragCoord = stxy;
21
+ }