testing shader fragments

This commit is contained in:
2024-05-28 22:10:25 +03:00
parent 42ab16309c
commit 063624d7bb
9 changed files with 1260 additions and 335 deletions

50
2d_thing.frag Normal file
View File

@ -0,0 +1,50 @@
#ifdef GL_ES
precision mediump float;
#endif
const float PI = 3.14159265;
uniform vec2 u_resolution;
uniform float u_time;
vec3 palette(float t) {
vec3 a = vec3(0.5, 0.5, 0.5);
vec3 b = vec3(1.0, 1.0, 1.0);
vec3 c = vec3(1.0, 1.0, 1.0);
vec3 d = vec3(0.0, 0.6666, 0.3333);
return a + b * cos(6.28318 * (c*t+d));
}
mat2 rotate(float angle){
return mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
}
float polygon(vec2 position, float radius, float sides){
float a = atan(position.x, position.y);
float slice = PI * 2.0 / sides;
return 1. - step(radius, cos(floor(0.5 + a / slice) * slice - a) * length(position));
}
float star(vec2 position, float radius, float sides){
float a = atan(position.x, position.y);
float slice = PI * 2. / sides;
return 1. - step(radius, cos(floor(-2.0 + a / slice) * slice - a));
}
void main() {
vec2 uv = (gl_FragCoord.xy * 2. - u_resolution.xy) / u_resolution.y;
vec3 color = vec3(0.08, 0.22, 0.39);
vec3 mixer = vec3(0.);
for(float i = 1.; i < 3.; i++){
vec2 translate = uv;
translate *= rotate(i*1.4/5.); // + u_time);
float sides = 11.;
mixer += vec3(star(translate, 0.06, sides))*vec3(0.5725, 0.8275, 0.9451)*(i*0.7)*0.2;
}
color = mix( color, mixer, 0.5);
// color = max(color, polygon(uv, 0.3, 6.)),
gl_FragColor = vec4(color, 1.0);
}

233
cogs.frag Normal file
View File

@ -0,0 +1,233 @@
#ifdef GL_ES
precision mediump float;
#endif
#define MAX_STEPS 100
#define MAX_DIST 20.
#define SURF_DIST .001
#define TAU 6.283185
#define PI 3.141592
#define FOG_DENSITY 0.01
uniform vec2 u_resolution;
uniform float u_time;
struct Obj {
float distance; // distance map
int material; // material Id
};
mat2 Rot(float a) {
float s=sin(a), c=cos(a);
return mat2(c, -s, s, c);
}
vec3 applyFog(in vec3 color, in float distance) {
float fogAmount = 1.0 - exp(-distance*FOG_DENSITY);
vec3 fogColor = vec3(0.17, 0.16, 0.24);
return mix( color, fogColor, fogAmount );
}
float opExtrusion( in vec3 p, in float sdf, in float h )
{
vec2 w = vec2( sdf, abs(p.z) - h);
return min(max(w.x,w.y),0.0) + length(max(w,0.0));
}
float sdCog2d(vec2 pos) {
float r = length(pos)*2.;
float a = atan(pos.y,pos.x);
float f = 1. - smoothstep(-0.2, .8, sin(a * 12.))*0.14;
f = smoothstep(f,f + 2.,r);
return f;
}
float opSmoothSubtraction( float d1, float d2, float k )
{
float h = max(k-abs(-d1-d2),0.0);
return max(-d1, d2) + h*h*0.25/k;
}
float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
{
vec3 pa = p - a, ba = b - a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
return length( pa - ba*h ) - r;
}
float sdCog(vec3 pos, float angle) {
pos.xy *= Rot(angle);
float d1 = opExtrusion(pos, sdCog2d(pos.xy), 0.15);
float d2 = sdCapsule(pos - vec3(0.,0., -0.5), vec3(0., 0.0, 0.), vec3(0., 0., 1.), 0.2);
return 0.8 * opSmoothSubtraction(d2,d1,0.02)-0.001;
}
// Scene
Obj mapScene(in vec3 p) {
float d = 1e10;
float dGround = p.y +1.5 + sin(p.z*0.6)*.2 + sin(p.x*1.3)*.1;
Obj ground = Obj(dGround, 0);
{
float d1 = sdCog(p+vec3(1., 0., 0.), u_time);
d = min(d, d1);
}
{
float d1 = sdCog(p+vec3(0.5, -.87, 0.), -u_time);
d = min(d, d1);
}
{
float d1 = sdCog(p+vec3(0.5, .87, 0.), -u_time);
d = min(d, d1);
}
Obj ob1 = Obj(d, 1);
if (ground.distance > ob1.distance) return ob1;
return ground;
}
Obj castRay(vec3 ro, vec3 rd) {
float t = 0.0;
Obj res = Obj(-1., -1);
for(int i=0; i<MAX_STEPS; i++) {
vec3 p = ro + rd * t;
res = mapScene(p);
t += res.distance;
if (t > MAX_DIST || res.distance < abs(SURF_DIST*t) ) break;
}
if (t > MAX_DIST) t = -1.0;
res.distance = t;
return res;
}
float castShadow(vec3 ro, vec3 rd) {
float res = 1.0;
float t = 0.001;
for(int i = 0; i < MAX_STEPS; i++) {
vec3 pos = ro + t* rd;
float h = mapScene(pos).distance;
res = min(res, 10.0*h/t);
if (abs(h) < (0.001*t) ) break;
t += h;
if (t > 20.) break;
}
return clamp(res,0., 1.);
}
vec3 calcNormal(vec3 pos) {
vec2 e = vec2(.001, 0.);
vec3 n = vec3( mapScene(pos+e.xyy).distance - mapScene(pos-e.xyy).distance,
mapScene(pos+e.yxy).distance - mapScene(pos-e.yxy).distance,
mapScene(pos+e.yyx).distance - mapScene(pos-e.yyx).distance
);
return normalize(n);
}
vec3 fresnel( vec3 F0, vec3 h, vec3 l ) {
return F0 + ( 1.0 - F0 ) * pow( clamp( 1.0 - dot( h, l ), 0.0, 1.0 ), 5.0 );
}
vec3 shading(vec3 v, vec3 n, vec3 dir, int material) {
float shininess = 1.;
vec3 final = vec3( 0.0 );
vec3 ref = reflect( dir, n );
vec3 Ks = vec3( 0.5 );
vec3 Kd = vec3( 1.0 );
vec3 outMaterial = vec3(0.1255, 0.1255, 0.1255);
if (material == 0) {
outMaterial = vec3(0.1412, 0.1412, 0.1412);
shininess = 3.1;
} else if (material == 1) {
outMaterial = vec3(0.1765, 0.1961, 0.2275);
shininess = 21.;
}
// light 0
{
vec3 light_pos = vec3( -2.,.3, 10. );
vec3 light_color = vec3(0.71, 0.51, 0.72) * 5.;
vec3 vl = normalize( light_pos - v );
vec3 diffuse = Kd * vec3( max( 0.0, dot( vl, n ) ) );
vec3 specular = vec3( max( 0.0, dot( vl, ref ) ) );
vec3 F = fresnel( Ks, normalize( vl - dir ), vl );
specular = pow( specular, vec3( shininess ) );
final += outMaterial * specular * light_color * mix( diffuse, specular, F );
}
// light 1
{
vec3 light_pos = vec3( 5.0, 5.0, -20.0 );
vec3 light_color = vec3(0.14, 0.36, 0.83)* 7.;
vec3 vl = normalize( light_pos - v );
vec3 diffuse = Kd * vec3( max( 0.0, dot( vl, n ) ) );
vec3 specular = vec3( max( 0.0, dot( vl, ref ) ) );
vec3 F = fresnel( Ks, normalize( vl - dir ), vl );
specular = pow( specular, vec3( shininess ) );
final += outMaterial * specular * light_color * mix( diffuse, specular, F );
}
{
vec3 SUN_DIR = vec3(0. , .4, 1.);
float sun_dif = clamp(dot(n, SUN_DIR), 0., 1.);
float shadow = castShadow(v + n*0.02, SUN_DIR);
final += outMaterial * vec3(1.1,1.2, 1.5) * sun_dif * sun_dif * shadow;
}
{
vec3 SUN_DIR = vec3(0. , .6, -1.);
float sun_dif = clamp(dot(n, SUN_DIR), 0., 1.);
final += outMaterial * vec3(0.0353, 0.2667, 0.4784) * sun_dif;
}
// final += texture( iChannel0, ref ).rgb * fresnel( Ks, n, -dir );
// vec3 col = vec3(0.4)* ref.x;
//vec3 col = vec3(0.0588, 0.0588, 0.1216);// - vec3(0.149, 0.0863, 0.2314) * v.x;
//final += col * fresnel( vec3(.5), ref, -dir );
return final;
}
void main()
{
vec2 p = (2.0 * gl_FragCoord.xy - u_resolution.xy) / u_resolution.y;
float angle = u_time*0.4;
// angle = 2.0; // comment to rotate
// gl_FragColor = vec4(vec3(sdCog2d(p)), 1.);
// return;
// camera
vec3 ta = vec3(0.0, 0., 0.0);
vec3 ro = ta + vec3(4.*sin(angle), cos(angle), 4.*cos(angle)); // *cos(angle))
vec3 ww = normalize(ta-ro);
vec3 uu = normalize(cross(ww, vec3(0,1,0)));
vec3 vv = normalize(cross(uu,ww));
vec3 rd = normalize(p.x * uu + p.y*vv + 1.4*ww); // camera
// global light
vec3 col = vec3(0.1451, 0.1098, 0.1608) - vec3(0.9725, 0.5176, 0.0) *rd.y;
Obj t = castRay(ro, rd);
if (t.distance > 0.) {
vec3 pos = ro + rd * t.distance;
vec3 nor = calcNormal(pos);
col = shading(pos, nor, rd , t.material);
// apply fog
col = applyFog(col, t.distance);
}
gl_FragColor = vec4( pow( col, vec3(1.0/1.3) ), 1.0 );
}

