'convert' shaders to ts
This commit is contained in:
parent
553cecbcc7
commit
ad6484ef03
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable */
|
||||
export default `#define MAX_STEPS 1000
|
||||
#define MAX_DIST 500.
|
||||
#define E 0.000001
|
||||
|
@ -104,3 +105,4 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
|||
//col = myvec;
|
||||
fragColor = vec4(col,1.0);
|
||||
}`;
|
||||
/* eslint-enable */
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable */
|
||||
export default `#define MAX_STEPS 1280
|
||||
#define MAX_DIST 1280.
|
||||
#define E 0.00001
|
||||
|
@ -75,3 +76,4 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
|
|||
col += vec3(dif);
|
||||
fragColor = vec4(col, 1.0);
|
||||
}`;
|
||||
/* eslint-enable */
|
|
@ -1,204 +1,205 @@
|
|||
export default `
|
||||
#define MAX_STEPS 1280
|
||||
#define MAX_DIST 1280.
|
||||
#define E 0.01
|
||||
#define PI 3.141592
|
||||
#define MYTIME iTime * 1.
|
||||
|
||||
// Turn to 1 to activate displacement mapping
|
||||
#define DISPLACEMENT_MAPPING 1
|
||||
|
||||
vec3 rotX(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x, v.y * cos(a) - v.z * sin(a), v.y * sin(a) + v.z * cos(a));
|
||||
}
|
||||
|
||||
vec3 rotY(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x * cos(a) + v.z * sin(a), v.y, v.z * cos(a) - v.x * sin(a));
|
||||
}
|
||||
|
||||
vec3 rotZ(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x * cos(a) - v.y * sin(a), v.x * sin(a) + v.y * cos(a), v.z);
|
||||
}
|
||||
|
||||
vec3 modSDF(vec3 p, vec3 c)
|
||||
{
|
||||
return mod(p + 0.5 * c, c) - 0.5 * c;
|
||||
}
|
||||
|
||||
vec3 modSDFlim( in vec3 p, in float c, in vec3 l)
|
||||
{
|
||||
return p-c*vec3(clamp(floor(p.x/c + 0.5),-l.x,l.x), clamp(floor(p.y/c + 0.5),-l.y,l.y), clamp(floor(p.z/c + 0.5),-l.z,l.z));
|
||||
}
|
||||
|
||||
vec3 twistSDF(in vec3 p, float k )
|
||||
{
|
||||
float c = cos(k*p.y);
|
||||
float s = sin(k*p.y);
|
||||
mat2 m = mat2(c,-s,s,c);
|
||||
vec3 q = vec3(m*p.xz,p.y);
|
||||
return q;
|
||||
}
|
||||
|
||||
float sdfBox( 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);
|
||||
}
|
||||
|
||||
// blackbody by aiekick : https://www.shadertoy.com/view/lttXDn
|
||||
|
||||
// -------------blackbody----------------- //
|
||||
|
||||
// return color from temperature
|
||||
//http://www.physics.sfasu.edu/astro/color/blackbody.html
|
||||
//http://www.vendian.org/mncharity/dir3/blackbody/
|
||||
//http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html
|
||||
|
||||
vec3 blackbody(float Temp)
|
||||
{
|
||||
vec3 col = vec3(255.);
|
||||
col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.;
|
||||
col.y = 100.04 * log(Temp) - 623.6;
|
||||
if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.;
|
||||
col.z = 194.18 * log(Temp) - 1448.6;
|
||||
col = clamp(col, 0., 255.)/255.;
|
||||
if (Temp < 1000.) col *= Temp/1000.;
|
||||
return col;
|
||||
}
|
||||
|
||||
// -------------blackbody----------------- //
|
||||
|
||||
|
||||
float scene(vec3 p)
|
||||
{
|
||||
float d = 10000.;
|
||||
float bd1 = sdfBox(
|
||||
twistSDF(
|
||||
modSDFlim(
|
||||
twistSDF(p - vec3(0., 12., 0.), smoothstep(0.30, 0.20, abs(sin(MYTIME))) * 0.02),
|
||||
12., vec3(1. + smoothstep(0.45, 0.55, abs(sin(MYTIME))) * floor(abs(mod(MYTIME / (PI), 16.) - 8.)), 1. + smoothstep(0.45, 0.55, abs(sin(MYTIME))) * floor(abs(mod(MYTIME / (PI), 16.) - 8.)), 1. + smoothstep(0.45, 0.55, abs(sin(MYTIME))))), smoothstep(0.70, 0.80, abs(sin(MYTIME))) * -0.1),
|
||||
vec3(4. + smoothstep(0.25, 0.75, abs(sin(MYTIME * 2.))),4. + smoothstep(0.25, 0.75, abs(sin(MYTIME * 2.))),4. + smoothstep(0.25, 0.75, abs(sin(MYTIME * 2.)))));
|
||||
if (DISPLACEMENT_MAPPING == 1)
|
||||
bd1 += sin(p.x / 2. * abs(mod(iTime, 6.) - 3.)) * 1. * sin(p.y / 2. * abs(mod(iTime, 6.) - 3.)) * 1. * sin(p.z / 2. * abs(mod(iTime, 6.) - 3.)) * 1.;
|
||||
float bd2 = sdfBox(modSDF(p - vec3(0., -24., 0.), vec3(10., 0., 10.)), vec3(4.5,4.5,4.5)) * 1.;
|
||||
d = min(bd1, d);
|
||||
d = min(bd2, d);
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
vec2 march(vec3 ro, vec3 rd)
|
||||
{
|
||||
float dO = 0.;
|
||||
float mind = 10000.;
|
||||
for (int steps = 0; steps < MAX_STEPS; steps++)
|
||||
{
|
||||
vec3 p = ro + rd * dO;
|
||||
float dS = scene(p);
|
||||
if (steps == 3)
|
||||
mind = dS;
|
||||
dO += dS;
|
||||
if (dS < E || dO > MAX_DIST)
|
||||
break;
|
||||
}
|
||||
return vec2(dO, mind);
|
||||
}
|
||||
|
||||
vec3 normal(vec3 p)
|
||||
{
|
||||
float d = scene(p);
|
||||
vec2 e = vec2(0.001, 0);
|
||||
|
||||
vec3 n = d - vec3(
|
||||
scene(p - e.xyy),
|
||||
scene(p - e.yxy),
|
||||
scene(p - e.yyx));
|
||||
return (normalize(n));
|
||||
}
|
||||
|
||||
float light(vec3 p, vec3 n)
|
||||
{
|
||||
vec3 lightPos = vec3(-250. * sin(MYTIME), 75., -250. * cos(MYTIME));
|
||||
vec3 l = normalize(lightPos - p);
|
||||
|
||||
float dif = clamp(dot(l, n), 0., 1.);
|
||||
//vec2 d = march(p+n*E * 30., l);
|
||||
//if (d.x < length(lightPos - p))
|
||||
// dif *= 0.1;
|
||||
|
||||
return (dif*0.3);
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 uv = ((fragCoord - .5 * iResolution.xy) / iResolution.y);
|
||||
|
||||
vec3 ro = vec3(-235. * sin(iTime / 2.), 75. + sin(iTime / 2.) * 15., -235. * cos(iTime / 2.));
|
||||
vec3 rd = normalize(vec3(uv.x, uv.y, 1.));
|
||||
rd = rotX(rd, PI /8.);
|
||||
rd = rotY(rd, iTime / 2.);
|
||||
|
||||
vec2 d = march(ro, rd);
|
||||
|
||||
vec3 p = ro + rd * d.x;
|
||||
vec3 n = normal(p);
|
||||
p += n * E * 10.;
|
||||
float dif = light(p, n);
|
||||
vec3 col = vec3(0);
|
||||
if (d.x < MAX_DIST * 0.9)
|
||||
{
|
||||
col = blackbody(d.y* (p.y + 19.2) * 2. * (50. - abs(mod(p.x * p.z / 30. + 25. + MYTIME * 50., 100.) - 50.)));
|
||||
col.xyz = col.zyx;
|
||||
col.xy *= 0.5;
|
||||
col.x *= uv.x;
|
||||
col.y *= uv.y;
|
||||
if (col.z > 0.001)
|
||||
{
|
||||
col = 0.5 * (1. - col);
|
||||
col = vec3(col.z, col.z, (col.x + col.y) / 2.);
|
||||
col.x = col.x / 2. + col.z * uv.x;
|
||||
col.y = col.y / 2. + col.z * uv.y;
|
||||
}
|
||||
col /= 2.;
|
||||
}
|
||||
col += vec3(dif / 2.,dif / 2., dif / 2.);
|
||||
vec3 rr = rd - (2. * n * (dot(rd, n)));
|
||||
vec2 d2 = march(p, rr);
|
||||
vec3 p2 = p + rr * d2.x;
|
||||
vec3 n2 = normal(p2);
|
||||
dif = light(p2, n2);
|
||||
if (d2.x < MAX_DIST * 0.9)
|
||||
{
|
||||
vec3 col2 = blackbody(d2.y* (p2.y + 19.2) * 2. * (50. - abs(mod(p2.x * p2.z / 30. + 25. + MYTIME * 50., 100.) - 50.)));
|
||||
col2.xyz = col2.zyx;
|
||||
col2.xy *= 0.5;
|
||||
col2.x *= uv.x;
|
||||
col2.y *= uv.y;
|
||||
if (col2.z > 0.001)
|
||||
{
|
||||
col2 = 0.5 * (1. - col2);
|
||||
col2 = vec3(col.z, col2.z, (col2.x + col2.y) / 2.);
|
||||
col2.x = col2.x / 2. + col2.z * uv.x;
|
||||
col2.y = col2.y / 2. + col2.z * uv.y;
|
||||
}
|
||||
col2 /= 2.;
|
||||
col += col2;
|
||||
}
|
||||
if (d.x < MAX_DIST * 0.9)
|
||||
{
|
||||
vec3 col2 = blackbody(d2.y* (p.y + 19.2) * 2. * (50. - abs(mod(p.x * p.z / 30. + 25. + MYTIME * 50., 100.) - 50.)));
|
||||
col += col2.yxz;
|
||||
}
|
||||
if (d2.x < MAX_DIST * 0.9)
|
||||
{
|
||||
vec3 col2 = blackbody(d2.y* (p2.y + 19.2) * 2. * (50. - abs(mod(p2.x * p2.z / 30. + 25. + MYTIME * 50., 100.) - 50.)));
|
||||
col += col2.yxz;
|
||||
}
|
||||
col += vec3(dif / 2., dif / 2., dif / 2.);
|
||||
//col = pow(col, vec3(0.454545));
|
||||
fragColor = vec4(col, 1.0);
|
||||
}
|
||||
`
|
||||
/* eslint-disable */
|
||||
export default `
|
||||
#define MAX_STEPS 1280
|
||||
#define MAX_DIST 1280.
|
||||
#define E 0.01
|
||||
#define PI 3.141592
|
||||
#define MYTIME iTime * 1.
|
||||
|
||||
// Turn to 1 to activate displacement mapping
|
||||
#define DISPLACEMENT_MAPPING 1
|
||||
|
||||
vec3 rotX(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x, v.y * cos(a) - v.z * sin(a), v.y * sin(a) + v.z * cos(a));
|
||||
}
|
||||
|
||||
vec3 rotY(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x * cos(a) + v.z * sin(a), v.y, v.z * cos(a) - v.x * sin(a));
|
||||
}
|
||||
|
||||
vec3 rotZ(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x * cos(a) - v.y * sin(a), v.x * sin(a) + v.y * cos(a), v.z);
|
||||
}
|
||||
|
||||
vec3 modSDF(vec3 p, vec3 c)
|
||||
{
|
||||
return mod(p + 0.5 * c, c) - 0.5 * c;
|
||||
}
|
||||
|
||||
vec3 modSDFlim( in vec3 p, in float c, in vec3 l)
|
||||
{
|
||||
return p-c*vec3(clamp(floor(p.x/c + 0.5),-l.x,l.x), clamp(floor(p.y/c + 0.5),-l.y,l.y), clamp(floor(p.z/c + 0.5),-l.z,l.z));
|
||||
}
|
||||
|
||||
vec3 twistSDF(in vec3 p, float k )
|
||||
{
|
||||
float c = cos(k*p.y);
|
||||
float s = sin(k*p.y);
|
||||
mat2 m = mat2(c,-s,s,c);
|
||||
vec3 q = vec3(m*p.xz,p.y);
|
||||
return q;
|
||||
}
|
||||
|
||||
float sdfBox( 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);
|
||||
}
|
||||
|
||||
// blackbody by aiekick : https://www.shadertoy.com/view/lttXDn
|
||||
|
||||
// -------------blackbody----------------- //
|
||||
|
||||
// return color from temperature
|
||||
//http://www.physics.sfasu.edu/astro/color/blackbody.html
|
||||
//http://www.vendian.org/mncharity/dir3/blackbody/
|
||||
//http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html
|
||||
|
||||
vec3 blackbody(float Temp)
|
||||
{
|
||||
vec3 col = vec3(255.);
|
||||
col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.;
|
||||
col.y = 100.04 * log(Temp) - 623.6;
|
||||
if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.;
|
||||
col.z = 194.18 * log(Temp) - 1448.6;
|
||||
col = clamp(col, 0., 255.)/255.;
|
||||
if (Temp < 1000.) col *= Temp/1000.;
|
||||
return col;
|
||||
}
|
||||
|
||||
// -------------blackbody----------------- //
|
||||
|
||||
|
||||
float scene(vec3 p)
|
||||
{
|
||||
float d = 10000.;
|
||||
float bd1 = sdfBox(
|
||||
twistSDF(
|
||||
modSDFlim(
|
||||
twistSDF(p - vec3(0., 12., 0.), smoothstep(0.30, 0.20, abs(sin(MYTIME))) * 0.02),
|
||||
12., vec3(1. + smoothstep(0.45, 0.55, abs(sin(MYTIME))) * floor(abs(mod(MYTIME / (PI), 16.) - 8.)), 1. + smoothstep(0.45, 0.55, abs(sin(MYTIME))) * floor(abs(mod(MYTIME / (PI), 16.) - 8.)), 1. + smoothstep(0.45, 0.55, abs(sin(MYTIME))))), smoothstep(0.70, 0.80, abs(sin(MYTIME))) * -0.1),
|
||||
vec3(4. + smoothstep(0.25, 0.75, abs(sin(MYTIME * 2.))),4. + smoothstep(0.25, 0.75, abs(sin(MYTIME * 2.))),4. + smoothstep(0.25, 0.75, abs(sin(MYTIME * 2.)))));
|
||||
if (DISPLACEMENT_MAPPING == 1)
|
||||
bd1 += sin(p.x / 2. * abs(mod(iTime, 6.) - 3.)) * 1. * sin(p.y / 2. * abs(mod(iTime, 6.) - 3.)) * 1. * sin(p.z / 2. * abs(mod(iTime, 6.) - 3.)) * 1.;
|
||||
float bd2 = sdfBox(modSDF(p - vec3(0., -24., 0.), vec3(10., 0., 10.)), vec3(4.5,4.5,4.5)) * 1.;
|
||||
d = min(bd1, d);
|
||||
d = min(bd2, d);
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
vec2 march(vec3 ro, vec3 rd)
|
||||
{
|
||||
float dO = 0.;
|
||||
float mind = 10000.;
|
||||
for (int steps = 0; steps < MAX_STEPS; steps++)
|
||||
{
|
||||
vec3 p = ro + rd * dO;
|
||||
float dS = scene(p);
|
||||
if (steps == 3)
|
||||
mind = dS;
|
||||
dO += dS;
|
||||
if (dS < E || dO > MAX_DIST)
|
||||
break;
|
||||
}
|
||||
return vec2(dO, mind);
|
||||
}
|
||||
|
||||
vec3 normal(vec3 p)
|
||||
{
|
||||
float d = scene(p);
|
||||
vec2 e = vec2(0.001, 0);
|
||||
|
||||
vec3 n = d - vec3(
|
||||
scene(p - e.xyy),
|
||||
scene(p - e.yxy),
|
||||
scene(p - e.yyx));
|
||||
return (normalize(n));
|
||||
}
|
||||
|
||||
float light(vec3 p, vec3 n)
|
||||
{
|
||||
vec3 lightPos = vec3(-250. * sin(MYTIME), 75., -250. * cos(MYTIME));
|
||||
vec3 l = normalize(lightPos - p);
|
||||
|
||||
float dif = clamp(dot(l, n), 0., 1.);
|
||||
//vec2 d = march(p+n*E * 30., l);
|
||||
//if (d.x < length(lightPos - p))
|
||||
// dif *= 0.1;
|
||||
|
||||
return (dif*0.3);
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 uv = ((fragCoord - .5 * iResolution.xy) / iResolution.y);
|
||||
|
||||
vec3 ro = vec3(-235. * sin(iTime / 2.), 75. + sin(iTime / 2.) * 15., -235. * cos(iTime / 2.));
|
||||
vec3 rd = normalize(vec3(uv.x, uv.y, 1.));
|
||||
rd = rotX(rd, PI /8.);
|
||||
rd = rotY(rd, iTime / 2.);
|
||||
|
||||
vec2 d = march(ro, rd);
|
||||
|
||||
vec3 p = ro + rd * d.x;
|
||||
vec3 n = normal(p);
|
||||
p += n * E * 10.;
|
||||
float dif = light(p, n);
|
||||
vec3 col = vec3(0);
|
||||
if (d.x < MAX_DIST * 0.9)
|
||||
{
|
||||
col = blackbody(d.y* (p.y + 19.2) * 2. * (50. - abs(mod(p.x * p.z / 30. + 25. + MYTIME * 50., 100.) - 50.)));
|
||||
col.xyz = col.zyx;
|
||||
col.xy *= 0.5;
|
||||
col.x *= uv.x;
|
||||
col.y *= uv.y;
|
||||
if (col.z > 0.001)
|
||||
{
|
||||
col = 0.5 * (1. - col);
|
||||
col = vec3(col.z, col.z, (col.x + col.y) / 2.);
|
||||
col.x = col.x / 2. + col.z * uv.x;
|
||||
col.y = col.y / 2. + col.z * uv.y;
|
||||
}
|
||||
col /= 2.;
|
||||
}
|
||||
col += vec3(dif / 2.,dif / 2., dif / 2.);
|
||||
vec3 rr = rd - (2. * n * (dot(rd, n)));
|
||||
vec2 d2 = march(p, rr);
|
||||
vec3 p2 = p + rr * d2.x;
|
||||
vec3 n2 = normal(p2);
|
||||
dif = light(p2, n2);
|
||||
if (d2.x < MAX_DIST * 0.9)
|
||||
{
|
||||
vec3 col2 = blackbody(d2.y* (p2.y + 19.2) * 2. * (50. - abs(mod(p2.x * p2.z / 30. + 25. + MYTIME * 50., 100.) - 50.)));
|
||||
col2.xyz = col2.zyx;
|
||||
col2.xy *= 0.5;
|
||||
col2.x *= uv.x;
|
||||
col2.y *= uv.y;
|
||||
if (col2.z > 0.001)
|
||||
{
|
||||
col2 = 0.5 * (1. - col2);
|
||||
col2 = vec3(col.z, col2.z, (col2.x + col2.y) / 2.);
|
||||
col2.x = col2.x / 2. + col2.z * uv.x;
|
||||
col2.y = col2.y / 2. + col2.z * uv.y;
|
||||
}
|
||||
col2 /= 2.;
|
||||
col += col2;
|
||||
}
|
||||
if (d.x < MAX_DIST * 0.9)
|
||||
{
|
||||
vec3 col2 = blackbody(d2.y* (p.y + 19.2) * 2. * (50. - abs(mod(p.x * p.z / 30. + 25. + MYTIME * 50., 100.) - 50.)));
|
||||
col += col2.yxz;
|
||||
}
|
||||
if (d2.x < MAX_DIST * 0.9)
|
||||
{
|
||||
vec3 col2 = blackbody(d2.y* (p2.y + 19.2) * 2. * (50. - abs(mod(p2.x * p2.z / 30. + 25. + MYTIME * 50., 100.) - 50.)));
|
||||
col += col2.yxz;
|
||||
}
|
||||
col += vec3(dif / 2., dif / 2., dif / 2.);
|
||||
//col = pow(col, vec3(0.454545));
|
||||
fragColor = vec4(col, 1.0);
|
||||
}`;
|
||||
/* eslint-enable */
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable */
|
||||
export default `#define MAX_STEPS 1280
|
||||
#define MAX_DIST 1024.
|
||||
#define E 0.0001
|
||||
|
@ -221,3 +222,4 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
|||
}
|
||||
fragColor = vec4(col, 1.0);
|
||||
}`;
|
||||
/* eslint-enable */
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable */
|
||||
export default `
|
||||
#define MAX_STEPS 1280
|
||||
#define MAX_DIST 128.
|
||||
|
@ -141,4 +142,5 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
|||
// Output to screen
|
||||
col = pow(col, vec3(0.454545));
|
||||
fragColor = vec4(col, 1.0);
|
||||
}`
|
||||
}`;
|
||||
/* eslint-enable */
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable */
|
||||
export default `#define MAX_STEPS 1280
|
||||
#define MAX_DIST 1280.
|
||||
#define E 0.00001
|
||||
|
@ -228,3 +229,4 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
|||
col += dif;
|
||||
fragColor = vec4(col, 1.0);
|
||||
}`;
|
||||
/* eslint-enable */
|
|
@ -1,206 +1,207 @@
|
|||
export default `
|
||||
#define MAX_STEPS 12800
|
||||
#define MAX_DIST 128.
|
||||
#define E 0.001
|
||||
#define PI 3.141592
|
||||
|
||||
vec3 rotX(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x, v.y * cos(a) - v.z * sin(a), v.y * sin(a) + v.z * cos(a));
|
||||
}
|
||||
|
||||
vec3 rotY(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x * cos(a) + v.z * sin(a), v.y, v.z * cos(a) - v.x * sin(a));
|
||||
}
|
||||
|
||||
vec3 rotZ(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x * cos(a) - v.y * sin(a), v.x * sin(a) + v.y * cos(a), v.z);
|
||||
}
|
||||
|
||||
vec3 modSDF(vec3 p, vec3 c)
|
||||
{
|
||||
return mod(p + 0.5 * c, c) - 0.5 * c;
|
||||
}
|
||||
|
||||
vec3 modSDFlim( in vec3 p, in float c, in vec3 l)
|
||||
{
|
||||
return p-c*vec3(clamp(floor(p.x/c + 0.5),-l.x,l.x), clamp(floor(p.y/c + 0.5),-l.y,l.y), clamp(floor(p.z/c + 0.5),-l.z,l.z));
|
||||
}
|
||||
|
||||
vec3 elongateSDF(in vec3 p, in vec3 h )
|
||||
{
|
||||
vec3 q = abs(p)-h;
|
||||
return max(q,0.0) + min(max(q.x,max(q.y,q.z)), 0.0);
|
||||
}
|
||||
|
||||
vec3 twistSDF(in vec3 p, float k )
|
||||
{
|
||||
float c = cos(k*p.y);
|
||||
float s = sin(k*p.y);
|
||||
mat2 m = mat2(c,-s,s,c);
|
||||
vec3 q = vec3(m*p.xz,p.y);
|
||||
return q;
|
||||
}
|
||||
|
||||
float sdfBox( 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 sdfTorus(vec3 p, vec2 r)
|
||||
{
|
||||
float x = length(p.xz) - r.x;
|
||||
return length(vec2(x, p.y)) - r.y;
|
||||
}
|
||||
|
||||
float sdfSphere(vec3 p, float r)
|
||||
{
|
||||
return length(p) - r;
|
||||
}
|
||||
|
||||
// blackbody by aiekick : https://www.shadertoy.com/view/lttXDn
|
||||
|
||||
// -------------blackbody----------------- //
|
||||
|
||||
// return color from temperature
|
||||
//http://www.physics.sfasu.edu/astro/color/blackbody.html
|
||||
//http://www.vendian.org/mncharity/dir3/blackbody/
|
||||
//http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html
|
||||
|
||||
vec3 blackbody(float Temp)
|
||||
{
|
||||
vec3 col = vec3(255.);
|
||||
col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.;
|
||||
col.y = 100.04 * log(Temp) - 623.6;
|
||||
if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.;
|
||||
col.z = 194.18 * log(Temp) - 1448.6;
|
||||
col = clamp(col, 0., 255.)/255.;
|
||||
if (Temp < 1000.) col *= Temp/1000.;
|
||||
return col;
|
||||
}
|
||||
|
||||
// -------------blackbody----------------- //
|
||||
|
||||
|
||||
vec2 scene(vec3 p)
|
||||
{
|
||||
float d = 10000.;
|
||||
float sd1 = 10000.;
|
||||
//float td1 = sdfTorus(elongateSDF(
|
||||
// twistSDF(
|
||||
// rotX(p, PI / 2.), sin(iTime) * 1.5), vec3(1., 1.,sin(iTime) * 2. + 1.))
|
||||
// , vec2(abs(sin(iTime * 0.3723)) * 2. + 1.2, 0.2))
|
||||
// + 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
|
||||
float td1 = sdfTorus(
|
||||
twistSDF(
|
||||
rotX(p, PI / 2.), sin(iTime) * 1.5)
|
||||
, vec2(abs(sin(iTime * 0.3723)) * 2. + 1.2, 0.2))
|
||||
+ 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
|
||||
//float td1 = 10000.;
|
||||
//float td2 = sdfTorus(twistSDF(rotX(p, PI / 2.), cos(iTime) * 3.), vec2(abs(sin(iTime * 0.3723)) * 1. + 0.2, 0.1))
|
||||
// + 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
|
||||
float td2 = 10000.;
|
||||
td2 = sdfTorus(
|
||||
twistSDF(
|
||||
rotX(p, PI / 2.), cos(iTime) * 1.5)
|
||||
, vec2(abs(sin(iTime * 0.3723)) * 2. + 2.2, 0.2))
|
||||
+ 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
|
||||
//float td1 = 10000.;
|
||||
sd1 = sdfSphere(p - vec3(0.,0.,0.),abs(sin(iTime * 0.3723)) * 2. + 0.4) * 0.19;
|
||||
|
||||
|
||||
td1 *= 0.2;
|
||||
td2 *= 0.2;
|
||||
d = min(td1, d);
|
||||
d = min(td2, d);
|
||||
d = min(sd1, d);
|
||||
if (sd1 > d - E && sd1 < d + E)
|
||||
return vec2(d, 1.);
|
||||
if ((td1 > d - E && td1 < d + E) || (td2 > d - E && td2 < d + E))
|
||||
return vec2(d, 2.);
|
||||
return vec2(d, -1.);
|
||||
}
|
||||
|
||||
|
||||
vec3 march(vec3 ro, vec3 rd)
|
||||
{
|
||||
float dO = 0.;
|
||||
float mind = 10000.;
|
||||
float object = -1.;
|
||||
for (int steps = 0; steps < MAX_STEPS; steps++)
|
||||
{
|
||||
vec3 p = ro + rd * dO;
|
||||
vec2 dS = scene(p);
|
||||
object = dS.y;
|
||||
if (dS.x < mind)
|
||||
mind = dS.x;
|
||||
dO += dS.x;
|
||||
if (dS.x < E || dO > MAX_DIST)
|
||||
break;
|
||||
}
|
||||
return vec3(dO, mind, object);
|
||||
}
|
||||
|
||||
vec3 normal(vec3 p)
|
||||
{
|
||||
vec2 d = scene(p);
|
||||
vec2 e = vec2(0.0001, 0);
|
||||
|
||||
vec3 n = d.x - vec3(
|
||||
scene(p - e.xyy).x,
|
||||
scene(p - e.yxy).x,
|
||||
scene(p - e.yyx).x);
|
||||
return (normalize(n));
|
||||
}
|
||||
|
||||
float light(vec3 p, vec3 n)
|
||||
{
|
||||
vec3 lightPos = vec3(-12. * sin(iTime), 0., -12. * cos(iTime));
|
||||
vec3 l = normalize(lightPos - p);
|
||||
|
||||
float dif = clamp(dot(l, n), 0., 1.);
|
||||
vec3 d = march(p+n, l);
|
||||
if (d.x < length(lightPos - p))
|
||||
dif *= 0.1;
|
||||
|
||||
return (dif);
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec3 col = vec3(0);
|
||||
vec2 uv = ((fragCoord - .5 * iResolution.xy) / iResolution.y);
|
||||
vec3 ro = vec3(-12. * sin(iTime), 0., -12. * cos(iTime));
|
||||
vec3 rd = normalize(vec3(uv.x, uv.y, 1.));
|
||||
rd = rotY(rd, iTime);
|
||||
|
||||
vec3 d = march(ro, rd);
|
||||
|
||||
vec3 p = ro + rd * d.x;
|
||||
vec3 n = normal(p);
|
||||
p += n * E * 10.;
|
||||
float dif = light(p, n);
|
||||
if (d.z > 1. + E || d.z < 1. - E)
|
||||
col = blackbody(d.y * 10000.);
|
||||
if (d.x < MAX_DIST * 0.9)
|
||||
{
|
||||
if (d.z > 2. - E && d.z < 2. +E)
|
||||
col += vec3(dif * abs(p.x - 0.5), dif * abs(p.y - 0.5), dif * abs(p.z - 0.5));
|
||||
|
||||
vec3 rr = rd - (2. * n * (dot(rd, n)));
|
||||
vec3 d2 = march(p, rr);
|
||||
vec3 p2 = p + rr * d2.x;
|
||||
vec3 n2 = normal(p2);
|
||||
dif = light(p2, n2);
|
||||
if (d.z > 1. - E && d.z < 1. + E)
|
||||
{
|
||||
col += vec3(dif * abs(p2.x - 0.5), dif * abs(p2.y - 0.5), dif * abs(p2.z - 0.5));
|
||||
}
|
||||
}
|
||||
col = pow(col, vec3(0.454545));
|
||||
fragColor = vec4(col, 1.);
|
||||
}
|
||||
`
|
||||
/* eslint-disable */
|
||||
export default `
|
||||
#define MAX_STEPS 12800
|
||||
#define MAX_DIST 128.
|
||||
#define E 0.001
|
||||
#define PI 3.141592
|
||||
|
||||
vec3 rotX(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x, v.y * cos(a) - v.z * sin(a), v.y * sin(a) + v.z * cos(a));
|
||||
}
|
||||
|
||||
vec3 rotY(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x * cos(a) + v.z * sin(a), v.y, v.z * cos(a) - v.x * sin(a));
|
||||
}
|
||||
|
||||
vec3 rotZ(vec3 v, float a)
|
||||
{
|
||||
return vec3(v.x * cos(a) - v.y * sin(a), v.x * sin(a) + v.y * cos(a), v.z);
|
||||
}
|
||||
|
||||
vec3 modSDF(vec3 p, vec3 c)
|
||||
{
|
||||
return mod(p + 0.5 * c, c) - 0.5 * c;
|
||||
}
|
||||
|
||||
vec3 modSDFlim( in vec3 p, in float c, in vec3 l)
|
||||
{
|
||||
return p-c*vec3(clamp(floor(p.x/c + 0.5),-l.x,l.x), clamp(floor(p.y/c + 0.5),-l.y,l.y), clamp(floor(p.z/c + 0.5),-l.z,l.z));
|
||||
}
|
||||
|
||||
vec3 elongateSDF(in vec3 p, in vec3 h )
|
||||
{
|
||||
vec3 q = abs(p)-h;
|
||||
return max(q,0.0) + min(max(q.x,max(q.y,q.z)), 0.0);
|
||||
}
|
||||
|
||||
vec3 twistSDF(in vec3 p, float k )
|
||||
{
|
||||
float c = cos(k*p.y);
|
||||
float s = sin(k*p.y);
|
||||
mat2 m = mat2(c,-s,s,c);
|
||||
vec3 q = vec3(m*p.xz,p.y);
|
||||
return q;
|
||||
}
|
||||
|
||||
float sdfBox( 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 sdfTorus(vec3 p, vec2 r)
|
||||
{
|
||||
float x = length(p.xz) - r.x;
|
||||
return length(vec2(x, p.y)) - r.y;
|
||||
}
|
||||
|
||||
float sdfSphere(vec3 p, float r)
|
||||
{
|
||||
return length(p) - r;
|
||||
}
|
||||
|
||||
// blackbody by aiekick : https://www.shadertoy.com/view/lttXDn
|
||||
|
||||
// -------------blackbody----------------- //
|
||||
|
||||
// return color from temperature
|
||||
//http://www.physics.sfasu.edu/astro/color/blackbody.html
|
||||
//http://www.vendian.org/mncharity/dir3/blackbody/
|
||||
//http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html
|
||||
|
||||
vec3 blackbody(float Temp)
|
||||
{
|
||||
vec3 col = vec3(255.);
|
||||
col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.;
|
||||
col.y = 100.04 * log(Temp) - 623.6;
|
||||
if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.;
|
||||
col.z = 194.18 * log(Temp) - 1448.6;
|
||||
col = clamp(col, 0., 255.)/255.;
|
||||
if (Temp < 1000.) col *= Temp/1000.;
|
||||
return col;
|
||||
}
|
||||
|
||||
// -------------blackbody----------------- //
|
||||
|
||||
|
||||
vec2 scene(vec3 p)
|
||||
{
|
||||
float d = 10000.;
|
||||
float sd1 = 10000.;
|
||||
//float td1 = sdfTorus(elongateSDF(
|
||||
// twistSDF(
|
||||
// rotX(p, PI / 2.), sin(iTime) * 1.5), vec3(1., 1.,sin(iTime) * 2. + 1.))
|
||||
// , vec2(abs(sin(iTime * 0.3723)) * 2. + 1.2, 0.2))
|
||||
// + 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
|
||||
float td1 = sdfTorus(
|
||||
twistSDF(
|
||||
rotX(p, PI / 2.), sin(iTime) * 1.5)
|
||||
, vec2(abs(sin(iTime * 0.3723)) * 2. + 1.2, 0.2))
|
||||
+ 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
|
||||
//float td1 = 10000.;
|
||||
//float td2 = sdfTorus(twistSDF(rotX(p, PI / 2.), cos(iTime) * 3.), vec2(abs(sin(iTime * 0.3723)) * 1. + 0.2, 0.1))
|
||||
// + 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
|
||||
float td2 = 10000.;
|
||||
td2 = sdfTorus(
|
||||
twistSDF(
|
||||
rotX(p, PI / 2.), cos(iTime) * 1.5)
|
||||
, vec2(abs(sin(iTime * 0.3723)) * 2. + 2.2, 0.2))
|
||||
+ 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
|
||||
//float td1 = 10000.;
|
||||
sd1 = sdfSphere(p - vec3(0.,0.,0.),abs(sin(iTime * 0.3723)) * 2. + 0.4) * 0.19;
|
||||
|
||||
|
||||
td1 *= 0.2;
|
||||
td2 *= 0.2;
|
||||
d = min(td1, d);
|
||||
d = min(td2, d);
|
||||
d = min(sd1, d);
|
||||
if (sd1 > d - E && sd1 < d + E)
|
||||
return vec2(d, 1.);
|
||||
if ((td1 > d - E && td1 < d + E) || (td2 > d - E && td2 < d + E))
|
||||
return vec2(d, 2.);
|
||||
return vec2(d, -1.);
|
||||
}
|
||||
|
||||
|
||||
vec3 march(vec3 ro, vec3 rd)
|
||||
{
|
||||
float dO = 0.;
|
||||
float mind = 10000.;
|
||||
float object = -1.;
|
||||
for (int steps = 0; steps < MAX_STEPS; steps++)
|
||||
{
|
||||
vec3 p = ro + rd * dO;
|
||||
vec2 dS = scene(p);
|
||||
object = dS.y;
|
||||
if (dS.x < mind)
|
||||
mind = dS.x;
|
||||
dO += dS.x;
|
||||
if (dS.x < E || dO > MAX_DIST)
|
||||
break;
|
||||
}
|
||||
return vec3(dO, mind, object);
|
||||
}
|
||||
|
||||
vec3 normal(vec3 p)
|
||||
{
|
||||
vec2 d = scene(p);
|
||||
vec2 e = vec2(0.0001, 0);
|
||||
|
||||
vec3 n = d.x - vec3(
|
||||
scene(p - e.xyy).x,
|
||||
scene(p - e.yxy).x,
|
||||
scene(p - e.yyx).x);
|
||||
return (normalize(n));
|
||||
}
|
||||
|
||||
float light(vec3 p, vec3 n)
|
||||
{
|
||||
vec3 lightPos = vec3(-12. * sin(iTime), 0., -12. * cos(iTime));
|
||||
vec3 l = normalize(lightPos - p);
|
||||
|
||||
float dif = clamp(dot(l, n), 0., 1.);
|
||||
vec3 d = march(p+n, l);
|
||||
if (d.x < length(lightPos - p))
|
||||
dif *= 0.1;
|
||||
|
||||
return (dif);
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec3 col = vec3(0);
|
||||
vec2 uv = ((fragCoord - .5 * iResolution.xy) / iResolution.y);
|
||||
vec3 ro = vec3(-12. * sin(iTime), 0., -12. * cos(iTime));
|
||||
vec3 rd = normalize(vec3(uv.x, uv.y, 1.));
|
||||
rd = rotY(rd, iTime);
|
||||
|
||||
vec3 d = march(ro, rd);
|
||||
|
||||
vec3 p = ro + rd * d.x;
|
||||
vec3 n = normal(p);
|
||||
p += n * E * 10.;
|
||||
float dif = light(p, n);
|
||||
if (d.z > 1. + E || d.z < 1. - E)
|
||||
col = blackbody(d.y * 10000.);
|
||||
if (d.x < MAX_DIST * 0.9)
|
||||
{
|
||||
if (d.z > 2. - E && d.z < 2. +E)
|
||||
col += vec3(dif * abs(p.x - 0.5), dif * abs(p.y - 0.5), dif * abs(p.z - 0.5));
|
||||
|
||||
vec3 rr = rd - (2. * n * (dot(rd, n)));
|
||||
vec3 d2 = march(p, rr);
|
||||
vec3 p2 = p + rr * d2.x;
|
||||
vec3 n2 = normal(p2);
|
||||
dif = light(p2, n2);
|
||||
if (d.z > 1. - E && d.z < 1. + E)
|
||||
{
|
||||
col += vec3(dif * abs(p2.x - 0.5), dif * abs(p2.y - 0.5), dif * abs(p2.z - 0.5));
|
||||
}
|
||||
}
|
||||
col = pow(col, vec3(0.454545));
|
||||
fragColor = vec4(col, 1.);
|
||||
}`;
|
||||
/* eslint-enable */
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable */
|
||||
export default `#define MAX_STEPS 1280
|
||||
#define MAX_DIST 128.
|
||||
#define E 0.0001
|
||||
|
@ -151,3 +152,4 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
|||
col = pow(col, vec3(0.454545));
|
||||
fragColor = vec4(col, 1.0);
|
||||
}`;
|
||||
/* eslint-enable */
|
Loading…
Reference in New Issue