315 lines
8.0 KiB
GLSL
315 lines
8.0 KiB
GLSL
// Compofiller Studio by Yzi 2018
|
|
//
|
|
// Default template shader
|
|
|
|
// This shader program is executed in the GPU (or a CPU-based emulation) for
|
|
// every pixel (i.e. "fragment" in OpenGL jargon) of every frame.
|
|
|
|
// The "uniforms" are the same (i.e. uniform) for all pixels/fragments of the frame,
|
|
// and they come from the main program.
|
|
uniform float time;
|
|
uniform vec2 resolution;
|
|
|
|
// If you choose to save some bytes and not use either of these uniforms, you have to
|
|
// do some additional tricks.
|
|
// * time : if you uncheck "[ ] Use time uniform" checkbox, time is in gl_Color.y (green component)
|
|
// * resolution : if you uncheck "[ ] Use resolution uniform" checkbox, you'll have to hard-code the resolution manually
|
|
|
|
// The uniform-less version could look like this, 88200.0 being the time divider
|
|
//float time = gl_Color.y * 256.0 * (65536.0 / 88200.0);
|
|
//vec2 resolution = vec2(1280.0, 720.0);
|
|
|
|
// Uncomment this to use the texture-based features
|
|
uniform sampler2D texture_sampler;
|
|
|
|
// Uncomment this to use the texture-based features
|
|
uniform sampler2D texts;
|
|
|
|
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
|
|
// Created by S. Guillitte 2015
|
|
|
|
float zoom=1.;
|
|
|
|
vec2 cmul( vec2 a, vec2 b ) { return vec2( a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x ); }
|
|
vec2 csqr( vec2 a ) { return vec2( a.x*a.x - a.y*a.y, 2.*a.x*a.y ); }
|
|
|
|
|
|
mat2 rot(float a) {
|
|
return mat2(cos(a),sin(a),-sin(a),cos(a));
|
|
}
|
|
|
|
vec2 iSphere( in vec3 ro, in vec3 rd, in vec4 sph )//from iq
|
|
{
|
|
vec3 oc = ro - sph.xyz;
|
|
float b = dot( oc, rd );
|
|
float c = dot( oc, oc ) - sph.w*sph.w;
|
|
float h = b*b - c;
|
|
if( h<0.0 ) return vec2(-1.0);
|
|
h = sqrt(h);
|
|
return vec2(-b-h, -b+h );
|
|
}
|
|
|
|
float map(in vec3 p) {
|
|
|
|
float res = 0.;
|
|
|
|
vec3 c = p;
|
|
for (int i = 0; i < 10; ++i) {
|
|
p =.7*abs(p)/dot(p,p) -.7;
|
|
p.yz= csqr(p.yz);
|
|
p=p.zxy;
|
|
res += exp(-19. * abs(dot(p,c)));
|
|
|
|
}
|
|
return res/2.;
|
|
}
|
|
|
|
|
|
|
|
vec3 raymarch( in vec3 ro, vec3 rd, vec2 tminmax )
|
|
{
|
|
float t = tminmax.x;
|
|
float dt = .02;
|
|
//float dt = .2 - .195*cos(iTime*.05);//animated
|
|
vec3 col= vec3(0.);
|
|
float c = 0.;
|
|
for( int i=0; i<64; i++ )
|
|
{
|
|
t+=dt*exp(-2.*c);
|
|
if(t>tminmax.y)break;
|
|
|
|
c = map(ro+t*rd);
|
|
|
|
col = .99*col+ .08*vec3(c*c, c, c*c*c);//green
|
|
//col = .99*col+ .08*vec3(c*c*c, c*c, c);//blue
|
|
}
|
|
return col;
|
|
}
|
|
|
|
|
|
void CoolSphere( out vec4 fragColor, in vec2 fragCoord )
|
|
{
|
|
float time = time;
|
|
vec2 q = fragCoord.xy / resolution.xy;
|
|
vec2 p = -1.0 + 2.0 * q;
|
|
p.x *= resolution.x/resolution.y;
|
|
vec2 m = vec2(0.);
|
|
m-=.5;
|
|
|
|
// camera
|
|
|
|
vec3 ro = zoom*vec3(4.);
|
|
ro.yz*=rot(m.y);
|
|
ro.xz*=rot(m.x+ 0.1*time);
|
|
vec3 ta = vec3( 0.0 , 0.0, 0.0 );
|
|
vec3 ww = normalize( ta - ro );
|
|
vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) );
|
|
vec3 vv = normalize( cross(uu,ww));
|
|
vec3 rd = normalize( p.x*uu + p.y*vv + 4.0*ww );
|
|
|
|
|
|
vec2 tmm = iSphere( ro, rd, vec4(0.,0.,0.,2.) );
|
|
|
|
// raymarch
|
|
vec3 col = raymarch(ro,rd,tmm);
|
|
if (tmm.x<0.)col = texture2D(texture_sampler, rd).rgb;
|
|
else {
|
|
vec3 nor=(ro+tmm.x*rd)/2.;
|
|
nor = reflect(rd, nor);
|
|
float fre = pow(.5+ clamp(dot(nor,rd),0.0,1.0), 3. )*1.3;
|
|
col += texture2D(texture_sampler, nor).rgb * fre;
|
|
|
|
}
|
|
|
|
// shade
|
|
|
|
col = .5 *(log(1.+col));
|
|
col = clamp(col,0.,1.);
|
|
fragColor = vec4( col, 1.0 );
|
|
|
|
}
|
|
|
|
|
|
float bar = time; // this is just a coding nicety to highlight that in some calculations we want musical time ... you wouldn't want to have this in a real prod's final version
|
|
// --- noise from procedural pseudo-Perlin (better but not so nice derivatives) ---------
|
|
// ( adapted from IQ )
|
|
|
|
float gTime = 0.;
|
|
|
|
float sdBox( vec3 p, vec3 b )
|
|
{
|
|
vec3 q = abs(p) - b;
|
|
return length(max(q,0.0)) + min(max(q.x,max(q.y,q.z)),0.0);
|
|
}
|
|
|
|
float box(vec3 pos, float scale) {
|
|
pos *= scale;
|
|
float base = sdBox(pos, vec3(.4,.4,.1)) /1.5;
|
|
pos.xy *= 5.;
|
|
pos.y -= 3.5;
|
|
pos.xy *= rot(.75);
|
|
float result = -base;
|
|
return result;
|
|
}
|
|
|
|
float box_set(vec3 pos, float time) {
|
|
vec3 pos_origin = pos;
|
|
pos = pos_origin;
|
|
pos .y += sin(gTime * 0.4) * 2.5;
|
|
pos.xy *= rot(.8);
|
|
float box1 = box(pos,2. - abs(sin(gTime * 0.4)) * 1.5);
|
|
pos = pos_origin;
|
|
pos .y -=sin(gTime * 0.4) * 2.5;
|
|
pos.xy *= rot(.8);
|
|
float box2 = box(pos,2. - abs(sin(gTime * 0.4)) * 1.5);
|
|
pos = pos_origin;
|
|
pos .x +=sin(gTime * 0.4) * 2.5;
|
|
pos.xy *= rot(.8);
|
|
float box3 = box(pos,2. - abs(sin(gTime * 0.4)) * 1.5);
|
|
pos = pos_origin;
|
|
pos .x -=sin(gTime * 0.4) * 2.5;
|
|
pos.xy *= rot(.8);
|
|
float box4 = box(pos,2. - abs(sin(gTime * 0.4)) * 1.5);
|
|
pos = pos_origin;
|
|
pos.xy *= rot(.8);
|
|
float box5 = box(pos,.5) * 6.;
|
|
pos = pos_origin;
|
|
float box6 = box(pos,.5) * 6.;
|
|
float result = max(max(max(max(max(box1,box2),box3),box4),box5),box6);
|
|
return result;
|
|
}
|
|
|
|
float map(vec3 pos, float time) {
|
|
vec3 pos_origin = pos;
|
|
float box_set1 = box_set(pos, time);
|
|
|
|
return box_set1;
|
|
}
|
|
|
|
|
|
void mainImage2( out vec4 fragColor, in vec2 fragCoord ) {
|
|
vec2 p = (fragCoord.xy * 2. - resolution.xy) / min(resolution.x, resolution.y);
|
|
vec3 ro = vec3(0., -0.2 ,time * 4.);
|
|
vec3 ray = normalize(vec3(p, 1.5));
|
|
ray.xy = ray.xy * rot(sin(time * .03) * 5.);
|
|
ray.yz = ray.yz * rot(sin(time * .05) * .2);
|
|
float t = 0.1;
|
|
vec3 col = vec3(0.);
|
|
float ac = 0.0;
|
|
|
|
|
|
for (int i = 0; i < 99; i++){
|
|
vec3 pos = ro + ray * t;
|
|
pos = mod(pos-2., 4.) -2.;
|
|
gTime = time -float(i) * 0.01;
|
|
|
|
float d = map(pos, time);
|
|
|
|
d = max(abs(d), 0.01);
|
|
ac += exp(-d*23.);
|
|
|
|
t += d* 0.55;
|
|
}
|
|
|
|
col = vec3(ac * 0.02);
|
|
|
|
col +=vec3(0.,0.2 * abs(sin(time)),0.5 + sin(time) * 0.2);
|
|
|
|
|
|
fragColor = vec4(col ,1.0 - t * (0.02 + 0.02 * sin (time)));
|
|
}
|
|
|
|
float noise3( vec3 x ) {
|
|
vec3 p = floor(x),f = fract(x);
|
|
|
|
f = f*f*(3.-2.*f); // or smoothstep // to make derivative continuous at borders
|
|
|
|
#define hash3(p) fract(sin(1e3*dot(p,vec3(1,57,-13.7)))*4375.5453) // rand
|
|
|
|
return mix( mix(mix( hash3(p+vec3(0,0,0)), hash3(p+vec3(1,0,0)),f.x), // triilinear interp
|
|
mix( hash3(p+vec3(0,1,0)), hash3(p+vec3(1,1,0)),f.x),f.y),
|
|
mix(mix( hash3(p+vec3(0,0,1)), hash3(p+vec3(1,0,1)),f.x),
|
|
mix( hash3(p+vec3(0,1,1)), hash3(p+vec3(1,1,1)),f.x),f.y), f.z);
|
|
}
|
|
|
|
#define noise(x) (noise3(x)+noise3(x+11.5)) / 2. // pseudoperlin improvement from foxes idea
|
|
|
|
void mainImage3( out vec4 O, vec2 U ) // ------------ draw isovalues
|
|
{
|
|
vec2 R = resolution.xy;
|
|
float n = noise(vec3(U*8./R.y, .1*time)),
|
|
v = sin(6.28*10.*n),
|
|
t = time;
|
|
|
|
v = smoothstep(1.,0., .5*abs(v)/fwidth(v));
|
|
|
|
O = mix( exp(-33./R.y )* texture2D( texture_sampler, (U+vec2(1,sin(t)))/R), // .97
|
|
.5+.5*sin(12.*n+vec4(0,2.1,-2.1,0)),
|
|
v );
|
|
|
|
}
|
|
|
|
/* "Vortex" by @kishimisu (2024) - https://www.shadertoy.com/view/MX33Dr
|
|
|
|
It eventually leads somewhere...
|
|
|
|
[388 → 378 chars by @Xor]
|
|
*/
|
|
|
|
#define R mat2(cos(vec4(0,11,33,0)
|
|
|
|
void mainImage(out vec4 O, vec2 F) {
|
|
|
|
vec2 V = resolution;
|
|
vec3 o;
|
|
float r = time;
|
|
float t= .1;
|
|
float e,x;
|
|
|
|
for (O *= e; e++ < 40.;
|
|
|
|
o.y += t*t*.09,
|
|
o.z = mod(o.z + r, .2) - .1,
|
|
x = t*.06 - r*.2,
|
|
|
|
o.x = fract(
|
|
o.xy *= R+floor(((atan(o.y, o.x) - x) / .314) +0.5) * .314 + x))
|
|
).x - .8,
|
|
|
|
t += x = length(o)*.5 - .014,
|
|
|
|
O += (1. + cos(t*.5 + r + vec4(0,1,2,0)))
|
|
* (.3 + sin(3.*t + r*5.)/4.)
|
|
/ (8. + x*4e2)
|
|
)
|
|
o = t * normalize(vec3((F+F-V.xy)*R+r*.15)),V.y));
|
|
}
|
|
|
|
void main(void)
|
|
{
|
|
float abstime = abs(time);
|
|
vec3 l;
|
|
if (abstime < 10.0)
|
|
CoolSphere(gl_FragColor, gl_FragCoord.xy);
|
|
else if (abstime < 15.0)
|
|
{
|
|
mainImage2(gl_FragColor, gl_FragCoord.xy);
|
|
}
|
|
else if (abstime < 20.0)
|
|
{
|
|
mainImage(gl_FragColor, gl_FragCoord.xy);
|
|
}
|
|
else
|
|
{
|
|
mainImage3(gl_FragColor, gl_FragCoord.xy);
|
|
}
|
|
|
|
vec2 texttop = vec2(0., -.35), pt = (gl_FragCoord.xy / resolution) - texttop;
|
|
if (pt.y > 0.)
|
|
l = gl_FragColor + texture2D(texts, pt);
|
|
|
|
|
|
gl_FragColor = vec4(l * (1.0), 1.0);
|
|
|
|
}
|