View File

@ -10,8 +10,10 @@ include $(PARENT_CONFIG)
EXE_LINKER_PROGRAM=Crinkler
CRINKLER_ORDERTRIES=4000
SHADER_FILE=shader_minified.h
TIME_UNIFORM_NAME='y'
RESOLUTION_UNIFORM_NAME='v'
TEXTS_UNIFORM_NAME='s'
TIME_UNIFORM_NAME='v'
RESOLUTION_UNIFORM_NAME='m'
TEXTS_UNIFORM_NAME='d'
USE_WIDECHAR_TEXTS=1
TIME_DIVIDER=72993.102
TIME_BASE=bars
TIME_DIVIDER_INT=72993

174
sea.frag Normal file
View File

@ -0,0 +1,174 @@
#ifdef GL_ES
precision mediump float;
#endif
#define MAX_STEPS 100
#define MAX_DIST 80.
#define SURF_DIST .001
#define TAU 6.283185
#define PI 3.141592
//#define SUN_DIR vec3(0.5, 0.4, 2.)
#define FOG_DENSITY 0.02
uniform vec2 u_resolution;
uniform float u_time;
struct Obj {
float distance; // distance map
int material; // material Id
};
mat2 Rot(float a) {
float s=sin(a), c=cos(a);
return mat2(c, -s, s, c);
}
float sdBox(vec3 p, vec3 s) {
p = abs(p)-s;
return length(max(p, 0.))+min(max(p.x, max(p.y, p.z)), 0.);
}
vec3 applyFog(in vec3 color, in float distance) {
float fogAmount = 1.0 - exp(-distance*FOG_DENSITY);
vec3 fogColor = vec3(0.1, 0.18, 0.43);
return mix( color, fogColor, fogAmount );
}
vec3 translate(vec3 p) {
p.xy *= Rot(u_time*0.4);
p.yz *= Rot(u_time*0.4);
return p;
}
float opExtrusion( in vec3 p, in float sdf, in float h )
{
vec2 w = vec2( sdf, abs(p.z) - h);
return min(max(w.x,w.y),0.0) + length(max(w,0.0));
}
vec2 opRevolution( in vec3 p, float w )
{
return vec2( length(p.xz) - w, p.y );
}
vec4 opElongate( in vec3 p, in vec3 h )
{
vec3 q = abs(p)-h;
return vec4( max(q,0.0), min(max(q.x,max(q.y,q.z)),0.0) );
}
// Scene
Obj mapScene(vec3 p) {
vec3 p0 = p;
float dGround = p.y - 0.5*(sin(0.4*p.x+u_time*1.)+sin(1.0*p.z+u_time*1.));
dGround *=0.8;
Obj ground = Obj(dGround, 0);
p0.y = dGround + 0.1;
float d1 = length(p0) - 0.3;
Obj ob1 = Obj(d1, 1);
if (ground.distance > ob1.distance) return ob1;
return ground;
}
Obj castRay(vec3 ro, vec3 rd) {
float t = 0.0;
Obj res = Obj(-1., -1);
for(int i=0; i<MAX_STEPS; i++) {
vec3 p = ro + rd * t;
res = mapScene(p);
t += res.distance;
if (t > MAX_DIST || res.distance < abs(SURF_DIST*t) ) break;
}
if (t > MAX_DIST) t = -1.0;
res.distance = t;
return res;
}
float castShadow(vec3 ro, vec3 rd) {
float res = 1.0;
float t = 0.0001;
for(int i=0; i<MAX_STEPS; i++) {
vec3 pos = ro + t* rd;
float h = mapScene(pos).distance;
res = min(res, 10.0*h/t);
if (abs(h) < (0.001*t) ) break;
t += h;
if (t > 20.) break;
}
return clamp(res,0., 1.);
}
vec3 calcNormal(vec3 pos) {
vec2 e = vec2(.0001, 0.);
vec3 n = vec3( mapScene(pos+e.xyy).distance - mapScene(pos-e.xyy).distance,
mapScene(pos+e.yxy).distance - mapScene(pos-e.yxy).distance,
mapScene(pos+e.yyx).distance - mapScene(pos-e.yyx).distance
);
return normalize(n);
}
void main()
{
vec2 p = (2.0 * gl_FragCoord.xy - u_resolution.xy) / u_resolution.y;
float angle = u_time*0.2;
angle = 4.6; // comment to rotate
// camera
vec3 ta = vec3(0.0, .5, 0.0);
vec3 ro = ta + vec3(1.*sin(angle), .7, 2.); // *cos(angle))
vec3 ww = normalize(ta-ro);
vec3 uu = normalize(cross(ww, vec3(0,1,0)));
vec3 vv = normalize(cross(uu,ww));
vec3 rd = normalize(p.x * uu + p.y*vv + 1.3*ww); // camera
// global light
vec3 col = vec3(0.1216, 0.2863, 0.5529) - 0.5*rd.y;
Obj t = castRay(ro, rd);
if (t.distance > 0.) {
vec3 pos = ro + rd * t.distance;
vec3 nor = calcNormal(pos);
// vec3 r = reflect(rd, nor);
vec3 outMaterial = vec3(0.1255, 0.1176, 0.1176);
if (t.material == 0) {
outMaterial = vec3(0.0039, 0.2235, 0.4) + sin(t.distance)*0.1;
} else if (t.material == 1) {
outMaterial = vec3(0.8392, 0.0118, 0.0118);
}
vec3 SUN_DIR = vec3(0.5+sin(u_time*0.1), 0.4, 2.0+sin(u_time*0.2)*0.5);
float sun_dif = clamp(dot(nor, SUN_DIR), 0., 1.);
float sun_sha = castShadow(pos + nor*0.02, SUN_DIR);
float sky_dif = clamp(0.5 + 0.5 * dot(nor, vec3(0.,1.,0.)), 0., 1.);
float bounce_dif = clamp(0.5 + 0.5 * dot(nor, vec3(.7,.5, 0.)), 0., 1.);
// format color + what to apply
col = outMaterial * vec3(2.0,1.5, .2) * sun_dif * sun_dif * sun_sha;
col += outMaterial * vec3(0.0196, 0.2078, 0.4196) * sky_dif;
col += outMaterial * vec3(0.051, 0.0588, 0.5686) * bounce_dif;
// apply fog
col = applyFog(col, t.distance);
}
col = pow(col, vec3(.4545)); // gamma correction
gl_FragColor = vec4(col,1.0);
}

