Added shader packs
This commit is contained in:
BIN
tools/packsrc/Alien Ocean/images/iChannel1.png
Normal file
BIN
tools/packsrc/Alien Ocean/images/iChannel1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
31
tools/packsrc/Alien Ocean/pack.json
Normal file
31
tools/packsrc/Alien Ocean/pack.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"author": "NLIBS",
|
||||
"name": "Alien Ocean",
|
||||
"version": "1.0.0",
|
||||
"description": "A stylized alien ocean inspired by Very fast procedural ocean by afl_ext Can you spot the other planet in the sky?",
|
||||
"license": "CC BY-NC-SA 3.0",
|
||||
"engine": "shadertoy",
|
||||
"id": "wldBRf",
|
||||
"tags": [
|
||||
"reflection",
|
||||
"raymarching",
|
||||
"distance",
|
||||
"neon"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 1,
|
||||
|
||||
"bufferA":
|
||||
{
|
||||
"source": "./shaders/Buffer A.frag.qsb"
|
||||
},
|
||||
|
||||
"channel0": "{bufferA}",
|
||||
|
||||
"channel1":
|
||||
{
|
||||
"type": 0,
|
||||
"source": "./images/iChannel1.png"
|
||||
}
|
||||
}
|
||||
33
tools/packsrc/Alien Ocean/shaders/Buffer A.frag
Normal file
33
tools/packsrc/Alien Ocean/shaders/Buffer A.frag
Normal file
@@ -0,0 +1,33 @@
|
||||
float ray(vec3 ro, vec3 rd, float t)
|
||||
{
|
||||
vec3 p = ro+t*rd;
|
||||
float h = 0.;
|
||||
for (int i=0;i<100;i++) {
|
||||
float h = p.y-srf(p.xz,ITERS_RAY, iTime).x;
|
||||
if (h<t*EPS*4.) return t;
|
||||
t+=h;
|
||||
p+=rd*h;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void mainImage( out vec4 O, in vec2 u )
|
||||
{
|
||||
vec2 R = iResolution.xy;
|
||||
if (all(lessThan(u*8.,R))) {
|
||||
vec2 uv = (16.*u-R)/R.x,
|
||||
muv = (2.*iMouse.xy-R)/R.x*-float(iMouse.z>1.)*PI;
|
||||
|
||||
//Camera
|
||||
vec3 vo = vec3(iTime,1.01,iTime),
|
||||
vd = camera_ray(vo,uv,muv,iTime);
|
||||
|
||||
float t = -vo.y/(vd.y-1.0+EPS*8.);
|
||||
if (t>0.) {
|
||||
//march to surface with high epsilon
|
||||
t = ray(vo,vd, t);
|
||||
}
|
||||
|
||||
O = vec4(t);
|
||||
}
|
||||
}
|
||||
57
tools/packsrc/Alien Ocean/shaders/Common.frag
Normal file
57
tools/packsrc/Alien Ocean/shaders/Common.frag
Normal file
@@ -0,0 +1,57 @@
|
||||
#define PI 3.141592
|
||||
#define EPS 0.005
|
||||
|
||||
#define ITERS_RAY 17
|
||||
#define ITERS_NORMAL 45
|
||||
#define W_DEPTH 2.2
|
||||
#define W_SPEED 1.4
|
||||
#define W_DETAIL .75
|
||||
|
||||
const mat2 rot = mat2(cos(12.),sin(12.),-sin(12.),cos(12.));
|
||||
|
||||
vec3 srf(vec2 pos, int n, float time)
|
||||
{
|
||||
pos *= W_DEPTH;
|
||||
float freq = 0.6;
|
||||
float t = W_SPEED*time;
|
||||
float weight = 1.0;
|
||||
float w = 0.0;
|
||||
vec2 dx = vec2(0);
|
||||
|
||||
vec2 dir = vec2(1,0);
|
||||
for(int i=0;i<n;i++){
|
||||
dir = rot*dir;
|
||||
float x = dot(dir, pos) * freq + t;
|
||||
float wave = exp(sin(x)-1.);
|
||||
vec2 res = vec2(wave, wave*cos(x)) * weight;
|
||||
pos -= dir*res.y*.48;
|
||||
w += res.x;
|
||||
dx += res.y*dir / pow(weight,W_DETAIL);
|
||||
weight *= .8;
|
||||
freq *= 1.2;
|
||||
t *= 1.08;
|
||||
}
|
||||
float ws = (pow(.8,float(n))-1.)*-5.; //Geometric sum
|
||||
|
||||
return vec3(w / ws,dx / pow(ws,1.-W_DETAIL));
|
||||
}
|
||||
|
||||
vec3 norm(vec2 p, int n, float time){
|
||||
return normalize(vec3(-srf(p.xy, n, time).yz,1.).xzy);
|
||||
}
|
||||
|
||||
vec3 camera_ray(vec3 vo, vec2 uv, vec2 muv, float iTime)
|
||||
{
|
||||
vec3 vd = normalize(vec3(uv,1));
|
||||
|
||||
//Add Mouse rotation
|
||||
vec4 cs = vec4(cos(muv),sin(muv));
|
||||
vd.yz = mat2(cs.y,cs.w,-cs.w,cs.y)*vd.yz;
|
||||
vd.xz = mat2(cs.x,cs.z,-cs.z,cs.x)*vd.xz;
|
||||
//Add Water bobbing
|
||||
vec2 ang = norm(vo.xz,5, iTime).xz*-.05*PI;
|
||||
cs = vec4(cos(ang),sin(ang));
|
||||
vd.xy = mat2(cs.x,cs.z,-cs.z,cs.x)*vd.xy;
|
||||
vd.zy = mat2(cs.y,cs.w,-cs.w,cs.y)*vd.zy;
|
||||
return vd;
|
||||
}
|
||||
96
tools/packsrc/Alien Ocean/shaders/Image.frag
Normal file
96
tools/packsrc/Alien Ocean/shaders/Image.frag
Normal file
@@ -0,0 +1,96 @@
|
||||
const vec3 star_dir = vec3(0.,.199,.98);
|
||||
const vec3 star_col = vec3(1.,.5,.06)*200.;
|
||||
|
||||
float ray(vec3 ro, vec3 rd, float t)
|
||||
{
|
||||
vec3 p = ro+t*rd;
|
||||
float h = 0.0;
|
||||
for (int i=0;i<50;i++) {
|
||||
float h = p.y-srf(p.xz,ITERS_RAY, iTime).x;
|
||||
t+=h;
|
||||
p+=rd*h;
|
||||
if (h<EPS*t) return t;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
vec3 sky(vec3 rd)
|
||||
{
|
||||
float z = rd.z*.5+.5;
|
||||
float v = max(dot(rd,star_dir),0.);
|
||||
vec3 star = pow(min(pow(v,5.),.992),450.)*star_col + pow(v,40.)*vec3(1.,.4,.03);
|
||||
star *= 1.-smoothstep(4e-3,3e-3,length(rd-vec3(-.049,.291,.955)))*.7;
|
||||
|
||||
float mist_col = exp(min(-rd.y*8.,0.))*0.03;
|
||||
vec3 sky_col = mix(vec3(.2,.5,.8)*(z+1.)*.01,vec3(.25,.02,.01),z*z*.9)*1.5;
|
||||
vec3 col = sky_col+mist_col+star;
|
||||
return col;
|
||||
}
|
||||
|
||||
float fresnel(vec3 rd, vec3 N, float n1, float n2)
|
||||
{
|
||||
float I = acos(abs(dot(rd, N))-1e-5);
|
||||
float cosI = cos(I);
|
||||
float cosR = n1/n2 * sin(I);
|
||||
if(cosR > 1.) return 1.;
|
||||
cosR = sqrt(1. - cosR * cosR);
|
||||
float Rs = (n1*cosI - n2 * cosR)/(n1*cosI + n2 * cosR);
|
||||
float Rp = (n1*cosR - n2 * cosI)/(n1*cosR + n2 * cosI);
|
||||
return mix(Rs*Rs, Rp*Rp, .5);
|
||||
}
|
||||
|
||||
void mainImage( out vec4 O, in vec2 u )
|
||||
{
|
||||
vec2 R = iResolution.xy,
|
||||
uv = (2.*u-R)/R.x,
|
||||
muv = (2.*iMouse.xy-R)/R.x*-float(iMouse.z>1.)*PI;
|
||||
|
||||
//Camera
|
||||
vec3 vo = vec3(iTime,1.01,iTime),
|
||||
vd = camera_ray(vo,uv,muv,iTime),
|
||||
//Sky colour
|
||||
sky_col = sky(vd),
|
||||
col = sky_col;
|
||||
|
||||
if ((1.0-vo.y)/vd.y>0.0) {
|
||||
//raymarch using previous pass
|
||||
float t = texelFetch(iChannel0,ivec2(u)>>3,0).x;
|
||||
t = ray(vo,vd, t);
|
||||
|
||||
//normal using derivative
|
||||
vec3 p = vo+vd*t;
|
||||
vec3 N = norm(p.xz, max(ITERS_NORMAL+min(int(log(t)*-10.),0),1), iTime);
|
||||
|
||||
//Reflected ray
|
||||
vec3 refd = reflect(vd,N);
|
||||
//Approx reflection occlusion from other waves
|
||||
float ref_hit = clamp((p.y+refd.y*100.-.5)*.5,0.,1.);
|
||||
//vec3 ref_col = mix(vec3(0),sky(refd),ref_hit);
|
||||
vec3 ref_col = mix(sky(normalize(refd+vec3(0,.2,0)))*.4,sky(refd),ref_hit);
|
||||
|
||||
//approx SSS
|
||||
vec3 H = normalize(star_dir+N*.05);
|
||||
float thick = pow(1.-p.y,2.);
|
||||
float I = pow(max(dot(vd,H),0.), 8.)*.002;
|
||||
vec3 ss_col = I*star_col*pow(vec3(.8,.15,.02)*.5,vec3(.3+thick*2.));
|
||||
|
||||
//Mix using fresnel
|
||||
col = mix(ss_col,ref_col,fresnel(vd,N,1.,1.333));
|
||||
|
||||
//Fog
|
||||
col = mix(sky_col,col,exp(-pow(t,1.5)*.007));
|
||||
//col = ss_col;
|
||||
}
|
||||
|
||||
vec2 d = pow(abs(uv*.5)+.1,vec2(4.));
|
||||
col *= pow(1.-.84*pow(d.x+d.y,.25),2.); //vignette
|
||||
col += col*col;
|
||||
col = 1.-exp(-col);
|
||||
col = pow(col,vec3(1./2.2));
|
||||
|
||||
vec3 noise = pow(texelFetch(iChannel1, ivec2(u)%1024, 0).rgb,vec3(1./2.2));
|
||||
noise = (noise*2.-1.)*0.499*2.;
|
||||
col += noise/256.;
|
||||
|
||||
O = vec4(col,1.);
|
||||
}
|
||||
22
tools/packsrc/Audio Reactive Galaxy/pack.json
Normal file
22
tools/packsrc/Audio Reactive Galaxy/pack.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"author": "JelyMe314",
|
||||
"name": "Audio Reactive Galaxy",
|
||||
"version": "1.0.0",
|
||||
"description": "A version of CBS's simplicity galaxy shader, to be used with lively wallpaper.",
|
||||
"license": "",
|
||||
"engine": "shadertoy",
|
||||
"id": "ms3Gzl",
|
||||
"tags": [
|
||||
"reactive",
|
||||
"galaxy",
|
||||
"fractal"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 1,
|
||||
|
||||
"channel0":
|
||||
{
|
||||
"type": 4
|
||||
}
|
||||
}
|
||||
85
tools/packsrc/Audio Reactive Galaxy/shaders/Image.frag
Normal file
85
tools/packsrc/Audio Reactive Galaxy/shaders/Image.frag
Normal file
@@ -0,0 +1,85 @@
|
||||
//CBS
|
||||
//Parallax scrolling fractal galaxy.
|
||||
//Inspired by JoshP's Simplicity shader: https://www.shadertoy.com/view/lslGWr
|
||||
|
||||
// http://www.fractalforums.com/new-theories-and-research/very-simple-formula-for-fractal-patterns/
|
||||
float field(in vec3 p,float s) {
|
||||
float strength = 7. + .03 * log(1.e-6 + fract(sin(iTime) * 4373.11));
|
||||
float accum = s/4.;
|
||||
float prev = 0.;
|
||||
float tw = 0.;
|
||||
for (int i = 0; i < 26; ++i) {
|
||||
float mag = dot(p, p);
|
||||
p = abs(p) / mag + vec3(-.5, -.4, -1.5);
|
||||
float w = exp(-float(i) / 7.);
|
||||
accum += w * exp(-strength * pow(abs(mag - prev), 2.2));
|
||||
tw += w;
|
||||
prev = mag;
|
||||
}
|
||||
return max(0., 5. * accum / tw - .7);
|
||||
}
|
||||
|
||||
// Less iterations for second layer
|
||||
float field2(in vec3 p, float s) {
|
||||
float strength = 7. + .03 * log(1.e-6 + fract(sin(iTime) * 4373.11));
|
||||
float accum = s/4.;
|
||||
float prev = 0.;
|
||||
float tw = 0.;
|
||||
for (int i = 0; i < 18; ++i) {
|
||||
float mag = dot(p, p);
|
||||
p = abs(p) / mag + vec3(-.5, -.4, -1.5);
|
||||
float w = exp(-float(i) / 7.);
|
||||
accum += w * exp(-strength * pow(abs(mag - prev), 2.2));
|
||||
tw += w;
|
||||
prev = mag;
|
||||
}
|
||||
return max(0., 5. * accum / tw - .7);
|
||||
}
|
||||
|
||||
vec3 nrand3( vec2 co )
|
||||
{
|
||||
vec3 a = fract( cos( co.x*8.3e-3 + co.y )*vec3(1.3e5, 4.7e5, 2.9e5) );
|
||||
vec3 b = fract( sin( co.x*0.3e-3 + co.y )*vec3(8.1e5, 1.0e5, 0.1e5) );
|
||||
vec3 c = mix(a, b, 0.5);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
|
||||
vec2 uv = 2. * fragCoord.xy / iResolution.xy - 1.;
|
||||
vec2 uvs = uv * iResolution.xy / max(iResolution.x, iResolution.y);
|
||||
vec3 p = vec3(uvs / 4., 0) + vec3(1., -1.3, 0.);
|
||||
p += .2 * vec3(sin(iTime / 16.), sin(iTime / 12.), sin(iTime / 128.));
|
||||
|
||||
float freqs[4];
|
||||
//Sound
|
||||
freqs[0] = texture( iChannel0, vec2( 0.01, 0.25 ) ).x;
|
||||
freqs[1] = texture( iChannel0, vec2( 0.07, 0.25 ) ).x;
|
||||
freqs[2] = texture( iChannel0, vec2( 0.15, 0.25 ) ).x;
|
||||
freqs[3] = texture( iChannel0, vec2( 0.30, 0.25 ) ).x;
|
||||
|
||||
float t = field(p,freqs[2]);
|
||||
float v = (1. - exp((abs(uv.x) - 1.) * 6.)) * (1. - exp((abs(uv.y) - 1.) * 6.));
|
||||
|
||||
//Second Layer
|
||||
vec3 p2 = vec3(uvs / (4.+sin(iTime*0.11)*0.2+0.2+sin(iTime*0.15)*0.3+0.4), 1.5) + vec3(2., -1.3, -1.);
|
||||
p2 += 0.25 * vec3(sin(iTime / 16.), sin(iTime / 12.), sin(iTime / 128.));
|
||||
float t2 = field2(p2,freqs[3]);
|
||||
vec4 c2 = mix(.4, 1., v) * vec4(1.3 * t2 * t2 * t2 ,1.8 * t2 * t2 , t2* freqs[0], t2);
|
||||
|
||||
|
||||
//Let's add some stars
|
||||
//Thanks to http://glsl.heroku.com/e#6904.0
|
||||
vec2 seed = p.xy * 2.0;
|
||||
seed = floor(seed * iResolution.x);
|
||||
vec3 rnd = nrand3( seed );
|
||||
vec4 starcolor = vec4(pow(rnd.y,40.0));
|
||||
|
||||
//Second Layer
|
||||
vec2 seed2 = p2.xy * 2.0;
|
||||
seed2 = floor(seed2 * iResolution.x);
|
||||
vec3 rnd2 = nrand3( seed2 );
|
||||
starcolor += vec4(pow(rnd2.y,40.0));
|
||||
|
||||
fragColor = mix(freqs[3]-.3, 1., v) * vec4(1.5*freqs[2] * t * t* t , 1.2*freqs[1] * t * t, freqs[3]*t, 1.0)+c2+starcolor;
|
||||
}
|
||||
32
tools/packsrc/Blueprint/pack.json
Normal file
32
tools/packsrc/Blueprint/pack.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"author": "s23b",
|
||||
"name": "Blueprint of the Arkiteckt",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"license": "CC BY-NC-SA 3.0",
|
||||
"engine": "shadertoys",
|
||||
"id": "4tySDW",
|
||||
"tags": [
|
||||
"reactive",
|
||||
"raymarching",
|
||||
"fractal",
|
||||
"edge detect",
|
||||
"mouse"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 1,
|
||||
|
||||
"channel0":
|
||||
{
|
||||
"type": 2,
|
||||
"source": "./shaders/Buffer A.frag.qsb",
|
||||
"frame_buffer_channel": 1,
|
||||
|
||||
"channel0":
|
||||
{
|
||||
"type": 4,
|
||||
"invert": true
|
||||
}
|
||||
}
|
||||
}
|
||||
8
tools/packsrc/Blueprint/shaders/Buffer A.frag
Normal file
8
tools/packsrc/Blueprint/shaders/Buffer A.frag
Normal file
@@ -0,0 +1,8 @@
|
||||
// the purpose of this buffer is too smooth out the sudden changes in the fft
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 uv = fragCoord.xy / iResolution.xy;
|
||||
float old = texture(iChannel1, uv).x;
|
||||
float new = texture(iChannel0, uv).x;
|
||||
fragColor = vec4(mix(old, new, new > old ? .4 : .04));
|
||||
}
|
||||
356
tools/packsrc/Blueprint/shaders/Image.frag
Normal file
356
tools/packsrc/Blueprint/shaders/Image.frag
Normal file
@@ -0,0 +1,356 @@
|
||||
#define SPEED .1
|
||||
#define FOV 3.
|
||||
|
||||
#define MAX_STEPS 80
|
||||
#define EPS .001
|
||||
#define RENDER_DIST 5.
|
||||
#define AO_SAMPLES 4.
|
||||
#define AO_RANGE 100.
|
||||
|
||||
#define PI 3.14159265359
|
||||
#define saturate(x) clamp(x, 0., 1.)
|
||||
|
||||
// precomputed globals
|
||||
float _house = 0.;
|
||||
float _boat = 0.;
|
||||
float _spaceship = 0.;
|
||||
float _atmosphere = 0.;
|
||||
mat3 _kifsRot = mat3(1, 0, 0, 0, 1, 0, 0, 0, 1);
|
||||
float _kifsOffset = 0.;
|
||||
|
||||
// rotate 2d space with given angle
|
||||
void tRotate(inout vec2 p, float angel) {
|
||||
float s = sin(angel), c = cos(angel);
|
||||
p *= mat2(c, -s, s, c);
|
||||
}
|
||||
|
||||
// divide 2d space into s chunks around the center
|
||||
void tFan(inout vec2 p, float s) {
|
||||
float k = s / PI / 2.;
|
||||
tRotate(p, -floor((atan(p.y, p.x)) * k + .5) / k);
|
||||
}
|
||||
|
||||
// rectangle distance
|
||||
float sdRect(vec2 p, vec2 r) {
|
||||
p = abs(p) - r;
|
||||
return min(max(p.x, p.y), 0.) + length(max(p, 0.));
|
||||
}
|
||||
|
||||
// box distance
|
||||
float sdBox(vec3 p, vec3 r) {
|
||||
p = abs(p) - r;
|
||||
return min(max(p.x, max(p.y, p.z)), 0.) + length(max(p, 0.));
|
||||
}
|
||||
|
||||
// sphere distance
|
||||
float sdSphere(vec3 p, float r) {
|
||||
return length(p) - r;
|
||||
}
|
||||
|
||||
// 3d cross distance
|
||||
float sdCross(vec3 p, vec3 r) {
|
||||
p =abs(p) - r;
|
||||
p.xy = p.x < p.y ? p.xy : p.yx;
|
||||
p.yz = p.y < p.z ? p.yz : p.zy;
|
||||
p.xy = p.x < p.y ? p.xy : p.yx;
|
||||
return length(min(p.yz, 0.)) - max(p.y, 0.);
|
||||
}
|
||||
|
||||
// union
|
||||
float opU(float a, float b) {
|
||||
return min(a, b);
|
||||
}
|
||||
|
||||
// intersection
|
||||
float opI(float a, float b) {
|
||||
return max(a, b);
|
||||
}
|
||||
|
||||
// substraction
|
||||
float opS(float a, float b) {
|
||||
return max(a, -b);
|
||||
}
|
||||
|
||||
// smooth union
|
||||
float opSU(float a, float b, float k)
|
||||
{
|
||||
float h = clamp(.5 + .5 * (b - a) / k, 0., 1.);
|
||||
return mix(b, a, h) - k * h * (1. - h);
|
||||
}
|
||||
|
||||
// house distance
|
||||
float sdHouse(vec3 p) {
|
||||
p.y += .075;
|
||||
vec3 boxDim = vec3(.2, .15, .2);
|
||||
|
||||
// add the walls
|
||||
float d = sdBox(p, boxDim);
|
||||
|
||||
// add the windows
|
||||
vec3 q = abs(p);
|
||||
vec3 windSize = vec3(.04, .04, .06);
|
||||
q -= windSize + vec3(.005);
|
||||
d = opI(d, opU(sdCross(q, windSize), .11 - abs(p.y)));
|
||||
|
||||
// add the roof
|
||||
q = p;
|
||||
q.y -= .38;
|
||||
tFan(q.xz, 4.);
|
||||
tRotate(q.xy, PI/4.);
|
||||
d = opU(d, sdBox(q, vec3(.35, .01, .35)));
|
||||
|
||||
// make it hollow
|
||||
d = opS(d, sdBox(p, boxDim - vec3(.02)));
|
||||
return d;
|
||||
}
|
||||
|
||||
// boat distance
|
||||
float sdBoat(vec3 p) {
|
||||
|
||||
// add the mast (a word I learned today :P)
|
||||
float d = sdBox(p + vec3(0, .05, 0), vec3(.01, .2, .01));
|
||||
|
||||
// add the sail
|
||||
vec3 q = p + vec3(0, -.05, .12);
|
||||
float a = sdSphere(q, .2);
|
||||
a = opS(a, sdSphere(q, .195));
|
||||
q.x = abs(q.x);
|
||||
tRotate(q.yx, .1);
|
||||
a = opI(a, sdBox(q - vec3(0, 0, .1), vec3(.1)));
|
||||
d = opU(d, a);
|
||||
|
||||
// add the body of the boat
|
||||
p.x = abs(p.x);
|
||||
p.x += .1;
|
||||
a = sdSphere(p, .3);
|
||||
a = opS(a, sdSphere(p, .29));
|
||||
a = opI(a, p.y + .15);
|
||||
d = opU(d,a);
|
||||
return d;
|
||||
}
|
||||
|
||||
// spaceship distance
|
||||
float sdSpaceship(vec3 p) {
|
||||
tFan(p.xz, 6.);
|
||||
p.x += .3;
|
||||
|
||||
// add the cap
|
||||
float d = sdSphere(p, .4);
|
||||
d = opS(d, p.y - .12);
|
||||
|
||||
// add the body
|
||||
d = opU(d, sdSphere(p, .39));
|
||||
|
||||
// add the fins (another word I learned, thanks google :P)
|
||||
d = opU(d, opI(sdSphere(p + vec3(0, .24, 0), .41), sdRect(p.zx, vec2(.005, .5))));
|
||||
d = opS(d, sdSphere(p + vec3(0, .3, 0), .37));
|
||||
d = opS(d, p.y + .25);
|
||||
return d;
|
||||
}
|
||||
|
||||
// atmosphere distance
|
||||
float sdAtmosphere(vec3 p) {
|
||||
float time = iTime;
|
||||
tRotate(p.yz, time);
|
||||
vec3 q = p;
|
||||
tFan(q.xz, 12.);
|
||||
float d = sdBox(q - vec3(.3, 0, 0), vec3(.01));
|
||||
tRotate(p.yx, time);
|
||||
q = p;
|
||||
tFan(q.yz, 12.);
|
||||
d = opU(d, sdBox(q - vec3(0, .23, 0), vec3(.01)));
|
||||
tRotate(p.xz, time);
|
||||
q = p;
|
||||
tFan(q.yx, 12.);
|
||||
d = opU(d, sdBox(q - vec3(0, .16, 0), vec3(.01)));
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
// distance estimation of everything together
|
||||
float map(vec3 p) {
|
||||
float d = _house <= 0. ? 5. : sdHouse(p) + .1 - _house * .1;
|
||||
if (_boat > 0.) d = opU(d, sdBoat(p) + .1 - _boat * .1);
|
||||
if (_spaceship > 0.) d = opU(d, sdSpaceship(p) + .1 - _spaceship * .1);
|
||||
if (_atmosphere > 0.) d = opU(d, sdAtmosphere(p) + .1 - _atmosphere * .1);
|
||||
|
||||
//return d;
|
||||
float s = 1.;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
tFan(p.xz, 10.);
|
||||
p = abs(p);
|
||||
p -= _kifsOffset;
|
||||
|
||||
p *= _kifsRot;
|
||||
s *= 2.;
|
||||
}
|
||||
|
||||
return opSU(d, sdBox(p * s, vec3(s / 17.)) / s, .1);
|
||||
}
|
||||
|
||||
// trace the scene from ro (origin) to rd (direction, normalized)
|
||||
// until hit or reached maxDist, outputs distance traveled, the number of steps
|
||||
// and the closest distance achieved during marching (used of cheap edge detection)
|
||||
float trace(vec3 ro, vec3 rd, float maxDist, out float steps, out float nt) {
|
||||
float total = 0.;
|
||||
steps = 0.;
|
||||
nt = 100.;
|
||||
|
||||
for (int i = 0; i < MAX_STEPS; ++i) {
|
||||
++steps;
|
||||
float d = map(ro + rd * total);
|
||||
nt = min(d, nt);
|
||||
total += d;
|
||||
if (d < EPS || maxDist < total) break;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
// calculate the normal vector
|
||||
vec3 getNormal(vec3 p) {
|
||||
vec2 e = vec2(.0001, 0);
|
||||
return normalize(vec3(
|
||||
map(p + e.xyy) - map(p - e.xyy),
|
||||
map(p + e.yxy) - map(p - e.yxy),
|
||||
map(p + e.yyx) - map(p - e.yyx)
|
||||
));
|
||||
}
|
||||
|
||||
// ambient occlusion
|
||||
float calculateAO(vec3 p, vec3 n) {
|
||||
|
||||
float r = 0., w = 1., d;
|
||||
|
||||
for (float i = 1.; i <= AO_SAMPLES; i++){
|
||||
d = i / AO_SAMPLES / AO_RANGE;
|
||||
r += w * (d - map(p + n * d));
|
||||
w *= .5;
|
||||
}
|
||||
|
||||
return 1.-saturate(r * AO_RANGE);
|
||||
}
|
||||
|
||||
// a lovely function that goes up and down periodically between 0 and 1, pausing at the extremes
|
||||
float pausingWave(float x, float a, float b) {
|
||||
x = abs(fract(x) - .5) * 1. - .5 + a;
|
||||
return smoothstep(0., a - b, x);
|
||||
}
|
||||
|
||||
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
|
||||
// transform screen coordinates
|
||||
vec2 uv = fragCoord.xy / iResolution.xy;
|
||||
uv = uv * 2. - 1.;
|
||||
uv.x *= iResolution.x / iResolution.y;
|
||||
|
||||
// transform mouse coordinates
|
||||
vec2 mouse = iMouse.xy / iResolution.xy * 2. - 1.;
|
||||
mouse.x *= iResolution.x / iResolution.y;
|
||||
mouse *= 2.;
|
||||
|
||||
// set time dependent constants
|
||||
float speed = .25 / 10.5;
|
||||
float time = mod(iTime, 290.);
|
||||
time -= 10.5;
|
||||
if (time > 167.) time -= 167.; else
|
||||
if (time > 63.) time -= 63.;
|
||||
time -= 5.25;
|
||||
time *= speed;
|
||||
|
||||
// these determine which object to show
|
||||
_house = pausingWave(time, .15, .125);
|
||||
_boat = pausingWave(time - .125 / .1, .15, .125);
|
||||
_spaceship = pausingWave(time - .25 / .1, .15, .125);
|
||||
_atmosphere = pausingWave(time - .375 / .1, .15, .125) * step(10., iTime);
|
||||
|
||||
// set up kifs rotation matrix
|
||||
float a = -texture(iChannel0, vec2(.5, .25)).x + sin(iTime) * .2 + .9;
|
||||
float s = sin(a), c = cos(a);
|
||||
_kifsRot *= mat3(c, -s, 0, s, c, 0, 0, 0, 1);
|
||||
_kifsRot *= mat3(1, 0, 0, 0, c, -s, 0, s, c);
|
||||
_kifsRot *= mat3(c, 0, s, 0, 1, 0, -s, 0, c);
|
||||
|
||||
// set up kifs offset
|
||||
_kifsOffset = .07 + texture(iChannel0, vec2(.1, .25)).x * .06;
|
||||
|
||||
// set up camera position
|
||||
vec3 rd = normalize(vec3(uv, FOV));
|
||||
vec3 ro = vec3(0, 0, -2);
|
||||
|
||||
// light is relative to the camera
|
||||
vec3 light = vec3(-1., .5, 0);
|
||||
|
||||
vec2 rot = vec2(0);
|
||||
if (iMouse.z > 0. && iMouse.x > 0. && iMouse.y > 0.) {
|
||||
// rotate the scene using the mouse
|
||||
rot = -mouse;
|
||||
} else {
|
||||
// otherwise rotate constantly as time passes
|
||||
rot = vec2(
|
||||
iTime * SPEED * PI,//had to slightly modify \/ this value due to an issue reported by Fabrice
|
||||
mix(sin(iTime * SPEED) * PI / 8., PI / 2. - 1e-5, saturate(exp(-iTime + 10.5))));
|
||||
}
|
||||
|
||||
tRotate(rd.yz, rot.y);
|
||||
tRotate(rd.xz, rot.x);
|
||||
tRotate(light.xz, rot.x);
|
||||
tRotate(ro.yz, rot.y);
|
||||
tRotate(ro.xz, rot.x);
|
||||
|
||||
// march
|
||||
float steps, outline, dist = trace(ro, rd, RENDER_DIST, steps, outline);
|
||||
|
||||
// calculate hit point coordinates
|
||||
vec3 p = ro + rd * dist;
|
||||
|
||||
// calculate normal
|
||||
vec3 normal = getNormal(p);
|
||||
|
||||
// light direction
|
||||
vec3 l = normalize(light - p);
|
||||
|
||||
// ambient light
|
||||
float ambient = .1;
|
||||
|
||||
// diffuse light
|
||||
float diffuse = max(0., dot(l, normal));
|
||||
|
||||
// specular light
|
||||
float specular = pow(max(0., dot(reflect(-l, normal), -rd)), 4.);
|
||||
|
||||
// "ambient occlusion"
|
||||
float ao = calculateAO(p, normal);
|
||||
|
||||
// create the background grid
|
||||
vec2 gridUv = fragCoord.xy - iResolution.xy / 2.;
|
||||
float grid = dot(step(mod(gridUv.xyxy, vec4(20, 20, 100, 100)), vec4(1)), vec4(.1, .1, .2, .2));
|
||||
|
||||
// create blue background
|
||||
vec3 bg = vec3(0, .1, .3) * saturate(1.5 - length(uv) * .5);
|
||||
|
||||
// find the edges in the geometry
|
||||
float edgeWidth = .0015;
|
||||
float edge = smoothstep(1., .0, dot(normal, getNormal(p - normal * edgeWidth))) * step(length(p), 1.);
|
||||
|
||||
// get the outline of the shapes
|
||||
outline = smoothstep(.005, .0, outline) * step(1., length(p));
|
||||
|
||||
// diagonal strokes used for shading
|
||||
vec2 strokes = sin(vec2(uv.x + uv.y, uv.x - uv.y) * iResolution.y * PI / 4.) * .5 - .5;
|
||||
|
||||
// first part of the shading: ao + marching steps
|
||||
float highlights = (steps / float(MAX_STEPS) + sqrt(1. - ao)) * step(length(p), 1.) * .5;
|
||||
highlights = floor(highlights * 5.) / 10.;
|
||||
|
||||
// second part of the shading: ambient + diffuse + specular light
|
||||
float fog = saturate(length(ro) - dist * dist * .25);
|
||||
float lightValue = (ambient + diffuse + specular) * fog;
|
||||
lightValue = floor(lightValue * 5.) / 10.;
|
||||
|
||||
fragColor.rgb = mix(bg, vec3(1., .9, .7),
|
||||
max(max(max(saturate(highlights + strokes.x), saturate(lightValue + strokes.y)) * fog,
|
||||
(edge + outline) * 2. + strokes.y), grid));
|
||||
|
||||
// gamma correction
|
||||
fragColor = pow(saturate(fragColor), vec4(1. / 2.2)) * step(abs(uv.y), 1.);
|
||||
}
|
||||
28
tools/packsrc/Kaleidoscopic Warp Tunnel /pack.json
Normal file
28
tools/packsrc/Kaleidoscopic Warp Tunnel /pack.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"author": "Hyeve",
|
||||
"name": "Kaleidoscopic Warp Tunnel",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"license": "",
|
||||
"engine": "shadertoy",
|
||||
"id": "sddBzl",
|
||||
"tags": [
|
||||
"3d",
|
||||
"raymarching",
|
||||
"transparency",
|
||||
"glass",
|
||||
"reflections",
|
||||
"crystal"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 0.5,
|
||||
|
||||
"bufferA":
|
||||
{
|
||||
"source": "./shaders/Buffer A.frag.qsb",
|
||||
"frame_buffer_channel": 0
|
||||
},
|
||||
|
||||
"channel0":"{bufferA}"
|
||||
}
|
||||
122
tools/packsrc/Kaleidoscopic Warp Tunnel /shaders/Buffer A.frag
Normal file
122
tools/packsrc/Kaleidoscopic Warp Tunnel /shaders/Buffer A.frag
Normal file
@@ -0,0 +1,122 @@
|
||||
#define DTR 0.01745329
|
||||
#define rot(a) mat2(cos(a),sin(a),-sin(a),cos(a))
|
||||
|
||||
|
||||
vec2 uv=vec2(0);
|
||||
vec3 cp,cn,cr,ss,oc,gl=vec3(0),vb,ro,rd,so,ld;
|
||||
vec4 fc=vec4(0),cc=vec4(0);
|
||||
float tt,cd,sd,md,io,oa,td=0.,li;
|
||||
int es=0,ec=0,fi=1;
|
||||
|
||||
|
||||
float bx(vec3 p,vec3 s){vec3 q=abs(p)-s;return min(max(q.x,max(q.y,q.z)),0.)+length(max(q,0.));}
|
||||
float cy(vec3 p, vec2 s){p.y+=s.x/2.;p.y-=clamp(p.y,0.,s.x);return length(p)-s.y;}
|
||||
float tor(vec3 p,vec2 t){return length(vec2(length(p.xz)-t.x,p.y))-t.y;}
|
||||
float gy(vec3 p, vec3 s){return (abs(dot(sin(p*s.x),cos((p*s.y).zxy)))-s.z)/(max(s.x,s.y)*1.8);}
|
||||
float smin(float a, float b, float k){float h=clamp(0.5+0.5*(b-a)/k,0.,1.);return mix(b,a,h)-k*h*(1.-h);}
|
||||
|
||||
float h11 (float a){return fract(sin((a)*12.9898)*43758.5453123);}
|
||||
|
||||
#define pi 3.1415926535
|
||||
vec3 pal( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d ){
|
||||
return a + b*cos(2.*pi*(c*t+d));
|
||||
}
|
||||
|
||||
vec3 mpal(vec3 pt)
|
||||
{
|
||||
vec3 e = vec3(0.5); return pal(length(vec3(pt.z,sin(pt.y)*0.5,cos(pt.x)*0.5)), e*0.8,e-0.1,e,vec3(0.11,0.33,0.66));
|
||||
}
|
||||
|
||||
float mid()
|
||||
{
|
||||
float s = pow(sin(tt)*0.5+0.5,1.5);
|
||||
return sin(s + tt*0.1)*pi;
|
||||
}
|
||||
|
||||
float mp(vec3 p)
|
||||
{
|
||||
vec3 pp = p;
|
||||
|
||||
p.xy *= rot(tt*0.1);
|
||||
p.xy += sin(p.z*0.1);
|
||||
|
||||
p.z += tt*4.;
|
||||
p.z=mod(p.z,30.)-15.;
|
||||
|
||||
for(float i = 0.; i < 4.; i++)
|
||||
{
|
||||
p.xy = abs(p.xy) - 1.7;
|
||||
p.xy *= rot(i + tt*0.1);
|
||||
p.z=abs(p.z)-3.;
|
||||
}
|
||||
|
||||
|
||||
sd = bx(p,vec3(1.5,1.5,1));
|
||||
sd = max(-cy(pp.yzx, vec2(100,5)),sd);
|
||||
sd = min(sd,bx(pp+vec3(0,0,-15),vec3(10,10,1)));
|
||||
//sd = min(sd, length(pp-vec3(0,0,-50))-5.);
|
||||
|
||||
sd=abs(sd)-0.001;
|
||||
|
||||
|
||||
|
||||
if(sd<0.01)
|
||||
{
|
||||
io=-1. + length(pp.xy)*0.35 > 1. ? length(pp.xy)*0.5 : -1.;
|
||||
oc=vec3(0.);
|
||||
oa=0.2;
|
||||
ss=mpal(vec3(p.xy,mid())) * (sin(p.x + p.y*1.1 + p.z*1.3)*0.5+0.5);
|
||||
ec=2;
|
||||
|
||||
}
|
||||
return sd;
|
||||
}
|
||||
|
||||
void nm(){mat3 k=mat3(cp,cp,cp)-mat3(.001);cn=normalize(mp(cp)-vec3(mp(k[0]),mp(k[1]),mp(k[2])));cn=normalize(cn);}
|
||||
void shtr(){so=cp+cn*0.05;md=64.;for(li=cd=0.;cd<64.;li++,cd+=mp(cp=ro+cn*0.05-ld*cd)){if(sd<md&&sd<cd)md=sd;if(sd<0.001||li>64.)break;}}
|
||||
void tr(){for(li=cd=0.;cd<128.;){li++;cd+=mp(cp=ro+rd*cd);td+=sd;if(sd<0.0001||li>512.)break;}nm();}
|
||||
|
||||
|
||||
void px(vec3 rd)
|
||||
{
|
||||
vec3 bg=cc.rgb=mpal(vec3(2,0,mid()))*0.5 -pow(length(uv),4.)*0.8+gl;
|
||||
if(cd<128.)
|
||||
{cc.a=oa;ld=normalize(cp-vec3(0, 0, -40));
|
||||
float df=max(dot(cn,-ld),0.),sp=max(1.-length(cross(rd+ld,cn)),0.)*(1.2-oa),
|
||||
fo = exp(-pow(0.001*td,10.)),ao=1.-clamp(mp(cp+cn*.1)/.1,0.,1.);
|
||||
vec3 fr=pow(1.-abs(dot(rd,-cn)),3.)*mix(cc.rgb,oc,0.);
|
||||
cc.rgb=(oc*df+fr+sp+ss)-ao*0.;
|
||||
shtr();cc.rgb-=(1.-clamp(md/0.05,0.,1.))*0.3;
|
||||
cc.rgb = mix(bg, cc.rgb, fo);}
|
||||
else cc.a=1.;cc.rgb+=gl;
|
||||
cc.rgb*=max(max(cc.r,max(cc.g,cc.b)),1.);
|
||||
}
|
||||
|
||||
void render(vec2 frag, vec2 res, float time, out vec4 col)
|
||||
{
|
||||
uv=vec2(frag.x/res.x,frag.y/res.y);
|
||||
uv-=0.5;uv/=vec2(res.y/res.x,1);
|
||||
tt=mod(time+10.,100.);
|
||||
|
||||
ro=vec3(cos(tt)*0.3,sin(tt)*0.3,-45. + (length(uv)+0.1)*pow(sin(tt)*0.5+0.5,1.5)*50.);
|
||||
rd=normalize(vec3(uv*(cos(tt*0.5)*0.1+0.9),1.));
|
||||
|
||||
for(int i=0;i<10;i++)
|
||||
{
|
||||
tr();ro=cp-cn*(io<0.?-0.01:0.01);
|
||||
cr=refract(rd,cn,i%2==0?1./io:io);
|
||||
if((length(cr)==0.&&es<=0)||io<0.)
|
||||
{i++;cr=reflect(rd,cn);es=(io<0.?es:ec);}
|
||||
px(rd);if(max(es,0)%3==0) rd=cr;
|
||||
es--;fc=fc+vec4(cc.rgb*cc.a,cc.a)*(1.-fc.a);
|
||||
if(fc.a>=1.)break;
|
||||
}
|
||||
col=fc/fc.a;
|
||||
}
|
||||
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
if(mod(float(iFrame), 60./FPS) < 1. || iFrame < 5) render(fragCoord.xy,iResolution.xy,iTime,fragColor);
|
||||
else fragColor = texture(iChannel0, fragCoord / iResolution.xy);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
//fps control for performance. Assumes the refresh rate of your monitor is 60hz
|
||||
//(120hz monitor set to 30 here will actually run at 60fps)
|
||||
#define FPS 30.
|
||||
@@ -0,0 +1,6 @@
|
||||
//See the common tab for fps control.
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
fragColor = texture(iChannel0, fragCoord / iResolution.xy);
|
||||
}
|
||||
BIN
tools/packsrc/Lucid Dreams/images/iChannel2.png
Normal file
BIN
tools/packsrc/Lucid Dreams/images/iChannel2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
36
tools/packsrc/Lucid Dreams/pack.json
Normal file
36
tools/packsrc/Lucid Dreams/pack.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"author": "DigitalArtifex",
|
||||
"name": "Lucid Dreams",
|
||||
"version": "1.0.0",
|
||||
"description": "A mix of xx by XX and Watercolor Filter by mds2",
|
||||
"license": "",
|
||||
"engine": "shadertoy",
|
||||
"id": "ms3Gzl",
|
||||
"tags": [
|
||||
"reactive",
|
||||
"galaxy",
|
||||
"fractal"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 1,
|
||||
|
||||
"bufferA":
|
||||
{
|
||||
"source": "./shaders/Buffer A.frag.qsb",
|
||||
"frame_buffer_channel": 0,
|
||||
|
||||
"channel1":
|
||||
{
|
||||
"type": 2,
|
||||
"source":"./shaders/"
|
||||
},
|
||||
"channel2":
|
||||
{
|
||||
"type": 0,
|
||||
"source": "./images/iChannel2.png"
|
||||
}
|
||||
},
|
||||
|
||||
"channel0":"{bufferA}"
|
||||
}
|
||||
25
tools/packsrc/Lucid Dreams/shaders/Buffer A.frag
Normal file
25
tools/packsrc/Lucid Dreams/shaders/Buffer A.frag
Normal file
@@ -0,0 +1,25 @@
|
||||
// The MIT License
|
||||
// Copyright © 2017 Michael Schuresko
|
||||
// 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.
|
||||
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 blend_uv = fragCoord.xy / iResolution.xy;
|
||||
vec2 uv = vec2(1.0 - blend_uv.x, blend_uv.y);
|
||||
vec3 intensity = 1.0 - texture(iChannel1, uv).rgb;
|
||||
|
||||
float vidSample = dot(vec3(1.0), texture(iChannel1, uv).rgb);
|
||||
float delta = 0.005;
|
||||
float vidSampleDx = dot(vec3(1.0),
|
||||
texture(iChannel1, uv + vec2(delta, 0.0)).rgb);
|
||||
float vidSampleDy = dot(vec3(1.0),
|
||||
texture(iChannel1, uv + vec2(0.0, delta)).rgb);
|
||||
|
||||
vec2 flow = delta * vec2 (vidSampleDy - vidSample, vidSample - vidSampleDx);
|
||||
|
||||
intensity = 0.005 * intensity + 0.995 *
|
||||
(1.0 - texture(iChannel0,
|
||||
blend_uv + vec2(-1.0, 1.0) * flow).rgb);
|
||||
fragColor = vec4(1.0 - intensity,1.0);
|
||||
}
|
||||
9
tools/packsrc/Lucid Dreams/shaders/Image.frag
Normal file
9
tools/packsrc/Lucid Dreams/shaders/Image.frag
Normal file
@@ -0,0 +1,9 @@
|
||||
// The MIT License
|
||||
// Copyright © 2017 Michael Schuresko
|
||||
// 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.
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 uv = fragCoord.xy / iResolution.xy;
|
||||
fragColor = texture (iChannel0, uv);
|
||||
}
|
||||
52
tools/packsrc/Multiscale MIP Fluid/pack.json
Normal file
52
tools/packsrc/Multiscale MIP Fluid/pack.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"author": "cornusammonis",
|
||||
"name": "Multiscale MIP Fluid",
|
||||
"version": "1.0.0",
|
||||
"description": "Motivated by https://codepen.io/brainjam/pen/GaYJjJ . clearly, there's still a lot of room for code optimization.",
|
||||
"license": "CC BY-NC-SA 3.0",
|
||||
"engine": "shadertoy",
|
||||
"id": "tsKXR3",
|
||||
"tags": [
|
||||
"simulation",
|
||||
"water",
|
||||
"fluid",
|
||||
"mipmap",
|
||||
"turbulence"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 4,
|
||||
|
||||
"bufferA":
|
||||
{
|
||||
"source": "./shaders/Buffer A.frag.qsb",
|
||||
"frame_buffer_channel": 0,
|
||||
"channel1": "{bufferD}",
|
||||
"channel2": "{bufferB}",
|
||||
"channel3": "{bufferC}"
|
||||
},
|
||||
|
||||
"bufferB":
|
||||
{
|
||||
"source": "./shaders/Buffer B.frag.qsb",
|
||||
"channel0": "{bufferA}"
|
||||
},
|
||||
|
||||
"bufferC":
|
||||
{
|
||||
"type": 2,
|
||||
"source": "./shaders/Buffer C.frag.qsb",
|
||||
|
||||
"channel0": "{bufferB}"
|
||||
},
|
||||
|
||||
"bufferD":
|
||||
{
|
||||
"source": "./shaders/Buffer D.frag.qsb",
|
||||
"frame_buffer_channel": 1,
|
||||
|
||||
"channel0": "{bufferA}"
|
||||
},
|
||||
|
||||
"channel0": "{bufferA}"
|
||||
}
|
||||
193
tools/packsrc/Multiscale MIP Fluid/shaders/Buffer A.frag
Normal file
193
tools/packsrc/Multiscale MIP Fluid/shaders/Buffer A.frag
Normal file
@@ -0,0 +1,193 @@
|
||||
#define TURBULENCE_SAMPLER iChannel3
|
||||
#define CONFINEMENT_SAMPLER iChannel2
|
||||
#define POISSON_SAMPLER iChannel1
|
||||
#define VELOCITY_SAMPLER iChannel0
|
||||
|
||||
#define V(d) texture(TURBULENCE_SAMPLER, fract(uv+(d+0.))).xy
|
||||
|
||||
vec2 gaussian_turbulence(vec2 uv) {
|
||||
vec2 texel = 1.0/iResolution.xy;
|
||||
vec4 t = vec4(texel, -texel.y, 0);
|
||||
|
||||
vec2 d = V( t.ww); vec2 d_n = V( t.wy); vec2 d_e = V( t.xw);
|
||||
vec2 d_s = V( t.wz); vec2 d_w = V(-t.xw); vec2 d_nw = V(-t.xz);
|
||||
vec2 d_sw = V(-t.xy); vec2 d_ne = V( t.xy); vec2 d_se = V( t.xz);
|
||||
|
||||
return 0.25 * d + 0.125 * (d_e + d_w + d_n + d_s) + 0.0625 * (d_ne + d_nw + d_se + d_sw);
|
||||
}
|
||||
|
||||
#define C(d) texture(CONFINEMENT_SAMPLER, fract(uv+(d+0.))).xy
|
||||
|
||||
vec2 gaussian_confinement(vec2 uv) {
|
||||
vec2 texel = 1.0/iResolution.xy;
|
||||
vec4 t = vec4(texel, -texel.y, 0);
|
||||
|
||||
vec2 d = C( t.ww); vec2 d_n = C( t.wy); vec2 d_e = C( t.xw);
|
||||
vec2 d_s = C( t.wz); vec2 d_w = C(-t.xw); vec2 d_nw = C(-t.xz);
|
||||
vec2 d_sw = C(-t.xy); vec2 d_ne = C( t.xy); vec2 d_se = C( t.xz);
|
||||
|
||||
return 0.25 * d + 0.125 * (d_e + d_w + d_n + d_s) + 0.0625 * (d_ne + d_nw + d_se + d_sw);
|
||||
}
|
||||
|
||||
#define D(d) texture(POISSON_SAMPLER, fract(uv+d)).x
|
||||
|
||||
vec2 diff(vec2 uv) {
|
||||
vec2 texel = 1.0/iResolution.xy;
|
||||
vec4 t = vec4(texel, -texel.y, 0);
|
||||
|
||||
float d = D( t.ww); float d_n = D( t.wy); float d_e = D( t.xw);
|
||||
float d_s = D( t.wz); float d_w = D(-t.xw); float d_nw = D(-t.xz);
|
||||
float d_sw = D(-t.xy); float d_ne = D( t.xy); float d_se = D( t.xz);
|
||||
|
||||
return vec2(
|
||||
0.5 * (d_e - d_w) + 0.25 * (d_ne - d_nw + d_se - d_sw),
|
||||
0.5 * (d_n - d_s) + 0.25 * (d_ne + d_nw - d_se - d_sw)
|
||||
);
|
||||
}
|
||||
|
||||
#define N(d) texture(VELOCITY_SAMPLER, fract(uv+(d+0.)))
|
||||
|
||||
vec4 gaussian_velocity(vec2 uv) {
|
||||
vec2 texel = 1.0/iResolution.xy;
|
||||
vec4 t = vec4(texel, -texel.y, 0);
|
||||
|
||||
vec4 d = N( t.ww); vec4 d_n = N( t.wy); vec4 d_e = N( t.xw);
|
||||
vec4 d_s = N( t.wz); vec4 d_w = N(-t.xw); vec4 d_nw = N(-t.xz);
|
||||
vec4 d_sw = N(-t.xy); vec4 d_ne = N( t.xy); vec4 d_se = N( t.xz);
|
||||
|
||||
return 0.25 * d + 0.125 * (d_e + d_w + d_n + d_s) + 0.0625 * (d_ne + d_nw + d_se + d_sw);
|
||||
}
|
||||
|
||||
vec2 vector_laplacian(vec2 uv) {
|
||||
const float _K0 = -20.0/6.0, _K1 = 4.0/6.0, _K2 = 1.0/6.0;
|
||||
vec2 texel = 1.0/iResolution.xy;
|
||||
vec4 t = vec4(texel, -texel.y, 0);
|
||||
|
||||
vec4 d = N( t.ww); vec4 d_n = N( t.wy); vec4 d_e = N( t.xw);
|
||||
vec4 d_s = N( t.wz); vec4 d_w = N(-t.xw); vec4 d_nw = N(-t.xz);
|
||||
vec4 d_sw = N(-t.xy); vec4 d_ne = N( t.xy); vec4 d_se = N( t.xz);
|
||||
|
||||
return (_K0 * d + _K1 * (d_e + d_w + d_n + d_s) + _K2 * (d_ne + d_nw + d_se + d_sw)).xy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 uv = fragCoord/iResolution.xy;
|
||||
vec2 tx = 1.0/iResolution.xy;
|
||||
|
||||
|
||||
vec2 turb, confine, div, delta_v, offset, lapl = vec2(0);
|
||||
vec4 vel, adv = vec4(0);
|
||||
vec4 init = N();
|
||||
|
||||
#ifdef RECALCULATE_OFFSET
|
||||
for (int i = 0; i < ADVECTION_STEPS; i++) {
|
||||
#ifdef BLUR_TURBULENCE
|
||||
turb = gaussian_turbulence(uv + tx * offset);
|
||||
#else
|
||||
turb = V(tx * offset);
|
||||
#endif
|
||||
|
||||
#ifdef BLUR_CONFINEMENT
|
||||
confine = gaussian_confinement(uv + tx * offset);
|
||||
#else
|
||||
confine = C(tx * offset);
|
||||
#endif
|
||||
|
||||
#ifdef BLUR_VELOCITY
|
||||
vel = gaussian_velocity(uv + tx * offset);
|
||||
#else
|
||||
vel = N(tx * offset);
|
||||
#endif
|
||||
|
||||
// an alternative, but seems to give less smooth results:
|
||||
// offset += (1.0 / float(ADVECTION_STEPS)) * ...
|
||||
offset = (float(i+1) / float(ADVECTION_STEPS)) * - ADVECTION_SCALE * (ADVECTION_VELOCITY * vel.xy + ADVECTION_TURBULENCE * turb - ADVECTION_CONFINEMENT * confine + ADVECTION_DIVERGENCE * div);
|
||||
|
||||
div = diff(uv + tx * DIVERGENCE_LOOKAHEAD * offset);
|
||||
|
||||
lapl = vector_laplacian(uv + tx * LAPLACIAN_LOOKAHEAD * offset);
|
||||
|
||||
adv += N(tx * offset);
|
||||
|
||||
delta_v += VELOCITY_LAPLACIAN * lapl + VELOCITY_TURBULENCE * turb + VELOCITY_CONFINEMENT * confine - DAMPING * vel.xy - DIVERGENCE_MINIMIZATION * div;
|
||||
}
|
||||
adv /= float(ADVECTION_STEPS);
|
||||
delta_v /= float(ADVECTION_STEPS);
|
||||
#else
|
||||
#ifdef BLUR_TURBULENCE
|
||||
turb = gaussian_turbulence(uv);
|
||||
#else
|
||||
turb = V();
|
||||
#endif
|
||||
|
||||
#ifdef BLUR_CONFINEMENT
|
||||
confine = gaussian_confinement(uv);
|
||||
#else
|
||||
confine = C();
|
||||
#endif
|
||||
|
||||
#ifdef BLUR_VELOCITY
|
||||
vel = gaussian_velocity(uv);
|
||||
#else
|
||||
vel = N();
|
||||
#endif
|
||||
|
||||
offset = - ADVECTION_SCALE * (ADVECTION_VELOCITY * vel.xy + ADVECTION_TURBULENCE * turb - ADVECTION_CONFINEMENT * confine + ADVECTION_DIVERGENCE * div);
|
||||
|
||||
div = diff(uv + tx * DIVERGENCE_LOOKAHEAD * offset);
|
||||
|
||||
lapl = vector_laplacian(uv + tx * LAPLACIAN_LOOKAHEAD * offset);
|
||||
|
||||
delta_v += VELOCITY_LAPLACIAN * lapl + VELOCITY_TURBULENCE * turb + VELOCITY_CONFINEMENT * confine - DAMPING * vel.xy - DIVERGENCE_MINIMIZATION * div;
|
||||
|
||||
for (int i = 0; i < ADVECTION_STEPS; i++) {
|
||||
adv += N((float(i+1) / float(ADVECTION_STEPS)) * tx * offset);
|
||||
}
|
||||
adv /= float(ADVECTION_STEPS);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// define a pump, either at the center of the screen,
|
||||
// or alternating at the sides of the screen.
|
||||
vec2 pq = 2.0*(uv*2.0-1.0) * vec2(1,tx.x/tx.y);
|
||||
#ifdef CENTER_PUMP
|
||||
vec2 pump = sin(PUMP_CYCLE*iTime)*PUMP_SCALE*pq.xy / (dot(pq,pq)+0.01);
|
||||
#else
|
||||
vec2 pump = vec2(0);
|
||||
#define AMP 15.0
|
||||
#define SCL -50.0
|
||||
float uvy0 = exp(SCL*pow(pq.y,2.0));
|
||||
float uvx0 = exp(SCL*pow(uv.x,2.0));
|
||||
pump += -AMP*vec2(max(0.0,cos(PUMP_CYCLE*iTime))*PUMP_SCALE*uvx0*uvy0,0);
|
||||
|
||||
float uvy1 = exp(SCL*pow(pq.y,2.0));
|
||||
float uvx1 = exp(SCL*pow(1.0 - uv.x,2.0));
|
||||
pump += AMP*vec2(max(0.0,cos(PUMP_CYCLE*iTime + 3.1416))*PUMP_SCALE*uvx1*uvy1,0);
|
||||
|
||||
float uvy2 = exp(SCL*pow(pq.x,2.0));
|
||||
float uvx2 = exp(SCL*pow(uv.y,2.0));
|
||||
pump += -AMP*vec2(0,max(0.0,sin(PUMP_CYCLE*iTime))*PUMP_SCALE*uvx2*uvy2);
|
||||
|
||||
float uvy3 = exp(SCL*pow(pq.x,2.0));
|
||||
float uvx3 = exp(SCL*pow(1.0 - uv.y,2.0));
|
||||
pump += AMP*vec2(0,max(0.0,sin(PUMP_CYCLE*iTime + 3.1416))*PUMP_SCALE*uvx3*uvy3);
|
||||
#endif
|
||||
|
||||
fragColor = mix(adv + vec4(VELOCITY_SCALE * (delta_v + pump), offset), init, UPDATE_SMOOTHING);
|
||||
|
||||
if (iMouse.z > 0.0) {
|
||||
vec4 mouseUV = iMouse / iResolution.xyxy;
|
||||
vec2 delta = normz(mouseUV.zw - mouseUV.xy);
|
||||
vec2 md = (mouseUV.xy - uv) * vec2(1.0,tx.x/tx.y);
|
||||
float amp = exp(max(-12.0,-dot(md,md)/MOUSE_RADIUS));
|
||||
fragColor.xy += VELOCITY_SCALE * MOUSE_AMP * clamp(amp * delta,-1.0,1.0);
|
||||
}
|
||||
|
||||
// Adding a very small amount of noise on init fixes subtle numerical precision blowup problems
|
||||
if (iFrame==0) fragColor=1e-6*rand4(fragCoord, iResolution.xy, iFrame);
|
||||
}
|
||||
96
tools/packsrc/Multiscale MIP Fluid/shaders/Buffer B.frag
Normal file
96
tools/packsrc/Multiscale MIP Fluid/shaders/Buffer B.frag
Normal file
@@ -0,0 +1,96 @@
|
||||
#define TURB_CH xy
|
||||
#define TURB_SAMPLER iChannel0
|
||||
#define DEGREE TURBULENCE_SCALES
|
||||
|
||||
#define D(d) textureLod(TURB_SAMPLER, fract(uv+d), mip).TURB_CH
|
||||
|
||||
void tex(vec2 uv, inout mat3 mx, inout mat3 my, int degree) {
|
||||
vec2 texel = 1.0/iResolution.xy;
|
||||
float stride = float(1 << degree);
|
||||
float mip = float(degree);
|
||||
vec4 t = stride * vec4(texel, -texel.y, 0);
|
||||
|
||||
vec2 d = D( t.ww); vec2 d_n = D( t.wy); vec2 d_e = D( t.xw);
|
||||
vec2 d_s = D( t.wz); vec2 d_w = D(-t.xw); vec2 d_nw = D(-t.xz);
|
||||
vec2 d_sw = D(-t.xy); vec2 d_ne = D( t.xy); vec2 d_se = D( t.xz);
|
||||
|
||||
mx = mat3(d_nw.x, d_n.x, d_ne.x,
|
||||
d_w.x, d.x, d_e.x,
|
||||
d_sw.x, d_s.x, d_se.x);
|
||||
|
||||
my = mat3(d_nw.y, d_n.y, d_ne.y,
|
||||
d_w.y, d.y, d_e.y,
|
||||
d_sw.y, d_s.y, d_se.y);
|
||||
}
|
||||
|
||||
float reduce(mat3 a, mat3 b) {
|
||||
mat3 p = matrixCompMult(a, b);
|
||||
return p[0][0] + p[0][1] + p[0][2] +
|
||||
p[1][0] + p[1][1] + p[1][2] +
|
||||
p[2][0] + p[2][1] + p[2][2];
|
||||
}
|
||||
|
||||
void turbulence(vec2 fragCoord, inout vec2 turb, inout float curl)
|
||||
{
|
||||
vec2 uv = fragCoord.xy / iResolution.xy;
|
||||
|
||||
mat3 turb_xx = (2.0 - TURB_ISOTROPY) * mat3(
|
||||
0.125, 0.25, 0.125,
|
||||
-0.25, -0.5, -0.25,
|
||||
0.125, 0.25, 0.125
|
||||
);
|
||||
|
||||
mat3 turb_yy = (2.0 - TURB_ISOTROPY) * mat3(
|
||||
0.125, -0.25, 0.125,
|
||||
0.25, -0.5, 0.25,
|
||||
0.125, -0.25, 0.125
|
||||
);
|
||||
|
||||
mat3 turb_xy = TURB_ISOTROPY * mat3(
|
||||
0.25, 0.0, -0.25,
|
||||
0.0, 0.0, 0.0,
|
||||
-0.25, 0.0, 0.25
|
||||
);
|
||||
|
||||
const float norm = 8.8 / (4.0 + 8.0 * CURL_ISOTROPY); // 8.8 takes the isotropy as 0.6
|
||||
float c0 = CURL_ISOTROPY;
|
||||
|
||||
mat3 curl_x = mat3(
|
||||
c0, 1.0, c0,
|
||||
0.0, 0.0, 0.0,
|
||||
-c0, -1.0, -c0
|
||||
);
|
||||
|
||||
mat3 curl_y = mat3(
|
||||
c0, 0.0, -c0,
|
||||
1.0, 0.0, -1.0,
|
||||
c0, 0.0, -c0
|
||||
);
|
||||
|
||||
mat3 mx, my;
|
||||
vec2 v = vec2(0);
|
||||
float turb_wc, curl_wc = 0.0;
|
||||
curl = 0.0;
|
||||
for (int i = 0; i < DEGREE; i++) {
|
||||
tex(uv, mx, my, i);
|
||||
float turb_w = TURB_W_FUNCTION;
|
||||
float curl_w = CURL_W_FUNCTION;
|
||||
v += turb_w * vec2(reduce(turb_xx, mx) + reduce(turb_xy, my), reduce(turb_yy, my) + reduce(turb_xy, mx));
|
||||
curl += curl_w * (reduce(curl_x, mx) + reduce(curl_y, my));
|
||||
turb_wc += turb_w;
|
||||
curl_wc += curl_w;
|
||||
}
|
||||
|
||||
turb = float(DEGREE) * v / turb_wc;
|
||||
curl = norm * curl / curl_wc;
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 turb;
|
||||
float curl;
|
||||
turbulence(fragCoord, turb, curl);
|
||||
fragColor = vec4(turb,0,curl);
|
||||
// Adding a very small amount of noise on init fixes subtle numerical precision blowup problems
|
||||
if (iFrame==0) fragColor=1e-6*rand4(fragCoord, iResolution.xy, iFrame);
|
||||
}
|
||||
82
tools/packsrc/Multiscale MIP Fluid/shaders/Buffer C.frag
Normal file
82
tools/packsrc/Multiscale MIP Fluid/shaders/Buffer C.frag
Normal file
@@ -0,0 +1,82 @@
|
||||
#define CURL_CH w
|
||||
#define CURL_SAMPLER iChannel0
|
||||
#define DEGREE VORTICITY_SCALES
|
||||
|
||||
#define CURL(d) textureLod(CURL_SAMPLER, fract(uv+(d+0.0)), mip).CURL_CH
|
||||
#define D(d) abs(textureLod(CURL_SAMPLER, fract(uv+d), mip).CURL_CH)
|
||||
|
||||
void tex(vec2 uv, inout mat3 mc, inout float curl, int degree) {
|
||||
vec2 texel = 1.0/iResolution.xy;
|
||||
float stride = float(1 << degree);
|
||||
float mip = float(degree);
|
||||
vec4 t = stride * vec4(texel, -texel.y, 0);
|
||||
|
||||
float d = D( t.ww); float d_n = D( t.wy); float d_e = D( t.xw);
|
||||
float d_s = D( t.wz); float d_w = D(-t.xw); float d_nw = D(-t.xz);
|
||||
float d_sw = D(-t.xy); float d_ne = D( t.xy); float d_se = D( t.xz);
|
||||
|
||||
mc = mat3(d_nw, d_n, d_ne,
|
||||
d_w, d, d_e,
|
||||
d_sw, d_s, d_se);
|
||||
|
||||
curl = CURL();
|
||||
|
||||
}
|
||||
|
||||
float reduce(mat3 a, mat3 b) {
|
||||
mat3 p = matrixCompMult(a, b);
|
||||
return p[0][0] + p[0][1] + p[0][2] +
|
||||
p[1][0] + p[1][1] + p[1][2] +
|
||||
p[2][0] + p[2][1] + p[2][2];
|
||||
}
|
||||
|
||||
vec2 confinement(vec2 fragCoord)
|
||||
{
|
||||
vec2 uv = fragCoord.xy / iResolution.xy;
|
||||
|
||||
float k0 = CONF_ISOTROPY;
|
||||
float k1 = 1.0 - 2.0*(CONF_ISOTROPY);
|
||||
|
||||
mat3 conf_x = mat3(
|
||||
-k0, -k1, -k0,
|
||||
0.0, 0.0, 0.0,
|
||||
k0, k1, k0
|
||||
);
|
||||
|
||||
mat3 conf_y = mat3(
|
||||
-k0, 0.0, k0,
|
||||
-k1, 0.0, k1,
|
||||
-k0, 0.0, k0
|
||||
);
|
||||
|
||||
mat3 mc;
|
||||
vec2 v = vec2(0);
|
||||
float curl;
|
||||
|
||||
float cacc = 0.0;
|
||||
vec2 nacc = vec2(0);
|
||||
float wc = 0.0;
|
||||
for (int i = 0; i < DEGREE; i++) {
|
||||
tex(uv, mc, curl, i);
|
||||
float w = CONF_W_FUNCTION;
|
||||
vec2 n = w * normz(vec2(reduce(conf_x, mc), reduce(conf_y, mc)));
|
||||
v += curl * n;
|
||||
cacc += curl;
|
||||
nacc += n;
|
||||
wc += w;
|
||||
}
|
||||
|
||||
#ifdef PREMULTIPLY_CURL
|
||||
return v / wc;
|
||||
#else
|
||||
return nacc * cacc / wc;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
fragColor = vec4(confinement(fragCoord),0,0);
|
||||
// Adding a very small amount of noise on init fixes subtle numerical precision blowup problems
|
||||
if (iFrame==0) fragColor=1e-6*rand4(fragCoord, iResolution.xy, iFrame);
|
||||
}
|
||||
115
tools/packsrc/Multiscale MIP Fluid/shaders/Buffer D.frag
Normal file
115
tools/packsrc/Multiscale MIP Fluid/shaders/Buffer D.frag
Normal file
@@ -0,0 +1,115 @@
|
||||
#define VORT_CH xy
|
||||
#define VORT_SAMPLER iChannel0
|
||||
#define POIS_SAMPLER iChannel1
|
||||
#define POIS_CH x
|
||||
#define DEGREE POISSON_SCALES
|
||||
|
||||
#define D(d) textureLod(VORT_SAMPLER, fract(uv+d), mip).VORT_CH
|
||||
#define P(d) textureLod(POIS_SAMPLER, fract(uv+d), mip).POIS_CH
|
||||
|
||||
float laplacian_poisson(vec2 fragCoord) {
|
||||
const float _K0 = -20.0/6.0, _K1 = 4.0/6.0, _K2 = 1.0/6.0;
|
||||
vec2 texel = 1.0/iResolution.xy;
|
||||
vec2 uv = fragCoord * texel;
|
||||
vec4 t = vec4(texel, -texel.y, 0);
|
||||
float mip = 0.0;
|
||||
|
||||
float p = P( t.ww); float p_n = P( t.wy); float p_e = P( t.xw);
|
||||
float p_s = P( t.wz); float p_w = P(-t.xw); float p_nw = P(-t.xz);
|
||||
float p_sw = P(-t.xy); float p_ne = P( t.xy); float p_se = P( t.xz);
|
||||
|
||||
return _K0 * p + _K1 * (p_e + p_w + p_n + p_s) + _K2 * (p_ne + p_nw + p_se + p_sw);
|
||||
}
|
||||
|
||||
void tex(vec2 uv, inout mat3 mx, inout mat3 my, inout mat3 mp, int degree) {
|
||||
vec2 texel = 1.0/iResolution.xy;
|
||||
float stride = float(1 << degree);
|
||||
float mip = float(degree);
|
||||
vec4 t = stride * vec4(texel, -texel.y, 0);
|
||||
|
||||
vec2 d = D( t.ww); vec2 d_n = D( t.wy); vec2 d_e = D( t.xw);
|
||||
vec2 d_s = D( t.wz); vec2 d_w = D(-t.xw); vec2 d_nw = D(-t.xz);
|
||||
vec2 d_sw = D(-t.xy); vec2 d_ne = D( t.xy); vec2 d_se = D( t.xz);
|
||||
|
||||
float p = P( t.ww); float p_n = P( t.wy); float p_e = P( t.xw);
|
||||
float p_s = P( t.wz); float p_w = P(-t.xw); float p_nw = P(-t.xz);
|
||||
float p_sw = P(-t.xy); float p_ne = P( t.xy); float p_se = P( t.xz);
|
||||
|
||||
mx = mat3(d_nw.x, d_n.x, d_ne.x,
|
||||
d_w.x, d.x, d_e.x,
|
||||
d_sw.x, d_s.x, d_se.x);
|
||||
|
||||
my = mat3(d_nw.y, d_n.y, d_ne.y,
|
||||
d_w.y, d.y, d_e.y,
|
||||
d_sw.y, d_s.y, d_se.y);
|
||||
|
||||
mp = mat3(p_nw, p_n, p_ne,
|
||||
p_w, p, p_e,
|
||||
p_sw, p_s, p_se);
|
||||
}
|
||||
|
||||
float reduce(mat3 a, mat3 b) {
|
||||
mat3 p = matrixCompMult(a, b);
|
||||
return p[0][0] + p[0][1] + p[0][2] +
|
||||
p[1][0] + p[1][1] + p[1][2] +
|
||||
p[2][0] + p[2][1] + p[2][2];
|
||||
}
|
||||
|
||||
vec2 pois(vec2 fragCoord)
|
||||
{
|
||||
vec2 uv = fragCoord.xy / iResolution.xy;
|
||||
|
||||
float k0 = POIS_ISOTROPY;
|
||||
float k1 = 1.0 - 2.0*(POIS_ISOTROPY);
|
||||
|
||||
mat3 pois_x = mat3(
|
||||
k0, 0.0, -k0,
|
||||
k1, 0.0, -k1,
|
||||
k0, 0.0, -k0
|
||||
);
|
||||
|
||||
mat3 pois_y = mat3(
|
||||
-k0, -k1, -k0,
|
||||
0.0, 0.0, 0.0,
|
||||
k0, k1, k0
|
||||
);
|
||||
|
||||
mat3 gauss = mat3(
|
||||
0.0625, 0.125, 0.0625,
|
||||
0.125, 0.25, 0.125,
|
||||
0.0625, 0.125, 0.0625
|
||||
);
|
||||
|
||||
mat3 mx, my, mp;
|
||||
vec2 v = vec2(0);
|
||||
|
||||
float wc = 0.0;
|
||||
for (int i = 0; i < DEGREE; i++) {
|
||||
tex(uv, mx, my, mp, i);
|
||||
float w = POIS_W_FUNCTION;
|
||||
wc += w;
|
||||
v += w * vec2(reduce(pois_x, mx) + reduce(pois_y, my), reduce(gauss, mp));
|
||||
}
|
||||
|
||||
return v / wc;
|
||||
|
||||
}
|
||||
|
||||
#define V(d) textureLod(VORT_SAMPLER, fract(uv+d), mip).zw
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
|
||||
vec2 p = pois(fragCoord);
|
||||
#ifdef USE_PRESSURE_ADVECTION
|
||||
float mip = 0.0;
|
||||
vec2 tx = 1.0 / iResolution.xy;
|
||||
vec2 uv = fragCoord * tx;
|
||||
float prev = P(0.0002 * PRESSURE_ADVECTION * tx * V(vec2(0)));
|
||||
fragColor = vec4(mix(p.x + p.y, prev + PRESSURE_LAPLACIAN * laplacian_poisson(fragCoord), PRESSURE_UPDATE_SMOOTHING));
|
||||
#else
|
||||
fragColor = vec4(p.x + p.y);
|
||||
#endif
|
||||
// Adding a very small amount of noise on init fixes subtle numerical precision blowup problems
|
||||
if (iFrame==0) fragColor=1e-6*rand4(fragCoord, iResolution.xy, iFrame);
|
||||
}
|
||||
230
tools/packsrc/Multiscale MIP Fluid/shaders/Common.frag
Normal file
230
tools/packsrc/Multiscale MIP Fluid/shaders/Common.frag
Normal file
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
Number of scales to use in computation of each value. Lowering these will change the
|
||||
result drastically, also note that the heightmap is used for rendering, so changing
|
||||
POISSON_SCALES will alter the appearance of lighting/shadows. Weighting functions
|
||||
for each scale are defined below.
|
||||
*/
|
||||
#define TURBULENCE_SCALES 11
|
||||
#define VORTICITY_SCALES 11
|
||||
#define POISSON_SCALES 11
|
||||
|
||||
// If defined, recalculate the advection offset at every substep. Otherwise, subdivide the offset.
|
||||
// Leaving this undefined is much cheaper for large ADVECTION_STEPS but yields worse results; this
|
||||
// can be improved by defining the BLUR_* options below.
|
||||
#define RECALCULATE_OFFSET
|
||||
// Number of advection substeps to use. Useful to increase this for large ADVECTION_SCALE. Must be >= 1
|
||||
#define ADVECTION_STEPS 3
|
||||
// Advection distance multiplier.
|
||||
#define ADVECTION_SCALE 40.0
|
||||
// Scales the effect of turbulence on advection.
|
||||
#define ADVECTION_TURBULENCE 1.0
|
||||
// Scales the effect of turbulence on velocity. Use small values.
|
||||
#define VELOCITY_TURBULENCE 0.0000
|
||||
// Scales the effect of vorticity confinement on velocity.
|
||||
#define VELOCITY_CONFINEMENT 0.01
|
||||
// Scales diffusion.
|
||||
#define VELOCITY_LAPLACIAN 0.02
|
||||
// Scales the effect of vorticity confinement on advection.
|
||||
#define ADVECTION_CONFINEMENT 0.6
|
||||
// Scales the effect of divergence on advection.
|
||||
#define ADVECTION_DIVERGENCE 0.0
|
||||
// Scales the effect of velocity on advection.
|
||||
#define ADVECTION_VELOCITY -0.05
|
||||
// Amount of divergence minimization. Too much will cause instability.
|
||||
#define DIVERGENCE_MINIMIZATION 0.1
|
||||
// If 0.0, compute the gradient at (0,0). If 1.0, compute the gradient at the advection distance.
|
||||
#define DIVERGENCE_LOOKAHEAD 1.0
|
||||
// If 0.0, compute the laplacian at (0,0). If 1.0, compute the laplacian at the advection distance.
|
||||
#define LAPLACIAN_LOOKAHEAD 1.0
|
||||
// Scales damping force.
|
||||
#define DAMPING 0.0001
|
||||
// Overall velocity multiplier
|
||||
#define VELOCITY_SCALE 1.0
|
||||
// Mixes the previous velocity with the new velocity (range 0..1).
|
||||
#define UPDATE_SMOOTHING 0.0
|
||||
|
||||
|
||||
|
||||
// These control the (an)isotropy of the various kernels
|
||||
#define TURB_ISOTROPY 0.9 // [0..2.0]
|
||||
#define CURL_ISOTROPY 0.6 // >= 0
|
||||
#define CONF_ISOTROPY 0.25 // [0..0.5]
|
||||
#define POIS_ISOTROPY 0.16 // [0..0.5]
|
||||
|
||||
|
||||
|
||||
// If defined, multiply curl by vorticity, then accumulate. If undefined, accumulate, then multiply.
|
||||
#define PREMULTIPLY_CURL
|
||||
|
||||
|
||||
|
||||
// These apply a gaussian blur to the various values used in the velocity/advection update. More expensive when defined.
|
||||
//#define BLUR_TURBULENCE
|
||||
//#define BLUR_CONFINEMENT
|
||||
//#define BLUR_VELOCITY
|
||||
|
||||
|
||||
|
||||
// These define weighting functions applied at each of the scales, i=0 being the finest detail.
|
||||
//#define TURB_W_FUNCTION 1.0/float(i+1)
|
||||
#define TURB_W_FUNCTION 1.0
|
||||
//#define TURB_W_FUNCTION float(i+1)
|
||||
|
||||
//#define CURL_W_FUNCTION 1.0/float(1 << i)
|
||||
#define CURL_W_FUNCTION 1.0/float(i+1)
|
||||
//#define CURL_W_FUNCTION 1.0
|
||||
|
||||
//#define CONF_W_FUNCTION 1.0/float(i+1)
|
||||
#define CONF_W_FUNCTION 1.0
|
||||
//#define CONF_W_FUNCTION float(i+1)
|
||||
//#define CONF_W_FUNCTION float(1 << i)
|
||||
|
||||
//#define POIS_W_FUNCTION 1.0
|
||||
#define POIS_W_FUNCTION 1.0/float(i+1)
|
||||
//#define POIS_W_FUNCTION 1.0/float(1 << i)
|
||||
//#define POIS_W_FUNCTION float(i+1)
|
||||
//#define POIS_W_FUNCTION float(1 << i)
|
||||
|
||||
|
||||
|
||||
// These can help reduce mipmap artifacting, especially when POIS_W_FUNCTION emphasizes large scales.
|
||||
//#define USE_PRESSURE_ADVECTION
|
||||
// Scales pressure advection distance.
|
||||
#define PRESSURE_ADVECTION 0.0002 // higher values more likely to cause blowup if laplacian > 0.0
|
||||
// Pressure diffusion.
|
||||
#define PRESSURE_LAPLACIAN 0.1 // [0..0.3] higher values more likely to cause blowup
|
||||
// Mixes the previous pressure with the new pressure.
|
||||
#define PRESSURE_UPDATE_SMOOTHING 0.0 // [0..1]
|
||||
|
||||
|
||||
|
||||
// Scales mouse interaction effect
|
||||
#define MOUSE_AMP 0.05
|
||||
// Scales mouse interaction radius
|
||||
#define MOUSE_RADIUS 0.001
|
||||
|
||||
|
||||
|
||||
// If defined, "pump" velocity in the center of the screen. If undefined, alternate pumping from the sides of the screen.
|
||||
//#define CENTER_PUMP
|
||||
// Amplitude and cycle time for the "pump" at the center of the screen.
|
||||
#define PUMP_SCALE 0.001
|
||||
#define PUMP_CYCLE 0.2
|
||||
|
||||
|
||||
vec4 normz(vec4 x) {
|
||||
return x.xyz == vec3(0) ? vec4(0,0,0,x.w) : vec4(normalize(x.xyz),0);
|
||||
}
|
||||
|
||||
vec3 normz(vec3 x) {
|
||||
return x == vec3(0) ? vec3(0) : normalize(x);
|
||||
}
|
||||
|
||||
vec2 normz(vec2 x) {
|
||||
return x == vec2(0) ? vec2(0) : normalize(x);
|
||||
}
|
||||
|
||||
|
||||
// Only used for rendering, but useful helpers
|
||||
float softmax(float a, float b, float k) {
|
||||
return log(exp(k*a)+exp(k*b))/k;
|
||||
}
|
||||
|
||||
float softmin(float a, float b, float k) {
|
||||
return -log(exp(-k*a)+exp(-k*b))/k;
|
||||
}
|
||||
|
||||
vec4 softmax(vec4 a, vec4 b, float k) {
|
||||
return log(exp(k*a)+exp(k*b))/k;
|
||||
}
|
||||
|
||||
vec4 softmin(vec4 a, vec4 b, float k) {
|
||||
return -log(exp(-k*a)+exp(-k*b))/k;
|
||||
}
|
||||
|
||||
float softclamp(float a, float b, float x, float k) {
|
||||
return (softmin(b,softmax(a,x,k),k) + softmax(a,softmin(b,x,k),k)) / 2.0;
|
||||
}
|
||||
|
||||
vec4 softclamp(vec4 a, vec4 b, vec4 x, float k) {
|
||||
return (softmin(b,softmax(a,x,k),k) + softmax(a,softmin(b,x,k),k)) / 2.0;
|
||||
}
|
||||
|
||||
vec4 softclamp(float a, float b, vec4 x, float k) {
|
||||
return (softmin(vec4(b),softmax(vec4(a),x,k),k) + softmax(vec4(a),softmin(vec4(b),x,k),k)) / 2.0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// GGX from Noby's Goo shader https://www.shadertoy.com/view/lllBDM
|
||||
|
||||
// MIT License: https://opensource.org/licenses/MIT
|
||||
float G1V(float dnv, float k){
|
||||
return 1.0/(dnv*(1.0-k)+k);
|
||||
}
|
||||
|
||||
float ggx(vec3 n, vec3 v, vec3 l, float rough, float f0){
|
||||
float alpha = rough*rough;
|
||||
vec3 h = normalize(v+l);
|
||||
float dnl = clamp(dot(n,l), 0.0, 1.0);
|
||||
float dnv = clamp(dot(n,v), 0.0, 1.0);
|
||||
float dnh = clamp(dot(n,h), 0.0, 1.0);
|
||||
float dlh = clamp(dot(l,h), 0.0, 1.0);
|
||||
float f, d, vis;
|
||||
float asqr = alpha*alpha;
|
||||
const float pi = 3.14159;
|
||||
float den = dnh*dnh*(asqr-1.0)+1.0;
|
||||
d = asqr/(pi * den * den);
|
||||
dlh = pow(1.0-dlh, 5.0);
|
||||
f = f0 + (1.0-f0)*dlh;
|
||||
float k = alpha/1.0;
|
||||
vis = G1V(dnl, k)*G1V(dnv, k);
|
||||
float spec = dnl * d * f * vis;
|
||||
return spec;
|
||||
}
|
||||
// End Noby's GGX
|
||||
|
||||
|
||||
// Modified from Shane's Bumped Sinusoidal Warp shadertoy here:
|
||||
// https://www.shadertoy.com/view/4l2XWK
|
||||
vec3 light(vec2 uv, float BUMP, float SRC_DIST, vec2 dxy, float iTime, inout vec3 avd) {
|
||||
vec3 sp = vec3(uv-0.5, 0);
|
||||
vec3 light = vec3(cos(iTime/2.0)*0.5, sin(iTime/2.0)*0.5, -SRC_DIST);
|
||||
vec3 ld = light - sp;
|
||||
float lDist = max(length(ld), 0.001);
|
||||
ld /= lDist;
|
||||
avd = reflect(normalize(vec3(BUMP*dxy, -1.0)), vec3(0,1,0));
|
||||
return ld;
|
||||
}
|
||||
// End Shane's bumpmapping section
|
||||
|
||||
|
||||
// The MIT License
|
||||
// Copyright © 2017 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.
|
||||
float hash1( uint n )
|
||||
{
|
||||
// integer hash copied from Hugo Elias
|
||||
n = (n << 13U) ^ n;
|
||||
n = n * (n * n * 15731U + 789221U) + 1376312589U;
|
||||
return float( n & uvec3(0x7fffffffU))/float(0x7fffffff);
|
||||
}
|
||||
|
||||
vec3 hash3( uint n )
|
||||
{
|
||||
// integer hash copied from Hugo Elias
|
||||
n = (n << 13U) ^ n;
|
||||
n = n * (n * n * 15731U + 789221U) + 1376312589U;
|
||||
uvec3 k = n * uvec3(n,n*16807U,n*48271U);
|
||||
return vec3( k & uvec3(0x7fffffffU))/float(0x7fffffff);
|
||||
}
|
||||
|
||||
// a simple modification for this shader to get a vec4
|
||||
vec4 rand4( vec2 fragCoord, vec2 iResolution, int iFrame ) {
|
||||
uvec2 p = uvec2(fragCoord);
|
||||
uvec2 r = uvec2(iResolution);
|
||||
uint c = p.x + r.x*p.y + r.x*r.y*uint(iFrame);
|
||||
return vec4(hash3(c),hash1(c + 75132895U));
|
||||
}
|
||||
// End IQ's integer hash
|
||||
139
tools/packsrc/Multiscale MIP Fluid/shaders/Image.frag
Normal file
139
tools/packsrc/Multiscale MIP Fluid/shaders/Image.frag
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
Created by Cornus Ammonis (2019)
|
||||
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This is a mipmap-based approach to multiscale fluid dynamics.
|
||||
|
||||
Check the Common tab for lots of configurable parameters.
|
||||
|
||||
Click to interact with your mouse. I'd recommend turning off the "pump" by
|
||||
setting PUMP_SCALE to 0.0 on line 113 of the Common tab to play around with
|
||||
just mouse interaction.
|
||||
|
||||
Buffer B is a multiscale method for computing turbulence along the lines of
|
||||
the Large Eddy Simulation method; multiscale curl is also computed in Buffer B,
|
||||
to be passed along to Buffer C.
|
||||
|
||||
Buffer C is a fairly conventional Vorticity Confinement method, also multiscale,
|
||||
using the curl computed in Buffer B. It probably makes more sense to compute
|
||||
each curl scale separately before accumulating, but for the sake of efficiency
|
||||
and simplicity (a larger kernel would be required), I haven't done that here.
|
||||
|
||||
Buffer D is a multiscale Poisson solver, which converges rapidly but not to an
|
||||
exact solution - this nonetheless works well for the purposes of divergence
|
||||
minimization since we only need the gradient, with allowances for the choice of
|
||||
scale weighting.
|
||||
|
||||
Buffer A computes subsampled advection and velocity update steps, sampling
|
||||
from Buffers B, C, and D with a variety of smoothing options.
|
||||
|
||||
There are a number of options included to make this run faster.
|
||||
|
||||
Using mipmaps in this way has a variety of advantages:
|
||||
|
||||
1. The scale computations have no duplicative or dependent reads, we only need
|
||||
that for advection.
|
||||
2. No randomness or stochastic sampling is involved.
|
||||
3. The total number of reads can be greatly reduced for a comparable level of
|
||||
fidelity to some other methods.
|
||||
4. We can easily sample the entire buffer in one pass (on average).
|
||||
5. The computational complexity is deferred to mipmap generation (though with
|
||||
a large coefficient), because:
|
||||
6. The algorithm itself is O(n) with a fixed number of scales (or we could
|
||||
potentially do scale calculations in parallel with mipmap generation,
|
||||
equalling mipmap generation complexity at O(nlogn))
|
||||
|
||||
Notable downsides:
|
||||
|
||||
1. Using mipmaps introduces a number of issues, namely:
|
||||
a. Mipmaps can introduce artifacts due to interpolation and downsampling.
|
||||
Using Gaussian pyramids, or some other lowpass filtering method would
|
||||
be better.
|
||||
b. Using higher-order sampling of the texture buffer (e.g. bicubic) would
|
||||
also be better, but that would limit our performance gains.
|
||||
c. NPOT textures are problematic (as always). They can introduce weird
|
||||
anisotropy issues among other things.
|
||||
2. Stochastic or large-kernel methods are a better approximation to the true
|
||||
sampling distribution approximated here, for a large-enough number of
|
||||
samples.
|
||||
3. We're limited in how we construct our scale-space. Is a power-of-two stride
|
||||
length on both axes always ideal, even along diagonals? I'm not particularly
|
||||
sure. There are clever wavelet methods out there for Navier-Stokes solvers,
|
||||
and LES in particular, too.
|
||||
|
||||
*/
|
||||
|
||||
#define BUMP 3200.0
|
||||
|
||||
#define D(d) -textureLod(iChannel1, fract(uv+(d+0.0)), mip).w
|
||||
|
||||
vec2 diff(vec2 uv, float mip) {
|
||||
vec2 texel = 1.0/iResolution.xy;
|
||||
vec4 t = float(1<<int(mip))*vec4(texel, -texel.y, 0);
|
||||
|
||||
float d = D( t.ww); float d_n = D( t.wy); float d_e = D( t.xw);
|
||||
float d_s = D( t.wz); float d_w = D(-t.xw); float d_nw = D(-t.xz);
|
||||
float d_sw = D(-t.xy); float d_ne = D( t.xy); float d_se = D( t.xz);
|
||||
|
||||
return vec2(
|
||||
0.5 * (d_e - d_w) + 0.25 * (d_ne - d_nw + d_se - d_sw),
|
||||
0.5 * (d_n - d_s) + 0.25 * (d_ne + d_nw - d_se - d_sw)
|
||||
);
|
||||
}
|
||||
|
||||
vec4 contrast(vec4 col, float x) {
|
||||
return x * (col - 0.5) + 0.5;
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord ){
|
||||
vec2 uv = fragCoord.xy / iResolution.xy;
|
||||
|
||||
vec2 dxy = vec2(0);
|
||||
float occ, mip = 0.0;
|
||||
float d = D();
|
||||
|
||||
// blur the gradient to reduce appearance of artifacts,
|
||||
// and do cheap occlusion with mipmaps
|
||||
#define STEPS 10.0
|
||||
#define ODIST 2.0
|
||||
for(mip = 1.0; mip <= STEPS; mip += 1.0) {
|
||||
dxy += (1.0/pow(2.0,mip)) * diff(uv, mip-1.0);
|
||||
occ += softclamp(-ODIST, ODIST, d - D(),1.0)/(pow(1.5,mip));
|
||||
}
|
||||
dxy /= float(STEPS);
|
||||
|
||||
// I think this looks nicer than using smoothstep
|
||||
occ = pow(max(0.0,softclamp(0.2,0.8,100.0*occ + 0.5,1.0)),0.5);
|
||||
|
||||
vec3 avd;
|
||||
vec3 ld = light(uv, BUMP, 0.5, dxy, iTime, avd);
|
||||
|
||||
float spec = ggx(avd, vec3(0,1,0), ld, 0.1, 0.1);
|
||||
|
||||
#define LOG_SPEC 1000.0
|
||||
spec = (log(LOG_SPEC+1.0)/LOG_SPEC)*log(1.0+LOG_SPEC*spec);
|
||||
|
||||
#define VIEW_VELOCITY
|
||||
|
||||
#ifdef VIEW_VELOCITY
|
||||
vec4 diffuse = softclamp(0.0,1.0,6.0*vec4(texture(iChannel0,uv).xy,0,0)+0.5,2.0);
|
||||
#elif defined(VIEW_CURL)
|
||||
vec4 diffuse = mix(vec4(1,0,0,0),vec4(0,0,1,0),softclamp(0.0,1.0,0.5+2.0*texture(iChannel2,uv).w,2.0));
|
||||
#elif defined(VIEW_ADVECTION)
|
||||
vec4 diffuse = softclamp(0.0,1.0,0.0004*vec4(texture(iChannel0,uv).zw,0,0)+0.5,2.0);
|
||||
#elif defined(VIEW_GRADIENT)
|
||||
vec4 diffuse = softclamp(0.0,1.0,10.0*vec4(diff(uv,0.0),0,0)+0.5,4.0);
|
||||
#else // Vorticity confinement vectors
|
||||
vec4 diffuse = softclamp(0.0,1.0,4.0*vec4(texture(iChannel3,uv).xy,0,0)+0.5,4.0);
|
||||
#endif
|
||||
|
||||
fragColor = (diffuse + 4.0*mix(vec4(spec),1.5*diffuse*spec,0.3));
|
||||
fragColor = mix(1.0,occ,0.7) * (softclamp(0.0,1.0,contrast(fragColor,4.5),3.0));
|
||||
|
||||
//fragColor = vec4(occ);
|
||||
//fragColor = vec4(spec);
|
||||
//fragColor = diffuse;
|
||||
//fragColor = vec4(diffuse+(occ-0.5));
|
||||
}
|
||||
36
tools/packsrc/Neon Ball Pit/pack.json
Normal file
36
tools/packsrc/Neon Ball Pit/pack.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"author": "loicvdb",
|
||||
"name": "Neon Ball Pit",
|
||||
"version": "1.0.0",
|
||||
"description": "Raytracing in a grid to instantiate objects, cheap enough to run multisampling",
|
||||
"license": "",
|
||||
"engine": "shadertoy",
|
||||
"id": "WlVcWK",
|
||||
"tags": [
|
||||
"reflection",
|
||||
"dof",
|
||||
"bloom",
|
||||
"aa",
|
||||
"fresnel",
|
||||
"neon",
|
||||
"multisampling",
|
||||
"aces",
|
||||
"fsaa"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 1.0,
|
||||
|
||||
"bufferA":
|
||||
{
|
||||
"source": "./shaders/Buffer A.frag.qsb"
|
||||
},
|
||||
|
||||
"bufferB":
|
||||
{
|
||||
"source": "./shaders/Buffer B.frag.qsb",
|
||||
"channel0": "{bufferA}"
|
||||
},
|
||||
|
||||
"channel0":"{bufferB}"
|
||||
}
|
||||
54
tools/packsrc/Neon Ball Pit/shaders/Buffer A.frag
Normal file
54
tools/packsrc/Neon Ball Pit/shaders/Buffer A.frag
Normal file
@@ -0,0 +1,54 @@
|
||||
vec4 sphereI(vec3 pos, const vec3 dir, vec3 sPos){
|
||||
pos -= sPos;
|
||||
float b = -dot(pos, dir);
|
||||
float d = b * b - dot(pos, pos) + .2;
|
||||
if (d < 0.0) return vec4(-1.);
|
||||
b -= sqrt(d);
|
||||
return vec4(normalize(pos+b*dir), b);
|
||||
}
|
||||
|
||||
vec4 sceneI(const vec3 pos, const vec3 dir) {
|
||||
vec3 s = sign(dir);
|
||||
float t = max(0., -(pos.y+s.y*1.3)/dir.y);
|
||||
float end = max(0., -(pos.y-s.y*1.0)/dir.y);
|
||||
for(int i = 0; i < 16 && t < end; i++) {
|
||||
vec3 p = pos+t*dir;
|
||||
vec2 fp = floor(p.xz);
|
||||
vec2 co = cos(fp*.5+iTime);
|
||||
vec4 sI = sphereI(pos, dir, vec3(fp+.5, co.x*co.y).xzy);
|
||||
if(sI.w > 0.) return sI;
|
||||
vec2 l = (s.xz*.5+.5+fp-p.xz) / dir.xz;
|
||||
t += min(l.x, l.y) + .1;
|
||||
}
|
||||
return vec4(-1.);
|
||||
}
|
||||
|
||||
void mainImage(out vec4 o, vec2 u) {
|
||||
mat3 rot = rotationMatrix(vec3(-.7, iTime*.15, 0.));
|
||||
o = vec4(0.);
|
||||
for(int y = 1; y <= AA; y++) {
|
||||
for(int x = 1; x <= AA; x++) {
|
||||
vec2 uv = (floor(u)+vec2(x, y)/float(AA+1)-iResolution.xy*.5) / iResolution.y;
|
||||
vec3 pos = vec3(0., 0., 7.) * rot;
|
||||
vec3 dir = normalize(vec3(uv, -1.)) * rot;
|
||||
pos.x += iTime*2.;
|
||||
float att = 1.;
|
||||
float d = 10.;
|
||||
for(int i = 0; i < 2; i++) {
|
||||
vec4 t = sceneI(pos, dir);
|
||||
if(t.w < 0.) break;
|
||||
if(i == 0) d = t.w;
|
||||
pos += t.w*dir;
|
||||
vec3 orientation = normalize(vec3(cos(floor(pos.xz) - iTime), .5).xzy);
|
||||
vec3 emission = abs(dot(t.xyz, orientation)) < .2 ? (orientation.yxz+1.) : vec3(.0);
|
||||
emission *= 4.*abs(fract(orientation.y*5.)*2.-1.);
|
||||
float f = fresnel(dir, t.xyz);
|
||||
o.rgb += att*(1.-f) * emission;
|
||||
att *= f;
|
||||
dir = reflect(dir, t.xyz);
|
||||
}
|
||||
o += vec4(att*vec3(1., 1.5, 2.)*step(0., dir.y), d);
|
||||
}
|
||||
}
|
||||
o /= float(AA*AA);
|
||||
}
|
||||
3
tools/packsrc/Neon Ball Pit/shaders/Buffer B.frag
Normal file
3
tools/packsrc/Neon Ball Pit/shaders/Buffer B.frag
Normal file
@@ -0,0 +1,3 @@
|
||||
void mainImage(out vec4 o, vec2 u) {
|
||||
o = sampleDof(iChannel0, iResolution.xy, vec2(.71, .71), u);
|
||||
}
|
||||
47
tools/packsrc/Neon Ball Pit/shaders/Common.frag
Normal file
47
tools/packsrc/Neon Ball Pit/shaders/Common.frag
Normal file
@@ -0,0 +1,47 @@
|
||||
// uncomment this line for a faster version
|
||||
//#define LOW_QUALITY
|
||||
|
||||
|
||||
#ifdef LOW_QUALITY
|
||||
#define AA 1
|
||||
#define DOF_SAMPLES 3
|
||||
#else
|
||||
#define AA 2
|
||||
#define DOF_SAMPLES 6
|
||||
#endif
|
||||
|
||||
|
||||
#define APERTURE .01
|
||||
#define DOF_CLAMPING .7
|
||||
#define FOCAL_DISTANCE 8.
|
||||
|
||||
vec4 sampleDof(sampler2D channel, vec2 channelDim, vec2 dir, vec2 u) {
|
||||
float screenAperture = channelDim.y*APERTURE;
|
||||
float sampleToRad = screenAperture * DOF_CLAMPING / float(DOF_SAMPLES);
|
||||
vec4 o = vec4(0);
|
||||
float sum = 0.;
|
||||
for(int i = -DOF_SAMPLES; i <= DOF_SAMPLES; i++) {
|
||||
float sRad = float(i)*sampleToRad;
|
||||
vec4 p = texture(channel, (u+dir*sRad)/channelDim);
|
||||
float rad = min(abs(p.a-FOCAL_DISTANCE)/p.a, DOF_CLAMPING);
|
||||
float influence = clamp((rad*screenAperture - abs(sRad)) + .5, 0., 1.) / (rad*rad+.001);
|
||||
o += influence * p;
|
||||
sum += influence;
|
||||
}
|
||||
return o/sum;
|
||||
}
|
||||
|
||||
float fresnel(const vec3 dir, const vec3 n) {
|
||||
const float ior = 1.8;
|
||||
const float r0 = ((1. - ior) / (1. + ior)) * ((1. - ior) / (1. + ior));
|
||||
float x = 1.+dot(n, dir);
|
||||
return r0 + (1.-r0) * x*x*x*x*x;
|
||||
}
|
||||
|
||||
mat3 rotationMatrix(const vec3 rotation) {
|
||||
vec3 c = cos(rotation), s = sin(rotation);
|
||||
mat3 rx = mat3(1, 0, 0, 0, c.x, -s.x, 0, s.x, c.x);
|
||||
mat3 ry = mat3(c.y, 0, -s.y, 0, 1, 0, s.y, 0, c.y);
|
||||
mat3 rz = mat3(c.z, -s.z, 0, s.z, c.z, 0, 0, 0, 1);
|
||||
return rz * rx * ry;
|
||||
}
|
||||
8
tools/packsrc/Neon Ball Pit/shaders/Image.frag
Normal file
8
tools/packsrc/Neon Ball Pit/shaders/Image.frag
Normal file
@@ -0,0 +1,8 @@
|
||||
void mainImage(out vec4 o, vec2 u) {
|
||||
o = sampleDof(iChannel0, iResolution.xy, vec2(.71, -.71), u);
|
||||
float r = floor(log2(iResolution.y) - 5.5) + .5;
|
||||
for(int i = 0; i < 4; i++)
|
||||
o += texture(iChannel0, u/iResolution.xy, r+float(i*2))*.03;
|
||||
vec3 x = o.rgb;
|
||||
o = vec4((x*(2.51*x+.03))/(x*(2.43*x+.59)+.14), 1.);
|
||||
}
|
||||
BIN
tools/packsrc/Neon World/images/iChannel1.png
Normal file
BIN
tools/packsrc/Neon World/images/iChannel1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
39
tools/packsrc/Neon World/pack.json
Normal file
39
tools/packsrc/Neon World/pack.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"author": "zguerrero",
|
||||
"name": "Neon World",
|
||||
"version": "1.0.0",
|
||||
"description": "experimenting witch ray marching and distance field",
|
||||
"license": "CC BY-NC-SA 3.0",
|
||||
"engine": "shadertoys",
|
||||
"id": "MlscDj",
|
||||
"tags": [
|
||||
"reflection",
|
||||
"raymarching",
|
||||
"distance",
|
||||
"neon"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 1,
|
||||
|
||||
"bufferA":
|
||||
{
|
||||
"source": "./shaders/Buffer A.frag.qsb"
|
||||
},
|
||||
|
||||
"bufferB":
|
||||
{
|
||||
"source": "./shaders/Buffer B.frag.qsb",
|
||||
"frame_buffer_channel": 1,
|
||||
|
||||
"channel0": "{bufferA}"
|
||||
},
|
||||
|
||||
"channel0": "{bufferB}",
|
||||
|
||||
"channel1":
|
||||
{
|
||||
"type": 0,
|
||||
"source": "./images/iChannel1.png"
|
||||
}
|
||||
}
|
||||
281
tools/packsrc/Neon World/shaders/Buffer A.frag
Normal file
281
tools/packsrc/Neon World/shaders/Buffer A.frag
Normal file
@@ -0,0 +1,281 @@
|
||||
const float epsilon = 0.02;
|
||||
const float pi = 3.14159265359;
|
||||
const float speed = 3.0;
|
||||
const vec3 wallsColor = vec3(0.05, 0.025, 0.025);
|
||||
const vec3 lightColor = vec3(0.3, 0.6, 1.0);
|
||||
const vec3 lightColor2 = vec3(0.5, 0.35, 0.35);
|
||||
const vec3 fogColor = vec3(0.05, 0.05, 0.2);
|
||||
const float curvAmout = 0.075;
|
||||
const float reflAmout = 0.8;
|
||||
|
||||
//Distance Field functions by iq :
|
||||
//https://iquilezles.org/articles/distfunctions
|
||||
float sdCylinder( vec3 p, vec3 c )
|
||||
{
|
||||
return length(c.xy - p.xz) - c.z;
|
||||
}
|
||||
|
||||
float sdCappedCylinder( vec3 p, vec2 h )
|
||||
{
|
||||
vec2 d = abs(vec2(length(p.xz),p.y)) - h;
|
||||
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
|
||||
}
|
||||
|
||||
float sdSphere( vec3 p, float s )
|
||||
{
|
||||
return length(p)-s;
|
||||
}
|
||||
|
||||
float sdBox( vec3 p, vec3 b )
|
||||
{
|
||||
vec3 d = abs(p) - b;
|
||||
return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
|
||||
}
|
||||
|
||||
vec3 opRep( vec3 p, vec3 c )
|
||||
{
|
||||
return mod(p,c)-0.5*c;
|
||||
}
|
||||
|
||||
vec2 linearStep2(vec2 mi, vec2 ma, vec2 v)
|
||||
{
|
||||
return clamp((v - mi) / (ma - mi), 0.0 ,1.0);
|
||||
}
|
||||
|
||||
float tunnel( vec3 p, vec3 c )
|
||||
{
|
||||
return -length(c.xy - p.xz) + c.z;
|
||||
}
|
||||
|
||||
vec4 distfunc(vec3 pos)
|
||||
{
|
||||
vec3 repPos = opRep(pos, vec3(4.0, 1.0, 4.0));
|
||||
vec2 sinPos = sin((pos.z * pi / 8.0) + vec2(0.0, pi)) * 1.75;
|
||||
vec3 repPosSin = opRep(pos.xxz + vec3(sinPos.x, sinPos.y, 0.0), vec3(4.0, 4.0, 0.0));
|
||||
|
||||
float cylinders = sdCylinder(vec3(repPos.x, pos.y, repPos.z), vec3(0.0, 0.0, 0.5));
|
||||
float s = sin(iTime*3.0 + floor(pos.z*0.25));
|
||||
float cutCylinders1 = sdBox(vec3(pos.x, pos.y, repPos.z), vec3(100.0, clamp(s, 0.025, 0.75), 1.0));
|
||||
float cutCylinders2 = sdBox(vec3(repPos.x, pos.y, repPos.z), vec3(0.035, 100.0, 10.0));
|
||||
float cuttedCylinders = max(-cutCylinders2, max(-cutCylinders1, cylinders));
|
||||
|
||||
float innerCylinders = sdCylinder(vec3(repPos.x, pos.y, repPos.z), vec3(0.0, 0.0, 0.15));
|
||||
float tubes1 = sdCylinder(vec3(repPosSin.x, 0.0, pos.y - 0.85), vec3(0.0, 0.0, 0.025));
|
||||
float tubes2 = sdCylinder(vec3(repPosSin.y, 0.0, pos.y + 0.85), vec3(0.0, 0.0, 0.025));
|
||||
float tubes = min(tubes1, tubes2);
|
||||
float lightsGeom = min(tubes, innerCylinders);
|
||||
|
||||
float resultCylinders = min(cuttedCylinders, lightsGeom);
|
||||
|
||||
float spheres = sdSphere(vec3(repPos.x, pos.y, repPos.z), (s*0.5+0.5)*1.5);
|
||||
float light = min(tubes, spheres);
|
||||
|
||||
vec2 planeMod = abs(fract(pos.xx * vec2(0.25, 4.0) + 0.5) * 4.0 - 2.0) - 1.0;
|
||||
float planeMod2 = clamp(planeMod.y, -0.02, 0.02) * min(0.0, planeMod.x);
|
||||
float cylindersCutPlane = sdCylinder(vec3(repPos.x, pos.y, repPos.z), vec3(0.0, 0.0, 0.6));
|
||||
float spheresCutPlane = sdSphere(vec3(repPos.x, pos.y, repPos.z), 1.3);
|
||||
|
||||
float plane = 1.0 - abs(pos.y + clamp(planeMod.x, -0.04, 0.04) + planeMod2);
|
||||
float t = tunnel(pos.xzy * vec3(1.0, 1.0, 3.0), vec3(0.0, 0.0, 8.5));
|
||||
float cutTunnel = sdBox(vec3(pos.x, pos.y, repPos.z), vec3(100.0, 100.0, 0.1));
|
||||
plane = min(max(-cutTunnel, t), max(-spheresCutPlane, max(-cylindersCutPlane, plane)));
|
||||
|
||||
float dist = min(resultCylinders, plane);
|
||||
float occ = min(cuttedCylinders, plane);
|
||||
|
||||
float id = 0.0;
|
||||
|
||||
if(lightsGeom < epsilon)
|
||||
{
|
||||
id = 1.0;
|
||||
}
|
||||
|
||||
return vec4(dist, id, light, occ);
|
||||
}
|
||||
|
||||
vec3 rayMarch(vec3 rayDir, vec3 cameraOrigin)
|
||||
{
|
||||
const int maxItter = 100;
|
||||
const float maxDist = 30.0;
|
||||
|
||||
float totalDist = 0.0;
|
||||
vec3 pos = cameraOrigin;
|
||||
vec4 dist = vec4(epsilon);
|
||||
|
||||
for(int i = 0; i < maxItter; i++)
|
||||
{
|
||||
dist = distfunc(pos);
|
||||
totalDist += dist.x;
|
||||
pos += dist.x * rayDir;
|
||||
|
||||
if(dist.x < epsilon || totalDist > maxDist)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return vec3(dist.x, totalDist, dist.y);
|
||||
}
|
||||
|
||||
vec3 rayMarchReflection(vec3 rayDir, vec3 cameraOrigin)
|
||||
{
|
||||
const int maxItter = 30;
|
||||
const float maxDist = 20.0;
|
||||
|
||||
float totalDist = 0.0;
|
||||
vec3 pos = cameraOrigin;
|
||||
vec4 dist = vec4(epsilon);
|
||||
|
||||
for(int i = 0; i < maxItter; i++)
|
||||
{
|
||||
dist = distfunc(pos);
|
||||
totalDist += dist.x;
|
||||
pos += dist.x * rayDir;
|
||||
|
||||
if(dist.x < epsilon || totalDist > maxDist)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return vec3(dist.x, totalDist, dist.y);
|
||||
}
|
||||
|
||||
//Inpired From iq's ao :
|
||||
//https://www.shadertoy.com/view/Xds3zN
|
||||
vec2 AOandFakeAreaLights(vec3 pos, vec3 n)
|
||||
{
|
||||
vec4 res = vec4(0.0);
|
||||
|
||||
for( int i=0; i<3; i++ )
|
||||
{
|
||||
vec3 aopos = pos + n*0.3*float(i);
|
||||
vec4 d = distfunc(aopos);
|
||||
res += d;
|
||||
}
|
||||
|
||||
float ao = clamp(res.w, 0.0, 1.0);
|
||||
float light = 1.0 - clamp(res.z*0.3, 0.0, 1.0);
|
||||
|
||||
return vec2(ao, light * ao);
|
||||
}
|
||||
|
||||
//Camera Function by iq :
|
||||
//https://www.shadertoy.com/view/Xds3zN
|
||||
mat3 setCamera( in vec3 ro, in vec3 ta, float cr )
|
||||
{
|
||||
vec3 cw = normalize(ta-ro);
|
||||
vec3 cp = vec3(sin(cr), cos(cr),0.0);
|
||||
vec3 cu = normalize( cross(cw,cp) );
|
||||
vec3 cv = normalize( cross(cu,cw) );
|
||||
return mat3( cu, cv, cw );
|
||||
}
|
||||
|
||||
//Normal and Curvature Function by Nimitz;
|
||||
//https://www.shadertoy.com/view/Xts3WM
|
||||
vec4 norcurv(in vec3 p)
|
||||
{
|
||||
vec2 e = vec2(-epsilon, epsilon);
|
||||
float t1 = distfunc(p + e.yxx).x, t2 = distfunc(p + e.xxy).x;
|
||||
float t3 = distfunc(p + e.xyx).x, t4 = distfunc(p + e.yyy).x;
|
||||
|
||||
float curv = .25/e.y*(t1 + t2 + t3 + t4 - 4.0 * distfunc(p).x);
|
||||
return vec4(normalize(e.yxx*t1 + e.xxy*t2 + e.xyx*t3 + e.yyy*t4), curv);
|
||||
}
|
||||
|
||||
vec4 lighting(vec3 n, vec3 rayDir, vec3 reflectDir, vec3 pos)
|
||||
{
|
||||
vec3 light = vec3(0.0, 0.0, 2.0 + iTime * speed);
|
||||
vec3 lightVec = light - pos;
|
||||
vec3 lightDir = normalize(lightVec);
|
||||
float atten = clamp(1.0 - length(lightVec)*0.1, 0.0, 1.0);
|
||||
float spec = pow(max(0.0, dot(reflectDir, lightDir)), 10.0);
|
||||
float rim = (1.0 - max(0.0, dot(-n, rayDir)));
|
||||
|
||||
return vec4(spec*atten*lightColor2 + rim*0.2, rim);
|
||||
}
|
||||
|
||||
vec3 color(float id, vec3 pos)
|
||||
{
|
||||
vec2 fp = vec2(1.0) - linearStep2(vec2(0.0), vec2(0.01), abs(fract(pos.xz * vec2(0.25, 1.0) + vec2(0.0, 0.5)) - 0.5));
|
||||
float s = fp.y + fp.x;
|
||||
return mix(wallsColor + s*lightColor*0.5, lightColor, id);
|
||||
}
|
||||
|
||||
vec4 finalColor(vec3 rayDir, vec3 reflectDir, vec3 pos, vec3 normal, float ao, float id)
|
||||
{
|
||||
vec4 l = lighting(normal, rayDir, reflectDir, pos);
|
||||
vec3 col = color(id, pos);
|
||||
float ao1 = 0.5 * ao + 0.5;
|
||||
float ao2 = 0.25 * ao + 0.75;
|
||||
vec3 res = (mix(col * ao1, col, id) + l.xyz) * ao2;
|
||||
return vec4(res, l.w);
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 uv = fragCoord.xy/iResolution.xy;
|
||||
|
||||
float move = iTime * speed;
|
||||
vec2 sinMove = sin((move * pi) / 16.0 + vec2(1.0, -1.0)) * vec2(5.0, 0.35);
|
||||
float camX = sinMove.x;
|
||||
float camY = 0.0;
|
||||
float camZ = -5.0 + move;
|
||||
vec3 cameraOrigin = vec3(camX, camY, camZ);
|
||||
|
||||
vec3 cameraTarget = vec3(0.0, 0.0, cameraOrigin.z + 10.0);
|
||||
|
||||
vec2 screenPos = uv * 2.0 - 1.0;
|
||||
|
||||
screenPos.x *= iResolution.x/iResolution.y;
|
||||
|
||||
mat3 cam = setCamera(cameraOrigin, cameraTarget, sinMove.y);
|
||||
|
||||
vec3 rayDir = cam*normalize(vec3(screenPos.xy,1.0));
|
||||
vec3 dist = rayMarch(rayDir, cameraOrigin);
|
||||
|
||||
vec3 res;
|
||||
vec2 fog;
|
||||
|
||||
if(dist.x < epsilon)
|
||||
{
|
||||
vec3 pos = cameraOrigin + dist.y*rayDir;
|
||||
vec4 n = norcurv(pos);
|
||||
vec2 ao = AOandFakeAreaLights(pos, n.xyz);
|
||||
vec3 r = reflect(rayDir, n.xyz);
|
||||
vec3 rpos = pos + n.xyz*0.02;
|
||||
vec3 reflectDist = rayMarchReflection(r, rpos);
|
||||
fog = clamp(1.0 / exp(vec2(dist.y, reflectDist.y)*vec2(0.15, 0.2)), 0.0, 1.0);
|
||||
vec4 direct = finalColor(rayDir, r, pos, n.xyz, ao.x, dist.z) + n.w*curvAmout;
|
||||
|
||||
vec4 reflN;
|
||||
vec2 reflAO;
|
||||
vec3 reflFinal;
|
||||
|
||||
if(reflectDist.x < epsilon)
|
||||
{
|
||||
vec3 reflPos = rpos + reflectDist.y*r;
|
||||
reflN = norcurv(reflPos);
|
||||
reflAO = AOandFakeAreaLights(reflPos, reflN.xyz);
|
||||
vec3 rr = reflect(r, reflN.xyz);
|
||||
vec4 refl = finalColor(r, rr, reflPos, reflN.xyz, reflAO.x, reflectDist.z);
|
||||
vec3 reflAreaLights = reflAO.y * lightColor * 0.5;
|
||||
reflFinal = (refl.xyz + reflN.w*curvAmout + reflAreaLights) * fog.y * reflAmout * direct.w;
|
||||
}
|
||||
else
|
||||
{
|
||||
reflFinal = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
vec3 areaLightsColor = ao.y * lightColor * 0.5;
|
||||
|
||||
res = mix(fogColor, direct.xyz + reflFinal + areaLightsColor, fog.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = fogColor;
|
||||
fog = vec2(0.0);
|
||||
}
|
||||
|
||||
fragColor = vec4(res, (dist.z) * fog);
|
||||
}
|
||||
31
tools/packsrc/Neon World/shaders/Buffer B.frag
Normal file
31
tools/packsrc/Neon World/shaders/Buffer B.frag
Normal file
@@ -0,0 +1,31 @@
|
||||
const float radialBlurInstensity = 0.01;
|
||||
const float speed = 3.0;
|
||||
const float pi = 3.14159265359;
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
float s = sin(iTime*speed * pi / 16.0 - 1.0);
|
||||
vec2 radialBlurCenter = vec2((s * 0.5 + 0.5) * 0.5 + 0.25, abs(s)* 0.2 + 0.35);
|
||||
|
||||
vec2 uv = fragCoord.xy/iResolution.xy;
|
||||
vec2 uvCenter = uv - radialBlurCenter;
|
||||
float c = length(uv - radialBlurCenter);
|
||||
vec4 texBlurred = texture(iChannel0, uv);
|
||||
|
||||
float itter = 0.0;
|
||||
|
||||
for(float itter1 = 0.0; itter1 < 5.0; itter1++)
|
||||
{
|
||||
itter = itter1;
|
||||
texBlurred += texture(iChannel0, uvCenter * (1.0 - radialBlurInstensity *
|
||||
itter1 * c) + radialBlurCenter);
|
||||
}
|
||||
|
||||
vec4 res = texBlurred / itter;
|
||||
|
||||
vec4 prev = texture(iChannel1, uv);
|
||||
|
||||
float motionBlur = mix(res.w, prev.w, 0.75);
|
||||
vec3 light = motionBlur * vec3(0.25, 0.5, 0.75);
|
||||
fragColor = vec4(res.xyz + light*2.0, motionBlur);
|
||||
}
|
||||
15
tools/packsrc/Neon World/shaders/Image.frag
Normal file
15
tools/packsrc/Neon World/shaders/Image.frag
Normal file
@@ -0,0 +1,15 @@
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 uv = fragCoord.xy/iResolution.xy;
|
||||
|
||||
float b = step(fract(uv.y * 50.0 + iTime), 0.5);
|
||||
vec4 tex = texture(iChannel0, uv);
|
||||
vec4 tex2 = texture(iChannel0, uv + vec2((b - 0.5)*0.005, 0.0));
|
||||
|
||||
vec2 vign = smoothstep(vec2(0.5, 1.5), vec2(1.0, 0.98 + b*0.02), vec2(length(uv - 0.5) * 2.0));
|
||||
|
||||
vec4 grain = texture(iChannel1, fragCoord.xy/256.0 + vec2(0.0, iTime*10.0));
|
||||
vec4 res = mix(tex, vec4(tex.x, tex.y, tex2.z, tex.w), vign.x);
|
||||
vec4 col = res * vign.y * (0.85 + grain*0.15);
|
||||
fragColor = pow(col*1.75, vec4(1.25));
|
||||
}
|
||||
21
tools/packsrc/PolarVisualizer/pack.json
Normal file
21
tools/packsrc/PolarVisualizer/pack.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"author": "Lallis",
|
||||
"name": "PolarVisualizer",
|
||||
"version": "1.0.0",
|
||||
"description": "Yet another audio visualizer. Tried to fake some depth with the light and reflection. Try reversing the band order.",
|
||||
"license": "CC BY-NC-SA 3.0",
|
||||
"engine": "shadertoy",
|
||||
"id": "4lySzy",
|
||||
"tags": [
|
||||
"reactive",
|
||||
"2d"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 1.0,
|
||||
|
||||
"channel0":
|
||||
{
|
||||
"type": 4
|
||||
}
|
||||
}
|
||||
133
tools/packsrc/PolarVisualizer/shaders/Image.frag
Normal file
133
tools/packsrc/PolarVisualizer/shaders/Image.frag
Normal file
@@ -0,0 +1,133 @@
|
||||
#define time iTime
|
||||
#define PI 3.14159265359
|
||||
|
||||
#define NUM_BANDS 32
|
||||
|
||||
//#define REVERSED
|
||||
|
||||
float noise3D(vec3 p)
|
||||
{
|
||||
return fract(sin(dot(p ,vec3(12.9898,78.233,12.7378))) * 43758.5453)*2.0-1.0;
|
||||
}
|
||||
|
||||
vec3 mixc(vec3 col1, vec3 col2, float v)
|
||||
{
|
||||
v = clamp(v,0.0,1.0);
|
||||
return col1+v*(col2-col1);
|
||||
}
|
||||
|
||||
vec3 drawBands(vec2 uv)
|
||||
{
|
||||
uv = 2.0*uv-1.0;
|
||||
uv.x*=iResolution.x/iResolution.y;
|
||||
uv = vec2(length(uv), atan(uv.y,uv.x));
|
||||
|
||||
//uv.x-=0.25;
|
||||
//uv.x = max(0.0,uv.x);
|
||||
|
||||
uv.y -= PI*0.5;
|
||||
vec2 uv2 = vec2(uv.x, uv.y*-1.0);
|
||||
uv.y = mod(uv.y,PI*2.0);
|
||||
uv2.y = mod(uv2.y,PI*2.0);
|
||||
|
||||
vec3 col = vec3(0.0);
|
||||
vec3 col2 = vec3(0.0);
|
||||
|
||||
float nBands = float(NUM_BANDS);
|
||||
float i = floor(uv.x*nBands);
|
||||
float f = fract(uv.x*nBands);
|
||||
float band = i/nBands;
|
||||
float s;
|
||||
|
||||
#ifdef REVERSED
|
||||
band = 1.0-band;
|
||||
#endif
|
||||
|
||||
//cubic easing
|
||||
band *= band*band;
|
||||
|
||||
band = band*0.99;
|
||||
band += 0.01;
|
||||
|
||||
s = texture( iChannel0, vec2(band,0.25) ).x;
|
||||
|
||||
if(band<0.0||band>=1.0){
|
||||
s = 0.0;
|
||||
}
|
||||
|
||||
/* Gradient colors and amount here */
|
||||
const int nColors = 4;
|
||||
vec3 colors[nColors];
|
||||
colors[0] = vec3(0.05,0.05,1.0);
|
||||
colors[1] = vec3(0.05,1.00,1.00);
|
||||
colors[2] = vec3(0.50,1.00,0.25);
|
||||
colors[3] = vec3(1.00,0.75,0.25);
|
||||
|
||||
vec3 gradCol = colors[0];
|
||||
float n = float(nColors)-1.0;
|
||||
for(int i = 1; i < nColors; i++)
|
||||
{
|
||||
gradCol = mixc(gradCol,colors[i],(s-float(i-1)/n)*n);
|
||||
}
|
||||
|
||||
float h = PI*0.5;
|
||||
|
||||
col += vec3(1.0-smoothstep(-0.5,0.0,uv.y-s*h));
|
||||
col *= gradCol;
|
||||
|
||||
col2 += vec3(1.0-smoothstep(-0.5,0.0,uv2.y-s*h));
|
||||
col2*= gradCol;
|
||||
|
||||
col = mix(col,col2,step(0.0,uv.y-PI));
|
||||
|
||||
col *= smoothstep(0.125,0.375,f);
|
||||
col *= smoothstep(0.875,0.625,f);
|
||||
|
||||
col = clamp(col,0.0,1.0);
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 uv = fragCoord.xy / iResolution.xy;
|
||||
|
||||
vec2 p = vec2(uv.x, uv.y+0.2);
|
||||
vec3 col = vec3(0.0);
|
||||
col += drawBands(p);//*smoothstep(1.0,0.5,uv.y);;
|
||||
|
||||
vec3 ref = vec3(0.0);
|
||||
vec2 eps = vec2(0.0025,-0.0025);
|
||||
|
||||
ref += drawBands(vec2(p.x,1.0-p.y)+eps.xx);
|
||||
ref += drawBands(vec2(p.x,1.0-p.y)+eps.xy);
|
||||
ref += drawBands(vec2(p.x,1.0-p.y)+eps.yy);
|
||||
ref += drawBands(vec2(p.x,1.0-p.y)+eps.yx);
|
||||
|
||||
ref += drawBands(vec2(p.x+eps.x,1.0-p.y));
|
||||
ref += drawBands(vec2(p.x+eps.y,1.0-p.y));
|
||||
ref += drawBands(vec2(p.x,1.0-p.y+eps.x));
|
||||
ref += drawBands(vec2(p.x,1.0-p.y+eps.y));
|
||||
|
||||
ref /= 8.0;
|
||||
|
||||
float colStep = length(smoothstep(0.0,0.1,col));
|
||||
|
||||
vec3 cs1 = drawBands(vec2(0.5,0.51));
|
||||
vec3 cs2 = drawBands(vec2(0.5,0.93));
|
||||
|
||||
vec3 plCol = mix(cs1,cs2,length(p*2.0-1.0))*0.15*smoothstep(0.75,-0.25,length(p*2.0-1.0));
|
||||
vec3 plColBg = vec3(0.05)*smoothstep(1.0,0.0,length(p*2.0-1.0));
|
||||
vec3 pl = (plCol+plColBg)*smoothstep(0.5,0.65,1.0-uv.y);
|
||||
|
||||
col += clamp(pl*(1.0-colStep),0.0,1.0);
|
||||
|
||||
col += ref*smoothstep(0.125,1.6125,p.y);
|
||||
|
||||
col = clamp(col, 0.0, 1.0);
|
||||
|
||||
float dither = noise3D(vec3(uv,time))*2.0/256.0;
|
||||
col += dither;
|
||||
|
||||
fragColor = vec4(col,1.0);
|
||||
}
|
||||
28
tools/packsrc/Simulated Swampland/pack.json
Normal file
28
tools/packsrc/Simulated Swampland/pack.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"author": "Hyeve",
|
||||
"name": "Simulated Swampland",
|
||||
"version": "1.0.0",
|
||||
"description": "this scene is a awful, awful mess... but at least with this lighting and these effects, you can't tell (;",
|
||||
"license": "",
|
||||
"engine": "shadertoy",
|
||||
"id": "ms3Gzl",
|
||||
"tags": [
|
||||
"3d",
|
||||
"raymarching",
|
||||
"transparency",
|
||||
"glass",
|
||||
"reflections",
|
||||
"crystal"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 1,
|
||||
|
||||
"bufferA":
|
||||
{
|
||||
"source": "./shaders/Buffer A.frag.qsb",
|
||||
"frame_buffer_channel": 0
|
||||
},
|
||||
|
||||
"channel0":"{bufferA}"
|
||||
}
|
||||
247
tools/packsrc/Simulated Swampland/shaders/Buffer A.frag
Normal file
247
tools/packsrc/Simulated Swampland/shaders/Buffer A.frag
Normal file
@@ -0,0 +1,247 @@
|
||||
#define pi 3.1415926535
|
||||
#define DTR 0.01745329
|
||||
#define ang(a) mat2(cos(a),sin(a),-sin(a),cos(a))
|
||||
#define vmin(a, b) (a.x < b.x ? a : b)
|
||||
|
||||
|
||||
vec2 uv=vec2(0);
|
||||
vec3 cp,cn,cr,ss,oc,gl=vec3(0),vb,ro,rd,so,ld,no,on,lp;
|
||||
vec4 fc=vec4(0),cc=vec4(0),vs,hs,sp;
|
||||
float tt,cd,sd,md,io,oa,td=0.,li;
|
||||
int sk,sc;
|
||||
|
||||
//3D Shapes
|
||||
float bx(vec3 p,vec3 s){vec3 q=abs(p)-s;return min(max(q.x,max(q.y,q.z)),0.)+length(max(q,0.));}
|
||||
float fcy(vec3 p,vec2 s){vec2 w=vec2(length(p.xy)-s.x,abs(p.z)-s.y);return min(max(w.x,w.y),0.0)+length(max(w,0.0));}
|
||||
|
||||
//Maths
|
||||
float h11(float a){return fract(sin((a)*12.9898)*43758.5453123);}
|
||||
float noise(float p){float i=floor(p),f=fract(p);return mix(h11(i)*f,h11(i+1.)*(f-1.),f*f*(3.0-2.0*f));}
|
||||
vec3 rot(vec3 a,vec3 r){a.zy*=ang(r.x);a.xz*=ang(r.y);a.yx*=ang(r.z);return a;}
|
||||
float sharp(float inp,float sca){return 1.-pow(1.-pow(inp,sca),sca*2.);}
|
||||
vec3 thsv(vec3 c){vec4 K=vec4(0.,-1./3.,2./3.,-1.),p=mix(vec4(c.bg,K.wz),vec4(c.gb,K.xy),step(c.b,c.g)),
|
||||
q=mix(vec4(p.xyw,c.r),vec4(c.r,p.yzx),step(p.x,c.r));float d=q.x-min(q.w,q.y);
|
||||
return vec3(abs(q.z+(q.w-q.y)/(6.*d)),d/(q.x),q.x);}
|
||||
vec3 trgb(vec3 c){vec4 K=vec4(1.,2./3.,1./3.,3.);vec3 p=abs(fract(c.xxx+K.xyz)*6.-K.www);
|
||||
return c.z*mix(K.xxx,clamp(p-K.xxx,0.,1.),c.y);}
|
||||
|
||||
//SDF Maths
|
||||
float smin(float a,float b,float k){float h=clamp(0.5+0.5*(b-a)/k,0.,1.);return mix(b,a,h)-k*h*(1.-h);}
|
||||
|
||||
float gyroid(vec3 pos, vec3 size) {
|
||||
return abs(dot(sin(pos * size.x), cos((pos * size.y).zxy)) - size.z) / max(size.x, size.y) * 1.8;
|
||||
}
|
||||
|
||||
|
||||
float fbm(float x, float h, float n, float o)
|
||||
{
|
||||
vec2 g = vec2(2,exp2(-h));
|
||||
vec3 f = vec3(1,1,0);
|
||||
x -= o * 0.5;
|
||||
for(float i=0.; i<n; i++){f=vec3(f.xy*g,f.z+f.y*sin(f.x*x+o));}
|
||||
return f.z;
|
||||
}
|
||||
|
||||
|
||||
float surface(vec3 p, vec3 o)
|
||||
{
|
||||
float v = p.y;
|
||||
v -= fbm(p.z * 0.5, 1., 3., o.x)*o.z+0.5;
|
||||
v -= fbm(p.x * 0.5, 1., 3., o.y)*o.z+0.5;
|
||||
return abs(v)-0.1;
|
||||
}
|
||||
|
||||
|
||||
float mp(vec3 p)
|
||||
{
|
||||
//p.xz *= ang(35.*DTR);
|
||||
|
||||
vec3 pp = p;
|
||||
|
||||
//p.xz*=ang(tt*0.2);
|
||||
|
||||
p.z+=tt;
|
||||
|
||||
float surf = surface(p,vec3(tt*0.3,tt,0.1));
|
||||
|
||||
|
||||
//p.xz*=ang(tt*0.2);
|
||||
|
||||
|
||||
p.x+=10.;
|
||||
|
||||
|
||||
vec2 moid = floor((p.xz+10.)/20.);
|
||||
float hid = h11(length(moid)+floor(tt*0.1));
|
||||
p.xz = mod(p.xz+10.,20.)-10.;
|
||||
p.xy += hid-0.5;
|
||||
float slice = h11(floor(tt*5.)*7.7);
|
||||
float tree = fcy(p.xzy, vec2(3.-p.y*0.03+hid*3.,999))+fbm(p.y*2.,1.,3.,tt)*0.1;
|
||||
if(hid>0.5||length(hid-slice)<0.03) tree = abs(fcy(p.xzy,vec2(5,100)))+1.;
|
||||
|
||||
vec3 tp = p;
|
||||
|
||||
p=pp;
|
||||
|
||||
p.z += tt;
|
||||
p.y -= mix(30.,50.,noise(p.x*0.05+p.z*0.05+tt*0.05));
|
||||
|
||||
|
||||
p.xz = mod(p.xz+10.,20.)-10.;
|
||||
|
||||
float canopy = length(p) - 3.;
|
||||
|
||||
for(li=0.;li<3.;li++) {
|
||||
p=abs(p)-2.9-li;
|
||||
p=rot(p,vec3(0,h11(li*2.)*10.,0));
|
||||
p+=vec3(h11(li),h11(li*2.),h11(li*3.));
|
||||
canopy = smin(canopy, length(p) - 3.+li*0.5,8.);
|
||||
}
|
||||
|
||||
|
||||
|
||||
tree = min(tree, canopy);
|
||||
|
||||
surf = abs(surf) - 0.001;
|
||||
|
||||
sd = min(surf, tree);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(sd<0.05)
|
||||
{
|
||||
if(surf<sd+0.01) {
|
||||
io=pp.y<1.05?1.1:-1.;
|
||||
oc=vec3(0.1,0.3,0.7);
|
||||
oa=0.3;
|
||||
sp=vec4(1.3,1.5,0.,0.);
|
||||
no = vec3(0,0,0);
|
||||
}
|
||||
else if(canopy<sd+0.01){
|
||||
no = vec3(noise(p.x+p.y),noise(p.y+p.z),noise(p.z+p.x))-0.5;
|
||||
io=1.;
|
||||
oc=vec3(0.1,0.8,0.)*1.-hid*0.1;
|
||||
oa=1.;
|
||||
sp=vec4(1.,5.,0.,0.);
|
||||
}
|
||||
else {
|
||||
no = vec3(0,noise(tp.x*3.+hid*5.)+noise(tp.z*3.-hid*5.),0);
|
||||
io=1.;
|
||||
oc=vec3(0.,0.5+noise(p.y)*0.1,0.);
|
||||
oa=1.;
|
||||
sp=vec4(1.5,2.,0.,0.);
|
||||
}
|
||||
|
||||
|
||||
ss=vec3(0);
|
||||
|
||||
lp = vec3(0,50,1000);
|
||||
sk = -1;
|
||||
}
|
||||
|
||||
vs = vec4(1.5,1.,0.1, 16);
|
||||
hs = vec4(3.,0.3,3.,-0.3);
|
||||
|
||||
return sd;
|
||||
}
|
||||
|
||||
void nm(){mat3 k=mat3(cp,cp,cp)-mat3(.001);cn=on=normalize(mp(cp)-vec3(mp(k[0]),mp(k[1]),mp(k[2])));cn=rot(cn,no);cn=dot(cn,-rd)>0.?cn:reflect(cn,rd);}
|
||||
|
||||
|
||||
void tr(vec4 i){for(li=cd=0.,md=64.;li+cd<i.x;li++,td+=sd*i.w){cd+=mp(cp=ro+on*i.y+(i.w>0.?rd:-ld)*cd)*i.z;if(sd<md&&cd<128.)md=sd;if(sd<(i.w>0.?1e-4:1e-2))break;}md/=.5;cp-=rd*.005;nm();}
|
||||
void tr(vec3 o, vec3 d){for(li=cd=0.;li<12.;li++){cd+=mp(o+d*cd);if(cd<1e-3||cd>32.)break;}}
|
||||
|
||||
vec3 tone(vec4 b, float d){
|
||||
vec3 r=thsv(b.rgb);
|
||||
r.z=decim(pow(max(b.w*r.z+vs.z,0.),vs.x)*vs.y-d,vs.w);
|
||||
r.x+=pow(1.-min(r.z*0.5,1.),hs.x)*hs.y*(r.x>.19&&r.x<.69?1.:-1.);
|
||||
r.y+=pow(1.-min(r.z*0.5,1.),hs.z)*hs.w;r.y*=2.-r.z;
|
||||
return trgb(r);
|
||||
}
|
||||
|
||||
void px(vec3 rd, int i)
|
||||
{
|
||||
vec3 bg=cc.rgb=decim(vec3(0.2,0.5,0.2)-pow(length(uv),5.)*0.5,vs.w)*0.3;
|
||||
|
||||
|
||||
|
||||
if(cd<128.){
|
||||
|
||||
|
||||
|
||||
cc.a=oa;ld=normalize(cp-lp);
|
||||
float df=max(dot(cn,-ld),0.),ps=pow(max(1.-length(cross(rd+ld,cn)),0.),sp.y)*sp.x,
|
||||
fo=exp(-pow(0.015*td,3.)),ao=0.,
|
||||
fr=max(pow(1.-abs(dot(rd,-cn)),3.),1e-4);vec3 sc=oc;float sh=0.;
|
||||
if(sp.w>0.){tr(cp+on*0.005,on);ao=(1.-pow(clamp(cd/24.,0.,1.),0.1))*sp.w;}
|
||||
if(sp.z>0.){tr(vec4(256,0.5,0.4,0.));sh=max(pow(1.-clamp(md,0.,1.),1.5),0.)*sp.z;}
|
||||
|
||||
|
||||
|
||||
|
||||
cc.rgb=tone(vec4(sc+(fr*mix(cc.rgb,oc,0.))+ss,df+(ps*max(1.-sh,0.))+fr*0.5),sh+ao);
|
||||
cc.rgb=mix(bg,cc.rgb,fo);
|
||||
|
||||
|
||||
}else {cc.a=1.;}cc.rgb+=gl;
|
||||
cc.rgb*=max(max(cc.r,max(cc.g,cc.b)),1.);
|
||||
}
|
||||
|
||||
vec3 refracter(vec3 I, vec3 N, float ior)
|
||||
{
|
||||
float k = 1.0 - ior * ior * (1.0 - dot(N, I) * dot(N, I));
|
||||
|
||||
k = abs(k);
|
||||
|
||||
if (k < 0.0)
|
||||
return vec3(0);
|
||||
else
|
||||
return ior * I - (ior * dot(N, I) + sqrt(k)) * N;
|
||||
|
||||
}
|
||||
|
||||
void render(vec2 frag, vec2 res, float time, out vec4 col)
|
||||
{
|
||||
uv=vec2(frag.x/res.x,frag.y/res.y);
|
||||
uv-=0.5;uv/=vec2(res.y/res.x,1);
|
||||
tt=mod(time, 100.);
|
||||
|
||||
|
||||
vec2 pix = decim(uv, 100.);
|
||||
vec2 id = vec2(h11(pix.x),h11(pix.y));
|
||||
|
||||
uv.x += (length(id)*sin(uv.y*30.+tt*h11(id.x)*5.))*id.x>0.2?0.03*pow(1.1-length(uv.y),5.):0.;
|
||||
|
||||
uv.x += fract(uv.y*0.53+tt*0.1)>0.5?0.05:0.;
|
||||
|
||||
uv*=1.-pow(length(uv),5.)*0.2;
|
||||
|
||||
ro=vec3(0,5,-20);
|
||||
rd = normalize(vec3(uv, 1));
|
||||
|
||||
for(int i=0;i<20;i++)
|
||||
{
|
||||
tr(vec4(256,0,1,1));ro=cp-cn*(io<0.?-0.01:0.01);
|
||||
cr=refract(rd,cn,i%2==0?1./io:io);
|
||||
if(io<0.)cr=reflect(rd,cn);px(rd, i);
|
||||
if(length(cr)!=0.)rd=cr;
|
||||
|
||||
|
||||
if(sc<1) fc=fc+vec4(cc.rgb*cc.a,cc.a)*(1.-fc.a);
|
||||
if(fc.a>=1.)break;sc=sc==0?io<0.?0:sk:sc-1;
|
||||
}
|
||||
col=fc/fc.a;
|
||||
|
||||
col *= 1.-pow(length(uv), 1.)*0.8;
|
||||
col = pow(col,vec4(0.9));
|
||||
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
if(mod(float(iFrame), 60./FPS) < 1. || iFrame < 5) render(fragCoord.xy,iResolution.xy,iTime,fragColor);
|
||||
else fragColor = texture(iChannel0, fragCoord / iResolution.xy);
|
||||
}
|
||||
5
tools/packsrc/Simulated Swampland/shaders/Common.frag
Normal file
5
tools/packsrc/Simulated Swampland/shaders/Common.frag
Normal file
@@ -0,0 +1,5 @@
|
||||
//fps control for performance. Assumes the refresh rate of your monitor is 60hz
|
||||
//(120hz monitor set to 30 here will actually run at 60fps)
|
||||
#define FPS 60.
|
||||
|
||||
#define decim(a, b) (floor((a)*(b))/(b))
|
||||
6
tools/packsrc/Simulated Swampland/shaders/Image.frag
Normal file
6
tools/packsrc/Simulated Swampland/shaders/Image.frag
Normal file
@@ -0,0 +1,6 @@
|
||||
//See the common tab for fps control.
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
fragColor = texture(iChannel0, fragCoord / iResolution.xy);
|
||||
}
|
||||
21
tools/packsrc/Voxel Land 2/pack.json
Normal file
21
tools/packsrc/Voxel Land 2/pack.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"author": "Nrx",
|
||||
"name": "Voxel Land 2",
|
||||
"version": "1.0.0",
|
||||
"description": "Rework of Voxel land to be faster on mobile devices (no reflection) and propose different colors...",
|
||||
"license": "CC BY-NC-SA 3.0",
|
||||
"engine": "shadertoy",
|
||||
"id": "XlfGR4",
|
||||
"tags": [
|
||||
"reactive",
|
||||
"voxels"
|
||||
],
|
||||
|
||||
"source": "./shaders/Image.frag.qsb",
|
||||
"speed": 0.5,
|
||||
|
||||
"channel0":
|
||||
{
|
||||
"type": 4
|
||||
}
|
||||
}
|
||||
115
tools/packsrc/Voxel Land 2/shaders/Image.frag
Normal file
115
tools/packsrc/Voxel Land 2/shaders/Image.frag
Normal file
@@ -0,0 +1,115 @@
|
||||
// Parameters
|
||||
#define CAMERA_FOCAL_LENGTH 1.5
|
||||
#define VOXEL_STEP 50.0
|
||||
#define SOUND
|
||||
#define MOUSE
|
||||
#define HSV2RGB_FAST
|
||||
|
||||
// Constants
|
||||
#define PI 3.14159265359
|
||||
#define SQRT2 1.41421356237
|
||||
|
||||
// PRNG
|
||||
// From https://www.shadertoy.com/view/4djSRW
|
||||
float rand (in vec2 seed) {
|
||||
seed = fract (seed * vec2 (5.3983, 5.4427));
|
||||
seed += dot (seed.yx, seed.xy + vec2 (21.5351, 14.3137));
|
||||
return fract (seed.x * seed.y * 95.4337);
|
||||
}
|
||||
|
||||
// HSV to RGB
|
||||
vec3 hsv2rgb (in vec3 hsv) {
|
||||
#ifdef HSV2RGB_SAFE
|
||||
hsv.yz = clamp (hsv.yz, 0.0, 1.0);
|
||||
#endif
|
||||
#ifdef HSV2RGB_FAST
|
||||
return hsv.z * (1.0 + 0.5 * hsv.y * (cos (2.0 * PI * (hsv.x + vec3 (0.0, 2.0 / 3.0, 1.0 / 3.0))) - 1.0));
|
||||
#else
|
||||
return hsv.z * (1.0 + hsv.y * clamp (abs (fract (hsv.x + vec3 (0.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - 3.0) - 2.0, -1.0, 0.0));
|
||||
#endif
|
||||
}
|
||||
|
||||
// Main function
|
||||
void mainImage (out vec4 fragColor, in vec2 fragCoord) {
|
||||
|
||||
// Define the ray corresponding to this fragment
|
||||
vec3 ray = normalize (vec3 ((2.0 * fragCoord.xy - iResolution.xy) / iResolution.y, CAMERA_FOCAL_LENGTH));
|
||||
|
||||
// Get the music info
|
||||
#ifdef SOUND
|
||||
float soundBass = texture (iChannel0, vec2 (0.0)).x;
|
||||
float soundTreble = texture (iChannel0, vec2 (0.9, 0.0)).x;
|
||||
#else
|
||||
float soundBass = 0.6 + 0.4 * cos (iTime * 0.2);
|
||||
float soundTreble = 0.5 + 0.5 * cos (iTime * 1.2);
|
||||
#endif
|
||||
|
||||
// Set the camera
|
||||
vec3 origin = vec3 (0.0, 6.0 - 3.0 * cos (iTime * 0.3), iTime * 2.0 + 700.0 * (0.5 + 0.5 * sin (iTime * 0.1)));
|
||||
float cameraAngle = iTime * 0.1;
|
||||
#ifdef MOUSE
|
||||
cameraAngle += 2.0 * PI * iMouse.x / iResolution.x;
|
||||
#endif
|
||||
vec3 cameraForward = vec3 (cos (cameraAngle), cos (iTime * 0.3) - 1.5, sin (cameraAngle));
|
||||
vec3 cameraUp = vec3 (0.2 * cos (iTime * 0.7), 1.0, 0.0);
|
||||
mat3 cameraRotation;
|
||||
cameraRotation [2] = normalize (cameraForward);
|
||||
cameraRotation [0] = normalize (cross (cameraUp, cameraForward));
|
||||
cameraRotation [1] = cross (cameraRotation [2], cameraRotation [0]);
|
||||
ray = cameraRotation * ray;
|
||||
|
||||
// Voxel
|
||||
vec3 color = vec3 (0.0);
|
||||
|
||||
vec2 voxelSign = sign (ray.xz);
|
||||
vec2 voxelIncrement = voxelSign / ray.xz;
|
||||
float voxelTimeCurrent = 0.0;
|
||||
vec2 voxelTimeNext = (0.5 + voxelSign * (0.5 - fract (origin.xz + 0.5))) * voxelIncrement;
|
||||
vec2 voxelPosition = floor (origin.xz + 0.5);
|
||||
float voxelHeight = 0.0;
|
||||
bool voxelDone = false;
|
||||
vec3 voxelNormal = vec3 (0.0);
|
||||
|
||||
for (float voxelStep = 1.0; voxelStep <= VOXEL_STEP; ++voxelStep) {
|
||||
|
||||
// Compute the height of this column
|
||||
voxelHeight = 2.0 * rand (voxelPosition) * smoothstep (0.2, 0.5, soundBass) * sin (soundBass * 8.0 + voxelPosition.x * voxelPosition.y) - 5.0 * (0.5 + 0.5 * cos (voxelPosition.y * 0.15));
|
||||
|
||||
// Check whether we hit the side of the column
|
||||
if (voxelDone = voxelHeight > origin.y + voxelTimeCurrent * ray.y) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Check whether we hit the top of the column
|
||||
float timeNext = min (voxelTimeNext.x, voxelTimeNext.y);
|
||||
float timeIntersect = (voxelHeight - origin.y) / ray.y;
|
||||
if (voxelDone = timeIntersect > voxelTimeCurrent && timeIntersect < timeNext) {
|
||||
voxelTimeCurrent = timeIntersect;
|
||||
voxelNormal = vec3 (0.0, 1.0, 0.0);
|
||||
break;
|
||||
}
|
||||
|
||||
// Next voxel...
|
||||
voxelTimeCurrent = timeNext;
|
||||
voxelNormal.xz = step (voxelTimeNext.xy, voxelTimeNext.yx);
|
||||
voxelTimeNext += voxelNormal.xz * voxelIncrement;
|
||||
voxelPosition += voxelNormal.xz * voxelSign;
|
||||
}
|
||||
if (voxelDone) {
|
||||
origin += voxelTimeCurrent * ray;
|
||||
|
||||
// Compute the local color
|
||||
vec3 mapping = origin;
|
||||
mapping.y -= voxelHeight + 0.5;
|
||||
mapping *= 1.0 - voxelNormal;
|
||||
mapping += 0.5;
|
||||
float id = rand (voxelPosition);
|
||||
color = hsv2rgb (vec3 ((iTime + floor (mapping.y)) * 0.05 + voxelPosition.x * 0.01, smoothstep (0.2, 0.4, soundBass), 0.7 + 0.3 * cos (id * iTime + PI * soundTreble)));
|
||||
color *= smoothstep (0.8 - 0.6 * cos (soundBass * PI), 0.1, length (fract (mapping) - 0.5));
|
||||
color *= 0.5 + smoothstep (0.90, 0.95, cos (id * 100.0 + soundTreble * PI * 0.5 + iTime * 0.5));
|
||||
color *= 1.0 - voxelTimeCurrent / VOXEL_STEP * SQRT2;
|
||||
}
|
||||
|
||||
// Set the fragment color
|
||||
fragColor = vec4 (color, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user