Repository navigation
Expand file tree
/
Copy pathwarp.glsl
More file actions
179 lines (148 loc) · 4.59 KB
/
Copy pathwarp.glsl
File metadata and controls
179 lines (148 loc) · 4.59 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
uniform float iTime;
uniform vec3 iResolution;
uniform vec4 iMouse;
uniform float iTimeDelta;
uniform int iFrame;
// Copyright Inigo Quilez, 2013 - https://iquilezles.org/
// I am the sole copyright owner of this Work. You cannot
// host, display, distribute or share this Work neither as
// is or altered, in any form including physical and
// digital. You cannot use this Work in any commercial or
// non-commercial product, website or project. You cannot
// sell this Work and you cannot mint an NFTs of it. You
// cannot use this Work to train AI models. I share this
// Work for educational purposes, you can link to it as
// an URL, proper attribution and unmodified screenshot,
// as part of your educational material. If these
// conditions are too restrictive please contact me.
// Tutorial:
//
// https://iquilezles.org/articles/warp
//
// More warping examples:
//
// https://www.shadertoy.com/view/4s23zz
// https://www.shadertoy.com/view/lsl3RH
// https://www.shadertoy.com/view/XsfSD4
// https://www.shadertoy.com/view/MdSXzz
// https://www.shadertoy.com/view/3XlfWH
#if HW_PERFORMANCE==0
#define AA 1
#else
#define AA 2
#endif
float hash(vec2 p) // replace this by something better
{
p = fract( p*0.6180339887 );
p *= 25.0;
return fract( p.x*p.y*(p.x+p.y) );
}
// consider replacing this by a proper noise function
float noise( in vec2 x )
{
vec2 p = floor(x);
vec2 f = fract(x);
f = f*f*(3.0-2.0*f);
float a = hash(p+vec2(0,0));
float b = hash(p+vec2(1,0));
float c = hash(p+vec2(0,1));
float d = hash(p+vec2(1,1));
return mix(mix( a, b,f.x), mix( c, d,f.x),f.y);
}
const mat2 mtx = mat2( 0.80, 0.60, -0.60, 0.80 );
float fbm4( vec2 p )
{
float f = 0.0;
f += 0.5000*(-1.0+2.0*noise( p )); p = mtx*p*2.02;
f += 0.2500*(-1.0+2.0*noise( p )); p = mtx*p*2.03;
f += 0.1250*(-1.0+2.0*noise( p )); p = mtx*p*2.01;
f += 0.0625*(-1.0+2.0*noise( p ));
return f/0.9375;
}
float fbm6( vec2 p )
{
float f = 0.0;
f += 0.500000*noise( p ); p = mtx*p*2.02;
f += 0.250000*noise( p ); p = mtx*p*2.03;
f += 0.125000*noise( p ); p = mtx*p*2.01;
f += 0.062500*noise( p ); p = mtx*p*2.04;
f += 0.031250*noise( p ); p = mtx*p*2.01;
f += 0.015625*noise( p );
return f/0.96875;
}
vec2 fbm4_2( vec2 p )
{
return vec2( fbm4(p+vec2(1.0)), fbm4(p+vec2(6.2)) );
}
vec2 fbm6_2( vec2 p )
{
return vec2( fbm6(p+vec2(9.2)), fbm6(p+vec2(5.7)) );
}
float func( vec2 q, out vec2 o, out vec2 n )
{
q += 0.05*sin(vec2(0.11,0.13)*iTime + length( q )*4.0);
q *= 0.7 + 0.2*cos(0.05*iTime);
o = 0.5 + 0.5*fbm4_2( q );
o += 0.02*sin(vec2(0.13,0.11)*iTime*length( o ));
n = fbm6_2( 4.0*o );
vec2 p = q + 2.0*n + 1.0;
float f = 0.5 + 0.5*fbm4( 2.0*p );
f = mix( f, f*f*f*3.5, f*abs(n.x) );
f *= 1.0-0.5*pow( 0.5+0.5*sin(8.0*p.x)*sin(8.0*p.y), 8.0 );
return f;
}
float funcs( in vec2 q )
{
vec2 t1, t2;
return func(q,t1,t2);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec3 tot = vec3(0.0);
#if AA>1
for( int mi=0; mi<AA; mi++ )
for( int ni=0; ni<AA; ni++ )
{
// pixel coordinates
vec2 of = vec2(float(mi),float(ni)) / float(AA) - 0.5;
vec2 q = (2.0*(fragCoord+of)-iResolution.xy)/iResolution.y;
#else
vec2 q = (2.0*fragCoord-iResolution.xy)/iResolution.y;
#endif
vec2 o, n;
float f = func(q, o, n);
vec3 col = vec3(0.2,0.1,0.4);
col = mix( col, vec3(0.3,0.05,0.05), f );
col = mix( col, vec3(0.9,0.9,0.9), dot(n,n) );
col = mix( col, vec3(0.5,0.2,0.2), 0.5*o.y*o.y );
col = mix( col, vec3(0.0,0.2,0.4), 0.5*smoothstep(1.2,1.3,abs(n.y)+abs(n.x)) );
col *= f*2.0;
vec2 ex = vec2( 1.0 / iResolution.x, 0.0 );
vec2 ey = vec2( 0.0, 1.0 / iResolution.y );
#if AA>1
ex /= float(AA);
ey /= float(AA);
#endif
vec3 nor = normalize( vec3( funcs(q+ex) - f, ex.x, funcs(q+ey) - f ) );
vec3 lig = normalize( vec3( 0.9, -0.2, -0.4 ) );
float dif = clamp( 0.3+0.7*dot( nor, lig ), 0.0, 1.0 );
vec3 lin = vec3(0.85,0.90,0.95)*(nor.y*0.5+0.5);
lin += vec3(0.15,0.10,0.05)*dif;
col *= lin;
col = vec3(1.0)-col;
col = col*col;
col *= vec3(1.2,1.25,1.2);
tot += col;
#if AA>1
}
tot /= float(AA*AA);
#endif
vec2 p = fragCoord / iResolution.xy;
tot *= 0.5 + 0.5 * sqrt(16.0*p.x*p.y*(1.0-p.x)*(1.0-p.y));
fragColor = vec4( tot, 1.0 );
}
void main() {
vec4 fragColor = vec4(0.0);
mainImage(fragColor, gl_FragCoord.xy);
gl_FragColor = fragColor;
}