View File

@ -1,265 +1,233 @@
#version 120
uniform float time;
uniform vec2 resolution;
uniform sampler2D texture_sampler;
uniform sampler2D texts;
#define MAX_STEPS 100
#define MAX_DIST 20.
#define SURF_DIST .001
#define TAU 6.283185
#define PI 3.141592
float zoom = 1.;
float gTime = 0.;
#define FOG_DENSITY 0.01
float getBeat(void) {
return floor(abs(time*4.) / (60./145.) );
}
float getBar(void) {
return floor(abs(time) / (60./145.));
struct Obj {
float distance; // distance map
int material; // material Id
};
mat2 Rot(float a) {
float s=sin(a), c=cos(a);
return mat2(c, -s, s, c);
}
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(time*.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.xy).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.xy).rgb * fre;
}
// shade
col = .5 * (log(1. + col));
col = clamp(col, 0., 1.);
fragColor = vec4(col, 1.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;
}
vec4 mainImage2(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);
return vec4(col, 1.0 - t * (0.02 + 0.02 * sin(time)));
}
vec3 palette(float t) {
vec3 a = vec3(0.5, 0.5, 0.5);
vec3 b = vec3(1.0, 1.0, 1.0);
vec3 c = vec3(1.0, 1.0, 1.0);
vec3 d = vec3(0.0, 0.6666, 0.3333);
return a + b * cos(6.28318 * (c*t+d));
}
float rand(vec2 co) {
float a = 12.9898;
float b = 78.233;
float c = 43758.5453;
float dt= dot(co.xy ,vec2(a,b));
float sn= mod(dt,3.14);
return fract(sin(sn) * c);
}
vec3 random(vec2 uv) {
float rng = rand(vec2(uv.x+time, uv.y));
vec3 col = vec3(0.0+rng*0.1, 0.2+rng*0.1, 0.4+rng*0.1);
col.x += sin(uv.x+time*0.2)*0.1;
col.y += sin(uv.y+time*0.2)*0.1;
col.z += sin(uv.y+time*0.2)*0.1;
return col;
vec3 applyFog(in vec3 color, in float distance) {
float fogAmount = 1.0 - exp(-distance*FOG_DENSITY);
vec3 fogColor = vec3(0.17, 0.16, 0.24);
return mix( color, fogColor, fogAmount );
}
vec3 wave(vec2 uv, float phase, float _offset, float height, float waveLenght, float color) {
float val = -(sin(phase+uv.x*waveLenght+time) + (uv.y*6.+height)+_offset)*0.055;
val *= 1. + sin(phase + uv.x*waveLenght+time) + (uv.y*6.-height+_offset);
//return smoothstep(0.0, 1.0, val) * palette(color/360.);
return clamp(val, 0., .9) * palette(color/360.);
}
float gStartTime = 0.;
float gPrevTime = -0.1;
vec4 waveTexture(vec2 uv) {
uv.y = sin(uv.x*16. + time)/32. + uv.y-0.03;
uv.x -= (time-gStartTime)*0.2;
vec4 tex = texture2D(texts, uv);
if (tex.y > 0. && (gPrevTime != gStartTime)) {
gStartTime = time;
gPrevTime = gStartTime;
}
return vec4(tex.rgb, 1.0);
}
void TextScroller(out vec4 fragColor, in vec2 fragCoord)
float opExtrusion( in vec3 p, in float sdf, in float h )
{
// Normalized pixel coordinates (from -1 to 1, origo at 0,0)
vec2 uv = (fragCoord.xy * 2. - resolution.xy) / min(resolution.x, resolution.y);
vec3 col = vec3(0., 0.4, 0.6);
col += wave(uv, 0., 1., 3., 1., sin(time+0.3)*90.);
col += wave(uv, sin(time), 0., 3., -1., sin(time-1.2)*120.);
col += wave(uv, -3., 0., 3., 1., sin(time+0.5)*90.);
vec4 outBuf = waveTexture(uv * 0.1);
fragColor = max(mainImage2(gl_FragCoord.xy)*0.2, vec4(col*outBuf.xyz, 1.0)); // + vec4(random(uv*2.), 1.0);
vec2 w = vec2( sdf, abs(p.z) - h);
return min(max(w.x,w.y),0.0) + length(max(w,0.0));
}
void main(void) {
TextScroller(gl_FragColor, gl_FragCoord.xy);
/*else
float sdCog2d(vec2 pos) {
float r = length(pos)*2.;
float a = atan(pos.y,pos.x);
float f = 1. - smoothstep(-0.2, .8, sin(a * 12.))*0.14;
f = smoothstep(f,f + 2.,r);
return f;
}
float opSmoothSubtraction( float d1, float d2, float k )
{
float h = max(k-abs(-d1-d2),0.0);
return max(-d1, d2) + h*h*0.25/k;
}
float sdCapsule( vec3 p, vec3 a, vec3 b, float r )
{
vec3 pa = p - a, ba = b - a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
return length( pa - ba*h ) - r;
}
float sdCog(vec3 pos, float angle) {
pos.xy *= Rot(angle);
float d1 = opExtrusion(pos, sdCog2d(pos.xy), 0.15);
float d2 = sdCapsule(pos - vec3(0.,0., -0.5), vec3(0., 0.0, 0.), vec3(0., 0., 1.), 0.2);
return 0.8 * opSmoothSubtraction(d2,d1,0.02)-0.001;
}
// Scene
Obj mapScene(in vec3 p) {
float d = 1e10;
float dGround = p.y +1.5 + sin(p.z*0.6)*.2 + sin(p.x*1.3)*.1;
Obj ground = Obj(dGround, 0);
{
mainImage2(gl_FragColor, gl_FragCoord.xy);
vec4 l;
vec2 texttop = vec2(0., -.35), pt = (gl_FragCoord.xy / resolution) - texttop;
if(pt.y > 0.) {
l = gl_FragColor + texture2D(texts, pt);
}
float d1 = sdCog(p+vec3(1., 0., 0.), time);
d = min(d, d1);
}
{
float d1 = sdCog(p+vec3(0.5, -.87, 0.), -time);
d = min(d, d1);
}
{
float d1 = sdCog(p+vec3(0.5, .87, 0.), -time);
d = min(d, d1);
}
Obj ob1 = Obj(d, 1);
gl_FragColor = l;
} */
}
if (ground.distance > ob1.distance) return ob1;
return ground;
}
Obj castRay(vec3 ro, vec3 rd) {
float t = 0.0;
Obj res = Obj(-1., -1);
for(int i=0; i<MAX_STEPS; i++) {
vec3 p = ro + rd * t;
res = mapScene(p);
t += res.distance;
if (t > MAX_DIST || res.distance < abs(SURF_DIST*t) ) break;
}
if (t > MAX_DIST) t = -1.0;
res.distance = t;
return res;
}
float castShadow(vec3 ro, vec3 rd) {
float res = 1.0;
float t = 0.001;
for(int i = 0; i < MAX_STEPS; i++) {
vec3 pos = ro + t* rd;
float h = mapScene(pos).distance;
res = min(res, 10.0*h/t);
if (abs(h) < (0.001*t) ) break;
t += h;
if (t > 20.) break;
}
return clamp(res,0., 1.);
}
vec3 calcNormal(vec3 pos) {
vec2 e = vec2(.001, 0.);
vec3 n = vec3( mapScene(pos+e.xyy).distance - mapScene(pos-e.xyy).distance,
mapScene(pos+e.yxy).distance - mapScene(pos-e.yxy).distance,
mapScene(pos+e.yyx).distance - mapScene(pos-e.yyx).distance
);
return normalize(n);
}
vec3 fresnel( vec3 F0, vec3 h, vec3 l ) {
return F0 + ( 1.0 - F0 ) * pow( clamp( 1.0 - dot( h, l ), 0.0, 1.0 ), 5.0 );
}
vec3 shading(vec3 v, vec3 n, vec3 dir, int material) {
float shininess = 1.;
vec3 final = vec3( 0.0 );
vec3 ref = reflect( dir, n );
vec3 Ks = vec3( 0.5 );
vec3 Kd = vec3( 1.0 );
vec3 outMaterial = vec3(0.1255, 0.1255, 0.1255);
if (material == 0) {
outMaterial = vec3(0.1412, 0.1412, 0.1412);
shininess = 3.1;
} else if (material == 1) {
outMaterial = vec3(0.1765, 0.1961, 0.2275);
shininess = 21.;
}
// light 0
{
vec3 light_pos = vec3( -2.,.3, 10. );
vec3 light_color = vec3(0.71, 0.51, 0.72) * 5.;
vec3 vl = normalize( light_pos - v );
vec3 diffuse = Kd * vec3( max( 0.0, dot( vl, n ) ) );
vec3 specular = vec3( max( 0.0, dot( vl, ref ) ) );
vec3 F = fresnel( Ks, normalize( vl - dir ), vl );
specular = pow( specular, vec3( shininess ) );
final += outMaterial * specular * light_color * mix( diffuse, specular, F );
}
// light 1
{
vec3 light_pos = vec3( 5.0, 5.0, -20.0 );
vec3 light_color = vec3(0.14, 0.36, 0.83)* 7.;
vec3 vl = normalize( light_pos - v );
vec3 diffuse = Kd * vec3( max( 0.0, dot( vl, n ) ) );
vec3 specular = vec3( max( 0.0, dot( vl, ref ) ) );
vec3 F = fresnel( Ks, normalize( vl - dir ), vl );
specular = pow( specular, vec3( shininess ) );
final += outMaterial * specular * light_color * mix( diffuse, specular, F );
}
{
vec3 SUN_DIR = vec3(0. , .4, 1.);
float sun_dif = clamp(dot(n, SUN_DIR), 0., 1.);
float shadow = castShadow(v + n*0.02, SUN_DIR);
final += outMaterial * vec3(1.1,1.2, 1.5) * sun_dif * sun_dif * shadow;
}
{
vec3 SUN_DIR = vec3(0. , .6, -1.);
float sun_dif = clamp(dot(n, SUN_DIR), 0., 1.);
final += outMaterial * vec3(0.0353, 0.2667, 0.4784) * sun_dif;
}
// final += texture( iChannel0, ref ).rgb * fresnel( Ks, n, -dir );
// vec3 col = vec3(0.4)* ref.x;
//vec3 col = vec3(0.0588, 0.0588, 0.1216);// - vec3(0.149, 0.0863, 0.2314) * v.x;
//final += col * fresnel( vec3(.5), ref, -dir );
return final;
}
void main()
{
vec2 p = (2.0 * gl_FragCoord.xy - resolution.xy) / resolution.y;
float angle = time*0.4;
// angle = 2.0; // comment to rotate
// gl_FragColor = vec4(vec3(sdCog2d(p)), 1.);
// return;
// camera
vec3 ta = vec3(0.0, 0., 0.0);
vec3 ro = ta + vec3(4.*sin(angle), cos(angle), 4.*cos(angle)); // *cos(angle))
vec3 ww = normalize(ta-ro);
vec3 uu = normalize(cross(ww, vec3(0,1,0)));
vec3 vv = normalize(cross(uu,ww));
vec3 rd = normalize(p.x * uu + p.y*vv + 1.4*ww); // camera
// global light
vec3 col = vec3(0.1451, 0.1098, 0.1608) - vec3(0.9725, 0.5176, 0.0) *rd.y;
Obj t = castRay(ro, rd);
if (t.distance > 0.) {
vec3 pos = ro + rd * t.distance;
vec3 nor = calcNormal(pos);
col = shading(pos, nor, rd , t.material);
// apply fog
col = applyFog(col, t.distance);
}
gl_FragColor = vec4( pow( col, vec3(1.0/1.3) ), 1.0 );
}

