-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathInversionMachine.fs
150 lines (139 loc) · 3.72 KB
/
InversionMachine.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*{
"CREDIT" : "Inversion Machine by Kali",
"CATEGORIES" : [
"ci"
],
"DESCRIPTION": "",
"INPUTS": [
{
"NAME": "inputImage",
"TYPE" : "image"
},
{
"NAME": "iZoom",
"TYPE" : "float",
"MIN" : 0.1,
"MAX" : 2.0,
"DEFAULT" : 1.0
},
{
"NAME": "iSteps",
"TYPE" : "float",
"MIN" : 2.0,
"MAX" : 128.0,
"DEFAULT" : 64.0
},
{
"NAME": "iTimeMultiplier",
"TYPE" : "float",
"MIN" : 0.01,
"MAX" : 10.0,
"DEFAULT" : 1.0
},
{
"NAME" :"iMouse",
"TYPE" : "point2D",
"DEFAULT" : [0.0, 0.0],
"MAX" : [640.0, 480.0],
"MIN" : [0.0, 0.0]
},
{
"NAME": "iColor",
"TYPE" : "color",
"DEFAULT" : [
0.9,
0.6,
0.0,
1.0
]
}
],
}
*/
// https://www.shadertoy.com/view/4dsGD7
// The Inversion Machine by Kali
const float InversionMachineWidth=.22;
const float InversionMachineScale=4.;
const float InversionMachineDetail=.001;
vec3 InversionMachineLightdir=-vec3(.2,.5,1.);
mat2 InversionMachineRotation;
float InversionMachineRand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
float InversionMachineDE(vec3 p) {
float t=TIME;
float dotp=dot(p,p);
p.x+=sin(t*40.)*.007;
p=p/dotp*InversionMachineScale;
p=sin(p+vec3(sin(1.+t)*2.,-t,-t*2.));
float d=length(p.yz)-InversionMachineWidth;
d=min(d,length(p.xz)-InversionMachineWidth);
d=min(d,length(p.xy)-InversionMachineWidth);
d=min(d,length(p*p*p)-InversionMachineWidth*.3);
return d*dotp/InversionMachineScale;
}
vec3 InversionMachineNormal(vec3 p) {
vec3 e = vec3(0.0,InversionMachineDetail,0.0);
return normalize(vec3(
InversionMachineDE(p+e.yxx)-InversionMachineDE(p-e.yxx),
InversionMachineDE(p+e.xyx)-InversionMachineDE(p-e.xyx),
InversionMachineDE(p+e.xxy)-InversionMachineDE(p-e.xxy)
)
);
}
float InversionMachineLight(in vec3 p, in vec3 dir) {
vec3 ldir=normalize(InversionMachineLightdir);
vec3 n=InversionMachineNormal(p);
float sh=1.;
float diff=max(0.,dot(ldir,-n))+.1*max(0.,dot(normalize(dir),-n));
vec3 r = reflect(ldir,n);
float spec=max(0.,dot(dir,-r))*sh;
return diff+pow(spec,20.)*.7;
}
float InversionMachineRaymarch(in vec3 from, in vec3 dir)
{
vec2 uv = gl_FragCoord.xy / RENDERSIZE.xy*2.-1.;
uv.y*=RENDERSIZE.y/RENDERSIZE.x;
float st,d,col,totdist=st=0.;
vec3 p;
float ra=InversionMachineRand(uv.xy*TIME)-.5;
float ras=max(0.,sign(-.5+InversionMachineRand(vec2(1.3456,.3573)*floor(30.+TIME*20.))));
float rab=InversionMachineRand(vec2(1.2439,2.3453)*floor(10.+TIME*40.))*ras;
float rac=InversionMachineRand(vec2(1.1347,1.0331)*floor(40.+TIME));
float ral=InversionMachineRand(1.+floor(uv.yy*300.)*TIME)-.5;
for (int i=0; i<60; i++) {
p=from+totdist*dir;
d=InversionMachineDE(p);
if (d<InversionMachineDetail || totdist>3.) break;
totdist+=d;
st+=max(0.,.04-d);
}
vec2 li=uv*InversionMachineRotation;
float backg=.45*pow(1.5-min(1.,length(li+vec2(0.,-.6))),1.5);
if (d<InversionMachineDetail) {
col=InversionMachineLight(p-InversionMachineDetail*dir, dir);
} else {
col=backg;
}
col+=smoothstep(0.,1.,st)*.8*(.1+rab);
col+=pow(max(0.,1.-length(p)),8.)*(.5+10.*rab);
col+=pow(max(0.,1.-length(p)),30.)*50.;
col = mix(col, backg, 1.0-exp(-.25*pow(totdist,3.)));
if (rac>.7) col=col*.7+(.3+ra+ral*.5)*mod(uv.y+TIME*2.,.25);
col = mix(col, .5+ra+ral*.5, max(0.,3.-TIME)/3.);
return col+ra*.03+(ral*.1+ra*.1)*rab;
}
void main(void)
{
vec2 uv = iZoom * gl_FragCoord.xy / RENDERSIZE.xy;
float t=TIME*.2;
uv.x = uv.x *2.-1.;
uv.y = uv.y *2.-1.;
vec3 from=vec3(0.,0.1,-1.2);
vec3 dir=normalize(vec3(uv,1.));
InversionMachineRotation=mat2(cos(t),sin(t),-sin(t),cos(t));
dir.xy=dir.xy*InversionMachineRotation;
float col=InversionMachineRaymarch(from,dir);
col=pow(col,1.25);
gl_FragColor = vec4(vec3( col ),1.0);
}