summaryrefslogtreecommitdiffstats
path: root/spa/plugins/vulkan/shaders
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:28:17 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:28:17 +0000
commit7a46c07230b8d8108c0e8e80df4522d0ac116538 (patch)
treed483300dab478b994fe199a5d19d18d74153718a /spa/plugins/vulkan/shaders
parentInitial commit. (diff)
downloadpipewire-upstream.tar.xz
pipewire-upstream.zip
Adding upstream version 0.3.65.upstream/0.3.65upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--spa/plugins/vulkan/shaders/disk-intersection.comp143
-rw-r--r--spa/plugins/vulkan/shaders/filter-color.comp39
-rw-r--r--spa/plugins/vulkan/shaders/filter.comp44
-rw-r--r--spa/plugins/vulkan/shaders/filter.spvbin0 -> 4884 bytes
-rw-r--r--spa/plugins/vulkan/shaders/main.comp50
-rw-r--r--spa/plugins/vulkan/shaders/main.spvbin0 -> 9980 bytes
6 files changed, 276 insertions, 0 deletions
diff --git a/spa/plugins/vulkan/shaders/disk-intersection.comp b/spa/plugins/vulkan/shaders/disk-intersection.comp
new file mode 100644
index 0000000..7b92fdf
--- /dev/null
+++ b/spa/plugins/vulkan/shaders/disk-intersection.comp
@@ -0,0 +1,143 @@
+// The MIT License
+// Copyright © 2013 Inigo Quilez
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+// Other intersectors:
+//
+// Box: https://www.shadertoy.com/view/ld23DV
+// Triangle: https://www.shadertoy.com/view/MlGcDz
+// Capsule: https://www.shadertoy.com/view/Xt3SzX
+// Ellipsoid: https://www.shadertoy.com/view/MlsSzn
+// Sphere: https://www.shadertoy.com/view/4d2XWV
+// Capped Cylinder: https://www.shadertoy.com/view/4lcSRn
+// Disk: https://www.shadertoy.com/view/lsfGDB
+// Capped Cone: https://www.shadertoy.com/view/llcfRf
+// Rounded Box: https://www.shadertoy.com/view/WlSXRW
+// Rounded Cone: https://www.shadertoy.com/view/MlKfzm
+// Torus: https://www.shadertoy.com/view/4sBGDy
+// Sphere4: https://www.shadertoy.com/view/3tj3DW
+// Goursat: https://www.shadertoy.com/view/3lj3DW
+
+
+#define SC 3.0
+
+#if 1
+//
+// Elegant way to intersect a planar coordinate system (3x3 linear system)
+//
+vec3 intersectCoordSys(in vec3 o, in vec3 d, vec3 c, vec3 u, vec3 v)
+{
+ vec3 q = o - c;
+ return vec3(dot(cross(u, v), q),
+ dot(cross(q, u), d),
+ dot(cross(v, q), d)) / dot(cross(v, u), d);
+}
+
+#else
+//
+// Ugly (but faster) way to intersect a planar coordinate system: plane + projection
+//
+vec3 intersectCoordSys(in vec3 o, in vec3 d, vec3 c, vec3 u, vec3 v)
+{
+ vec3 q = o - c;
+ vec3 n = cross(u, v);
+ float t = -dot(n, q) / dot(d, n);
+ float r = dot(u, q + d * t);
+ float s = dot(v, q + d * t);
+ return vec3(t, s, r);
+}
+
+#endif
+
+vec3 hash3(float n)
+{
+ return fract(sin(vec3(n, n + 1.0, n + 2.0)) *
+ vec3(43758.5453123, 12578.1459123, 19642.3490423));
+}
+
+vec3 shade(in vec4 res)
+{
+ float ra = length(res.yz);
+ float an = atan(res.y, res.z) + 8.0 * iTime;
+ float pa = sin(3.0 * an);
+
+ vec3 cola =
+ 0.5 + 0.5 * sin((res.w / 64.0) * 3.5 + vec3(0.0, 1.0, 2.0));
+
+ vec3 col = vec3(0.0);
+ col += cola * 0.4 * (1.0 - smoothstep(0.90, 1.00, ra));
+ col +=
+ cola * 1.0 * (1.0 -
+ smoothstep(0.00, 0.03,
+ abs(ra - 0.8))) * (0.5 + 0.5 * pa);
+ col +=
+ cola * 1.0 * (1.0 -
+ smoothstep(0.00, 0.20,
+ abs(ra - 0.8))) * (0.5 + 0.5 * pa);
+ col +=
+ cola * 0.5 * (1.0 -
+ smoothstep(0.05, 0.10,
+ abs(ra - 0.5))) * (0.5 + 0.5 * pa);
+ col +=
+ cola * 0.7 * (1.0 -
+ smoothstep(0.00, 0.30,
+ abs(ra - 0.5))) * (0.5 + 0.5 * pa);
+
+ return col * 0.3;
+}
+
+vec3 render(in vec3 ro, in vec3 rd)
+{
+ // raytrace
+ vec3 col = vec3(0.0);
+ for (int i = 0; i < 64; i++) {
+ // position disk
+ vec3 r = 2.5 * (-1.0 + 2.0 * hash3(float (i)));
+ r *= SC;
+ // orientate disk
+ vec3 u = normalize(r.zxy);
+ vec3 v = normalize(cross(u, vec3(0.0, 1.0, 0.0)));
+
+ // intersect coord sys
+ vec3 tmp = intersectCoordSys(ro, rd, r, u, v);
+ tmp /= SC;
+ if (dot(tmp.yz, tmp.yz) < 1.0 && tmp.x > 0.0) {
+ // shade
+ col += shade(vec4(tmp, float (i)));
+ }
+ }
+
+ return col;
+}
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord)
+{
+ vec2 q = fragCoord.xy / iResolution.xy;
+ vec2 p = -1.0 + 2.0 * q;
+ p.x *= iResolution.x / iResolution.y;
+
+ // camera
+ vec3 ro =
+ 2.0 * vec3(cos(0.5 * iTime * 1.1), 0.0,
+ sin(0.5 * iTime * 1.1));
+ vec3 ta = vec3(0.0, 0.0, 0.0);
+ // camera matrix
+ vec3 ww = normalize(ta - ro);
+ vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
+ vec3 vv = normalize(cross(uu, ww));
+ // create view ray
+ vec3 rd = normalize(p.x * uu + p.y * vv + 1.0 * ww);
+
+ vec3 col = render(ro * SC, rd);
+
+ fragColor = vec4(col, 1.0);
+}
+
+void mainVR(out vec4 fragColor, in vec2 fragCoord, in vec3 fragRayOri,
+ in vec3 fragRayDir)
+{
+ vec3 col = render(fragRayOri + vec3(0.0, 0.0, 0.0), fragRayDir);
+
+ fragColor = vec4(col, 1.0);
+}
diff --git a/spa/plugins/vulkan/shaders/filter-color.comp b/spa/plugins/vulkan/shaders/filter-color.comp
new file mode 100644
index 0000000..e08b715
--- /dev/null
+++ b/spa/plugins/vulkan/shaders/filter-color.comp
@@ -0,0 +1,39 @@
+void mainImage( out vec4 fragColor, in vec2 fragCoord )
+{
+ vec2 p = fragCoord.xy/iResolution.xy;
+
+ vec4 col = texture(iChannel0, p);
+
+
+ //Desaturate
+ if(p.x<.25)
+ {
+ col = vec4( (col.r+col.g+col.b)/3. );
+ }
+ //Invert
+ else if (p.x<.5)
+ {
+ col = vec4(1.) - texture(iChannel0, p);
+ }
+ //Chromatic aberration
+ else if (p.x<.75)
+ {
+ vec2 offset = vec2(.01,.0);
+ col.r = texture(iChannel0, p+offset.xy).r;
+ col.g = texture(iChannel0, p ).g;
+ col.b = texture(iChannel0, p+offset.yx).b;
+ }
+ //Color switching
+ else
+ {
+ col.rgb = texture(iChannel0, p).brg;
+ }
+
+
+ //Line
+ if( mod(abs(p.x+.5/iResolution.y),.25)<0.5/iResolution.y )
+ col = vec4(1.);
+
+
+ fragColor = col;
+}
diff --git a/spa/plugins/vulkan/shaders/filter.comp b/spa/plugins/vulkan/shaders/filter.comp
new file mode 100644
index 0000000..f1ca486
--- /dev/null
+++ b/spa/plugins/vulkan/shaders/filter.comp
@@ -0,0 +1,44 @@
+#version 450
+#extension GL_ARB_separate_shader_objects : enable
+
+#define WORKGROUP_SIZE 32
+layout (local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1 ) in;
+
+layout(rgba32f, set = 0, binding = 0) uniform image2D resultImage;
+layout(set = 0, binding = 1) uniform sampler2D iChannel0;
+
+layout( push_constant ) uniform Constants {
+ float time;
+ int frame;
+ int width;
+ int height;
+} PushConstant;
+
+float iTime;
+int iFrame;
+vec3 iResolution;
+vec4 iMouse;
+
+void mainImage( out vec4 fragColor, in vec2 fragCoord );
+
+void main()
+{
+ iTime = PushConstant.time;
+ iFrame = PushConstant.frame;
+ iResolution = vec3(float(PushConstant.width), float(PushConstant.height), 0.0);
+ iMouse = vec4(0.0, 0.0, 0.0, 0.0);
+ vec2 coord = vec2(float(gl_GlobalInvocationID.x),
+ iResolution.y - float(gl_GlobalInvocationID.y));
+ vec4 outColor;
+
+ if(coord.x >= iResolution.x || coord.y >= iResolution.y)
+ return;
+
+ mainImage(outColor, coord);
+
+ imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), outColor);
+}
+
+//#include "smearcam.comp"
+#include "filter-color.comp"
+//#include "filter-ripple.comp"
diff --git a/spa/plugins/vulkan/shaders/filter.spv b/spa/plugins/vulkan/shaders/filter.spv
new file mode 100644
index 0000000..5bfd245
--- /dev/null
+++ b/spa/plugins/vulkan/shaders/filter.spv
Binary files differ
diff --git a/spa/plugins/vulkan/shaders/main.comp b/spa/plugins/vulkan/shaders/main.comp
new file mode 100644
index 0000000..368b7cf
--- /dev/null
+++ b/spa/plugins/vulkan/shaders/main.comp
@@ -0,0 +1,50 @@
+#version 450
+#extension GL_ARB_separate_shader_objects : enable
+
+#define WORKGROUP_SIZE 32
+layout (local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1 ) in;
+
+layout(rgba32f, binding = 0) uniform image2D resultImage;
+
+layout( push_constant ) uniform Constants {
+ float time;
+ int frame;
+ int width;
+ int height;
+} PushConstant;
+
+float iTime;
+int iFrame;
+vec3 iResolution;
+vec4 iMouse;
+
+void mainImage( out vec4 fragColor, in vec2 fragCoord );
+
+void main()
+{
+ iTime = PushConstant.time;
+ iFrame = PushConstant.frame;
+ iResolution = vec3(float(PushConstant.width), float(PushConstant.height), 0.0);
+ iMouse = vec4(0.0, 0.0, 0.0, 0.0);
+ vec2 coord = vec2(float(gl_GlobalInvocationID.x),
+ iResolution.y - float(gl_GlobalInvocationID.y));
+ vec4 outColor;
+
+ if(coord.x >= iResolution.x || coord.y >= iResolution.y)
+ return;
+
+ mainImage(outColor, coord);
+
+ imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), outColor);
+}
+
+//#include "plasma-globe.comp"
+//#include "mandelbrot-distance.comp"
+#include "disk-intersection.comp"
+//#include "ring-twister.comp"
+//#include "gears.comp"
+//#include "protean-clouds.comp"
+//#include "flame.comp"
+//#include "shader.comp"
+//#include "raymarching-primitives.comp"
+//#include "3d-primitives.comp"
diff --git a/spa/plugins/vulkan/shaders/main.spv b/spa/plugins/vulkan/shaders/main.spv
new file mode 100644
index 0000000..5da1755
--- /dev/null
+++ b/spa/plugins/vulkan/shaders/main.spv
Binary files differ