Add MIT licensed compute example instead

Fixes #218
This commit is contained in:
Wim Taymans 2020-03-18 17:20:36 +01:00
parent 8a2af908a7
commit 64e00165d5
4 changed files with 145 additions and 59 deletions

View file

@ -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);
}

View file

@ -47,7 +47,8 @@ void main()
} }
//#include "plasma-globe.comp" //#include "plasma-globe.comp"
#include "mandelbrot-distance.comp" //#include "mandelbrot-distance.comp"
#include "disk-intersection.comp"
//#include "ring-twister.comp" //#include "ring-twister.comp"
//#include "gears.comp" //#include "gears.comp"
//#include "protean-clouds.comp" //#include "protean-clouds.comp"

Binary file not shown.

View file

@ -1,58 +0,0 @@
// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
// This shader computes the distance to the Mandelbrot Set for everypixel, and colorizes
// it accoringly.
//
// Z -> Z²+c, Z0 = 0.
// therefore Z' -> 2·Z·Z' + 1
//
// The Hubbard-Douady potential G(c) is G(c) = log Z/2^n
// G'(c) = Z'/Z/2^n
//
// So the distance is |G(c)|/|G'(c)| = |Z|·log|Z|/|Z'|
//
// More info here: http://www.iquilezles.org/www/articles/distancefractals/distancefractals.htm
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 p = -1.0 + 2.0 * fragCoord.xy / iResolution.xy;
p.x *= iResolution.x/iResolution.y;
// animation
float tz = 0.5 - 0.5*cos(0.225*iTime);
float zoo = pow( 0.5, 13.0*tz );
vec2 c = vec2(-0.05,.6805) + p*zoo;
// iterate
float di = 1.0;
vec2 z = vec2(0.0);
float m2 = 0.0;
vec2 dz = vec2(0.0);
for( int i=0; i<300; i++ )
{
if( m2>1024.0 ) { di=0.0; break; }
// Z' -> 2·Z·Z' + 1
dz = 2.0*vec2(z.x*dz.x-z.y*dz.y, z.x*dz.y + z.y*dz.x) + vec2(1.0,0.0);
// Z -> Z² + c
z = vec2( z.x*z.x - z.y*z.y, 2.0*z.x*z.y ) + c;
m2 = dot(z,z);
}
// distance
// d(c) = |Z|·log|Z|/|Z'|
float d = 0.5*sqrt(dot(z,z)/dot(dz,dz))*log(dot(z,z));
if( di>0.5 ) d=0.0;
// do some soft coloring based on distance
d = clamp( pow(4.0*d/zoo,0.2), 0.0, 1.0 );
vec3 col = vec3( d );
fragColor = vec4( col, 1.0 );
}