id stringlengths 6 6 | author stringclasses 55
values | date timestamp[ns] | image_code stringlengths 746 52.3k | license stringclasses 7
values | func_bytes listlengths 5 5 | functions listlengths 1 32 | comment stringlengths 7 1.29k | header stringlengths 18 169 | body stringlengths 18 2.14k | model_inp stringlengths 30 1.35k | function_frequency int64 1 176 | header_frequency int64 1 16.3k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
lsfXWH | iq | 2014-05-15T00:14:43 | // The MIT License
// Copyright © 2014 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
3256,
3289,
3316,
3316,
3347
] | [
[
1978,
2039,
2083,
2083,
3254
],
[
3256,
3289,
3316,
3316,
3347
],
[
3348,
3348,
3375,
3375,
3410
],
[
3411,
3411,
3438,
3438,
3473
],
[
3474,
3474,
3501,
3501,
3536
],
[
3537,
3537,
... | // unrolled version of the above
| float SH_0_0( in vec3 s ) { | vec3 n = s.zxy; return k01; } | // unrolled version of the above
float SH_0_0( in vec3 s ) { | 3 | 3 |
4ssSRl | iq | 2014-07-18T08:21:44 | // The MIT License
// Copyright © 2014 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
0,
1196,
1243,
1243,
1363
] | [
[
0,
1196,
1243,
1243,
1363
],
[
1365,
1365,
1422,
1422,
3103
]
] | // The MIT License
// Copyright © 2014 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | float line( in vec2 a, in vec2 b, in vec2 p )
{ |
vec2 pa = p - a;
vec2 ba = b - a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
return length( pa - ba*h );
} | // The MIT License
// Copyright © 2014 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | 3 | 5 |
4djXzz | otaviogood | 2014-08-21T06:53:07 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
562,
589,
612,
612,
689
] | [
[
562,
589,
612,
612,
689
],
[
690,
690,
713,
713,
805
],
[
806,
806,
847,
847,
890
],
[
928,
928,
952,
952,
1225
],
[
1226,
1226,
1251,
1251,
1473
],
[
1474,
1474,
1496,
1496,
... | // various noise functions
| float Hash2d(vec2 uv)
{ |
float f = uv.x + uv.y * 47.0;
return fract(cos(f*3.333)*100003.9);
} | // various noise functions
float Hash2d(vec2 uv)
{ | 4 | 17 |
4dBXz3 | iq | 2014-10-24T08:55:07 | // The MIT License
// Copyright © 2014 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
1272,
1348,
1388,
1388,
1443
] | [
[
1272,
1348,
1388,
1388,
1443
],
[
1445,
1524,
1564,
1564,
1626
],
[
1628,
1704,
1744,
1744,
1834
],
[
1903,
1903,
1952,
1952,
2072
],
[
2074,
2115,
2179,
2179,
2977
],
[
3046,
3046,
... | // Flip v if in the negative half plane defined by r (this works in 3D too)
| vec2 flipIfNeg( in vec2 v, in vec2 r )
{ |
float k = dot(v,r);
return (k>0.0) ? v : -v;
} | // Flip v if in the negative half plane defined by r (this works in 3D too)
vec2 flipIfNeg( in vec2 v, in vec2 r )
{ | 1 | 1 |
4dBXz3 | iq | 2014-10-24T08:55:07 | // The MIT License
// Copyright © 2014 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
1445,
1524,
1564,
1564,
1626
] | [
[
1272,
1348,
1388,
1388,
1443
],
[
1445,
1524,
1564,
1564,
1626
],
[
1628,
1704,
1744,
1744,
1834
],
[
1903,
1903,
1952,
1952,
2072
],
[
2074,
2115,
2179,
2179,
2977
],
[
3046,
3046,
... | // Reflect v if in the negative half plane defined by r (this works in 3D too)
| vec2 reflIfNeg( in vec2 v, in vec2 r )
{ |
float k = dot(v,r);
return (k>0.0) ? v : v-2.0*r*k;
} | // Reflect v if in the negative half plane defined by r (this works in 3D too)
vec2 reflIfNeg( in vec2 v, in vec2 r )
{ | 1 | 1 |
4dBXz3 | iq | 2014-10-24T08:55:07 | // The MIT License
// Copyright © 2014 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
1628,
1704,
1744,
1744,
1834
] | [
[
1272,
1348,
1388,
1388,
1443
],
[
1445,
1524,
1564,
1564,
1626
],
[
1628,
1704,
1744,
1744,
1834
],
[
1903,
1903,
1952,
1952,
2072
],
[
2074,
2115,
2179,
2179,
2977
],
[
3046,
3046,
... | // Clip v if in the negative half plane defined by r (this works in 3D too)
| vec2 clipIfNeg( in vec2 v, in vec2 r )
{ |
float k = dot(v,r);
return (k>0.0) ? v : (v-r*k)*inversesqrt(1.0-k*k/dot(v,v));
} | // Clip v if in the negative half plane defined by r (this works in 3D too)
vec2 clipIfNeg( in vec2 v, in vec2 r )
{ | 1 | 1 |
4dBXz3 | iq | 2014-10-24T08:55:07 | // The MIT License
// Copyright © 2014 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
2074,
2115,
2179,
2179,
2977
] | [
[
1272,
1348,
1388,
1388,
1443
],
[
1445,
1524,
1564,
1564,
1626
],
[
1628,
1704,
1744,
1744,
1834
],
[
1903,
1903,
1952,
1952,
2072
],
[
2074,
2115,
2179,
2179,
2977
],
[
3046,
3046,
... | // https://www.shadertoy.com/view/slj3Dd
| float sdArrow( in vec2 p, vec2 a, vec2 b, float w1, float w2 )
{ |
const float k = 3.0;
vec2 ba = b - a;
float l2 = dot(ba,ba);
float l = sqrt(l2);
p = p-a;
p = mat2(ba.x,-ba.y,ba.y,ba.x)*p/l;
p.y = abs(p.y);
vec2 pz = p-vec2(l-w2*k,w2);
vec2 q = p;
q.x -= clamp( q.x, 0.0, l-w2*k );
q.y -= w1;
float di = dot(q,q);
q = pz;
q.y -... | // https://www.shadertoy.com/view/slj3Dd
float sdArrow( in vec2 p, vec2 a, vec2 b, float w1, float w2 )
{ | 1 | 2 |
ld2SzK | otaviogood | 2014-10-27T05:24:30 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
2076,
2262,
2316,
2316,
2619
] | [
[
997,
997,
1020,
1020,
1097
],
[
1098,
1098,
1121,
1121,
1213
],
[
1237,
1237,
1260,
1260,
1289
],
[
1290,
1290,
1313,
1313,
1342
],
[
1343,
1343,
1368,
1368,
1397
],
[
1399,
1399,
14... | // This function basically is a procedural environment map that makes the sun
vec3 sunCol = vec3(258.0, 208.0, 100.0) / 4255.0;//unfortunately, i seem to have 2 different sun colors. :(
| vec3 GetSunColorReflection(vec3 rayDir, vec3 sunDir)
{ |
vec3 localRay = normalize(rayDir);
float dist = 1.0 - (dot(localRay, sunDir) * 0.5 + 0.5);
float sunIntensity = 0.015 / dist;
sunIntensity = pow(sunIntensity, 0.3)*100.0;
sunIntensity += exp(-dist*12.0)*300.0;
sunIntensity = min(sunIntensity, 40000.0);
return sunCol * sunIntensity*0.0425;
} | // This function basically is a procedural environment map that makes the sun
vec3 sunCol = vec3(258.0, 208.0, 100.0) / 4255.0;//unfortunately, i seem to have 2 different sun colors. :(
vec3 GetSunColorReflection(vec3 rayDir, vec3 sunDir)
{ | 2 | 8 |
ld2SzK | otaviogood | 2014-10-27T05:24:30 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
2925,
2970,
3032,
3032,
3240
] | [
[
997,
997,
1020,
1020,
1097
],
[
1098,
1098,
1121,
1121,
1213
],
[
1237,
1237,
1260,
1260,
1289
],
[
1290,
1290,
1313,
1313,
1342
],
[
1343,
1343,
1368,
1368,
1397
],
[
1399,
1399,
14... | // This is a spline used for the camera path
| vec4 CatmullRom(vec4 p0, vec4 p1, vec4 p2, vec4 p3, float t)
{ |
float t2 = t*t;
float t3 = t*t*t;
return 0.5 *((2.0 * p1) +
(-p0 + p2) * t +
(2.0 * p0 - 5.0 * p1 + 4.0 * p2 - p3) * t2 +
(-p0 + 3.0 * p1- 3.0 * p2 + p3) * t3);
} | // This is a spline used for the camera path
vec4 CatmullRom(vec4 p0, vec4 p1, vec4 p2, vec4 p3, float t)
{ | 1 | 1 |
ld2SzK | otaviogood | 2014-10-27T05:24:30 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
3242,
3713,
3741,
3741,
4290
] | [
[
997,
997,
1020,
1020,
1097
],
[
1098,
1098,
1121,
1121,
1213
],
[
1237,
1237,
1260,
1260,
1289
],
[
1290,
1290,
1313,
1313,
1342
],
[
1343,
1343,
1368,
1368,
1397
],
[
1399,
1399,
14... | // This spiral noise works by successively adding and rotating sin waves while increasing frequency.
// It should work the same on all computers since it's not based on a hash function like some other noises.
// It can be much faster than other noise functions if you're ok with some repetition.
const float nudge = 0.73... | float SpiralNoiseC(vec3 p)
{ |
float n = 0.0; // noise amount
float iter = 1.0;
for (int i = 0; i < 8; i++)
{
// add sin and cos scaled inverse with the frequency
n += -abs(sin(p.y*iter) + cos(p.x*iter)) / iter; // abs for a ridged look
// rotate by adding perpendicular and scaling down
p.xy += vec2(p... | // This spiral noise works by successively adding and rotating sin waves while increasing frequency.
// It should work the same on all computers since it's not based on a hash function like some other noises.
// It can be much faster than other noise functions if you're ok with some repetition.
const float nudge = 0.73... | 7 | 17 |
ld2SzK | otaviogood | 2014-10-27T05:24:30 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
6229,
6323,
6345,
6345,
7577
] | [
[
997,
997,
1020,
1020,
1097
],
[
1098,
1098,
1121,
1121,
1213
],
[
1237,
1237,
1260,
1260,
1289
],
[
1290,
1290,
1313,
1313,
1342
],
[
1343,
1343,
1368,
1368,
1397
],
[
1399,
1399,
14... | // from a time t, this finds where in the camera path you are.
// It uses Catmull-Rom splines
| vec4 CamPos(float t)
{ |
t = mod(t, 14.0); // repeat after 14 time units
float bigTime = floor(t);
float smallTime = fract(t);
// Can't do arrays right, so write this all out.
if (bigTime == 0.0) return CatmullRom(c00, c01, c02, c03, smallTime);
if (bigTime == 1.0) return CatmullRom(c01, c02, c03, c04, smallTime);
... | // from a time t, this finds where in the camera path you are.
// It uses Catmull-Rom splines
vec4 CamPos(float t)
{ | 1 | 1 |
4dSXDd | otaviogood | 2014-11-27T22:26:38 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
695,
714,
737,
737,
810
] | [
[
695,
714,
737,
737,
810
],
[
811,
811,
834,
834,
905
],
[
906,
906,
929,
929,
1015
],
[
1016,
1016,
1057,
1057,
1100
],
[
1138,
1138,
1162,
1162,
1435
],
[
1436,
1436,
1458,
1458... | // noise functions
| float Hash1d(float u)
{ |
return fract(sin(u)*143.9); // scale this down to kill the jitters
} | // noise functions
float Hash1d(float u)
{ | 6 | 6 |
4dSXDd | otaviogood | 2014-11-27T22:26:38 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
3152,
3681,
3708,
3708,
4272
] | [
[
695,
714,
737,
737,
810
],
[
811,
811,
834,
834,
905
],
[
906,
906,
929,
929,
1015
],
[
1016,
1016,
1057,
1057,
1100
],
[
1138,
1138,
1162,
1162,
1435
],
[
1436,
1436,
1458,
1458... | // This spiral noise works by successively adding and rotating sin waves while increasing frequency.
// It should work the same on all computers since it's not based on a hash function like some other noises.
// It can be much faster than other noise functions if you're ok with some repetition.
const float nudge = 0.71... | float RustNoise3D(vec3 p)
{ |
float n = 0.0;
float iter = 1.0;
float pn = noise(p*0.125);
pn += noise(p*0.25)*0.5;
pn += noise(p*0.5)*0.25;
pn += noise(p*1.0)*0.125;
for (int i = 0; i < 7; i++)
{
//n += (sin(p.y*iter) + cos(p.x*iter)) / iter;
float wave = saturate(cos(p.y*0.25 + pn) - 0.998);
... | // This spiral noise works by successively adding and rotating sin waves while increasing frequency.
// It should work the same on all computers since it's not based on a hash function like some other noises.
// It can be much faster than other noise functions if you're ok with some repetition.
const float nudge = 0.71... | 1 | 2 |
4dSXDd | otaviogood | 2014-11-27T22:26:38 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
4341,
4412,
4444,
4534,
6672
] | [
[
695,
714,
737,
737,
810
],
[
811,
811,
834,
834,
905
],
[
906,
906,
929,
929,
1015
],
[
1016,
1016,
1057,
1057,
1100
],
[
1138,
1138,
1162,
1162,
1435
],
[
1436,
1436,
1458,
1458... | // This is the big money function that makes the crazy fractally shape
| float DistanceToObject(vec3 p)
{ |
if (dot(p, rotDir) > 1.0) p *= rotMat;
// Repeat our position so we can carve out many cylindrical-like things from our solid
vec3 rep = fract(p)-0.5;
//final = max(final, -(length(rep.xz*rep.xz)*1.0 - 0.0326));
float final = -(length(rep.xy*rep.xz) - 0.109);
final = max(final, -(length(rep.zy... | // This is the big money function that makes the crazy fractally shape
float DistanceToObject(vec3 p)
{ | 1 | 6 |
Mlf3R4 | otaviogood | 2014-12-20T22:43:30 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
3698,
3884,
3938,
3938,
4360
] | [
[
753,
777,
798,
798,
833
],
[
834,
834,
857,
857,
980
],
[
981,
981,
1001,
1001,
1059
],
[
1060,
1060,
1083,
1083,
1169
],
[
1171,
1171,
1212,
1212,
1257
],
[
1259,
1259,
1300,
13... | // This function basically is a procedural environment map that makes the sun
vec3 sunCol = vec3(258.0, 228.0, 170.0) / 3555.0;//unfortunately, i seem to have 2 different sun colors. :(
| vec3 GetSunColorReflection(vec3 rayDir, vec3 sunDir)
{ |
vec3 localRay = normalize(rayDir);
float dist = 1.0 - (dot(localRay, sunDir) * 0.5 + 0.5);
float sunIntensity = 0.015 / dist;
sunIntensity = pow(sunIntensity, 0.3)*100.0;
sunIntensity += exp(-dist*12.0)*300.0;
sunIntensity = min(sunIntensity, 40000.0);
//vec3 skyColor = mix(vec3(1.0, 0.95, 0.85), vec3(0.... | // This function basically is a procedural environment map that makes the sun
vec3 sunCol = vec3(258.0, 228.0, 170.0) / 3555.0;//unfortunately, i seem to have 2 different sun colors. :(
vec3 GetSunColorReflection(vec3 rayDir, vec3 sunDir)
{ | 2 | 8 |
XljGDz | otaviogood | 2015-04-07T03:58:40 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
1619,
1752,
1797,
1910,
2596
] | [
[
856,
856,
879,
879,
908
],
[
909,
909,
932,
932,
961
],
[
962,
962,
987,
987,
1016
],
[
1018,
1018,
1051,
1051,
1168
],
[
1169,
1169,
1202,
1202,
1318
],
[
1319,
1319,
1352,
1352... | // This is a procedural environment map with a giant overhead softbox,
// 4 lights in a horizontal circle, and a bottom-to-top fade.
| vec3 GetEnvColor2(vec3 rayDir, vec3 sunDir)
{ |
vec3 final = vec3(1.0) * dot(-rayDir, sunDir) * 0.5 + 0.5;
final *= 0.125;
// overhead softbox, stretched to a rectangle
if ((rayDir.y > abs(rayDir.x)*1.0) && (rayDir.y > abs(rayDir.z*0.25))) final = vec3(2.0)*rayDir.y;
// fade the softbox at the edges with a rounded rectangle.
float roundBox =... | // This is a procedural environment map with a giant overhead softbox,
// 4 lights in a horizontal circle, and a bottom-to-top fade.
vec3 GetEnvColor2(vec3 rayDir, vec3 sunDir)
{ | 2 | 2 |
XljGDz | otaviogood | 2015-04-07T03:58:40 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
2998,
3034,
3075,
3075,
3168
] | [
[
856,
856,
879,
879,
908
],
[
909,
909,
932,
932,
961
],
[
962,
962,
987,
987,
1016
],
[
1018,
1018,
1051,
1051,
1168
],
[
1169,
1169,
1202,
1202,
1318
],
[
1319,
1319,
1352,
1352... | // polynomial smooth min (k = 0.1);
| float smin( float a, float b, float k )
{ |
float h = clamp( 0.5+0.5*(b-a)/k, 0.0, 1.0 );
return mix( b, a, h ) - k*h*(1.0-h);
} | // polynomial smooth min (k = 0.1);
float smin( float a, float b, float k )
{ | 176 | 382 |
XljGDz | otaviogood | 2015-04-07T03:58:40 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
5821,
5860,
5952,
5952,
6182
] | [
[
856,
856,
879,
879,
908
],
[
909,
909,
932,
932,
961
],
[
962,
962,
987,
987,
1016
],
[
1018,
1018,
1051,
1051,
1168
],
[
1169,
1169,
1202,
1202,
1318
],
[
1319,
1319,
1352,
1352... | // dirVec MUST BE NORMALIZED FIRST!!!!
| float SphereIntersect(vec3 pos, vec3 dirVecPLZNormalizeMeFirst, vec3 spherePos, float rad)
{ |
vec3 radialVec = pos - spherePos;
float b = dot(radialVec, dirVecPLZNormalizeMeFirst);
float c = dot(radialVec, radialVec) - rad * rad;
float h = b * b - c;
if (h < 0.0) return -1.0;
return -b - sqrt(h);
} | // dirVec MUST BE NORMALIZED FIRST!!!!
float SphereIntersect(vec3 pos, vec3 dirVecPLZNormalizeMeFirst, vec3 spherePos, float rad)
{ | 3 | 3 |
llS3zd | otaviogood | 2015-05-13T04:11:09 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
3691,
3748,
3779,
3779,
4305
] | [
[
626,
626,
649,
649,
678
],
[
679,
679,
702,
702,
731
],
[
732,
732,
757,
757,
786
],
[
788,
788,
821,
821,
938
],
[
939,
939,
972,
972,
1088
],
[
1089,
1089,
1122,
1122,
1239... | // Calculate the distance field that defines the object.
| vec2 DistanceToObject(vec3 p)
{ |
float dist = 1000000.0;
float currentThick = 8.0;
float harmonicTime = spinTime*0.125*3.14159*4.0;
// make 15 discs inside each other
for (int i = 0; i < 15; i++)
{
dist = min(dist, Disc(p, currentThick));
p = RotateX(p, harmonicTime);
p = RotateZ(p, harmonicTime);
... | // Calculate the distance field that defines the object.
vec2 DistanceToObject(vec3 p)
{ | 1 | 8 |
XlfXR4 | iq | 2015-06-18T20:06:02 | // The MIT License
// Copyright © 2015 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
1373,
1382,
1403,
1403,
1454
] | [
[
1373,
1382,
1403,
1403,
1454
],
[
1455,
1486,
1507,
1507,
1584
],
[
1585,
1627,
1648,
1648,
1758
],
[
1804,
1804,
1832,
1832,
1978
],
[
2025,
2080,
2138,
2138,
2282
],
[
2285,
2338,
... | // curve
| vec3 mapD0(float t)
{ |
return 0.25 + a*cos(t+m)*(b+c*cos(t*7.0+n));
} | // curve
vec3 mapD0(float t)
{ | 1 | 1 |
XlfXR4 | iq | 2015-06-18T20:06:02 | // The MIT License
// Copyright © 2015 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
1455,
1486,
1507,
1507,
1584
] | [
[
1373,
1382,
1403,
1403,
1454
],
[
1455,
1486,
1507,
1507,
1584
],
[
1585,
1627,
1648,
1648,
1758
],
[
1804,
1804,
1832,
1832,
1978
],
[
2025,
2080,
2138,
2138,
2282
],
[
2285,
2338,
... | // curve derivative (velocity)
| vec3 mapD1(float t)
{ |
return -7.0*a*c*cos(t+m)*sin(7.0*t+n) - a*sin(t+m)*(b+c*cos(7.0*t+n));
} | // curve derivative (velocity)
vec3 mapD1(float t)
{ | 1 | 1 |
XlfXR4 | iq | 2015-06-18T20:06:02 | // The MIT License
// Copyright © 2015 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
1585,
1627,
1648,
1648,
1758
] | [
[
1373,
1382,
1403,
1403,
1454
],
[
1455,
1486,
1507,
1507,
1584
],
[
1585,
1627,
1648,
1648,
1758
],
[
1804,
1804,
1832,
1832,
1978
],
[
2025,
2080,
2138,
2138,
2282
],
[
2285,
2338,
... | // curve second derivative (acceleration)
| vec3 mapD2(float t)
{ |
return 14.0*a*c*sin(t+m)*sin(7.0*t+n) - a*cos(t+m)*(b+c*cos(7.0*t+n)) - 49.0*a*c*cos(t+m)*cos(7.0*t+n);
} | // curve second derivative (acceleration)
vec3 mapD2(float t)
{ | 1 | 1 |
XlfXR4 | iq | 2015-06-18T20:06:02 | // The MIT License
// Copyright © 2015 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
2025,
2080,
2138,
2138,
2282
] | [
[
1373,
1382,
1403,
1403,
1454
],
[
1455,
1486,
1507,
1507,
1584
],
[
1585,
1627,
1648,
1648,
1758
],
[
1804,
1804,
1832,
1832,
1978
],
[
2025,
2080,
2138,
2138,
2282
],
[
2285,
2338,
... | // unsigned squared distance between point and segment
| vec2 usqdPointSegment( in vec3 p, in vec3 a, in vec3 b )
{ |
vec3 pa = p - a;
vec3 ba = b - a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
vec3 q = pa - ba*h;
return vec2( dot(q,q), h );
} | // unsigned squared distance between point and segment
vec2 usqdPointSegment( in vec3 p, in vec3 a, in vec3 b )
{ | 1 | 1 |
XlfXR4 | iq | 2015-06-18T20:06:02 | // The MIT License
// Copyright © 2015 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
2285,
2338,
2394,
2394,
2724
] | [
[
1373,
1382,
1403,
1403,
1454
],
[
1455,
1486,
1507,
1507,
1584
],
[
1585,
1627,
1648,
1648,
1758
],
[
1804,
1804,
1832,
1832,
1978
],
[
2025,
2080,
2138,
2138,
2282
],
[
2285,
2338,
... | // unsigned squared distance between ray and segment
| vec2 usqdLineSegment( vec3 a, vec3 b, vec3 o, vec3 d )
{ |
#if 1
vec3 oa = a-o;
vec3 ob = b-o;
vec3 va = oa-d*dot(oa,d);
vec3 vb = ob-d*dot(ob,d);
vec3 ba = va-vb;
float h = clamp( dot(va,ba)/dot(ba,ba), 0.0, 1.0 );
vec3 q = va - ba*h;
return vec2( dot(q,q), h );
#else
return usqdPointSegment( vec3(0.0), o+d*dot(a-o,d)-a, o+d*dot(b-o,d)-b )... | // unsigned squared distance between ray and segment
vec2 usqdLineSegment( vec3 a, vec3 b, vec3 o, vec3 d )
{ | 1 | 1 |
4llXD7 | iq | 2015-07-18T05:24:14 | // The MIT License
// Copyright © 2015 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
1478,
1632,
1686,
1686,
1843
] | [
[
1478,
1632,
1686,
1686,
1843
],
[
1845,
1845,
1902,
1902,
2667
]
] | // b.x = width
// b.y = height
// r.x = roundness top-right
// r.y = roundness boottom-right
// r.z = roundness top-left
// r.w = roundness bottom-left
| float sdRoundBox( in vec2 p, in vec2 b, in vec4 r )
{ |
r.xy = (p.x>0.0)?r.xy : r.zw;
r.x = (p.y>0.0)?r.x : r.y;
vec2 q = abs(p)-b+r.x;
return min(max(q.x,q.y),0.0) + length(max(q,0.0)) - r.x;
} | // b.x = width
// b.y = height
// r.x = roundness top-right
// r.y = roundness boottom-right
// r.z = roundness top-left
// r.w = roundness bottom-left
float sdRoundBox( in vec2 p, in vec2 b, in vec4 r )
{ | 4 | 6 |
ltlSWf | otaviogood | 2015-08-25T04:26:33 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
4861,
4906,
4933,
4933,
4966
] | [
[
1278,
1307,
1326,
1326,
1371
],
[
1372,
1372,
1391,
1391,
1422
],
[
1423,
1423,
1446,
1446,
1482
],
[
1483,
1483,
1506,
1506,
1577
],
[
1578,
1578,
1600,
1600,
1687
],
[
1688,
1688,
... | // ---- functions to remap / warp space ----
| float repsDouble(float a)
{ |
return abs(a * 2.0 - 1.0);
} | // ---- functions to remap / warp space ----
float repsDouble(float a)
{ | 1 | 1 |
ltlSWf | otaviogood | 2015-08-25T04:26:33 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
5929,
6109,
6132,
6132,
6196
] | [
[
1278,
1307,
1326,
1326,
1371
],
[
1372,
1372,
1391,
1391,
1422
],
[
1423,
1423,
1446,
1446,
1482
],
[
1483,
1483,
1506,
1506,
1577
],
[
1578,
1578,
1600,
1600,
1687
],
[
1688,
1688,
... | // ---- shapes defined by distance fields ----
// See this site for a reference to more distance functions...
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
| float length8(vec2 v)
{ |
return pow(pow(abs(v.x),8.0) + pow(abs(v.y), 8.0), 1.0/8.0);
} | // ---- shapes defined by distance fields ----
// See this site for a reference to more distance functions...
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
float length8(vec2 v)
{ | 1 | 2 |
ltlSWf | otaviogood | 2015-08-25T04:26:33 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
6198,
6220,
6254,
6254,
6365
] | [
[
1278,
1307,
1326,
1326,
1371
],
[
1372,
1372,
1391,
1391,
1422
],
[
1423,
1423,
1446,
1446,
1482
],
[
1483,
1483,
1506,
1506,
1577
],
[
1578,
1578,
1600,
1600,
1687
],
[
1688,
1688,
... | // box distance field
| float sdBox(vec3 p, vec3 radius)
{ |
vec3 dist = abs(p) - radius;
return min(max(dist.x, max(dist.y, dist.z)), 0.0) + length(max(dist, 0.0));
} | // box distance field
float sdBox(vec3 p, vec3 radius)
{ | 10 | 10 |
ltlSWf | otaviogood | 2015-08-25T04:26:33 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
6367,
6411,
6463,
6463,
6633
] | [
[
1278,
1307,
1326,
1326,
1371
],
[
1372,
1372,
1391,
1391,
1422
],
[
1423,
1423,
1446,
1446,
1482
],
[
1483,
1483,
1506,
1506,
1577
],
[
1578,
1578,
1600,
1600,
1687
],
[
1688,
1688,
... | // Makes a warped torus that rotates around
| float sdTorusWobble( vec3 p, vec2 t, float offset)
{ |
float a = atan(p.x, p.z);
float subs = 2.0;
a = sin(a*subs+localTime*4.0+offset*3.234567);
vec2 q = vec2(length(p.xz)-t.x-a*0.1,p.y);
return length8(q)-t.y;
} | // Makes a warped torus that rotates around
float sdTorusWobble( vec3 p, vec2 t, float offset)
{ | 1 | 1 |
ltlSWf | otaviogood | 2015-08-25T04:26:33 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
6635,
6669,
6697,
6697,
6725
] | [
[
1278,
1307,
1326,
1326,
1371
],
[
1372,
1372,
1391,
1391,
1422
],
[
1423,
1423,
1446,
1446,
1482
],
[
1483,
1483,
1506,
1506,
1577
],
[
1578,
1578,
1600,
1600,
1687
],
[
1688,
1688,
... | // simple cylinder distance field
| float cyl(vec2 p, float r)
{ |
return length(p) - r;
} | // simple cylinder distance field
float cyl(vec2 p, float r)
{ | 3 | 6 |
4d33z4 | sagarpatel | 2015-11-23T08:44:22 | // @sagzorz
// My first shader on ShaderToy!
// The stuff below is pretty much all of the amazing @cabbibo's SDF tutorial
// https://www.shadertoy.com/view/Xl2XWt
// I read thorugh it then looked at IQ's page on distance functions
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// got inspi... | cc0-1.0 | [
15590,
15992,
16075,
16075,
16253
] | [
[
15590,
15992,
16075,
16075,
16253
],
[
16457,
16474,
16517,
16517,
17738
],
[
17740,
17740,
17773,
17773,
17838
],
[
17840,
17840,
17884,
17884,
18130
],
[
18132,
18132,
18169,
18169,
18519
],
[... | // This calculation basically gets a way for us to
// transform the rays coming out of our eyes and going through the window.
// If it doesn't make sense, thats ok. It doesn't make sense to me either :)
// Whats important to remember is that this basically gives us a way to position
// our window. We could you it to m... | mat3 calculateEyeRayTransformationMatrix( in vec3 ro, in vec3 ta, in float roll )
{ |
vec3 ww = normalize( ta - ro );
vec3 uu = normalize( cross(ww,vec3(sin(roll),cos(roll),0.0) ) );
vec3 vv = normalize( cross(uu,ww));
return mat3( uu, vv, ww );
} | // This calculation basically gets a way for us to
// transform the rays coming out of our eyes and going through the window.
// If it doesn't make sense, thats ok. It doesn't make sense to me either :)
// Whats important to remember is that this basically gives us a way to position
// our window. We could you it to m... | 5 | 5 |
4d33z4 | sagarpatel | 2015-11-23T08:44:22 | // @sagzorz
// My first shader on ShaderToy!
// The stuff below is pretty much all of the amazing @cabbibo's SDF tutorial
// https://www.shadertoy.com/view/Xl2XWt
// I read thorugh it then looked at IQ's page on distance functions
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// got inspi... | cc0-1.0 | [
16457,
16474,
16517,
16517,
17738
] | [
[
15590,
15992,
16075,
16075,
16253
],
[
16457,
16474,
16517,
16517,
17738
],
[
17740,
17740,
17773,
17773,
17838
],
[
17840,
17840,
17884,
17884,
18130
],
[
18132,
18132,
18169,
18169,
18519
],
[... | //'TAG: BALLOON'
| vec2 sdfBalloon( vec3 currentRayPosition ){ |
float ballOrbitSpeed = 0.85;
float ballOrbitRadius = 1.0;
vec3 ballOrbitOffset = vec3(1.0,0,0);
float balloonPosX = ballOrbitRadius * cos( ballOrbitSpeed * iTime);
float balloonPosY = ballOrbitRadius * sin( ballOrbitSpeed * iTime);
// First we define our balloon position
vec3 balloonPosition... | //'TAG: BALLOON'
vec2 sdfBalloon( vec3 currentRayPosition ){ | 1 | 2 |
4d33z4 | sagarpatel | 2015-11-23T08:44:22 | // @sagzorz
// My first shader on ShaderToy!
// The stuff below is pretty much all of the amazing @cabbibo's SDF tutorial
// https://www.shadertoy.com/view/Xl2XWt
// I read thorugh it then looked at IQ's page on distance functions
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// got inspi... | cc0-1.0 | [
19970,
20165,
20221,
20221,
20605
] | [
[
15590,
15992,
16075,
16075,
16253
],
[
16457,
16474,
16517,
16517,
17738
],
[
17740,
17740,
17773,
17773,
17838
],
[
17840,
17840,
17884,
17884,
18130
],
[
18132,
18132,
18169,
18169,
18519
],
[... | // 'TAG : WHICH AM I CLOSER TO?'
// This function takes in two things
// and says which is closer by using the
// distance to each thing, comparing them
// and returning the one that is closer!
| vec2 whichThingAmICloserTo( vec2 thing1 , vec2 thing2 ){ |
vec2 closestThing;
// Check out the balloon function
// and remember how the x of the returned
// information is the distance, and the y
// is the id of the thing!
if( thing1.x <= thing2.x ){
closestThing = thing1;
}else if( thing2.x < thing1.x ){
clos... | // 'TAG : WHICH AM I CLOSER TO?'
// This function takes in two things
// and says which is closer by using the
// distance to each thing, comparing them
// and returning the one that is closer!
vec2 whichThingAmICloserTo( vec2 thing1 , vec2 thing2 ){ | 3 | 3 |
4d33z4 | sagarpatel | 2015-11-23T08:44:22 | // @sagzorz
// My first shader on ShaderToy!
// The stuff below is pretty much all of the amazing @cabbibo's SDF tutorial
// https://www.shadertoy.com/view/Xl2XWt
// I read thorugh it then looked at IQ's page on distance functions
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// got inspi... | cc0-1.0 | [
20613,
20765,
20809,
20809,
21118
] | [
[
15590,
15992,
16075,
16075,
16253
],
[
16457,
16474,
16517,
16517,
17738
],
[
17740,
17740,
17773,
17773,
17838
],
[
17840,
17840,
17884,
17884,
18130
],
[
18132,
18132,
18169,
18169,
18519
],
[... | // Takes in the position of the ray, and feeds back
// 2 values of how close it is to things in the world
// what thing it is closest two in the world.
| vec2 mapTheWorld( vec3 currentRayPosition ){ |
vec2 result;
vec2 balloon = sdfBalloon( currentRayPosition );
//vec2 box = sdfBox( currentRayPosition );
vec2 torus = sdfTorus( currentRayPosition );
result = whichThingAmICloserTo( balloon , torus); //box );
result.x = opBlend( balloon.x, torus.x);
return result;
} | // Takes in the position of the ray, and feeds back
// 2 values of how close it is to things in the world
// what thing it is closest two in the world.
vec2 mapTheWorld( vec3 currentRayPosition ){ | 1 | 3 |
4d33z4 | sagarpatel | 2015-11-23T08:44:22 | // @sagzorz
// My first shader on ShaderToy!
// The stuff below is pretty much all of the amazing @cabbibo's SDF tutorial
// https://www.shadertoy.com/view/Xl2XWt
// I read thorugh it then looked at IQ's page on distance functions
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// got inspi... | cc0-1.0 | [
27214,
27576,
27625,
27625,
28622
] | [
[
15590,
15992,
16075,
16075,
16253
],
[
16457,
16474,
16517,
16517,
17738
],
[
17740,
17740,
17773,
17773,
17838
],
[
17840,
17840,
17884,
17884,
18130
],
[
18132,
18132,
18169,
18169,
18519
],
[... | // Here we are calcuting the normal of the surface
// Although it looks like alot of code, it actually
// is just trying to do something very simple, which
// is to figure out in what direction the SDF is increasing.
// What is amazing, is that this value is the same thing
// as telling you what direction the surface ... | vec3 getNormalOfSurface( in vec3 positionOfHit ){ |
vec3 tinyChangeX = vec3( 0.001, 0.0, 0.0 );
vec3 tinyChangeY = vec3( 0.0 , 0.001 , 0.0 );
vec3 tinyChangeZ = vec3( 0.0 , 0.0 , 0.001 );
float upTinyChangeInX = mapTheWorld( positionOfHit + tinyChangeX ).x;
float downTinyChangeInX = mapTheWorld( positionOfHit - tinyChangeX ).x;
f... | // Here we are calcuting the normal of the surface
// Although it looks like alot of code, it actually
// is just trying to do something very simple, which
// is to figure out in what direction the SDF is increasing.
// What is amazing, is that this value is the same thing
// as telling you what direction the surface ... | 3 | 3 |
4d33z4 | sagarpatel | 2015-11-23T08:44:22 | // @sagzorz
// My first shader on ShaderToy!
// The stuff below is pretty much all of the amazing @cabbibo's SDF tutorial
// https://www.shadertoy.com/view/Xl2XWt
// I read thorugh it then looked at IQ's page on distance functions
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// got inspi... | cc0-1.0 | [
28628,
28716,
28741,
28741,
28765
] | [
[
15590,
15992,
16075,
16075,
16253
],
[
16457,
16474,
16517,
16517,
17738
],
[
17740,
17740,
17773,
17773,
17838
],
[
17840,
17840,
17884,
17884,
18130
],
[
18132,
18132,
18169,
18169,
18519
],
[... | // doing our background color is easy enough,
// just make it pure black. like my soul.
| vec3 doBackgroundColor(){ |
return vec3( 0.75 );
} | // doing our background color is easy enough,
// just make it pure black. like my soul.
vec3 doBackgroundColor(){ | 1 | 3 |
4d33z4 | sagarpatel | 2015-11-23T08:44:22 | // @sagzorz
// My first shader on ShaderToy!
// The stuff below is pretty much all of the amazing @cabbibo's SDF tutorial
// https://www.shadertoy.com/view/Xl2XWt
// I read thorugh it then looked at IQ's page on distance functions
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// got inspi... | cc0-1.0 | [
31087,
31208,
31268,
31268,
31467
] | [
[
15590,
15992,
16075,
16075,
16253
],
[
16457,
16474,
16517,
16517,
17738
],
[
17740,
17740,
17773,
17773,
17838
],
[
17840,
17840,
17884,
17884,
18130
],
[
18132,
18132,
18169,
18169,
18519
],
[... | // Here we are using the normal of the surface,
// and mapping it to color, to show you just how cool
// normals can be!
| vec3 doBoxColor(vec3 positionOfHit , vec3 normalOfSurface ){ |
vec3 color = vec3( normalOfSurface.x , normalOfSurface.y , normalOfSurface.z );
//could also just write color = normalOfSurce
//but trying to be explicit.
return color;
} | // Here we are using the normal of the surface,
// and mapping it to color, to show you just how cool
// normals can be!
vec3 doBoxColor(vec3 positionOfHit , vec3 normalOfSurface ){ | 3 | 3 |
4d33z4 | sagarpatel | 2015-11-23T08:44:22 | // @sagzorz
// My first shader on ShaderToy!
// The stuff below is pretty much all of the amazing @cabbibo's SDF tutorial
// https://www.shadertoy.com/view/Xl2XWt
// I read thorugh it then looked at IQ's page on distance functions
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// got inspi... | cc0-1.0 | [
31472,
31573,
31650,
31714,
33042
] | [
[
15590,
15992,
16075,
16075,
16253
],
[
16457,
16474,
16517,
16517,
17738
],
[
17740,
17740,
17773,
17773,
17838
],
[
17840,
17840,
17884,
17884,
18130
],
[
18132,
18132,
18169,
18169,
18519
],
[... | // This is where we decide
// what color the world will be!
// and what marvelous colors it will be!
| vec3 colorTheWorld( vec2 rayHitInfo , vec3 eyePosition , vec3 rayDirection ){ |
vec3 color;
// THE LIL RAY WENT ALL THE WAY
// TO THE EDGE OF THE WORLD,
// AND DIDN'T HIT ANYTHING
if( rayHitInfo.y < 0.0 ){
color = doBackgroundColor();
// THE LIL RAY HIT SOMETHING!!!!
}else{
// If we hit something,
// we also know how far the ray has... | // This is where we decide
// what color the world will be!
// and what marvelous colors it will be!
vec3 colorTheWorld( vec2 rayHitInfo , vec3 eyePosition , vec3 rayDirection ){ | 1 | 3 |
llBSWc | qwert33 | 2015-11-06T23:18:34 | // Made by Dominik Schmid
// MIT license
// biases x to be closer to 0 or 1
// can act like a parameterized smoothstep
// https://www.desmos.com/calculator/c4w7ktzhhk
// if b is near 1.0 then numbers a little closer to 1.0 are returned
// if b is near 0.0 then numbers a little closer to 0.0 are returned
// if b is n... | mit | [
44,
360,
390,
390,
461
] | [
[
44,
360,
390,
390,
461
],
[
544,
544,
568,
568,
603
],
[
604,
604,
636,
636,
663
],
[
664,
664,
708,
708,
1985
],
[
1989,
2054,
2073,
2073,
2171
],
[
2173,
2238,
2267,
2267,
... | // biases x to be closer to 0 or 1
// can act like a parameterized smoothstep
// https://www.desmos.com/calculator/c4w7ktzhhk
// if b is near 1.0 then numbers a little closer to 1.0 are returned
// if b is near 0.0 then numbers a little closer to 0.0 are returned
// if b is near 0.5 then values near x are returned
| float bias(float x, float b) { |
b = -log2(1.0 - b);
return 1.0 - pow(1.0 - pow(x, 1./b), b);
} | // biases x to be closer to 0 or 1
// can act like a parameterized smoothstep
// https://www.desmos.com/calculator/c4w7ktzhhk
// if b is near 1.0 then numbers a little closer to 1.0 are returned
// if b is near 0.0 then numbers a little closer to 0.0 are returned
// if b is near 0.5 then values near x are returned
floa... | 1 | 5 |
llBSWc | qwert33 | 2015-11-06T23:18:34 | // Made by Dominik Schmid
// MIT license
// biases x to be closer to 0 or 1
// can act like a parameterized smoothstep
// https://www.desmos.com/calculator/c4w7ktzhhk
// if b is near 1.0 then numbers a little closer to 1.0 are returned
// if b is near 0.0 then numbers a little closer to 0.0 are returned
// if b is n... | mit | [
1989,
2054,
2073,
2073,
2171
] | [
[
44,
360,
390,
390,
461
],
[
544,
544,
568,
568,
603
],
[
604,
604,
636,
636,
663
],
[
664,
664,
708,
708,
1985
],
[
1989,
2054,
2073,
2073,
2171
],
[
2173,
2238,
2267,
2267,
... | // creates white noise in the range 0..1 including 0 excluding 1
| float rand(vec2 p){ |
p /= iResolution.xy;
return fract(sin(dot(p.xy, vec2(12.9898, 78.2377))) * 43758.5453);
} | // creates white noise in the range 0..1 including 0 excluding 1
float rand(vec2 p){ | 1 | 12 |
llBSWc | qwert33 | 2015-11-06T23:18:34 | // Made by Dominik Schmid
// MIT license
// biases x to be closer to 0 or 1
// can act like a parameterized smoothstep
// https://www.desmos.com/calculator/c4w7ktzhhk
// if b is near 1.0 then numbers a little closer to 1.0 are returned
// if b is near 0.0 then numbers a little closer to 0.0 are returned
// if b is n... | mit | [
2173,
2238,
2267,
2267,
2313
] | [
[
44,
360,
390,
390,
461
],
[
544,
544,
568,
568,
603
],
[
604,
604,
636,
636,
663
],
[
664,
664,
708,
708,
1985
],
[
1989,
2054,
2073,
2073,
2171
],
[
2173,
2238,
2267,
2267,
... | // creates white noise in the range 0..1 including 0 including 1
| float rand_inclusive(vec2 p){ |
return clamp(rand(p)*1.005, 0.0, 1.0);
} | // creates white noise in the range 0..1 including 0 including 1
float rand_inclusive(vec2 p){ | 1 | 1 |
Msc3zN | sagarpatel | 2015-11-25T11:26:57 | // CC0 1.0
// @sagzorz
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.com/view/Xl2XWt
// my original hacked up shader --> https://www.shadertoy.com/view/4d33z4
// this is a clean/from scratch re-implementation of my first shdaer/sdf,
... | cc0-1.0 | [
1343,
1478,
1511,
1511,
1539
] | [
[
1343,
1478,
1511,
1511,
1539
],
[
1541,
2768,
2797,
2797,
3021
],
[
3171,
3586,
3617,
3617,
3740
],
[
3862,
4109,
4142,
4142,
4261
],
[
4263,
4440,
4476,
4476,
4509
],
[
4511,
4750,
... | // ~~~~~~~ signed fistance fuction for sphere
// input r --> is sphere radius
// pretty simple, just compare point to radius of sphere
| float sdSphere(vec3 p, float r)
{ |
return length(p) - r;
} | // ~~~~~~~ signed fistance fuction for sphere
// input r --> is sphere radius
// pretty simple, just compare point to radius of sphere
float sdSphere(vec3 p, float r)
{ | 18 | 57 |
Msc3zN | sagarpatel | 2015-11-25T11:26:57 | // CC0 1.0
// @sagzorz
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.com/view/Xl2XWt
// my original hacked up shader --> https://www.shadertoy.com/view/4d33z4
// this is a clean/from scratch re-implementation of my first shdaer/sdf,
... | cc0-1.0 | [
3171,
3586,
3617,
3617,
3740
] | [
[
1343,
1478,
1511,
1511,
1539
],
[
1541,
2768,
2797,
2797,
3021
],
[
3171,
3586,
3617,
3617,
3740
],
[
3862,
4109,
4142,
4142,
4261
],
[
4263,
4440,
4476,
4476,
4509
],
[
4511,
4750,
... | // ~~~~~~~ signed distance function for torus
// input t --> torus specs where:
// t.x = torus circumference
// t.y = torus thickness
//
// think of the torus as circles wrappeed around 1 large cicle (perpendicular)
// first flatten the y axis of p (by using p.xz) and get the distance to
// the torus circumference/... | float sdTorus(vec3 p, vec2 t)
{ |
float distPtoTorusCircumference = length(vec2( length(p.xz)-t.x , p.y));
return distPtoTorusCircumference - t.y;
} | // ~~~~~~~ signed distance function for torus
// input t --> torus specs where:
// t.x = torus circumference
// t.y = torus thickness
//
// think of the torus as circles wrappeed around 1 large cicle (perpendicular)
// first flatten the y axis of p (by using p.xz) and get the distance to
// the torus circumference/... | 3 | 16 |
Msc3zN | sagarpatel | 2015-11-25T11:26:57 | // CC0 1.0
// @sagzorz
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.com/view/Xl2XWt
// my original hacked up shader --> https://www.shadertoy.com/view/4d33z4
// this is a clean/from scratch re-implementation of my first shdaer/sdf,
... | cc0-1.0 | [
3862,
4109,
4142,
4142,
4261
] | [
[
1343,
1478,
1511,
1511,
1539
],
[
1541,
2768,
2797,
2797,
3021
],
[
3171,
3586,
3617,
3617,
3740
],
[
3862,
4109,
4142,
4142,
4261
],
[
4263,
4440,
4476,
4476,
4509
],
[
4511,
4750,
... | // ~~~~~~~ smooth minimum function (polynomial version) from iq's page
// http://iquilezles.org/www/articles/smin/smin.htm
// input d1 --> distance value of object a
// input d1 --> distance value of object b
// output --> smoothed/blended output
| float smin( float d1, float d2)
{ |
float k = 0.6521;
float h = clamp( 0.5+0.5*(d2-d1)/k, 0.0, 1.0 );
return mix( d2, d1, h ) - k*h*(1.0-h);
} | // ~~~~~~~ smooth minimum function (polynomial version) from iq's page
// http://iquilezles.org/www/articles/smin/smin.htm
// input d1 --> distance value of object a
// input d1 --> distance value of object b
// output --> smoothed/blended output
float smin( float d1, float d2)
{ | 1 | 2 |
Msc3zN | sagarpatel | 2015-11-25T11:26:57 | // CC0 1.0
// @sagzorz
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.com/view/Xl2XWt
// my original hacked up shader --> https://www.shadertoy.com/view/4d33z4
// this is a clean/from scratch re-implementation of my first shdaer/sdf,
... | cc0-1.0 | [
4263,
4440,
4476,
4476,
4509
] | [
[
1343,
1478,
1511,
1511,
1539
],
[
1541,
2768,
2797,
2797,
3021
],
[
3171,
3586,
3617,
3617,
3740
],
[
3862,
4109,
4142,
4142,
4261
],
[
4263,
4440,
4476,
4476,
4509
],
[
4511,
4750,
... | // ~~~~~~~ distance deformation, blends 2 shapes based on their distances
// input d1 --> distance of object 1
// input d2 --> distance of object 2
// output --> blended object
| float opBlend( float d1, float d2)
{ |
return smin( d1, d2 );
} | // ~~~~~~~ distance deformation, blends 2 shapes based on their distances
// input d1 --> distance of object 1
// input d2 --> distance of object 2
// output --> blended object
float opBlend( float d1, float d2)
{ | 1 | 4 |
Msc3zN | sagarpatel | 2015-11-25T11:26:57 | // CC0 1.0
// @sagzorz
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.com/view/Xl2XWt
// my original hacked up shader --> https://www.shadertoy.com/view/4d33z4
// this is a clean/from scratch re-implementation of my first shdaer/sdf,
... | cc0-1.0 | [
4511,
4750,
4794,
4794,
4926
] | [
[
1343,
1478,
1511,
1511,
1539
],
[
1541,
2768,
2797,
2797,
3021
],
[
3171,
3586,
3617,
3617,
3740
],
[
3862,
4109,
4142,
4142,
4261
],
[
4263,
4440,
4476,
4476,
4509
],
[
4511,
4750,
... | // ~~~~~~~ domain deformation, twists the shape
// input p --> original ray position
// input t --> twist scale factor
// output --> twisted ray position
//
// need more max itterations on ray march for stronger/bigger domain deformation
| vec3 opTwist( vec3 p, float t, float yaw )
{ |
float c = cos(t * p.y + yaw);
float s = sin(t * p.y + yaw);
mat2 m = mat2(c,-s,s,c);
return vec3(m*p.xz,p.y);
} | // ~~~~~~~ domain deformation, twists the shape
// input p --> original ray position
// input t --> twist scale factor
// output --> twisted ray position
//
// need more max itterations on ray march for stronger/bigger domain deformation
vec3 opTwist( vec3 p, float t, float yaw )
{ | 3 | 3 |
Msc3zN | sagarpatel | 2015-11-25T11:26:57 | // CC0 1.0
// @sagzorz
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.com/view/Xl2XWt
// my original hacked up shader --> https://www.shadertoy.com/view/4d33z4
// this is a clean/from scratch re-implementation of my first shdaer/sdf,
... | cc0-1.0 | [
4928,
5100,
5128,
5128,
5198
] | [
[
1343,
1478,
1511,
1511,
1539
],
[
1541,
2768,
2797,
2797,
3021
],
[
3171,
3586,
3617,
3617,
3740
],
[
3862,
4109,
4142,
4142,
4261
],
[
4263,
4440,
4476,
4476,
4509
],
[
4511,
4750,
... | // ~~~~~~~ do Union / combine 2 sd objects
// input vec2 --> .x is the distance, .y is the object ID
// returns the closest object (basically does a min() but we use if()
| vec2 opU(vec2 o1, vec2 o2)
{ |
if(o1.x < o2.x)
return o1;
else
return o2;
} | // ~~~~~~~ do Union / combine 2 sd objects
// input vec2 --> .x is the distance, .y is the object ID
// returns the closest object (basically does a min() but we use if()
vec2 opU(vec2 o1, vec2 o2)
{ | 3 | 3 |
Msc3zN | sagarpatel | 2015-11-25T11:26:57 | // CC0 1.0
// @sagzorz
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.com/view/Xl2XWt
// my original hacked up shader --> https://www.shadertoy.com/view/4d33z4
// this is a clean/from scratch re-implementation of my first shdaer/sdf,
... | cc0-1.0 | [
5200,
5404,
5422,
5447,
6598
] | [
[
1343,
1478,
1511,
1511,
1539
],
[
1541,
2768,
2797,
2797,
3021
],
[
3171,
3586,
3617,
3617,
3740
],
[
3862,
4109,
4142,
4142,
4261
],
[
4263,
4440,
4476,
4476,
4509
],
[
4511,
4750,
... | // ~~~~~~~ map out the world
// input p --> is ray position
// basically find the object/point closest to the ray by
// checking all the objects with respect to p
// move objects/shapes by messing with p
| vec2 map(vec3 p)
{ |
vec2 res;
// define objects
// sphere 1
// sphere: radius, orbit radius, orbit speed, orbit offset, position
float sR = 1.359997;
float sOR = 2.666662;
float sOS = 0.85;
vec3 sOO = vec3(2.66662,0.0,0.0);
vec3 sP = p - (sOO + vec3(sOR*cos(sOS*iTime),sOR*sin(sOS*iTime),0.0)... | // ~~~~~~~ map out the world
// input p --> is ray position
// basically find the object/point closest to the ray by
// checking all the objects with respect to p
// move objects/shapes by messing with p
vec2 map(vec3 p)
{ | 1 | 113 |
Msc3zN | sagarpatel | 2015-11-25T11:26:57 | // CC0 1.0
// @sagzorz
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.com/view/Xl2XWt
// my original hacked up shader --> https://www.shadertoy.com/view/4d33z4
// this is a clean/from scratch re-implementation of my first shdaer/sdf,
... | cc0-1.0 | [
6600,
6822,
6855,
6906,
7900
] | [
[
1343,
1478,
1511,
1511,
1539
],
[
1541,
2768,
2797,
2797,
3021
],
[
3171,
3586,
3617,
3617,
3740
],
[
3862,
4109,
4142,
4142,
4261
],
[
4263,
4440,
4476,
4476,
4509
],
[
4511,
4750,
... | // ~~~~~~~ cast/march ray through the word and see what it hits
// input ro --> ray origin point/position
// input rd --> ray direction
// output is vec2 where
// .x = distance travelled by ray
// .y = hit object's ID
//
| vec2 castRay( vec3 ro, vec3 rd)
{ |
const int maxMarchCount = 300;
float maxRayDistance = 20.0;
float minPrecisionCheck = 0.001;
float t = 0.0; // travelled distance by ray
float id = -1.0; // object ID, default of -1 means background
for(int i = 0; i < maxMarchCount; i++)
{
// get closest object to current ... | // ~~~~~~~ cast/march ray through the word and see what it hits
// input ro --> ray origin point/position
// input rd --> ray direction
// output is vec2 where
// .x = distance travelled by ray
// .y = hit object's ID
//
vec2 castRay( vec3 ro, vec3 rd)
{ | 1 | 1 |
Msc3zN | sagarpatel | 2015-11-25T11:26:57 | // CC0 1.0
// @sagzorz
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.com/view/Xl2XWt
// my original hacked up shader --> https://www.shadertoy.com/view/4d33z4
// this is a clean/from scratch re-implementation of my first shdaer/sdf,
... | cc0-1.0 | [
8550,
8737,
8768,
8768,
9770
] | [
[
1343,
1478,
1511,
1511,
1539
],
[
1541,
2768,
2797,
2797,
3021
],
[
3171,
3586,
3617,
3617,
3740
],
[
3862,
4109,
4142,
4142,
4261
],
[
4263,
4440,
4476,
4476,
4509
],
[
4511,
4750,
... | // ~~~~~~~ render pixel --> find closest surface and apply color accordingly
// input ro --> pixel's ray original position
// input rd --> pixel's ray direction
// output --> pixel color
| vec3 render(vec3 ro, vec3 rd)
{ |
vec3 bkgColor = vec3(0.75);
vec3 light = normalize( vec3(1.0, 4.0, 3.0) );
vec3 objectColor_1 = vec3(1.0, 0.0, 0.0);
vec3 objectColor_2 = vec3( 0.25 , 0.95 , 0.25 );
vec3 objectColor_3 = vec3(0.12, 0.12, 0.9);
vec3 ambientLightColor = vec3( 0.3 , 0.1, 0.2 );
vec2 res = castRay(ro, rd);... | // ~~~~~~~ render pixel --> find closest surface and apply color accordingly
// input ro --> pixel's ray original position
// input rd --> pixel's ray direction
// output --> pixel color
vec3 render(vec3 ro, vec3 rd)
{ | 1 | 16 |
Msc3zN | sagarpatel | 2015-11-25T11:26:57 | // CC0 1.0
// @sagzorz
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.com/view/Xl2XWt
// my original hacked up shader --> https://www.shadertoy.com/view/4d33z4
// this is a clean/from scratch re-implementation of my first shdaer/sdf,
... | cc0-1.0 | [
9772,
10011,
10076,
10076,
10270
] | [
[
1343,
1478,
1511,
1511,
1539
],
[
1541,
2768,
2797,
2797,
3021
],
[
3171,
3586,
3617,
3617,
3740
],
[
3862,
4109,
4142,
4142,
4261
],
[
4263,
4440,
4476,
4476,
4509
],
[
4511,
4750,
... | // ~~~~~~~ creates camera matrix used to transform ray point/direction
// input camPos --> camera position
// input targetPos --> look at target position
// input roll --> how much camera roll
// output --> camera matrix used to transform
| mat3 setCamera( in vec3 camPos, in vec3 targetPos, float roll )
{ |
vec3 cw = normalize(targetPos - camPos);
vec3 cp = vec3(sin(roll), cos(roll),0.0);
vec3 cu = normalize( cross(cw,cp) );
vec3 cv = normalize( cross(cu,cw) );
return mat3( cu, cv, cw );
} | // ~~~~~~~ creates camera matrix used to transform ray point/direction
// input camPos --> camera position
// input targetPos --> look at target position
// input roll --> how much camera roll
// output --> camera matrix used to transform
mat3 setCamera( in vec3 camPos, in vec3 targetPos, float roll )
{ | 1 | 3 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
1507,
1728,
1757,
1757,
2660
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ silly function to access array memeber
// because webgl needs const index for array acess
// TODO : FIX THIS, disgusting branching etc
// THIS IS DEPRECATED, NO LONGER NEED AN ARRAY SINCE DIRECT COL MIX NOW
| vec3 accessColors(float id)
{ |
vec3 bkgColor = vec3(0.5,0.6,0.7);//vec3(0.75);
vec3 objectColor_1 = vec3(1.0, 0.0, 0.0);
vec3 objectColor_2 = vec3( 0.25 , 0.95 , 0.25 );
vec3 objectColor_3 = vec3(0.12, 0.12, 0.9);
vec3 objectColor_4 = vec3(0.65);
vec3 objectColor_5 = vec3(1.0,1.0,1.0);
vec3 colorsArray[6];
... | // ~~~~~~~ silly function to access array memeber
// because webgl needs const index for array acess
// TODO : FIX THIS, disgusting branching etc
// THIS IS DEPRECATED, NO LONGER NEED AN ARRAY SINCE DIRECT COL MIX NOW
vec3 accessColors(float id)
{ | 2 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
4491,
4907,
4938,
4938,
5061
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ signed distance function for torus
// input t --> torus specs where:
// t.x = torus circumference
// t.y = torus thickness
//
// think of the torus as circles wrappeed around 1 large cicle (perpendicular)
// first flatten the y axis of p (by using p.xz) and get the distance to
// the torus circumference... | float sdTorus(vec3 p, vec2 t)
{ |
float distPtoTorusCircumference = length(vec2( length(p.xz)-t.x , p.y));
return distPtoTorusCircumference - t.y;
} | // ~~~~~~~ signed distance function for torus
// input t --> torus specs where:
// t.x = torus circumference
// t.y = torus thickness
//
// think of the torus as circles wrappeed around 1 large cicle (perpendicular)
// first flatten the y axis of p (by using p.xz) and get the distance to
// the torus circumference... | 3 | 16 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
5182,
5395,
5418,
5418,
5436
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ signed distance function for plane
// input ps --> specs of plane
// ps.x --> size x
// ps.y --> size z
// plane extends indefinately in x and z,
// so just return height from floor (y)
| float sdPlane(vec3 p)
{ |
return p.y;
} | // ~~~~~~~ signed distance function for plane
// input ps --> specs of plane
// ps.x --> size x
// ps.y --> size z
// plane extends indefinately in x and z,
// so just return height from floor (y)
float sdPlane(vec3 p)
{ | 7 | 13 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
5438,
5713,
5755,
5755,
5856
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ smooth minimum function (polynomial version) from iq's page
// http://iquilezles.org/www/articles/smin/smin.htm
// input d1 --> distance value of object a
// input d1 --> distance value of object b
// input k --> blend factor
// output --> smoothed/blended output
| float smin( float d1, float d2, float k)
{ |
float h = clamp( 0.5+0.5*(d2-d1)/k, 0.0, 1.0 );
return mix( d2, d1, h ) - k*h*(1.0-h);
} | // ~~~~~~~ smooth minimum function (polynomial version) from iq's page
// http://iquilezles.org/www/articles/smin/smin.htm
// input d1 --> distance value of object a
// input d1 --> distance value of object b
// input k --> blend factor
// output --> smoothed/blended output
float smin( float d1, float d2, float k)
{ | 2 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
5858,
6156,
6199,
6199,
6490
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ distance deformation, blends 2 shapes based on their distances
// input o1 --> object 1 (dist and material color)
// input 02 --> object 2 (dist and material color)
// input bf --> blend factor
// output --> blended dist, blended material color
// TODO: FIX/IMPROVE COLOR BLENDING LOGIC
| vec4 opBlend( vec4 o1, vec4 o2, float bf)
{ |
float distBlend = smin( o1.x, o2.x, bf);
// blend color based on prozimity to surface
float dr1 = 1.0 - clamp(o1.x,0.0,1.0);
float dr2 = 1.0 - clamp(o2.x,0.0,1.0);
vec3 dc1 = dr1 * o1.yzw;
vec3 dc2 = dr2 * o2.yzw;
return vec4(distBlend, dc1+dc2);
} | // ~~~~~~~ distance deformation, blends 2 shapes based on their distances
// input o1 --> object 1 (dist and material color)
// input 02 --> object 2 (dist and material color)
// input bf --> blend factor
// output --> blended dist, blended material color
// TODO: FIX/IMPROVE COLOR BLENDING LOGIC
vec4 opBlend( vec4 o1,... | 2 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
7181,
7406,
7438,
7438,
7467
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ do shape subtract, cuts d2 out of d1
// by using the negative of d2, were effectively comparing wrt to internal d
// input d1 --> object/distance 1
// input d2 --> object/distance 2
// output --> cut out distance
| float opSub(float d1,float d2)
{ |
return max(d1,-d2);
} | // ~~~~~~~ do shape subtract, cuts d2 out of d1
// by using the negative of d2, were effectively comparing wrt to internal d
// input d1 --> object/distance 1
// input d2 --> object/distance 2
// output --> cut out distance
float opSub(float d1,float d2)
{ | 2 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
7470,
7561,
7586,
7586,
7839
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~~ generates world position of point light
// output --> wolrd pos of point light
| vec3 generateLightPos()
{ |
float lOR_X = 1.20;
float lOR_Y = 2.40;
float lOR_Z = 3.0;
float lORS = 0.65;
float lpX = lOR_X*cos(lORS*iTime);
float lpY = lOR_Y*sin(lORS*iTime);
float lpZ = lOR_Z*cos(lORS*iTime);
return vec3(lpX,abs(lpY),lpZ);
} | // ~~~~~~~~ generates world position of point light
// output --> wolrd pos of point light
vec3 generateLightPos()
{ | 1 | 1 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
7841,
8119,
8137,
8162,
10044
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ map out the world
// input p --> is ray position
// basically find the object/point closest to the ray by
// checking all the objects with respect to p
// move objects/shapes by messing with p
// outputs closest distance and blended colors for that surface as a vec4
| vec4 map(vec3 p)
{ |
vec4 res;
// define objects
// sphere 1
// sphere: radius, orbit radius, orbit speed, orbit offset, position
float sR = 1.359997;
float sOR = 2.666662;
float sOS = 0.85;
vec3 sOO = vec3(2.66662,0.0,0.0);
vec3 sOP = (sOO + vec3(sOR*cos(sOS*iTime),sOR*sin(sOS*iTime),0... | // ~~~~~~~ map out the world
// input p --> is ray position
// basically find the object/point closest to the ray by
// checking all the objects with respect to p
// move objects/shapes by messing with p
// outputs closest distance and blended colors for that surface as a vec4
vec4 map(vec3 p)
{ | 1 | 31 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
10046,
10367,
10424,
10478,
11655
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ cast/march ray through the word and see what it hits
// input ro --> ray origin point/position
// input rd --> ray direction
// in/out --> itterationRatio (used for AA),in/out cuz no more room in vec
// output is vec3 where
// .x = distance travelled by ray
// .y = hit object's ID
// .z = itteration ratio... | vec4 castRay( vec3 ro, vec3 rd, inout float itterRatio)
{ |
const float maxMarchCount = 200.0;
float maxRayDistance = 50.0;
// making this more precise can also help with AA detection
// value lower than 0.000001 causes noise
float minPrecisionCheck = 0.000001;
float t = 0.0; // travelled distance by ray
vec3 oc = vec3(1.0,0.0,1.0); // object c... | // ~~~~~~~ cast/march ray through the word and see what it hits
// input ro --> ray origin point/position
// input rd --> ray direction
// in/out --> itterationRatio (used for AA),in/out cuz no more room in vec
// output is vec3 where
// .x = distance travelled by ray
// .y = hit object's ID
// .z = itteration ratio... | 1 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
12559,
12842,
12886,
12886,
13601
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ softShadow, took pointers from iq's
// http://www.iquilezles.org/www/articles/rmshadows/rmshadows.htm
// and
// https://www.shadertoy.com/view/Xds3zN
// input sp --> position of surface we are shading
// input lp --> light position
// output float --> amount of shadow
| float castRay_SoftShadow(vec3 sp, vec3 lp)
{ |
const int ssMaxMarchCount = 90;
const float ssPrecision = 0.001;
// direction of ray, from shaded surface point to light pos
vec3 rd = normalize(lp - sp);
// max travel distance of hard shadow ray
float ssMaxT = length(lp - sp);
// travelled distance by hard shadow ray
float ssT = ... | // ~~~~~~~ softShadow, took pointers from iq's
// http://www.iquilezles.org/www/articles/rmshadows/rmshadows.htm
// and
// https://www.shadertoy.com/view/Xds3zN
// input sp --> position of surface we are shading
// input lp --> light position
// output float --> amount of shadow
float castRay_SoftShadow(vec3 sp, vec... | 2 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
13603,
13806,
13857,
13857,
14317
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ ambientOcclusion
// just cast from surface point in direction of normal to see if any hit
// basic concept from:
// http://9bitscience.blogspot.com/2013/07/raymarching-distance-fields_14.html
| float castRay_AmbientOcclusion(vec3 sp, vec3 nor)
{ |
const int aoMaxMarchCount = 20;
const float aoPrecision = 0.001;
// range of ambient occlusion
float aoMaxT = 1.0;
float aoT = 0.01;
float aoV = 1.0;
for(int i = 0; i < aoMaxMarchCount; i++)
{
float dist = map(sp + nor*aoT).x;
aoV = aoT/aoMaxT;
if(dist < aoPrecision... | // ~~~~~~~ ambientOcclusion
// just cast from surface point in direction of normal to see if any hit
// basic concept from:
// http://9bitscience.blogspot.com/2013/07/raymarching-distance-fields_14.html
float castRay_AmbientOcclusion(vec3 sp, vec3 nor)
{ | 2 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
14967,
15176,
15217,
15239,
15774
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ calculates the normals near point p in world space
// input p --> ray position world coordinates
// input oN --> normal vector at point p
// output --> averaged? out norals diffs of nearby points
| vec3 nearbyNormalsDiff(vec3 p, vec3 oN)
{ |
float wPD = 0.0;
wPD = 0.057;
//wPD = abs(0.05*sin(0.25*iTime)) + 0.1;
vec3 n1 = calculateNormal(p+vec3(wPD,wPD,wPD));
//vec3 n2 = calculateNormal(p+vec3(wPD,wPD,-wPD));
//vec3 n3 = calculateNormal(p+vec3(wPD,-wPD,wPD));
//vec3 n4 = calculateNormal(p+vec3(wPD,-wPD,-wPD));
// d... | // ~~~~~~~ calculates the normals near point p in world space
// input p --> ray position world coordinates
// input oN --> normal vector at point p
// output --> averaged? out norals diffs of nearby points
vec3 nearbyNormalsDiff(vec3 p, vec3 oN)
{ | 2 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
15776,
15992,
16027,
16027,
16065
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ do gamma correction
// from iq's pageon outdoor lighting:
// http://www.iquilezles.org/www/articles/outdoorslighting/outdoorslighting.htm
// input c --> original color
// output --> gamma corrected output
| vec3 applyGammaCorrection(vec3 c)
{ |
return pow( c, vec3(1.0/2.2) );
} | // ~~~~~~~ do gamma correction
// from iq's pageon outdoor lighting:
// http://www.iquilezles.org/www/articles/outdoorslighting/outdoorslighting.htm
// input c --> original color
// output --> gamma corrected output
vec3 applyGammaCorrection(vec3 c)
{ | 2 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
16067,
16520,
16595,
16595,
16786
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ do fog
// from iq's pageon fog:
// http://www.iquilezles.org/www/articles/fog/fog.htm
// input c --> original color
// input d --> pixel world distance
// input fc1 --> fog color 1
// input fc2 --> fog color 2
// input fs -- fog specs>
// fs.x --> fog density
// fs.y --> fog color lerp exponent (... | vec3 applyFog(vec3 c,float d,vec3 fc1,vec3 fc2,vec2 fs,vec3 cRD,vec3 lRD)
{ |
float fogAmount = 1.0 - exp(-d*fs.x);
float lightAmount = max( dot( cRD, lRD ), 0.0 );
vec3 fogColor = mix(fc1,fc2,pow(lightAmount,fs.y));
return mix(c,fogColor,fogAmount);
} | // ~~~~~~~ do fog
// from iq's pageon fog:
// http://www.iquilezles.org/www/articles/fog/fog.htm
// input c --> original color
// input d --> pixel world distance
// input fc1 --> fog color 1
// input fc2 --> fog color 2
// input fs -- fog specs>
// fs.x --> fog density
// fs.y --> fog color lerp exponent (... | 2 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
16790,
17113,
17178,
17178,
17246
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ calculates attenuation factor for light for a given distance and parameters
// input cF --> constant factor
// input lF --> linear factor
// input qF --> quadratic factor
// the factors above should range between 0 and 1
// pure realistic would follow inverse square law, i.e. pure quadtratic, so cF=0,lF=0,qF... | float calculateLightAttn(float cF, float lF, float qF, float d)
{ |
float falloff = 1.0/(cF + lF*d + qF*d*d);
return falloff;
} | // ~~~~~~~ calculates attenuation factor for light for a given distance and parameters
// input cF --> constant factor
// input lF --> linear factor
// input qF --> quadratic factor
// the factors above should range between 0 and 1
// pure realistic would follow inverse square law, i.e. pure quadtratic, so cF=0,lF=0,qF... | 1 | 1 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
20154,
20326,
20375,
20375,
20689
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ generate camera ray direction, different for each frag/pixel
// input fCoord --> pixel coordinate
// input cMatric --> camera matrix
// output --> ray direction
| vec3 calculateRayDir(vec2 fCoord, mat3 cMatrix)
{ |
vec2 p = ( -iResolution.xy + 2.0 * fCoord.xy ) / iResolution.y;
// determines ray direction based on camera matrix
// "lens length" seems to be related to field of view / ray divergence
float lensLen0gth = 2.0;
vec3 rD = cMatrix * normalize( vec3(p.xy,2.0) );
return rD;
} | // ~~~~~~~ generate camera ray direction, different for each frag/pixel
// input fCoord --> pixel coordinate
// input cMatric --> camera matrix
// output --> ray direction
vec3 calculateRayDir(vec2 fCoord, mat3 cMatrix)
{ | 2 | 2 |
Xs3GRM | sagarpatel | 2015-11-26T04:07:03 | // CC0 1.0
// @sagzorz
const bool isPseudoAA = false;
// Building on basics and creating helper functions
// POUET toolbox
// http://www.pouet.net/topic.php?which=7931&page=1&x=3&y=14
// NOTE: if you are new to SDFs, do @cabbibo's tutorial first!!!
//
// @cabbibo's original SDF tutorial --> https://www.shadertoy.c... | cc0-1.0 | [
20692,
20987,
21036,
21036,
22763
] | [
[
1507,
1728,
1757,
1757,
2660
],
[
2663,
2798,
2831,
2831,
2859
],
[
2861,
4088,
4117,
4117,
4341
],
[
4491,
4907,
4938,
4938,
5061
],
[
5182,
5395,
5418,
5418,
5436
],
[
5438,
5713,
... | // ~~~~~~~ render anti aliased, based on pixel's itteration/march count
// only effective for shape edges, doesn't fix surface col patterns
// input fCoord --> pixel coordinate
// input cPos --> camera position
// input cMat --> camera matrix
// output vec3 --> pixel antialaised color
| vec3 render_AA(vec2 fCoord,vec3 cPos,mat3 cMat)
{ |
vec3 rd = calculateRayDir(fCoord,cMat);
float aaF = 0.0;
vec4 pData = render(cPos,rd,aaF);
vec3 col = pData.xyz;
float aaThreashold = 0.845;
// controls blur amount/sample distance
float aaPD = 0.500;
// if requires AA, get color from nearby pixels and average out
//col = vec3(0... | // ~~~~~~~ render anti aliased, based on pixel's itteration/march count
// only effective for shape edges, doesn't fix surface col patterns
// input fCoord --> pixel coordinate
// input cPos --> camera position
// input cMat --> camera matrix
// output vec3 --> pixel antialaised color
vec3 render_AA(vec2 fCoor... | 1 | 2 |
MsyXDV | SparkX120 | 2016-06-23T04:30:06 | /**
* Adapted from my Mandelbrot-JS Project
* http://sparkx120.github.io/mandelbrot.html
* https://github.com/Sparkx120/mandelbrot-js
*
* By: James Wake (SparkX120)
* Copyright (c) 2016 James Wake
*
* MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software a... | mit | [
0,
1289,
1346,
1346,
2956
] | [
[
0,
1289,
1346,
1346,
2956
]
] | /**
* Adapted from my Mandelbrot-JS Project
* http://sparkx120.github.io/mandelbrot.html
* https://github.com/Sparkx120/mandelbrot-js
*
* By: James Wake (SparkX120)
* Copyright (c) 2016 James Wake
*
* MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software a... | void mainImage( out vec4 fragColor, in vec2 fragCoord )
{ |
const float iterations = 512.;
const float maxZoom = 20.;
vec2 R = iResolution.xy; // Resolution Variable
float scale = 0.5*exp2(mod(iTime, maxZoom)); // Set Scale to 2^time and Loop at MaxZoom
vec2 scalar = vec2(3.5,3.5*R.y/R.x)/scale; ... | /**
* Adapted from my Mandelbrot-JS Project
* http://sparkx120.github.io/mandelbrot.html
* https://github.com/Sparkx120/mandelbrot-js
*
* By: James Wake (SparkX120)
* Copyright (c) 2016 James Wake
*
* MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software a... | 1 | 16,281 |
MsVXDt | otaviogood | 2016-07-20T06:51:21 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
2400,
2602,
2636,
2636,
2747
] | [
[
1174,
1203,
1222,
1222,
1267
],
[
1268,
1268,
1287,
1287,
1318
],
[
1319,
1319,
1342,
1342,
1378
],
[
1379,
1379,
1402,
1402,
1473
],
[
1474,
1474,
1496,
1496,
1583
],
[
1584,
1584,
... | // ---- shapes defined by distance fields ----
// See this site for a reference to more distance functions...
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// box distance field
| float sdBox(vec3 p, vec3 radius)
{ |
vec3 dist = abs(p) - radius;
return min(max(dist.x, max(dist.y, dist.z)), 0.0) + length(max(dist, 0.0));
} | // ---- shapes defined by distance fields ----
// See this site for a reference to more distance functions...
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// box distance field
float sdBox(vec3 p, vec3 radius)
{ | 10 | 10 |
MsVXDt | otaviogood | 2016-07-20T06:51:21 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
2888,
3049,
3080,
3080,
4480
] | [
[
1174,
1203,
1222,
1222,
1267
],
[
1268,
1268,
1287,
1287,
1318
],
[
1319,
1319,
1342,
1342,
1378
],
[
1379,
1379,
1402,
1402,
1473
],
[
1474,
1474,
1496,
1496,
1583
],
[
1584,
1584,
... | // This is the function that makes the geometry.
// The input is a position in space.
// The output is the distance to the nearest surface and a material number
| vec2 DistanceToObject(vec3 p)
{ |
float time = localTime*2.0;
float cylRadBig = 1.0;
float cylRadSmall = 0.05;
float freq = 4.0;
float braidRad = 0.15;
float angle = atan(p.z, p.x);
float cylDist = length(p.xz) - cylRadBig;
vec3 cylWarp = vec3(cylDist, p.y, angle);
float amp = sin(angle + time) * 0.5 + 0.5;
flo... | // This is the function that makes the geometry.
// The input is a position in space.
// The output is the distance to the nearest surface and a material number
vec2 DistanceToObject(vec3 p)
{ | 2 | 8 |
ltVGWG | vmednis | 2016-10-15T10:36:55 | /*
Copyright (c) 2016 Valters Mednis
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute,... | mit | [
1147,
1202,
1230,
1230,
1509
] | [
[
1147,
1202,
1230,
1230,
1509
],
[
1511,
1563,
1615,
1683,
2423
],
[
2425,
2550,
2600,
2600,
3127
],
[
3129,
3129,
3186,
3186,
3720
]
] | //Function that returns a complex number to power of 5
| vec2 complexPower5(vec2 c)
{ |
vec2 cRes = c;
for(int i = 1; i < 5; i++)
{
//Multiply the result by the original complex number
vec2 cResCopy = cRes;
cRes.x = (c.x * cResCopy.x) - (c.y * cResCopy.y);
cRes.y = (c.x * cResCopy.y) + (c.y * cResCopy.x);
}
return cRes;
} | //Function that returns a complex number to power of 5
vec2 complexPower5(vec2 c)
{ | 1 | 1 |
ltVGWG | vmednis | 2016-10-15T10:36:55 | /*
Copyright (c) 2016 Valters Mednis
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute,... | mit | [
1511,
1563,
1615,
1683,
2423
] | [
[
1147,
1202,
1230,
1230,
1509
],
[
1511,
1563,
1615,
1683,
2423
],
[
2425,
2550,
2600,
2600,
3127
],
[
3129,
3129,
3186,
3186,
3720
]
] | //Returns the color of a biomorph at position coord
| vec4 colorBiomorph(vec2 coord, vec2 morphConstant)
{ |
vec2 z = coord;
for(int i = 0; i < ITERATIONS_MAX; i++)
{
if((z.x * z.x < EXIT_NUMBER * EXIT_NUMBER) && (z.y * z.y < EXIT_NUMBER * EXIT_NUMBER) && ((z.x * z.x) + (z.y * z.y) < EXIT_NUMBER * EXIT_NUMBER))
{
//z = z^5 + c
z = complexPower5(z) + morphConstant;
}
}... | //Returns the color of a biomorph at position coord
vec4 colorBiomorph(vec2 coord, vec2 morphConstant)
{ | 1 | 1 |
ltVGWG | vmednis | 2016-10-15T10:36:55 | /*
Copyright (c) 2016 Valters Mednis
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute,... | mit | [
2425,
2550,
2600,
2600,
3127
] | [
[
1147,
1202,
1230,
1230,
1509
],
[
1511,
1563,
1615,
1683,
2423
],
[
2425,
2550,
2600,
2600,
3127
],
[
3129,
3129,
3186,
3186,
3720
]
] | //Simple multisampling-antialising
//Effectively the same as rendering the thing in a larger resolution and then downscaling
| vec4 antiAliasedBiomorph(vec2 uv, vec2 constant)
{ |
vec4 result = vec4(0.0, 0.0, 0.0, 0.0);
vec2 sampleStep = 1.0 / iResolution.xy / float(ANTIALIAS_AMOUNT + 1);
for(int i = 1; i < ANTIALIAS_AMOUNT + 1; i++)
{
for(int j = 1; j < ANTIALIAS_AMOUNT + 1; j++)
{
vec2 currentPos = uv;
currentPos.x += sampleStep.x * floa... | //Simple multisampling-antialising
//Effectively the same as rendering the thing in a larger resolution and then downscaling
vec4 antiAliasedBiomorph(vec2 uv, vec2 constant)
{ | 1 | 1 |
4tc3DX | otaviogood | 2016-11-01T07:02:43 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
1074,
1103,
1126,
1126,
1166
] | [
[
1074,
1103,
1126,
1126,
1166
],
[
1168,
1633,
1722,
1772,
3200
],
[
3202,
3286,
3359,
3359,
3539
],
[
3541,
3631,
3727,
3727,
4044
],
[
4046,
4133,
4203,
4203,
4317
],
[
4319,
4413,
... | // Basically a triangle wave
| float repeat(float x) { | return abs(fract(x*0.5+0.5)-0.5)*2.0; } | // Basically a triangle wave
float repeat(float x) { | 1 | 1 |
4tc3DX | otaviogood | 2016-11-01T07:02:43 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
1168,
1633,
1722,
1772,
3200
] | [
[
1074,
1103,
1126,
1126,
1166
],
[
1168,
1633,
1722,
1772,
3200
],
[
3202,
3286,
3359,
3359,
3539
],
[
3541,
3631,
3727,
3727,
4044
],
[
4046,
4133,
4203,
4203,
4317
],
[
4319,
4413,
... | // This is it... what you have been waiting for... _The_ Glorious Line Algorithm.
// This function will make a signed distance field that says how far you are from the edge
// of the line at any point U,V.
// Pass it UVs, line end points, line thickness (x is along the line and y is perpendicular),
// How rounded the e... | float LineDistField(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded, float dashOn) { |
rounded = min(thick.y, rounded);
// midpoint
vec2 mid = (pB + pA) * 0.5;
// vector from point A to B
vec2 delta = pB - pA;
// Distance between endpoints
float lenD = length(delta);
// unit vector pointing in the line's direction
vec2 unit = delta / lenD;
// Check for when line e... | // This is it... what you have been waiting for... _The_ Glorious Line Algorithm.
// This function will make a signed distance field that says how far you are from the edge
// of the line at any point U,V.
// Pass it UVs, line end points, line thickness (x is along the line and y is perpendicular),
// How rounded the e... | 1 | 2 |
4tc3DX | otaviogood | 2016-11-01T07:02:43 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
3202,
3286,
3359,
3359,
3539
] | [
[
1074,
1103,
1126,
1126,
1166
],
[
1168,
1633,
1722,
1772,
3200
],
[
3202,
3286,
3359,
3359,
3539
],
[
3541,
3631,
3727,
3727,
4044
],
[
4046,
4133,
4203,
4203,
4317
],
[
4319,
4413,
... | // This makes a filled line in pixel units. A 1.0 thick line will be 1 pixel thick.
| float FillLinePix(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded) { |
float scale = abs(dFdy(uv).y);
thick = (thick * 0.5 - 0.5) * scale;
float df = LineDistField(uv, pA, pB, vec2(thick), rounded, 0.0);
return saturate(df / scale);
} | // This makes a filled line in pixel units. A 1.0 thick line will be 1 pixel thick.
float FillLinePix(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded) { | 1 | 1 |
4tc3DX | otaviogood | 2016-11-01T07:02:43 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
3541,
3631,
3727,
3727,
4044
] | [
[
1074,
1103,
1126,
1126,
1166
],
[
1168,
1633,
1722,
1772,
3200
],
[
3202,
3286,
3359,
3359,
3539
],
[
3541,
3631,
3727,
3727,
4044
],
[
4046,
4133,
4203,
4203,
4317
],
[
4319,
4413,
... | // This makes an outlined line in pixel units. A 1.0 thick outline will be 1 pixel thick.
| float DrawOutlinePix(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded, float outlineThick) { |
float scale = abs(dFdy(uv).y);
thick = (thick * 0.5 - 0.5) * scale;
rounded = (rounded * 0.5 - 0.5) * scale;
outlineThick = (outlineThick * 0.5 - 0.5) * scale;
float df = LineDistField(uv, pA, pB, vec2(thick), rounded, 0.0);
return saturate((abs(df + outlineThick) - outlineThick) / scale);
} | // This makes an outlined line in pixel units. A 1.0 thick outline will be 1 pixel thick.
float DrawOutlinePix(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded, float outlineThick) { | 1 | 1 |
4tc3DX | otaviogood | 2016-11-01T07:02:43 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
4046,
4133,
4203,
4203,
4317
] | [
[
1074,
1103,
1126,
1126,
1166
],
[
1168,
1633,
1722,
1772,
3200
],
[
3202,
3286,
3359,
3359,
3539
],
[
3541,
3631,
3727,
3727,
4044
],
[
4046,
4133,
4203,
4203,
4317
],
[
4319,
4413,
... | // This makes a line in UV units. A 1.0 thick line will span a whole 0..1 in UV space.
| float FillLine(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded) { |
float df = LineDistField(uv, pA, pB, vec2(thick), rounded, 0.0);
return saturate(df / abs(dFdy(uv).y));
} | // This makes a line in UV units. A 1.0 thick line will span a whole 0..1 in UV space.
float FillLine(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded) { | 1 | 1 |
4tc3DX | otaviogood | 2016-11-01T07:02:43 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
4319,
4413,
4487,
4487,
4601
] | [
[
1074,
1103,
1126,
1126,
1166
],
[
1168,
1633,
1722,
1772,
3200
],
[
3202,
3286,
3359,
3359,
3539
],
[
3541,
3631,
3727,
3727,
4044
],
[
4046,
4133,
4203,
4203,
4317
],
[
4319,
4413,
... | // This makes a dashed line in UV units. A 1.0 thick line will span a whole 0..1 in UV space.
| float FillLineDash(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded) { |
float df = LineDistField(uv, pA, pB, vec2(thick), rounded, 1.0);
return saturate(df / abs(dFdy(uv).y));
} | // This makes a dashed line in UV units. A 1.0 thick line will span a whole 0..1 in UV space.
float FillLineDash(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded) { | 1 | 1 |
4tc3DX | otaviogood | 2016-11-01T07:02:43 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
4603,
4695,
4788,
4788,
4939
] | [
[
1074,
1103,
1126,
1126,
1166
],
[
1168,
1633,
1722,
1772,
3200
],
[
3202,
3286,
3359,
3359,
3539
],
[
3541,
3631,
3727,
3727,
4044
],
[
4046,
4133,
4203,
4203,
4317
],
[
4319,
4413,
... | // This makes an outlined line in UV units. A 1.0 thick outline will span 0..1 in UV space.
| float DrawOutline(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded, float outlineThick) { |
float df = LineDistField(uv, pA, pB, vec2(thick), rounded, 0.0);
return saturate((abs(df + outlineThick) - outlineThick) / abs(dFdy(uv).y));
} | // This makes an outlined line in UV units. A 1.0 thick outline will span 0..1 in UV space.
float DrawOutline(vec2 uv, vec2 pA, vec2 pB, vec2 thick, float rounded, float outlineThick) { | 1 | 1 |
4tc3DX | otaviogood | 2016-11-01T07:02:43 | /*--------------------------------------------------------------------------------------
License CC0 - http://creativecommons.org/publicdomain/zero/1.0/
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This s... | cc0-1.0 | [
4941,
5033,
5082,
5082,
5178
] | [
[
1074,
1103,
1126,
1126,
1166
],
[
1168,
1633,
1722,
1772,
3200
],
[
3202,
3286,
3359,
3359,
3539
],
[
3541,
3631,
3727,
3727,
4044
],
[
4046,
4133,
4203,
4203,
4317
],
[
4319,
4413,
... | // This just draws a point for debugging using a different technique that is less glorious.
| void DrawPoint(vec2 uv, vec2 p, inout vec3 col) { |
col = mix(col, vec3(1.0, 0.25, 0.25), saturate(abs(dFdy(uv).y)*8.0/distance(uv, p)-4.0));
} | // This just draws a point for debugging using a different technique that is less glorious.
void DrawPoint(vec2 uv, vec2 p, inout vec3 col) { | 1 | 1 |
ll3Xzf | iq | 2016-12-05T05:42:03 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
2610,
2635,
2796,
2796,
2966
] | [
[
2175,
2441,
2530,
2530,
2607
],
[
2610,
2635,
2796,
2796,
2966
],
[
2969,
3006,
3070,
3108,
3388
],
[
3390,
3390,
3416,
3416,
3483
]
] | // ray-disk intersection
| float iDisk( in vec3 ro, in vec3 rd, // ray: origin, direction
in vec3 cen, in vec3 nor, float rad ) // disk: center, normal, radius
{ |
vec3 q = ro - cen;
float t = -dot(nor,q)/dot(rd,nor);
if( t<0.0 ) return -1.0;
vec3 d = q + rd*t;
if( dot(d,d)>(rad*rad) ) return -1.0;
return t;
} | // ray-disk intersection
float iDisk( in vec3 ro, in vec3 rd, // ray: origin, direction
in vec3 cen, in vec3 nor, float rad ) // disk: center, normal, radius
{ | 2 | 2 |
ll3Xzf | iq | 2016-12-05T05:42:03 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
2969,
3006,
3070,
3108,
3388
] | [
[
2175,
2441,
2530,
2530,
2607
],
[
2610,
2635,
2796,
2796,
2966
],
[
2969,
3006,
3070,
3108,
3388
],
[
3390,
3390,
3416,
3416,
3483
]
] | // ray-box intersection (simplified)
| vec2 iBox( in vec3 ro, in vec3 rd, in vec3 cen, in vec3 rad )
{ |
vec3 m = 1.0/rd;
vec3 n = m*(ro-cen);
vec3 k = abs(m)*rad;
vec3 t1 = -n - k;
vec3 t2 = -n + k;
float tN = max( max( t1.x, t1.y ), t1.z );
float tF = min( min( t2.x, t2.y ), t2.z );
if( tN > tF || tF < 0.0) return vec2(-1.0);
return vec2( tN, tF );
} | // ray-box intersection (simplified)
vec2 iBox( in vec3 ro, in vec3 rd, in vec3 cen, in vec3 rad )
{ | 5 | 5 |
MtcXRf | iq | 2016-12-05T05:43:39 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
2337,
2607,
2667,
2667,
2826
] | [
[
2337,
2607,
2667,
2667,
2826
],
[
2828,
2879,
3003,
3046,
3781
],
[
3784,
3808,
3872,
3872,
4152
],
[
4155,
4155,
4181,
4181,
4248
]
] | //---------------------------------------------------------------------------------------
// bounding box for a cylinder (http://iquilezles.org/www/articles/diskbbox/diskbbox.htm)
//---------------------------------------------------------------------------------------
| bound3 CylinderAABB( in vec3 pa, in vec3 pb, in float ra )
{ |
vec3 a = pb - pa;
vec3 e = ra*sqrt( 1.0 - a*a/dot(a,a) );
return bound3( min( pa - e, pb - e ),
max( pa + e, pb + e ) );
} | //---------------------------------------------------------------------------------------
// bounding box for a cylinder (http://iquilezles.org/www/articles/diskbbox/diskbbox.htm)
//---------------------------------------------------------------------------------------
bound3 CylinderAABB( in vec3 pa, in vec3 pb, in fl... | 1 | 1 |
MtcXRf | iq | 2016-12-05T05:43:39 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
2828,
2879,
3003,
3046,
3781
] | [
[
2337,
2607,
2667,
2667,
2826
],
[
2828,
2879,
3003,
3046,
3781
],
[
3784,
3808,
3872,
3872,
4152
],
[
4155,
4155,
4181,
4181,
4248
]
] | // ray-cylinder intersetion (returns t and normal)
| vec4 iCylinder( in vec3 ro, in vec3 rd,
in vec3 pa, in vec3 pb, in float ra ) // point a, point b, radius
{ |
vec3 cc = 0.5*(pa+pb);
float ch = length(pb-pa);
vec3 ca = (pb-pa)/ch;
ch *= 0.5;
vec3 oc = ro - cc;
float card = dot(ca,rd);
float caoc = dot(ca,oc);
float a = 1.0 - card*card;
float b = dot( oc, rd) - caoc*card;
float c = dot( oc, oc) - caoc*caoc - ra*ra;
float h =... | // ray-cylinder intersetion (returns t and normal)
vec4 iCylinder( in vec3 ro, in vec3 rd,
in vec3 pa, in vec3 pb, in float ra ) // point a, point b, radius
{ | 1 | 1 |
MtcXRf | iq | 2016-12-05T05:43:39 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
3784,
3808,
3872,
3872,
4152
] | [
[
2337,
2607,
2667,
2667,
2826
],
[
2828,
2879,
3003,
3046,
3781
],
[
3784,
3808,
3872,
3872,
4152
],
[
4155,
4155,
4181,
4181,
4248
]
] | // ray-box intersection
| vec2 iBox( in vec3 ro, in vec3 rd, in vec3 cen, in vec3 rad )
{ |
vec3 m = 1.0/rd;
vec3 n = m*(ro-cen);
vec3 k = abs(m)*rad;
vec3 t1 = -n - k;
vec3 t2 = -n + k;
float tN = max( max( t1.x, t1.y ), t1.z );
float tF = min( min( t2.x, t2.y ), t2.z );
if( tN > tF || tF < 0.0) return vec2(-1.0);
return vec2( tN, tF );
} | // ray-box intersection
vec2 iBox( in vec3 ro, in vec3 rd, in vec3 cen, in vec3 rad )
{ | 5 | 5 |
Xt3SzX | iq | 2016-12-03T01:02:35 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
1650,
1742,
1824,
1824,
2512
] | [
[
1650,
1742,
1824,
1824,
2512
],
[
2514,
2532,
2597,
2597,
2723
],
[
2726,
2744,
2822,
2822,
3036
],
[
3038,
3038,
3066,
3066,
3256
]
] | // intersect capsule : http://www.iquilezles.org/www/articles/intersectors/intersectors.htm
| float capIntersect( in vec3 ro, in vec3 rd, in vec3 pa, in vec3 pb, in float r )
{ |
vec3 ba = pb - pa;
vec3 oa = ro - pa;
float baba = dot(ba,ba);
float bard = dot(ba,rd);
float baoa = dot(ba,oa);
float rdoa = dot(rd,oa);
float oaoa = dot(oa,oa);
float a = baba - bard*bard;
float b = baba*rdoa - baoa*bard;
float c = baba*oaoa - baoa*baoa - r*r*baba;
... | // intersect capsule : http://www.iquilezles.org/www/articles/intersectors/intersectors.htm
float capIntersect( in vec3 ro, in vec3 rd, in vec3 pa, in vec3 pb, in float r )
{ | 2 | 6 |
Xt3SzX | iq | 2016-12-03T01:02:35 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
2514,
2532,
2597,
2597,
2723
] | [
[
1650,
1742,
1824,
1824,
2512
],
[
2514,
2532,
2597,
2597,
2723
],
[
2726,
2744,
2822,
2822,
3036
],
[
3038,
3038,
3066,
3066,
3256
]
] | // compute normal
| vec3 capNormal( in vec3 pos, in vec3 a, in vec3 b, in float r )
{ |
vec3 ba = b - a;
vec3 pa = pos - a;
float h = clamp(dot(pa,ba)/dot(ba,ba),0.0,1.0);
return (pa - h*ba)/r;
} | // compute normal
vec3 capNormal( in vec3 pos, in vec3 a, in vec3 b, in float r )
{ | 5 | 5 |
XttSz2 | iq | 2016-12-02T07:48:27 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
3586,
3623,
3674,
3674,
3942
] | [
[
1526,
1526,
1549,
1549,
1585
],
[
1768,
1768,
1794,
1794,
2629
],
[
2698,
2698,
2751,
2751,
2929
],
[
2931,
2931,
2955,
2955,
3380
],
[
3382,
3382,
3405,
3405,
3584
],
[
3586,
3623,
... | // ray-box intersection in box space
| vec2 iBox( in vec3 ro, in vec3 rd, in vec3 rad )
{ |
vec3 m = 1.0/rd;
vec3 n = m*ro;
vec3 k = abs(m)*rad;
vec3 t1 = -n - k;
vec3 t2 = -n + k;
float tN = max( max( t1.x, t1.y ), t1.z );
float tF = min( min( t2.x, t2.y ), t2.z );
if( tN > tF || tF < 0.0) return vec2(-1.0);
return vec2( tN, tF );
} | // ray-box intersection in box space
vec2 iBox( in vec3 ro, in vec3 rd, in vec3 rad )
{ | 4 | 24 |
XttSz2 | iq | 2016-12-02T07:48:27 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
3944,
3956,
3999,
3999,
4438
] | [
[
1526,
1526,
1549,
1549,
1585
],
[
1768,
1768,
1794,
1794,
2629
],
[
2698,
2698,
2751,
2751,
2929
],
[
2931,
2931,
2955,
2955,
3380
],
[
3382,
3382,
3405,
3405,
3584
],
[
3586,
3623,
... | // raymarch
| vec4 interesect( in vec3 ro, in vec3 rd )
{ |
vec4 res = vec4(-1.0);
// bounding volume
vec2 dis = iBox( ro, rd, vec3(1.5) ) ;
if( dis.y<0.0 ) return res;
// raymarch
float tmax = dis.y;
float t = dis.x;
for( int i=0; i<128; i++ )
{
vec3 pos = ro + t*rd;
vec4 hnor = map( pos );
res = vec4(t,hnor.yzw);
... | // raymarch
vec4 interesect( in vec3 ro, in vec3 rd )
{ | 1 | 3 |
XttSz2 | iq | 2016-12-02T07:48:27 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
4779,
4905,
4941,
4941,
5205
] | [
[
1526,
1526,
1549,
1549,
1585
],
[
1768,
1768,
1794,
1794,
2629
],
[
2698,
2698,
2751,
2751,
2929
],
[
2931,
2931,
2955,
2955,
3380
],
[
3382,
3382,
3405,
3405,
3584
],
[
3586,
3623,
... | // fibonazzi points in s aphsre, more info:
// http://lgdv.cs.fau.de/uploads/publications/spherical_fibonacci_mapping_opt.pdf
| vec3 forwardSF( float i, float n)
{ |
const float PI = 3.141592653589793238;
const float PHI = 1.618033988749894848;
float phi = 2.0*PI*fract(i/PHI);
float zi = 1.0 - (2.0*i+1.0)/n;
float sinTheta = sqrt( 1.0 - zi*zi);
return vec3( cos(phi)*sinTheta, sin(phi)*sinTheta, zi);
} | // fibonazzi points in s aphsre, more info:
// http://lgdv.cs.fau.de/uploads/publications/spherical_fibonacci_mapping_opt.pdf
vec3 forwardSF( float i, float n)
{ | 15 | 21 |
Mt3SWX | iq | 2017-01-08T04:48:49 | // The MIT License
// Copyright © 2016 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
4619,
4631,
4689,
4689,
5181
] | [
[
1201,
1201,
1224,
1224,
1260
],
[
1494,
1494,
1533,
1533,
3128
],
[
3197,
3197,
3250,
3250,
3428
],
[
3430,
3430,
3466,
3466,
3939
],
[
3941,
3941,
3976,
3976,
4259
],
[
4261,
4298,
... | // raymarch
| vec4 interesect( in vec3 ro, in vec3 rd, out mat3 resS )
{ |
vec4 res = vec4(-1.0);
resS = mat3(0.0);
// bounding volume
vec2 dis = iBox( ro, rd, vec3(1.5) ) ;
if( dis.y<0.0 ) return res;
// raymarch
float tmax = dis.y;
float t = dis.x;
for( int i=0; i<128; i++ )
{
vec3 pos = ro + t*rd;
mat3 dd;
vec4 hnor = map( pos, dd );
... | // raymarch
vec4 interesect( in vec3 ro, in vec3 rd, out mat3 resS )
{ | 1 | 1 |
XdXBRH | iq | 2017-05-14T07:01:57 | // The MIT License
// Copyright © 2017 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
2142,
2202,
2228,
2228,
3094
] | [
[
1940,
1940,
2001,
2001,
2139
],
[
2142,
2202,
2228,
2228,
3094
],
[
3148,
3148,
3205,
3205,
3404
]
] | // return gradient noise (in x) and its derivatives (in yz)
| vec3 noised( in vec2 p )
{ |
vec2 i = floor( p );
vec2 f = fract( p );
#if 1
// quintic interpolation
vec2 u = f*f*f*(f*(f*6.0-15.0)+10.0);
vec2 du = 30.0*f*f*(f*(f-2.0)+1.0);
#else
// cubic interpolation
vec2 u = f*f*(3.0-2.0*f);
vec2 du = 6.0*f*(1.0-f);
#endif
vec2 ga = hash( i + vec2(0.0,0.0) );
... | // return gradient noise (in x) and its derivatives (in yz)
vec3 noised( in vec2 p )
{ | 23 | 26 |
XtBfzz | iq | 2017-12-25T05:25:25 | // The MIT License
// Copyright © 2017 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
1401,
1415,
1480,
1498,
1799
] | [
[
1401,
1415,
1480,
1498,
1799
],
[
1829,
1829,
1861,
1880,
2143
],
[
2564,
2564,
2627,
2627,
2850
],
[
2852,
2852,
2910,
2910,
3018
],
[
3020,
3020,
3074,
3074,
3260
],
[
3861,
3861,
... | // grid ratio
| float gridTextureGradBox( in vec2 p, in vec2 ddx, in vec2 ddy )
{ |
vec2 w = max(abs(ddx), abs(ddy)) + 0.01;
// analytic (box) filtering
vec2 a = p + 0.5*w;
vec2 b = p - 0.5*w;
vec2 i = (floor(a)+min(fract(a)*N,1.0)-
floor(b)-min(fract(b)*N,1.0))/(N*w);
//pattern
return (1.0-i.x)*(1.0-i.y);
} | // grid ratio
float gridTextureGradBox( in vec2 p, in vec2 ddx, in vec2 ddy )
{ | 2 | 6 |
4dKfDV | iq | 2018-07-03T04:37:50 | // The MIT License
// Copyright © 2018 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publ... | mit | [
1333,
1388,
1412,
1412,
1545
] | [
[
1244,
1244,
1268,
1268,
1331
],
[
1333,
1388,
1412,
1412,
1545
],
[
1547,
1547,
1587,
1600,
1924
],
[
1927,
1927,
1975,
1975,
2234
],
[
2236,
2236,
2269,
2269,
2591
]
] | // gradient/derivative of map (common factors removed)
| vec3 dmap( in vec3 p )
{ |
return p*(1.0 - vec3(1,0,1)*torus.x/length(p.xz));
//return p*(dot(p,p)-torus.y*torus.y-torus.x*torus.x*vec3(1.0,-1.0,1.0));
} | // gradient/derivative of map (common factors removed)
vec3 dmap( in vec3 p )
{ | 1 | 1 |
lldyzM | ollj | 2018-07-20T10:46:29 | //self https://www.shadertoy.com/view/lldyzM
//analytical filter kernel,triangular
//https://www.shadertoy.com/view/llffWs
// Similar to https://www.shadertoy.com/view/XlXBWs,but with a triangular filter kernel,
// which produces less flickering animations that a box filter. Luckily,it's still easily
// http://iquile... | mit | [
3872,
3952,
3992,
3992,
4018
] | [
[
3872,
3952,
3992,
3992,
4018
],
[
4018,
4067,
4089,
4089,
4114
],
[
4114,
4262,
4285,
4285,
4314
],
[
4314,
4334,
4357,
4357,
4386
],
[
4386,
4403,
4426,
4426,
4455
],
[
4455,
4482,
... | //and this ray-transpose function is the strangest of em all to be useful here:
| void rayTransp(inout v33 a,inout v33 b){ | vec3 s=a.b;a.b=b.a;b.a=s;} | //and this ray-transpose function is the strangest of em all to be useful here:
void rayTransp(inout v33 a,inout v33 b){ | 1 | 1 |
lldyzM | ollj | 2018-07-20T10:46:29 | //self https://www.shadertoy.com/view/lldyzM
//analytical filter kernel,triangular
//https://www.shadertoy.com/view/llffWs
// Similar to https://www.shadertoy.com/view/XlXBWs,but with a triangular filter kernel,
// which produces less flickering animations that a box filter. Luckily,it's still easily
// http://iquile... | mit | [
4018,
4067,
4089,
4089,
4114
] | [
[
3872,
3952,
3992,
3992,
4018
],
[
4018,
4067,
4089,
4089,
4114
],
[
4114,
4262,
4285,
4285,
4314
],
[
4314,
4334,
4357,
4357,
4386
],
[
4386,
4403,
4426,
4426,
4455
],
[
4455,
4482,
... | //swap direction(.b)of [a] with origin(.a)of [b]
| v33 sub(v33 a,vec3 b){ | return v33(a.a-b,a.b-b);} | //swap direction(.b)of [a] with origin(.a)of [b]
v33 sub(v33 a,vec3 b){ | 1 | 1 |
lldyzM | ollj | 2018-07-20T10:46:29 | //self https://www.shadertoy.com/view/lldyzM
//analytical filter kernel,triangular
//https://www.shadertoy.com/view/llffWs
// Similar to https://www.shadertoy.com/view/XlXBWs,but with a triangular filter kernel,
// which produces less flickering animations that a box filter. Luckily,it's still easily
// http://iquile... | mit | [
4114,
4262,
4285,
4285,
4314
] | [
[
3872,
3952,
3992,
3992,
4018
],
[
4018,
4067,
4089,
4089,
4114
],
[
4114,
4262,
4285,
4285,
4314
],
[
4314,
4334,
4357,
4357,
4386
],
[
4386,
4403,
4426,
4426,
4455
],
[
4455,
4482,
... | //substract b from all ray components
//component wise ray substraction(this one is a bit odd,differential wise,is basically scaling a rays points)
| v33 subc(v33 a,v33 b){ | return v33(a.a-b.a,a.b-b.b);} | //substract b from all ray components
//component wise ray substraction(this one is a bit odd,differential wise,is basically scaling a rays points)
v33 subc(v33 a,v33 b){ | 1 | 1 |
lldyzM | ollj | 2018-07-20T10:46:29 | //self https://www.shadertoy.com/view/lldyzM
//analytical filter kernel,triangular
//https://www.shadertoy.com/view/llffWs
// Similar to https://www.shadertoy.com/view/XlXBWs,but with a triangular filter kernel,
// which produces less flickering animations that a box filter. Luckily,it's still easily
// http://iquile... | mit | [
4455,
4482,
4503,
4503,
4543
] | [
[
3872,
3952,
3992,
3992,
4018
],
[
4018,
4067,
4089,
4089,
4114
],
[
4114,
4262,
4285,
4285,
4314
],
[
4314,
4334,
4357,
4357,
4386
],
[
4386,
4403,
4426,
4426,
4455
],
[
4455,
4482,
... | //v33-differentials for AA
| vec2 dt(v33 a,v33 b){ | return vec2(dot(a.a,b.a),dot(a.b,b.b));} | //v33-differentials for AA
vec2 dt(v33 a,v33 b){ | 1 | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.