146
shader2d.frag Normal file
View File

@ -0,0 +1,146 @@
#ifdef GL_ES
precision mediump float;
#endif
const float PI = 3.14159265;
uniform vec2 u_resolution;
uniform float u_time;
vec3 palette(float t) {
vec3 a = vec3(0.5, 0.5, 0.5);
vec3 b = vec3(1.0, 1.0, 1.0);
vec3 c = vec3(1.0, 1.0, 1.0);
vec3 d = vec3(0.0, 0.6666, 0.3333);
return a + b * cos(6.28318 * (c*t+d));
}
mat2 rotate(float angle){
return mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
}
float star(vec2 position, float radius, float sides){
float a = atan(position.x, position.y);
float slice = PI * 2. / sides;
return 1. - step(radius, cos(floor(-2.0 + a / slice) * slice - a));
}
float polygon(vec2 position, float radius, float sides){
float a = atan(position.x, position.y);
float slice = PI * 2.0 / sides;
return 1. - step(radius, cos(floor(0.5 + a / slice) * slice - a) * length(position));
}
float sdSphere(vec3 p, float s) {
return length(p) - s; // renders sphere
}
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.);
}
/** smooth minimum */
float smin( float a, float b, float k) {
float h = max(k-abs(a-b), 0.)/k;
return min(a,b) - h*h*h*k*(1./6.);
}
vec3 rot3d(vec3 p, vec3 axis, float angle) {
return mix(dot(axis,p)*axis, p, cos(angle)) + cross(axis, p ) * sin(angle);
}
mat2 rot2d(float angle) {
float s = sin(angle);
float c = cos(angle);
return mat2(c,-s,s,c);
}
// distance to scene
float getDist(vec3 p) {
// vec3 pos = vec3(sin(u_time)*1.2, 0., -.7);
// float sphere = sdSphere(p - pos, 1.);
// float scale = 10.;
// mod(p, 1.) == fract(p)... no gap
//p.z += u_time;
//p = fract(p) - 0.5;
//p.xy *= rot2d(u_time);
//p.yz *= rot2d(u_time);
float box = sdSphere(p-vec3(0.,0., -1.), .3);
float ground = p.y + 0.5;
return min(ground, box);
//return min(ground, min(sphere, box)); // normal union
/**
other functions are:
substract: return max(-d1, d2);
intersetion: return max(d1, d2);
*/
}
vec3 getNormal(vec3 p) {
float d = getDist(p);
vec2 e = vec2(.01, 0.);
vec3 n = d - vec3(
getDist(p-e.xyy),
getDist(p-e.yxy),
getDist(p-e.yyx)
);
return normalize(n);
}
float rayMarch(vec3 ro, vec3 rd) {
float t = 0.; // total distance travelled
// raymarching
for (int i = 0; i < 100; i++) {
vec3 p = ro + rd * t; // position at the ray
// p.xy *= rot2d(-u_time);
// p.xy *= rot2d(2. * sin(u_time + t *.2));
//p.y += sin(t)*0.6;
//p.x += cos(t)*0.6;
float d = getDist(p); // current distance to scene
t +=d; // "march" of the ray
if (t > 100. || d < 0.01 ) break; // stop if ray hits, or distance too long
}
return t;
}
float getLight(vec3 p, vec3 lightPos) {
vec3 l = normalize(lightPos - p);
vec3 n = getNormal(p);
float dif = clamp(dot(n,l), 0., 1.);
float d = rayMarch(p + n*0.02,l);
if (d<length(lightPos-p)) dif *= 0.3;
return dif;
}
void main() {
vec2 uv = (gl_FragCoord.xy * 2. - u_resolution.xy) / u_resolution.y;
vec3 ro = vec3(0., 0., -2.); // ray origin
float fov = .9;
vec3 rd = normalize(vec3(uv * fov, 1.));
vec3 col = vec3(0.); // final pixel color
float d = rayMarch(ro, rd);
vec3 p = ro + rd * d;
float dif = getLight(p, vec3(5.*sin(u_time), 7., 4.*cos(u_time)));
col = vec3(dif);
//col = vec3(d*0.1);
gl_FragColor = vec4(col, 1.);
}

View File

@ -1,112 +1,160 @@
// Generated with Shader Minifier 1.3.6 (https://github.com/laurentlb/Shader_Minifier/)
#ifndef SHADER_MINIFIED_H_
# define SHADER_MINIFIED_H_
# define VAR_resolution "v"
# define VAR_texts "s"
# define VAR_texture_sampler "m"
# define VAR_time "y"
# define VAR_resolution "m"
# define VAR_texts "d"
# define VAR_texture_sampler "e"
# define VAR_time "v"
const char *__temp_cleaned_shader_glsl =
"#version 120\n"
"uniform float y;"
"uniform vec2 v;"
"uniform sampler2D m,s;"
"float f=0.;"
"mat2 n(float y)"
"uniform float v;"
"uniform vec2 m;"
"uniform sampler2D e,d;\n"
"#define MAX_STEPS 100\n"
"#define MAX_DIST 20.\n"
"#define SURF_DIST.001\n"
"#define TAU 6.283185\n"
"#define PI 3.141592\n"
"#define FOG_DENSITY 0.01\nstruct Obj{float distance;int material;};"
"mat2 n(float v)"
"{"
"return mat2(cos(y),sin(y),-sin(y),cos(y));"
"float m=sin(v),d=cos(v);"
"return mat2(d,-m,m,d);"
"}"
"float x(vec3 y)"
"vec3 n(vec3 v,float m)"
"{"
"vec3 v=abs(y)-vec3(.4,.4,.1);"
"return length(max(v,0.))+min(max(v.x,max(v.y,v.z)),0.);"
"float d=1.-exp(-m*FOG_DENSITY);"
"return mix(v,vec3(.17,.16,.24),d);"
"}"
"float n(vec3 y,float v)"
"float s(vec3 v,float m)"
"{"
"y*=v;"
"float a=x(y)/1.5;"
"y.xy*=5.;"
"y.y-=3.5;"
"y.xy*=n(.75);"
"return-a;"
"vec2 d=vec2(m,abs(v.z)-.15);"
"return min(max(d.x,d.y),0.)+length(max(d,0.));"
"}"
"float x(vec3 v,float y)"
"float s(vec2 v)"
"{"
"vec3 a=v;"
"v=a;"
"v.y+=sin(f*.4)*2.5;"
"v.xy*=n(.8);"
"float m=n(v,2.-abs(sin(f*.4))*1.5);"
"v=a;"
"v.y-=sin(f*.4)*2.5;"
"v.xy*=n(.8);"
"float s=n(v,2.-abs(sin(f*.4))*1.5);"
"v=a;"
"v.x+=sin(f*.4)*2.5;"
"v.xy*=n(.8);"
"float g=n(v,2.-abs(sin(f*.4))*1.5);"
"v=a;"
"v.x-=sin(f*.4)*2.5;"
"v.xy*=n(.8);"
"float c=n(v,2.-abs(sin(f*.4))*1.5);"
"v=a;"
"v.xy*=n(.8);"
"float z=n(v,.5)*6.;"
"v=a;"
"float e=n(v,.5)*6.;"
"return max(max(max(max(max(m,s),g),c),z),e);"
"float d=1.-smoothstep(-.2,.8,sin(atan(v.y,v.x)*12.))*.14;"
"return smoothstep(d,d+2.,length(v)*2.);"
"}"
"vec4 c(vec2 m)"
"float x(float m,float v)"
"{"
"vec3 a=vec3(0,-.2,y*4.),s=normalize(vec3((m.xy*2.-v.xy)/min(v.x,v.y),1.5));"
"s.xy=s.xy*n(sin(y*.03)*5.);"
"s.yz=s.yz*n(sin(y*.05)*.2);"
"float r=.1;"
"vec3 c=vec3(0);"
"float g=0.;"
"for(int z=0;z<99;z++)"
"float d=max(.02-abs(-m-v),0.);"
"return max(-m,v)+d*d*.25/.02;"
"}"
"float x(vec3 v)"
"{"
"vec3 m=vec3(0),d=v-m,y=vec3(0,0,1)-m;"
"return length(d-y*clamp(dot(d,y)/dot(y,y),0.,1.))-.2;"
"}"
"float p(vec3 v,float m)"
"{"
"v.xy*=n(m);"
"float d=s(v,s(v.xy)),y=x(v-vec3(0,0,-.5));"
"return.8*x(y,d)-.001;"
"}"
"Obj p(vec3 m)"
"{"
"float d=1e10;"
"Obj e=Obj(m.y+1.5+sin(m.z*.6)*.2+sin(m.x*1.3)*.1,0);"
"{"
"float y=p(m+vec3(1,0,0),v);"
"d=min(d,y);"
"}"
"{"
"float y=p(m+vec3(.5,-.87,0),-v);"
"d=min(d,y);"
"}"
"{"
"float y=p(m+vec3(.5,.87,0),-v);"
"d=min(d,y);"
"}"
"Obj y=Obj(d,1);"
"return e.distance>y.distance?"
"y:"
"e;"
"}"
"Obj t(vec3 v,vec3 m)"
"{"
"float d=0.;"
"Obj r=Obj(-1.,-1);"
"for(int y=0;y<MAX_STEPS;y++)"
"{"
"vec3 e=a+s*r;"
"e=mod(e-2.,4.)-2.;"
"f=y-float(z)*.01;"
"float i=x(e,y);"
"i=max(abs(i),.01);"
"g+=exp(-i*23.);"
"r+=i*.55;"
"vec3 e=v+m*d;"
"r=p(e);"
"d+=r.distance;"
"if(d>MAX_DIST||r.distance<abs(SURF_DIST*d))"
"break;"
"}"
"c=vec3(g*.02);"
"c+=vec3(0,.2*abs(sin(y)),.5+sin(y)*.2);"
"return vec4(c,1.-r*(.02+.02*sin(y)));"
"if(d>MAX_DIST)"
"d=-1.;"
"r.distance=d;"
"return r;"
"}"
"vec3 c(vec2 v,float m,float a,float c,float f)"
"float f(vec3 v,vec3 m)"
"{"
"float s=(-v.y*6.-3.-sin(m+v.x*c+y)-a)*.055;"
"s*=1.+sin(m+v.x*c+y)+(v.y*6.-3.+a);"
"return clamp(s,0.,.9)*(vec3(.5)+vec3(1)*cos(6.28318*(vec3(1)*(f/360.)+vec3(0,.6666,.3333))));"
"float d=1.,y=.001;"
"for(int r=0;r<MAX_STEPS;r++)"
"{"
"vec3 e=v+y*m;"
"float c=p(e).distance;"
"d=min(d,10.*c/y);"
"if(abs(c)<.001*y)"
"break;"
"y+=c;"
"if(y>20.)"
"break;"
"}"
"return clamp(d,0.,1.);"
"}"
"float a=0.,g=-.1;"
"vec4 e(vec2 v)"
"vec3 f(vec3 v)"
"{"
"v.y=sin(v.x*16.+y)/32.+v.y-.03;"
"v.x-=(y-a)*.2;"
"vec4 m=texture2D(s,v);"
"if(m.y>0.&&g!=a)"
"a=y,g=a;"
"return vec4(m.xyz,1);"
"vec2 m=vec2(.001,0);"
"vec3 d=vec3(p(v+m.xyy).distance-p(v-m.xyy).distance,p(v+m.yxy).distance-p(v-m.yxy).distance,p(v+m.yyx).distance-p(v-m.yyx).distance);"
"return normalize(d);"
"}"
"void c(out vec4 f,vec2 m)"
"vec3 f(vec3 m,vec3 v,vec3 d)"
"{"
"vec2 s=(m.xy*2.-v.xy)/min(v.x,v.y);"
"vec3 a=vec3(0,.4,.6);"
"a+=c(s,0.,1.,1.,sin(y+.3)*90.);"
"a+=c(s,sin(y),0.,-1.,sin(y-1.2)*120.);"
"a+=c(s,-3.,0.,1.,sin(y+.5)*90.);"
"vec4 g=e(s*.1);"
"f=max(c(gl_FragCoord.xy)*.2,vec4(a*g.xyz,1));"
"return m+(1.-m)*pow(clamp(1.-dot(v,d),0.,1.),5.);"
"}"
"vec3 f(vec3 v,vec3 d,vec3 m,int y)"
"{"
"float e=1.;"
"vec3 r=vec3(0),c=reflect(m,d),a=vec3(.5),i=vec3(1),n=vec3(.1255);"
"if(y==0)"
"n=vec3(.1412),e=3.1;"
"else if(y==1)"
"n=vec3(.1765,.1961,.2275),e=21.;"
"{"
"vec3 x=normalize(vec3(-2,.3,10)-v),O=vec3(max(0.,dot(x,c))),l=f(a,normalize(x-m),x);"
"O=pow(O,vec3(e));"
"r+=n*O*(vec3(.71,.51,.72)*5.)*mix(i*vec3(max(0.,dot(x,d))),O,l);"
"}"
"{"
"vec3 x=normalize(vec3(5,5,-20)-v),O=vec3(max(0.,dot(x,c))),l=f(a,normalize(x-m),x);"
"O=pow(O,vec3(e));"
"r+=n*O*(vec3(.14,.36,.83)*7.)*mix(i*vec3(max(0.,dot(x,d))),O,l);"
"}"
"{"
"vec3 x=vec3(0,.4,1);"
"float O=clamp(dot(d,x),0.,1.),l=f(v+d*.02,x);"
"r+=n*vec3(1.1,1.2,1.5)*O*O*l;"
"}"
"r+=n*vec3(.0353,.2667,.4784)*clamp(dot(d,vec3(0,.6,-1)),0.,1.);"
"return r;"
"}"
"void main()"
"{"
"c(gl_FragColor,gl_FragCoord.xy);"
"vec2 d=(2.*gl_FragCoord.xy-m.xy)/m.y;"
"float y=v*.4;"
"vec3 e=vec3(0),x=e+vec3(4.*sin(y),cos(y),4.*cos(y)),O=normalize(e-x),c=normalize(cross(O,vec3(0,1,0))),l=normalize(d.x*c+d.y*normalize(cross(c,O))+1.4*O),r=vec3(.1451,.1098,.1608)-vec3(.9725,.5176,0)*l.y;"
"Obj i=t(x,l);"
"if(i.distance>0.)"
"{"
"vec3 a=x+l*i.distance,s=f(a);"
"r=f(a,s,l,i.material);"
"r=n(r,i.distance);"
"}"
"gl_FragColor=vec4(pow(r,vec3(1./1.3)),1);"
"}";
#endif // SHADER_MINIFIED_H_

175
shader_old.glsl Normal file
View File

@ -0,0 +1,175 @@
uniform float time;
uniform vec2 resolution;
uniform sampler2D texture_sampler;
uniform sampler2D texts;
float zoom = 1.;
float gTime = 0.;
float getBeat(void) {
return floor(abs(time*4.) / (60./145.) );
}
float getBar(void) {
return floor(abs(time) / (60./145.));
}
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));
}
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, .2)) / 1.5;
pos.xy *= 5.;
pos.y -= 3.5;
pos.xy *= rot(.55);
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) {
float box_set1 = box_set(pos, time);
return box_set1;
}
vec4 mainImage2(vec2 fragCoord) {
vec2 p = (fragCoord.xy * 2. - resolution.xy) / min(resolution.x, resolution.y);
vec3 ro = vec3( time * 4., -time , time * 8.);
vec3 ray = normalize(vec3(p, 0.55));
ray.xy = ray.xy * rot(sin(time * .1) * 6.);
ray.yz = ray.yz * rot(sin(time * .01) * .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.5, 4.) - 2.;
gTime = time - float(i) * 0.01;
float d = map(pos, time);
d = max(abs(d), 0.03);
ac += exp(-d * 26.);
t += d * 0.55;
}
col = vec3(ac * 0.025);
col += vec3(0.1 + sin(time) * 0.2, 0.5, 0.);
return vec4(col, 1.0 - t * (0.02 + 0.02 * sin(time)));
}
vec3 palette(float t) {
vec3 a = vec3(0.5, 0.5, 0.5);
vec3 b = vec3(1.0, 1.0, 1.0);
vec3 c = vec3(1.0, 1.0, 1.0);
vec3 d = vec3(0.0, 0.6666, 0.3333);
return a + b * cos(6.28318 * (c*t+d));
}
float rand(vec2 co) {
float a = 12.9898;
float b = 78.233;
float c = 43758.5453;
float dt= dot(co.xy ,vec2(a,b));
float sn= mod(dt,3.14);
return fract(sin(sn) * c);
}
vec3 noise(vec2 uv) {
float rng = rand(vec2(uv.x+time, uv.y));
vec3 col = vec3(0.0+rng*0.1, 0.2+rng*0.1, 0.4+rng*0.1);
col.x += sin(uv.x+time*0.2)*0.1;
col.y += sin(uv.y+time*0.2)*0.1;
col.z += sin(uv.y+time*0.2)*0.1;
return col;
}
vec3 wave(vec2 uv, float phase, float _offset, float height, float waveLenght, float color) {
float val = -(sin(phase+uv.x*waveLenght+time) + (uv.y*6.+height)+_offset)*0.055;
val *= 1. + sin(phase + uv.x*waveLenght+time) + (uv.y*6.-height+_offset);
//return smoothstep(0.0, 1.0, val) * palette(color/360.);
return clamp(val, 0., .9) * palette(color/360.);
}
float gStartTime = 0.;
float gPrevTime = -0.1;
vec4 waveTexture(vec2 uv) {
uv.y = sin(uv.x*16. + time)/32. + uv.y-0.03;
uv.x -= (time-gStartTime)*0.2;
vec4 tex = texture2D(texts, uv);
if (tex.y > 0. && (gPrevTime != gStartTime)) {
gStartTime = time;
gPrevTime = gStartTime;
}
return vec4(tex.rgb, 1.0);
}
void TextScroller(out vec4 fragColor, in vec2 fragCoord)
{
// Normalized pixel coordinates (from -1 to 1, origo at 0,0)
vec2 uv = (fragCoord.xy * 2. - resolution.xy) / min(resolution.x, resolution.y);
vec3 col = vec3(0., 0.4, 0.6);
col += wave(uv, 0., 1., 3., 1., sin(time+0.3)*90.);
col += wave(uv, sin(time), 0., 3., -1., sin(time-1.2)*120.);
col += wave(uv, -3., 0., 3., 1., sin(time+0.5)*90.);
vec4 outBuf = waveTexture(uv * 0.1);
fragColor = max(mainImage2(gl_FragCoord.xy)*0.2, vec4(col*outBuf.xyz, 1.0)); // + vec4(random(uv*2.), 1.0);
}
void main(void) {
TextScroller(gl_FragColor, gl_FragCoord.xy);
/*else
{
mainImage2(gl_FragColor, gl_FragCoord.xy);
vec4 l;
vec2 texttop = vec2(0., -.35), pt = (gl_FragCoord.xy / resolution) - texttop;
if(pt.y > 0.) {
l = gl_FragColor + texture2D(texts, pt);
}
gl_FragColor = l;
} */
}

129
template.frag Normal file
View File

@ -0,0 +1,129 @@
#ifdef GL_ES
precision mediump float;
#endif
#define MAX_STEPS 50
#define MAX_DIST 50.
#define SURF_DIST .001
#define TAU 6.283185
#define PI 3.141592
#define S smoothstep
#define T u_time
uniform vec2 u_resolution;
uniform float u_time;
mat2 Rot(float a) {
float s=sin(a), c=cos(a);
return mat2(c, -s, s, c);
}
float sdBox(vec3 p, vec3 s) {
p = abs(p)-s;
return length(max(p, 0.))+min(max(p.x, max(p.y, p.z)), 0.);
}
vec3 translate(vec3 p) {
p.xy *= Rot(u_time*0.4);
p.yz *= Rot(u_time*0.4);
return p;
}
float GetDist(vec3 p) {
float d = sdBox(p, vec3(1));
/*
d += sin(p.x*5.+u_time)*0.5;
d += sin(p.y*2.+u_time)*0.5;
d += sin(p.z*5.+u_time)*0.5; */
return d;
}
float RayMarch(vec3 ro, vec3 rd) {
float dO=0.;
for(int i=0; i<MAX_STEPS; i++) {
vec3 p = ro + rd*dO;
float dS = GetDist(p);
dO += dS;
if(dO>MAX_DIST || abs(dS)<SURF_DIST) break;
}
return dO;
}
vec3 GetNormal(vec3 p) {
vec2 e = vec2(.001, 0);
vec3 n = GetDist(p) - vec3(GetDist(p-e.xyy), GetDist(p-e.yxy),GetDist(p-e.yyx));
return normalize(n);
}
vec3 GetRayDir(vec2 uv, vec3 p, vec3 l, float z) {
vec3
f = normalize(l-p),
r = normalize(cross(vec3(0,1,0), f)),
u = cross(f,r),
c = f*z,
i = c + uv.x*r + uv.y*u;
return normalize(i);
}
float star(vec2 position, float radius, float sides){
float a = atan(position.x, position.y);
float slice = PI * 2. / sides;
return 1. - step(radius, cos(floor(-2.0 + a / slice) * slice - a));
}
vec3 textu(vec2 uv) {
vec3 color = vec3(0.08, 0.22, 0.39);
vec3 mixer = vec3(0.);
for(float i = 1.; i < 3.; i++){
vec2 translate = uv;
// translate *= Rot(i*1.4/5. + u_time);
float sides = 11.;
mixer += vec3(star(translate, 0.06, sides))*vec3(0.5725, 0.8275, 0.9451)*(i*0.7)*0.2;
}
return mix( color, mixer, 0.5);
}
void main()
{
vec2 uv = (gl_FragCoord.xy -.5 * u_resolution.xy) / u_resolution.y;
vec3 ro = vec3(0., 3., -3.);
vec3 rd = GetRayDir(uv, ro, vec3(0.,0., 0.), 1.);
vec3 col = vec3(0.);
float d = RayMarch(ro, rd);
if (d < MAX_DIST) {
vec3 p = ro + rd * d;
vec3 n = GetNormal(p);
vec3 r = reflect(rd, n);
float dif = dot(n, normalize(vec3(1,2,3)))*.5+.5;
// col = vec3(dif);
vec3 colXZ = textu(p.xz).rgb;
vec3 colYZ = textu(p.yz).rgb;
vec3 colXY = textu(p.xy).rgb;
n = abs(n);
n *= pow(n, vec3(10));
n /= n.x + n.y + n.z;
col = (colXZ*n.y + colXY*n.z + colYZ * n.x)*dif;
}
col = pow(col, vec3(.4545)); // gamma correction
gl_FragColor = vec4(col,1.0);
}