学生作品選集
2022年度授業「コンピュータグラフィックス特論」の生徒作品を紹介します。一つのフラグメントシェーダーを使って蘭の花の画像を生成Aすることが目的でした。もし興味あったら宿題の説明をご覧ください。
// credit: Is
// frog: Ranitomeya amazonica
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float random(vec2 co) {
const highp float seed = 12.9898;
highp float a = seed;
highp float b = 78.233, c = 43758.5453;
highp float dt = dot(co.xy, vec2(a, b));
highp float sn = mod(dt, 3.14159265358979323846);
return fract(sin(sn) * c);
}
vec2 random2(vec2 p) { return vec2(random(p), random(p * 1000.0)); }
float stripe(vec2 st) {
float min_dist = 100.;
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec2 neighbor = vec2(float(x), float(y));
vec2 point = random2(floor(st) + neighbor);
point = 0.5 * sin(u_time + 8.155 * point);
min_dist =
min(min_dist, length(neighbor + point - (st - floor(st))));
}
}
return min_dist * abs(sin(st.x * 7.288));
}
float dots(vec2 st, float r) {
float min_dist = 100.;
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec2 neighbor = vec2(float(x), float(y));
vec2 point = random2(floor(st) + neighbor);
min_dist =
min(min_dist, length(neighbor + point - (st - floor(st))));
}
}
return step(r, min_dist);
}
float fbm_dots(in vec2 st) {
float value = 1.0;
float r = 0.208;
st *= 6.952;
st += vec2(10.0, 100.0) + u_time * 0.452;
for (int i = 0; i < 6; i++) {
value = min(value, dots(st, r));
st *= 1.312;
}
return value;
}
void main() {
vec2 st = gl_FragCoord.xy / u_resolution.xy * 0.764 - -0.116;
st = vec2(st.y, 1.0 - st.x); // rotate
float mask = 1.000;
{
// right eye
vec2 st1 = st - vec2(0.730, 0.700);
st1.x = -0.160 - st1.x;
vec2 p = vec2(-0.010, 0.000);
if (0.001 > 1.0 * pow(st1.x - p.x, 2.0) + 1.0 * pow(st1.y - p.y, 2.0)) {
colour_out = vec4(vec3(0.0), 1.0);
if (0.0001 > 1.0 * pow(st1.x - p.x + 0.01 * sin(u_time), 2.0) +
1.0 * pow(st1.y - p.y + 0.01 * sin(u_time), 2.0)) {
colour_out = vec4(vec3(1.0), 1.0);
}
return;
}
}
{
// left eye
vec2 st1 = st - vec2(0.580, 0.700);
st1.x = -0.160 - st1.x;
vec2 p = vec2(0.000, 0.000);
if (0.001 > 1.0 * pow(st1.x - p.x, 2.0) + 1.0 * pow(st1.y - p.y, 2.0)) {
colour_out = vec4(vec3(0.0), 1.0);
if (0.0001 >
1.0 * pow(st1.x - p.x - 0.01 * cos(u_time - 3.14 / 2.0), 2.0) +
1.0 * pow(st1.y - p.y + 0.01 * cos(u_time - 3.14 / 2.0),
2.0)) {
colour_out = vec4(vec3(1.0), 1.0);
}
return;
}
}
{
// body
if ((0.282 >
distance(vec2(st.x * 2.508, st.y), vec2(2.508 / 2.0, 0.5)) ||
0.178 > distance(vec2(st.x * 1.276, st.y),
vec2(1.276 / 2.0, 0.396))) &&
abs(st.x - 0.5) + st.y - 0.648 <= 0.120) {
st *= 7.616;
colour_out =
vec4(step(0.236, stripe(st)) * mix(vec3(0.865, 0.854, 0.019),
vec3(0.865, 0.383, 0.006),
abs(sin(u_time))),
1.0);
return;
}
}
{
// right back leg
vec2 st1 = st - vec2(0.110, -0.190);
mask *= step(0.003, 1.0 * pow(st1.x - 0.5, 2.000) +
1.0 * pow(st1.y - 0.5, 2.0) +
-1.320 * (st1.x - 0.5) * (st1.y - 0.5));
vec2 p1 = vec2(0.516, 0.476);
mask *= step(0.005, 2.520 * pow(st1.x - p1.x, 2.0) +
1.0 * pow(st1.y - p1.y, 2.0) +
-2.176 * (st1.x - p1.x) * (st1.y - p1.y));
vec2 p2 = vec2(0.548, 0.468);
mask *= step(0.002, 1.480 * pow(st1.x - p2.x, 2.0) +
1.0 * pow(st1.y - p2.y, 2.0) +
-2.120 * (st1.x - p2.x) * (st1.y - p2.y));
vec2 p3 = vec2(0.620, 0.556);
mask *= step(0.0001, 1.480 * pow(st1.x - p3.x, 2.0) +
1.0 * pow(st1.y - p3.y, 2.0) +
-2.312 * (st1.x - p3.x) * (st1.y - p3.y));
vec2 p4 = vec2(0.604, 0.564);
mask *= step(0.00015, 2.800 * pow(st1.x - p4.x, 2.0) +
1.0 * pow(st1.y - p4.y, 2.0) +
-2.960 * (st1.x - p4.x) * (st1.y - p4.y));
vec2 p5 = vec2(0.644, 0.556);
mask *= step(0.00015, 0.920 * pow(st1.x - p5.x, 2.0) +
2.960 * pow(st1.y - p5.y, 2.0) +
-2.616 * (st1.x - p5.x) * (st1.y - p5.y));
vec2 p6 = vec2(0.636, 0.540);
mask *= step(0.00028, 0.544 * pow(st1.x - p6.x, 2.0) +
6.888 * pow(st1.y - p6.y, 2.0));
}
{
// right front leg
vec2 st1 = st - vec2(0.090, 0.040);
vec2 p1 = vec2(0.508, 0.492);
mask *= step(0.005, 2.216 * pow(st1.x - p1.x, 2.0) +
2.352 * pow(st1.y - p1.y, 2.0) +
3.368 * (st1.x - p1.x) * (st1.y - p1.y));
vec2 p2 = vec2(0.572, 0.508);
mask *= step(0.002, 5.400 * pow(st1.x - p2.x, 2.0) +
0.368 * pow(st1.y - p2.y, 2.0) +
0.832 * (st1.x - p2.x) * (st1.y - p2.y));
vec2 p3 = vec2(0.584, 0.592);
mask *= step(0.0001, 1.480 * pow(st1.x - p3.x, 2.0) +
1.0 * pow(st1.y - p3.y, 2.0) +
-2.312 * (st1.x - p3.x) * (st1.y - p3.y));
vec2 p4 = vec2(0.576, 0.600);
mask *= step(0.00015, 2.800 * pow(st1.x - p4.x, 2.0) +
1.0 * pow(st1.y - p4.y, 2.0) +
-2.960 * (st1.x - p4.x) * (st1.y - p4.y));
vec2 p5 = vec2(0.6, 0.592);
mask *= step(0.00015, 0.920 * pow(st1.x - p5.x, 2.0) +
2.960 * pow(st1.y - p5.y, 2.0) +
-2.616 * (st1.x - p5.x) * (st1.y - p5.y));
vec2 p6 = vec2(0.592, 0.578);
mask *= step(0.00028, 0.544 * pow(st1.x - p6.x, 2.0) +
6.888 * pow(st1.y - p6.y, 2.0));
}
{
// left back leg
vec2 st1 = st - vec2(0.110, -0.190);
st1.x = 0.784 - st1.x;
mask *= step(0.003, 1.0 * pow(st1.x - 0.5, 2.000) +
1.0 * pow(st1.y - 0.5, 2.0) +
-1.320 * (st1.x - 0.5) * (st1.y - 0.5));
vec2 p1 = vec2(0.516, 0.476);
mask *= step(0.005, 2.520 * pow(st1.x - p1.x, 2.0) +
1.0 * pow(st1.y - p1.y, 2.0) +
-2.176 * (st1.x - p1.x) * (st1.y - p1.y));
vec2 p2 = vec2(0.548, 0.468);
mask *= step(0.002, 1.480 * pow(st1.x - p2.x, 2.0) +
1.0 * pow(st1.y - p2.y, 2.0) +
-2.120 * (st1.x - p2.x) * (st1.y - p2.y));
vec2 p3 = vec2(0.620, 0.556);
mask *= step(0.0001, 1.480 * pow(st1.x - p3.x, 2.0) +
1.0 * pow(st1.y - p3.y, 2.0) +
-2.312 * (st1.x - p3.x) * (st1.y - p3.y));
vec2 p4 = vec2(0.604, 0.564);
mask *= step(0.00015, 2.800 * pow(st1.x - p4.x, 2.0) +
1.0 * pow(st1.y - p4.y, 2.0) +
-2.960 * (st1.x - p4.x) * (st1.y - p4.y));
vec2 p5 = vec2(0.644, 0.556);
mask *= step(0.00015, 0.920 * pow(st1.x - p5.x, 2.0) +
2.960 * pow(st1.y - p5.y, 2.0) +
-2.616 * (st1.x - p5.x) * (st1.y - p5.y));
vec2 p6 = vec2(0.636, 0.540);
mask *= step(0.00028, 0.544 * pow(st1.x - p6.x, 2.0) +
6.888 * pow(st1.y - p6.y, 2.0));
}
{
// left front leg
vec2 st1 = vec2(-st.x, st.y) - vec2(-0.910, 0.040);
vec2 p1 = vec2(0.508, 0.492);
mask *= step(0.005, 2.216 * pow(st1.x - p1.x, 2.0) +
2.352 * pow(st1.y - p1.y, 2.0) +
3.368 * (st1.x - p1.x) * (st1.y - p1.y));
vec2 p2 = vec2(0.572, 0.508);
mask *= step(0.002, 5.400 * pow(st1.x - p2.x, 2.0) +
0.368 * pow(st1.y - p2.y, 2.0) +
0.832 * (st1.x - p2.x) * (st1.y - p2.y));
vec2 p3 = vec2(0.584, 0.592);
mask *= step(0.0001, 1.480 * pow(st1.x - p3.x, 2.0) +
1.0 * pow(st1.y - p3.y, 2.0) +
-2.312 * (st1.x - p3.x) * (st1.y - p3.y));
vec2 p4 = vec2(0.576, 0.600);
mask *= step(0.00015, 2.800 * pow(st1.x - p4.x, 2.0) +
1.0 * pow(st1.y - p4.y, 2.0) +
-2.960 * (st1.x - p4.x) * (st1.y - p4.y));
vec2 p5 = vec2(0.6, 0.592);
mask *= step(0.00015, 0.920 * pow(st1.x - p5.x, 2.0) +
2.960 * pow(st1.y - p5.y, 2.0) +
-2.616 * (st1.x - p5.x) * (st1.y - p5.y));
vec2 p6 = vec2(0.592, 0.578);
mask *= step(0.00028, 0.544 * pow(st1.x - p6.x, 2.0) +
6.888 * pow(st1.y - p6.y, 2.0));
}
if (mask == 0.0) {
// legs
colour_out = fbm_dots(st) * vec4(vec3(0.037, 0.475, 1.000), 1.0);
return;
} else {
// leaf
colour_out =
vec4(mix(vec3(0.221, 0.560, 0.044), vec3(0.320, 0.735, 0.235),
abs(sin(st.y * 100.0 + u_time * 5.0))),
1.0);
}
}
Ranitomeya amazonica by Is
// credit: ksaki73
// frog: Dendrobates auratus
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float sdCircle( vec2 p, float r ){
return length(p) - r;
}
vec4 light(in vec2 p, float size){
float x = u_resolution.x * p.x;
float y = u_resolution.y * p.y;
vec2 pos = vec2(x, y);
float dist = length(gl_FragCoord.xy - pos);
float color = pow(size / dist, 2.0);
return vec4(vec3(color), 1.0);
}
float sdEgg(in vec2 p, in float ra, in float rb, in float angle){
mat3 c = mat3(cos(angle), -1.0*sin(angle), 0,
sin(angle), cos(angle), 0,
0, 0, 1.0);
vec3 new_p = c * vec3(p.xy, 1.0);
const float k = sqrt(3.0);
float r = ra - rb;
new_p.x = abs(new_p.x);
return ((new_p.y<0.0) ? length(vec2(new_p.x, new_p.y )) - r :
(k*(new_p.x+r)<new_p.y) ? length(vec2(new_p.x, new_p.y-k*r)) :
length(vec2(new_p.x+r,new_p.y )) - 2.0*r)-rb;
}
float sdArc( in vec2 p, in vec2 sc, in float ra, float rb , in float angle){
mat3 c = mat3(cos(angle), -1.0*sin(angle), 0,
sin(angle), cos(angle), 0,
0, 0, 1.0);
vec3 new_p = c * vec3(p.xy, 1.0);
new_p.x = abs(new_p.x);
return ((sc.y*new_p.x>sc.x*new_p.y) ? length(new_p.xy-sc*ra) :
abs(length(new_p.xy)-ra)) - rb;
}
vec2 sincos(in float angle){
return vec2(sin(angle),cos(angle));
}
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec3 permute(vec3 x) {
return mod289(((x*34.0)+10.0)*x);
}
float snoise(vec2 v){
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
vec2 i1;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
i = mod289(i);
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 )) + i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
float fbm(vec2 p){
float f = 0.0, scale;
for (int i=0; i<4; i++){
scale = pow(pow(2.0, 4.0/3.0), float(i));
f += snoise(p*scale) / scale;
}
return f;
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
float noise = fbm(st/0.03);
int color=0;
float r = 0.2;
vec2 h_light;
if (sdArc(st-vec2(0.500,0.620), sincos(0.3), 0.2, 0.015, 2.164)<=0.0) color = 1; //l-f fing
if (sdArc(st-vec2(0.450,0.620), sincos(0.3), 0.2, 0.015, 2.364)<=0.0) {
color = 1; //l-f fing
if (sdEgg(st-vec2(0.240,0.520), 0.08, 0.1, -1.348) <= 0.0) color = 2;
}
if (sdArc(st-vec2(0.380,0.420), sincos(0.3), 0.2, 0.015, 2.364)<=0.0) {
color = 1; //l-b fing
if (sdEgg(st-vec2(0.170,0.350), 0.08, 0.1, -0.900) <= 0.0) color = 2;
}
if (sdArc(st-vec2(0.460,0.400), sincos(0.3), 0.2, 0.015, 1.948)<=0.0) color = 1; //l-b fing
if (sdArc(st-vec2(0.500,0.620), sincos(0.3), 0.2, 0.015, -2.164)<=0.0) {
color = 1;
if (sdEgg(st-vec2(0.760,0.560), 0.08, 0.1, -1.348) <= 0.0) color = 2;
}
if (sdArc(st-vec2(0.55,0.620), sincos(0.3), 0.2, 0.015, -2.364)<=0.0) {
color = 1;
if (sdEgg(st-vec2(0.760,0.560), 0.08, 0.1, -1.348) <= 0.0) color = 2;
}
if (sdArc(st-vec2(0.62,0.420), sincos(0.3), 0.2, 0.015, -2.364)<=0.0) color = 1;
if (sdArc(st-vec2(0.54,0.400), sincos(0.3), 0.2, 0.015, -1.948)<=0.0) {
color = 1;
if (sdEgg(st-vec2(0.760,0.440), 0.08, 0.1, -0.900) <= 0.0) color = 2;
}
if (sdEgg(st-vec2(0.350,0.230), 0.10, 0.05, 0.65) <= 0.0){
color = 1;
if (sdArc(st-vec2(0.250,0.100), sincos(0.5), 0.1, 0.02, -0.690)<=0.0) color = 2;
if (sdEgg(st-vec2(0.420,0.120), 0.08, 0.1, -0.900) <= 0.0) color = 2;
}
if (sdEgg(st-vec2(0.650,0.230), 0.10, 0.05, -0.65) <= 0.0){
color = 1;
if (sdArc(st-vec2(0.750,0.100), sincos(0.5), 0.1, 0.02, 0.690)<=0.0) color = 2;
if (sdEgg(st-vec2(0.580,0.120), 0.08, 0.1, 0.900) <= 0.0) color = 2;
}
if (sdEgg(st-vec2(0.5,0.3), 0.2, 0.0, 0.0) <= 0.0) {
color = 1;
if (sdEgg(st-vec2(0.360,0.370), 0.08, 0.01, -2.3) <= 0.0) color = 2;
if (sdEgg(st-vec2(1.0-0.360,0.370), 0.08, 0.01, 2.3) <= 0.0) color = 2;
if (sdEgg(st-vec2(0.420,0.120), 0.08, 0.1, -0.900) <= 0.0) color = 2;
if (sdEgg(st-vec2(0.580,0.120), 0.08, 0.1, 0.900) <= 0.0) color = 2;
}
if (sdArc(st-vec2(0.500,0.220), sincos(0.5), 0.1, 0.02, 3.14)<=0.0) color = 2;
if (sdEgg(st-vec2(0.500,0.650), 0.07, 0.06, 0.0) <= 0.0) color = 1;
if (sdEgg(st-vec2(0.500,0.520), 0.15, 0.11, 0.0) <= 0.0) color = 1;
if (sdEgg(st-vec2(0.500,0.520), 0.15, 0.11, 0.0) <= 0.0) color = 1;
if (sdEgg(st-vec2(0.500,0.550), 0.11, 0.03, 3.14) <= 0.0) color = 2;
if (sdEgg(st-vec2(0.500,0.590), 0.09, 0.1, 0.0) <= 0.0) color = 2;
if (sdEgg(st-vec2(0.500,0.270), 0.07, 0.08, 0.0) <= 0.0) color = 2; // low circle
if (sdArc(st-vec2(0.610,0.463), sincos(0.2), 0.2, 0.02, -3.984)<=0.0) color = 2;
if (sdArc(st-vec2(0.390,0.463), sincos(0.2), 0.2, 0.02, 3.984)<=0.0) color = 2;
if (sdEgg(st-vec2(0.400,0.650), 0.04, 0.08, -2.290) <= 0.0) color = 2; //eye
if (sdEgg(st-vec2(0.600,0.650), 0.04, 0.08, 2.290) <= 0.0) color = 2; //eye
if (color==1) colour_out = vec4(121.0/255.0,219.0/255.0, 209.0/255.0, noise/4.0 +1.0 ) ;
else if (color==2) colour_out = vec4(0.0, 0.0, 0.0, 1.0 );
else colour_out = vec4(1.0,1.0,1.0,1.0);
if (sdEgg(st-vec2(0.400,0.650), 0.04, 0.08, -2.290) <= 0.0) {
color = 2; //eye
h_light = vec2(0.400,0.670);
if (sdCircle(st-h_light, 0.02) <= 0.0) colour_out = light(h_light, 2.0);
}
if (sdEgg(st-vec2(0.600,0.650), 0.04, 0.08, 2.290) <= 0.0) {
color = 2; //eye
h_light = vec2(0.600,0.670);
if (sdCircle(st-h_light, 0.02) <= 0.0) colour_out = light(h_light, 2.0);
}
}
Dendrobates auratus by ksaki73
// credit: hosono
// frog: Dendrobates auratus
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float M_PI = 3.14159265359;
vec4 mod289(vec4 x)
{
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 permute(vec4 x)
{
return mod289(((x*34.0)+10.0)*x);
}
vec4 taylorInvSqrt(vec4 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
vec2 fade(vec2 t) {
return t*t*t*(t*(t*6.0-15.0)+10.0);
}
// Classic Perlin noise
float cnoise(vec2 P)
{
vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);
vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);
Pi = mod289(Pi); // To avoid truncation effects in permutation
vec4 ix = Pi.xzxz;
vec4 iy = Pi.yyww;
vec4 fx = Pf.xzxz;
vec4 fy = Pf.yyww;
vec4 i = permute(permute(ix) + iy);
vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
vec4 gy = abs(gx) - 0.5 ;
vec4 tx = floor(gx + 0.5);
gx = gx - tx;
vec2 g00 = vec2(gx.x,gy.x);
vec2 g10 = vec2(gx.y,gy.y);
vec2 g01 = vec2(gx.z,gy.z);
vec2 g11 = vec2(gx.w,gy.w);
vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
float n00 = dot(g00, vec2(fx.x, fy.x));
float n10 = dot(g10, vec2(fx.y, fy.y));
float n01 = dot(g01, vec2(fx.z, fy.z));
float n11 = dot(g11, vec2(fx.w, fy.w));
vec2 fade_xy = fade(Pf.xy);
vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
float n_xy = mix(n_x.x, n_x.y, fade_xy.y);
return 2.3 * n_xy;
}
float sdEllipse(vec2 p, vec2 ab)
{
p = abs(p); if( p.x > p.y ) {p=p.yx;ab=ab.yx;}
float l = ab.y*ab.y - ab.x*ab.x;
float m = ab.x*p.x/l; float m2 = m*m;
float n = ab.y*p.y/l; float n2 = n*n;
float c = (m2+n2-1.0)/3.0; float c3 = c*c*c;
float q = c3 + m2*n2*2.0;
float d = c3 + m2*n2;
float g = m + m*n2;
float co;
if( d<0.0 )
{
float h = acos(q/c3)/3.0;
float s = cos(h);
float t = sin(h)*sqrt(3.0);
float rx = sqrt( -c*(s + t + 2.0) + m2 );
float ry = sqrt( -c*(s - t + 2.0) + m2 );
co = (ry+sign(l)*rx+abs(g)/(rx*ry)- m)/2.0;
}
else
{
float h = 2.0*m*n*sqrt( d );
float s = sign(q+h)*pow(abs(q+h), 1.0/3.0);
float u = sign(q-h)*pow(abs(q-h), 1.0/3.0);
float rx = -s - u - c*4.0 + 2.0*m2;
float ry = (s - u)*sqrt(3.0);
float rm = sqrt( rx*rx + ry*ry );
co = (ry/sqrt(rm-rx)+2.0*g/rm-m)/2.0;
}
vec2 r = ab * vec2(co, sqrt(1.0-co*co));
return length(r-p) * sign(p.y-r.y);
}
float sdEquilateralTriangle(vec2 p)
{
const float k = sqrt(3.0);
p.x = abs(p.x) - 1.0;
p.y = p.y + 1.0/k;
if( p.x+k*p.y>0.0 ) p = vec2(p.x-k*p.y,-k*p.x-p.y)/2.0;
p.x -= clamp( p.x, -2.0, 0.0 );
return -length(p)*sign(p.y);
}
float sdMainBody(vec2 P, vec2 slides, float theta) {
theta = 2.0 * M_PI * theta / 360.0;
mat2 R = mat2(cos(theta), -sin(theta), sin(theta), cos(theta));
return sdEllipse(R * (P - slides), vec2(0.6, 0.35));
}
float sdHead(vec2 P, vec2 slides, float theta) {
theta = 2.0 * M_PI * theta / 360.0;
mat2 R = mat2(cos(theta), -sin(theta), sin(theta), cos(theta));
return sdEquilateralTriangle(5.232 * R * (P - slides)) - 0.8;
}
float sdUpperLeg(vec2 P, vec2 slides, float theta) {
theta = 2.0 * M_PI * theta / 360.0;
mat2 R = mat2(cos(theta), -sin(theta), sin(theta), cos(theta));
return sdEllipse(R * (P - slides), vec2(0.4, 0.1));
}
float sdLowerLeg(vec2 P, vec2 slides, float theta) {
theta = 2.0 * M_PI * theta / 360.0;
mat2 R = mat2(cos(theta), -sin(theta), sin(theta), cos(theta));
return sdEllipse(R * (P - slides), vec2(0.47, 0.13));
}
float sdFoot(vec2 P, vec2 slides, float theta) {
theta = 2.0 * M_PI * theta / 360.0;
mat2 R = mat2(cos(theta), -sin(theta), sin(theta), cos(theta));
return sdEllipse(R * (P - slides), vec2(0.3, 0.1));
}
float sdUpperArm(vec2 P, vec2 slides, float theta) {
theta = 2.0 * M_PI * theta / 360.0;
mat2 R = mat2(cos(theta), -sin(theta), sin(theta), cos(theta));
return sdEllipse(R * (P - slides), vec2(0.15, 0.05));
}
float sdLowerArm(vec2 P, vec2 slides, float theta) {
theta = 2.0 * M_PI * theta / 360.0;
mat2 R = mat2(cos(theta), -sin(theta), sin(theta), cos(theta));
return sdEllipse(R * (P - slides), vec2(0.23, 0.04));
}
vec3 get_bg_color(vec2 P) {
vec3 color1 = vec3(0.643,0.525,0.392);
vec3 color2 = vec3(0.447,0.474,0.514);
vec3 color3 = vec3(0.698,0.733,0.776);
float t = step(0.1, cnoise(2.0*P));
float u = step(0.3, cnoise(5.0*P));
vec3 out_color = mix(color1, mix(color2, color3, u), t);
out_color = mix(out_color, vec3(0.0), cnoise(200.0*P)*0.5);
return out_color;
}
vec3 get_frog_color(vec2 P) {
vec3 blue = vec3(0.43,0.71,0.90);
vec3 black = vec3(0.0);
float t = step(0.05, cnoise(12.0*P));
return mix(blue, black, t);
}
float get_frog_mask(vec2 P) {
P = P*2.0 - 1.0; // -1.0 <= P <= 1.0
float mask = 1.0;
mask *= step(0.0, sdMainBody(P, vec2(0.0, 0.1), -10.0));
mask *= step(0.0, sdHead(P, vec2(-0.5,0.2), 89.840));
mask *= step(0.0, sdUpperLeg(P, vec2(0.3, -0.2), 40.0));
mask *= step(0.0, sdLowerLeg(P, vec2(0.33, -0.35), 20.0));
mask *= step(0.0, sdFoot(P, vec2(0.6, -0.43), 70.0));
mask *= step(0.0, sdUpperArm(P, vec2(-0.22,-0.25), -30.0));
mask *= step(0.0, sdLowerArm(P, vec2(-0.31,-0.42), 30.0));
return mask;
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec4 bg_color = vec4(get_bg_color(st), 1.0);
vec4 frog_color = vec4(get_frog_color(st), 1.0);
float mask = get_frog_mask(st.xy);
colour_out = mix(frog_color, bg_color, mask);
}
unknown by hosono
// credit: jenniroutine
// frog: Dendrobates_leucomelas
precision mediump float;
uniform vec2 u_resolution;
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec3 permute(vec3 x) {
return mod289(((x*34.0)+10.0)*x);
}
float snoise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 3.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 230.0 * dot(m, g) ;
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
float mask = 1.0;
mask *= step( 0.096, distance( st.xy, vec2(0.690,0.690) ) );
mask *= step( 0.064, distance( st.xy, vec2(0.740,0.720) ) );
mask *= step( 0.056, distance( st.xy, vec2(0.660,0.740) ) );
mask *= step( 0.146, distance( st.xy, vec2(0.580,0.520) ) );
mask *= step( 0.166, distance( st.xy, vec2(0.540,0.450) ) );
mask *= step( 0.166, distance( st.xy, vec2(0.520,0.380) ) );
mask *= step( 0.082, distance( st.xy, vec2(0.370,0.280) ) );
float s = 1.048 + -0.348 * 0.864;
mask *= step( 0.072, distance( vec2(st.x*s,st.y), vec2(0.360,0.220) ) );
mask *= step( 0.064, distance( st.xy, vec2(0.570,0.150) ) );
mask *= step( 0.040, distance( st.xy, vec2(0.510,0.110) ) );
mask *= step( 0.040, distance( st.xy, vec2(0.470,0.100) ) );
mask *= step( 0.040, distance( st.xy, vec2(0.430,0.100) ) );
mask *= step( 0.040, distance( st.xy, vec2(0.390,0.110) ) );
mask *= step( 0.032, distance( st.xy, vec2(0.520,0.070) ) );
mask *= step( 0.040, distance( st.xy, vec2(0.680,0.390) ) );
mask *= step( 0.040, distance( st.xy, vec2(0.690,0.340) ) );
mask *= step( 0.035, distance( st.xy, vec2(0.710,0.300) ) );
mask *= step( 0.033, distance( st.xy, vec2(0.740,0.280) ) );
mask *= step( 0.033, distance( st.xy, vec2(0.770,0.260) ) );
mask *= step( 0.033, distance( st.xy, vec2(0.290,0.280) ) );
mask *= step( 0.033, distance( st.xy, vec2(0.270,0.260) ) );
mask *= step( 0.033, distance( st.xy, vec2(0.260,0.250) ) );
float n = snoise( gl_FragCoord.xy / 30.0 );
n = n*0.5 + 0.5; /* Map from [-1,1] to [0,1] */
colour_out = vec4( vec2(n), 0.0, 1.0 );
if (step( 0.050, distance( st.xy, vec2(0.730,0.630) ) )==0.0) colour_out = vec4( vec3(0.0), 1.0 );
if (step( 0.050, distance( st.xy, vec2(0.790,0.670) ) )==0.0) colour_out = vec4( vec3(0.0), 1.0 );
s = 1.024 + -0.332 * 0.936;
if (step( 0.082, distance( vec2(st.x*s,st.y), vec2(0.400,0.590) ) )==0.0) colour_out = vec4( vec3(0.0), 1.0 );
if (step( 0.082, distance( vec2(st.x*s,st.y), vec2(0.450,0.560) ) )==0.0) colour_out = vec4( vec3(0.0), 1.0 );
if (step( 0.082, distance( vec2(st.x*s,st.y), vec2(0.310,0.400) ) )==0.0) colour_out = vec4( vec3(0.0), 1.0 );
if (step( 0.082, distance( vec2(st.x*s,st.y), vec2(0.410,0.340) ) )==0.0) colour_out = vec4( vec3(0.0), 1.0 );
colour_out *= 1.0-mask;
}
Dendrobates leucomelas by jenniroutine
// name: oguni
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
// --------------------------------------------------------------------
// https://github.com/stegu/webgl-noise/blob/master/src/noise2D.glsl
//
// Description : Array and textureless GLSL 2D simplex noise function.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : stegu
// Lastmod : 20110822 (ijm)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise
// https://github.com/stegu/webgl-noise
//
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec3 permute(vec3 x) {
return mod289(((x*34.0)+10.0)*x);
}
float snoise(vec2 v) {
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
vec4 mod289(vec4 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 permute(vec4 x) {
return mod289(((x*34.0)+10.0)*x);
}
vec4 taylorInvSqrt(vec4 r) {
return 1.79284291400159 - 0.85373472095314 * r;
}
// https://github.com/stegu/webgl-noise/blob/master/src/noise3D.glsl
//
// Description : Array and textureless GLSL 2D/3D/4D simplex
// noise functions.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : stegu
// Lastmod : 20201014 (stegu)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise
// https://github.com/stegu/webgl-noise
float snoise(vec3 v) {
const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
// First corner
vec3 i = floor(v + dot(v, C.yyy) );
vec3 x0 = v - i + dot(i, C.xxx) ;
// Other corners
vec3 g = step(x0.yzx, x0.xyz);
vec3 l = 1.0 - g;
vec3 i1 = min( g.xyz, l.zxy );
vec3 i2 = max( g.xyz, l.zxy );
// x0 = x0 - 0.0 + 0.0 * C.xxx;
// x1 = x0 - i1 + 1.0 * C.xxx;
// x2 = x0 - i2 + 2.0 * C.xxx;
// x3 = x0 - 1.0 + 3.0 * C.xxx;
vec3 x1 = x0 - i1 + C.xxx;
vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
// Permutations
i = mod289(i);
vec4 p = permute( permute( permute(
i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
+ i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
+ i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
float n_ = 0.142857142857; // 1.0/7.0
vec3 ns = n_ * D.wyz - D.xzx;
vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
vec4 x_ = floor(j * ns.z);
vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
vec4 x = x_ *ns.x + ns.yyyy;
vec4 y = y_ *ns.x + ns.yyyy;
vec4 h = 1.0 - abs(x) - abs(y);
vec4 b0 = vec4( x.xy, y.xy );
vec4 b1 = vec4( x.zw, y.zw );
// vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
// vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
vec4 s0 = floor(b0)*2.0 + 1.0;
vec4 s1 = floor(b1)*2.0 + 1.0;
vec4 sh = -step(h, vec4(0.0));
vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
vec3 p0 = vec3(a0.xy,h.x);
vec3 p1 = vec3(a0.zw,h.y);
vec3 p2 = vec3(a1.xy,h.z);
vec3 p3 = vec3(a1.zw,h.w);
// Normalise gradients
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
// Mix final noise value
vec4 m = max(0.5 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
m = m * m;
return 105.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
dot(p2,x2), dot(p3,x3) ) );
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// https://iquilezles.org/articles/distfunctions2d/
float sdSegment( in vec2 p, in vec2 a, in vec2 b )
{
vec2 pa = p-a, ba = b-a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
return length( pa - ba*h );
}
// --------------------------------------------------------------------
float gamma_map(float x) {
return pow(x, 1.0/2.2);
}
float blurstep(float s, float x) {
return smoothstep(s - 0.01, s + 0.01, x);
}
float blurstep_foot(float s, float x) {
return smoothstep(s - 0.005, s + 0.0, x);
}
float mouse_y() {
return max(u_mouse.y, 0.1); // Without this, horror images are created when u_mouse.y is near 0.0
}
float frogmask(vec2 st) {
float mask = 1.0;
// head
mask *= blurstep(0.08, distance(st, vec2(0.23, 0.54 + pow(mouse_y(), 0.9) * 0.0006)));
mask *= blurstep(0.1, distance(st, vec2(0.29, 0.53 + pow(mouse_y(), 0.9) * 0.0005)));
mask *= blurstep(0.12, sdSegment(st, vec2(0.35, 0.5 + pow(mouse_y(), 0.9) * 0.0003), vec2(0.5, 0.4)));
// vocal sac
mask *= blurstep(0.08, distance(st, vec2(0.32, 0.47 - smoothstep(0.6, 0.8, smoothstep(sin(u_time * 2.0), -0.5, -1.0) * sin(u_time * 16.0)) * 0.02 + pow(mouse_y(), 0.9) * 0.0006)));
// body
mask *= blurstep(0.15, sdSegment(st, vec2(0.5, 0.4), vec2(0.7, 0.3)));
// left hind leg
mask *= blurstep_foot(0.06, sdSegment(st, vec2(0.670,0.200), vec2(0.430,0.120)));
mask *= blurstep_foot(0.03, sdSegment(st, vec2(0.430,0.120), vec2(0.750,0.110)));
mask *= blurstep_foot(0.03, sdSegment(st, vec2(0.750,0.110), vec2(0.490,0.040)));
// left hind foot fingers
vec2 a = vec2(0.7, 0.1) - vec2(0.3, 0.2);
mask *= blurstep_foot(0.014, sdSegment(st, vec2(0.070,0.140) + a, vec2(-0.010,0.130) + a));
mask *= blurstep_foot(0.014, sdSegment(st, vec2(0.090,0.130) + a, vec2(0.030,0.090) + a));
mask *= blurstep_foot(0.014, sdSegment(st, vec2(0.29, 0.18) + a, vec2(0.2, 0.2) + a));
// right hind leg
mask *= blurstep_foot(0.07, sdSegment(st, vec2(0.780,0.200) + vec2(0.05, 0.05), vec2(0.770,0.330) + vec2(0.05, 0.05)));
mask *= blurstep_foot(0.03, sdSegment(st, vec2(0.770,0.330) + vec2(0.05, 0.05), vec2(0.820,0.150) + vec2(0.05, 0.05)));
mask *= blurstep_foot(0.03, sdSegment(st, vec2(0.820,0.150) + vec2(0.05, 0.05), vec2(0.840,0.290) + vec2(0.05, 0.05)));
// left arm
mask *= blurstep_foot(0.035, sdSegment(st, vec2(0.6, 0.3), vec2(0.3, 0.2)));
// left hand fingers
mask *= blurstep_foot(0.014, sdSegment(st, vec2(0.3, 0.2), vec2(0.28, 0.26)));
mask *= blurstep_foot(0.014, sdSegment(st, vec2(0.3, 0.2), vec2(0.21, 0.25)));
mask *= blurstep_foot(0.014, sdSegment(st, vec2(0.3, 0.17), vec2(0.2, 0.2)));
return mask;
}
vec3 draw(vec2 st) {
vec2 st_frog = (st - vec2(-0.12, 0.1)) * 0.9;
vec2 mouse01 = 1.0 + u_mouse * 0.00001;
float pattern = snoise(st_frog * 8.0 + vec2(0.0, -mouse_y() * 0.003 * (1.0-st.x) * smoothstep(0.3, 1.0, st.y)));
pattern = mix(-1.0, pattern, smoothstep(0.0, 0.3, distance(vec2(0.920,0.150), st_frog)));
pattern = mix(-1.0, pattern, smoothstep(0.0, 0.3, distance(vec2(0.350,0.140), st_frog)));
float highlights = pow(
(snoise(vec3((st_frog + vec2(10.0, 10.0) - u_mouse * 0.0001) * 10.000 * mouse01.x, 6.0 + sin(u_time * 0.5) * 0.1)) + 0.2) *
(snoise(vec3((st_frog + vec2(10.8, 10.8) - u_mouse * 0.0001) * 10.0 * mouse01.y, 5.0 + sin(u_time * 0.5) * 0.1)) + 0.2),
2.0
);
highlights = pow(highlights, 2.0);
vec3 frog;
if (pattern < 0.1) {
float d = (0.1 - pattern) / 0.4;
frog = vec3(0.074,0.099,0.380) + d * vec3(0.057,0.053,0.120);
} else {
frog = vec3(0.1, 0.1, 0.1);
}
frog += highlights;
vec2 eye_center = vec2(0.280, 0.520 + pow(mouse_y(), 0.9) * 0.0005);
float eye_distance = length((st_frog - eye_center) * vec2(2.0, 2.3)) - 0.04;
// eye
float d = max(0.0, 1.0 - distance(st_frog - vec2(-0.015, 0.01), eye_center) / 0.04 * 4.0);
float eye_t = smoothstep(0.04, 0.02, eye_distance);
frog = mix(frog, vec3(pow(d, 2.0)), eye_t * 0.9);
frog.xyz += min(0.0, -(1.0-st.y - 0.4) * 1.0);
frog.xyz *= 1.0 + (
snoise((st_frog * 8.0 + vec2(0.0, -mouse_y() * 0.003 * (1.0-st.x) * smoothstep(0.3, 1.0, st.y))) * 10.0) * 0.04 +
snoise((st_frog * 8.0 + vec2(0.0, -mouse_y() * 0.003 * (1.0-st.x) * smoothstep(0.3, 1.0, st.y))) * 20.0) * 0.05 +
snoise((st_frog * 8.0 + vec2(0.0, -mouse_y() * 0.003 * (1.0-st.x) * smoothstep(0.3, 1.0, st.y))) * 40.0) * 0.025
) * 3.0;
// background
vec2 st_background = vec2((st.x - 0.5) * pow(st.y + 1.0, 1.5), log(1.0-(st.y - 0.01)));
float background_noise =
snoise(st_background * 20.0) * 0.3 *
snoise((st_background + vec2(0.0, 0.03)) * 20.0) * 0.3 +
snoise(vec3((st_background) * 1.0, sin(u_time) * 0.1)) * 0.2;
vec3 background = vec3(0.440, 0.367, 0.269) + background_noise;
// shadow
background.xyz -= (1.0 - frogmask(st_frog + vec2(0.0 - smoothstep(0.3, 0.6, st.y) * 0.3, 0.01 + smoothstep(0.3, 0.6, st.y) * 0.5))) * 0.3;
background.xyz -= (1.0 - frogmask((st_frog + vec2(0.0, 0.02)) + vec2(0.0 - smoothstep(0.3, 0.6, st.y) * 0.3, 0.01 + smoothstep(0.3, 0.6, st.y) * 0.5))) * 0.1;
background.xyz -= smoothstep(0.5, 0.0, distance(vec2(0.540,0.700), st * vec2(1.0, 2.0))) * 0.3;
float mask = frogmask(st_frog);
return mix(frog.xyz, background, mask);
}
void main() {
vec2 st = gl_FragCoord.xy / u_resolution.xy;
vec3 col = draw(st);
colour_out = vec4(col * 1.5 + smoothstep(0.4, 0.7, col) * 1.0, 1.0);
}
Dendrobates tinctorius by oguni
// credit: shaw
// frog: Dendrobates tinctorius Freetoast
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float hash( float n )
{
return fract(sin(n)*43758.5453);
}
float noise( vec2 x )
{
vec2 p = floor(x);
vec2 f = fract(x);
f = f*f*(3.0-2.0*f);
float n = p.x + p.y*57.0;
return mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
}
float marbleturbulence(vec2 p) {
float f = 0.0, scale;
for (int i=0; i<4; i++) {
scale = pow( pow(2.0, 4.0 / 3.0), float(i));
f += abs(noise( p * scale )) / scale;
}
return f;
}
mat2 m = mat2( 0.8, 0.6, -0.6, 0.8 );
float fbm( vec2 p ) {
float f = 0.0;
f += 0.5000 * noise( p ); p *= m*2.02;
f += 0.2500 * noise( p ); p *= m*2.01;
f += 0.1250 * noise( p ); p *= m*2.03;
f += 0.0625 * noise( p ); p *= m*2.04;
f /= 0.9375;
return f;
}
void main() {
vec2 p = gl_FragCoord.xy/u_resolution.xy;
float mask = 1.0;
mask *= step( 0.5, distance( p.xy, vec2(0.50,0.060) ) ); // down
mask *= step( 0.18, distance( p.xy, vec2(0.310,0.410) ) ); // right
mask *= step( 0.18, distance( p.xy, vec2(0.690,0.410) ) ); // left
vec3 background = vec3(89.0 / 255.0, 151.0 / 255.0, 30.0 / 255.0);
vec3 mouth = vec3(184.0 / 255.0, 223.0 / 255.0, 200.0 / 255.0);
// background fbm
float f = fbm(1.0 * p);
vec3 col = mix(background, vec3(0.1, 0.1, 0.1), f);
// head
vec3 head = vec3( 172.0 / 255.0, 229.0 / 255.0, 210.0 / 255.0 );
col = mix(head, col, mask);
if(mask == 0.0) {
// skin: random dots
vec2 ti = floor(9.0 + p / 0.08);
vec2 uv = fract(p / 0.08) - 0.5;
float rho = fract(111.0 * sin(1111.0 * ti.x + 1331.0 * ti.y));
rho = smoothstep(0.6, 1.1, rho)*exp(-dot(uv,uv)*24.0);
col *= mix(head, vec3(0.0), rho);
// skin: random black bars
float n = marbleturbulence(gl_FragCoord.xy / 500.0);
float t = 1.0 + sin(gl_FragCoord.x / 80.0 + 20.0 * n) / 2.0;
col = mix(col, 1.0 - vec3(t), 0.4*t);
// mouth
f = 1.0 - step(0.50, length(p - vec2(0.5, -0.25)));
col = mix(col, mouth, f);
f = 1.0 - step(0.05, length(p - vec2(0.35, 0.21)));
col = mix(col, mouth, f);
f = 1.0 - step(0.05, length(p - vec2(0.65, 0.21)));
col = mix(col, mouth, f);
// left eye
float r = length(p - vec2(0.690,0.410));
// outmost
f = 1.0 - smoothstep(0.09, 0.12, r);
col = mix(col, vec3(1.0), f);
// gray part
f = 1.0 - smoothstep(0.085, 0.1, r);
col = mix(col, vec3(0.15, 0.15, 0.15), f);
// yellow part
//f = 1.0 - smoothstep(0.03, 0.10, r);
//col = mix(col, vec3(0.9, 0.6, 0.2), f);
// center black circle
//f = 1.0 - smoothstep(0.02, 0.04, r);
//col = mix(col, vec3(0.0, 0.0, 0.0), f);
// highlight
f = 1.0 - smoothstep(0.0, 0.03, length(p - vec2(0.720, 0.420)));
col += vec3(1.0, 0.9, 0.8) * vec3(f) * 0.9;
// right eye
r = length(p - vec2(0.310,0.410));
f = 1.0 - smoothstep(0.09, 0.12, r);
col = mix(col, vec3(1.0), f);
f = 1.0 - smoothstep(0.085, 0.1, r);
col = mix(col, vec3(0.15, 0.15, 0.15), f);
f = 1.0 - smoothstep(0.0, 0.03, length(p - vec2(0.340, 0.420)));
col += vec3(1.0, 0.9, 0.8) * vec3(f) * 0.9;
}
colour_out = vec4(col, 1.0);
}
Dendrobates tinctorius Freetoast by
shaw
// credit: Tori
// frog: Dendrobates galactonotus
uniform vec2 u_resolution;
float myCircle( vec2 p, vec2 center, float r, float threshold )
{
return step( threshold, length( p-center ) - r );
}
float myUnevenCapsule( vec2 p, float r1, float r2, float h, float offset, float threshold )
{
p.x = abs(p.x - 0.5);
p.y -= offset;
float b = (r2-r1)/h;
float a = sqrt(1.0-b*b);
float k = dot(p,vec2(-b,a));
float val;
if( k < 0.0 )
val = length(p) - r2;
else if( k > a*h )
val = length(p-vec2(0.0,h)) - r1;
else
val = dot(p, vec2(a,b) ) - r2;
return step( threshold, val );
}
float myFrogLimb( vec2 pos, vec2 A, vec2 B, vec2 C, float threshold )
{
vec2 a = B - A;
vec2 b = A - 2.0*B + C;
vec2 c = a * 2.0;
vec2 d = A - pos;
float kk = 1.0/dot(b,b);
float kx = kk * dot(a,b);
float ky = kk * (2.0*dot(a,a)+dot(d,b)) / 3.0;
float kz = kk * dot(d,a);
float res = 0.0;
float p = ky - kx*kx;
float p3 = p*p*p;
float q = kx*(2.0*kx*kx-3.0*ky) + kz;
float h = q*q + 4.0*p3;
if( h >= 0.0 )
{
h = sqrt(h);
vec2 x = (vec2(h,-h)-q)/2.0;
vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0));
float t = clamp( uv.x+uv.y-kx, 0.0, 1.0 );
res = dot(d + (c + b*t)*t, d + (c + b*t)*t );
}
else
{
float z = sqrt(-p);
float v = acos( q/(p*z*2.0) ) / 3.0;
float m = cos(v);
float n = sin(v)*1.732050808;
vec3 t = clamp(vec3(m+m,-n-m,n-m)*z-kx,0.0,1.0);
res = min( dot(d+(c+b*t.x)*t.x, d+(c+b*t.x)*t.x),
dot(d+(c+b*t.y)*t.y, d+(c+b*t.y)*t.y) );
}
return step( threshold, sqrt( res ) );
}
float myFrogHand( vec2 p, float r, vec2 root, float arg, float threshold )
{
arg = arg * 3.14159 / 180.0;
p -= root;
float tmp = p.x;
arg -= 1.570795;
p.x = p.x * cos( arg ) - p.y * sin( arg );
p.y = tmp * sin( arg ) + p.y * cos( arg );
p += root;
if( atan( p.x - root.x, p.y - root.y ) < 0.0 )
return 1.0;
p = abs( p - root );
float an = 3.141593/8.0;
float en = 3.141593/7.0;
vec2 acs = vec2(cos(an),sin(an));
vec2 ecs = vec2(cos(en),sin(en));
float bn = mod(atan(p.x,p.y)+0.3925,2.0*an) - an;
p = length(p)*vec2(cos(bn),abs(sin(bn)));
p -= r*acs;
p += ecs*clamp( -dot(p,ecs), 0.0, r*acs.y/ecs.y);
return step( threshold, length(p)*sign(p.x) );
}
vec3 myBodyColor( vec2 p ){
float scale = 5.0;
p *= scale;
p.x += 0.4;
p.y += ( p.x - fract( p.x ) ) * 0.4;
vec2 center = vec2( p.x - fract( p.x ) + 0.5, p.y - fract( p.y ) + 0.5 );
float mask = step( 0.4, length( center - p ) );
return mask * vec3( 0.525, 0.922, 0.204 );
}
vec3 myLimbColor( vec2 p ){
float scale = 20.0;
p *= scale;
p.y += ( p.x - fract( p.x ) ) * 0.5;
vec2 center = vec2( p.x - fract( p.x ) + 0.5, p.y - fract( p.y ) + 0.5 );
float mask = step( 0.4, length( center - p ) );
return mask * vec3( 0.204, 0.729, 0.922 );
}
vec3 myBackColor( vec2 p ){
float sum1 = 2.0 * p.x + p.y;
float sum2 = p.x + 2.0 * p.y;
float diff = p.y - p.x;
float branchMask = 1.0;
branchMask = min( branchMask, step( 0.03, abs( diff + 0.3 ) ) );
if( diff > -0.3 ){
branchMask = min( branchMask, step( 0.03, abs( sum1 - 1.3 ) ) );
branchMask = min( branchMask, step( 0.03, abs( sum1 - 0.7 ) ) );
}else{
branchMask = min( branchMask, step( 0.03, abs( sum2 - 1.5 ) ) );
branchMask = min( branchMask, step( 0.03, abs( sum2 - 0.5 ) ) );
}
return mix( vec3( 0.541, 0.431, 0.275 ), vec3( 0.518, 0.580, 0.388 ), branchMask );
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
// body
float headRadius = 0.02;
float bodyRadius = 0.10;
float bodyLength = 0.4;
float bodyOffset = 0.3;
float bodyThreshold = 0.1;
// eye
float eyeRadius = 0.025;
vec2 leftEyeCenter = vec2( 0.4, 0.8 );
vec2 rightEyeCenter = vec2( 0.6, 0.8 );
float eyeThreshold = 0.01;
// arm
float armThreshold = 0.015;
vec2 leftArmRoot = vec2( 0.375, 0.65 );
vec2 leftArmAnchor = vec2( 0.3, 0.5 );
vec2 leftArmTip = vec2( 0.3, 0.7 );
vec2 rightArmRoot = vec2( 0.64, 0.6 );
vec2 rightArmAnchor = vec2( 0.675, 0.45 );
vec2 rightArmTip = vec2( 0.8, 0.6 );
// leg
float legThreshold = 0.02;
vec2 leftLegRoot = vec2( 0.35, 0.2 );
vec2 leftLegAnchor1 = vec2( 0.2, 0.5 );
vec2 leftLegJoint = vec2( 0.29, 0.2 );
vec2 leftLegAnchor2 = vec2( 0.4, 0.0 );
vec2 leftLegTip = vec2( 0.2, 0.3 );
vec2 rightLegRoot = vec2( 0.65, 0.2 );
vec2 rightLegAnchor1 = vec2( 0.8, 0.5 );
vec2 rightLegJoint = vec2( 0.71, 0.2 );
vec2 rightLegAnchor2 = vec2( 0.6, 0.0 );
vec2 rightLegTip = vec2( 0.8, 0.2 );
// hand
float handThreshold = 0.01;
float handSize = 0.1;
vec2 leftHandRoot = vec2( 0.3, 0.7 );
float leftHandArg = -10.0;
vec2 rightHandRoot = vec2( 0.8, 0.6 );
float rightHandArg = 20.0;
// foot
float footThreshold = 0.01;
float footSize = 0.1;
vec2 leftFootRoot = vec2( 0.2, 0.3 );
float leftFootArg = -35.0;
vec2 rightFootRoot = vec2( 0.8, 0.2 );
float rightFootArg = 45.0;
// background
float backMask = 1.0;
float bodyMask = 1.0;
bodyMask = min( bodyMask, myUnevenCapsule( st, headRadius, bodyRadius, bodyLength, bodyOffset, bodyThreshold ) );
bodyMask = min( bodyMask, myCircle( st, leftEyeCenter, eyeRadius, eyeThreshold ) );
bodyMask = min( bodyMask, myCircle( st, rightEyeCenter, eyeRadius, eyeThreshold ) );
backMask = min( backMask, bodyMask );
bodyMask = 1.0 - bodyMask;
vec3 bodyColor = myBodyColor( st );
bodyColor *= bodyMask;
float limbMask = 1.0;
limbMask = min( limbMask, myFrogLimb( st, leftArmRoot, leftArmAnchor, leftArmTip, armThreshold ) );
limbMask = min( limbMask, myFrogLimb( st, rightArmRoot, rightArmAnchor, rightArmTip, armThreshold ) );
limbMask = min( limbMask, myFrogLimb( st, leftLegRoot, leftLegAnchor1, leftLegJoint, legThreshold ) );
limbMask = min( limbMask, myFrogLimb( st, leftLegJoint, leftLegAnchor2, leftLegTip, legThreshold ) );
limbMask = min( limbMask, myFrogLimb( st, rightLegRoot, rightLegAnchor1, rightLegJoint, legThreshold ) );
limbMask = min( limbMask, myFrogLimb( st, rightLegJoint, rightLegAnchor2, rightLegTip, legThreshold ) );
limbMask = min( limbMask, myFrogHand( st, handSize, leftHandRoot, leftHandArg, handThreshold ) );
limbMask = min( limbMask, myFrogHand( st, handSize, rightHandRoot, rightHandArg, handThreshold ) );
limbMask = min( limbMask, myFrogHand( st, footSize, leftFootRoot, leftFootArg, footThreshold ) );
limbMask = min( limbMask, myFrogHand( st, footSize, rightFootRoot, rightFootArg, footThreshold ) );
backMask = min( backMask, limbMask );
limbMask = 1.0 - limbMask;
vec3 limbColor = myLimbColor( st );
limbColor *= limbMask;
vec3 backColor = myBackColor( st );
colour_out = vec4( backColor * backMask, 1.0 );
colour_out += vec4( max( bodyColor, limbColor ), 1.0 );
}
Dendrobates galactonotus by Tori
// Name - LeeHyeonJoon
// Scientific Name of the Frog - Oophaga pumilio (strawberry poison-dart frog)
uniform vec2 u_resolution;
// Modulo 289 without a division (only multiplications)
vec3 mod289(vec3 x){
return x-floor(x*(1./289.))*289.;
}
vec2 mod289(vec2 x){
return x-floor(x*(1./289.))*289.;
}
// Modulo 7 without a division
vec3 mod7(vec3 x){
return x-floor(x*(1./7.))*7.;
}
// Permutation polynomial: (34x^2 + 6x) mod 289
vec3 permute(vec3 x){
return mod289((34.*x+10.)*x);
}
// Cellular (Worley) noise, returning F1 and F2 in a vec2.
// Standard 3x3 search window for good F1 and F2 values
vec2 cellular(vec2 P){
#define K .142857142857// 1/7
#define Ko .428571428571// 3/7
#define jitter 1.0// Less gives more regular pattern
vec2 Pi=mod289(floor(P));
vec2 Pf=fract(P);
vec3 oi=vec3(-1.,0.,1.);
vec3 of=vec3(-.5,.5,1.5);
vec3 px=permute(Pi.x+oi);
vec3 p=permute(px.x+Pi.y+oi);// p11, p12, p13
vec3 ox=fract(p*K)-Ko;
vec3 oy=mod7(floor(p*K))*K-Ko;
vec3 dx=Pf.x+.5+jitter*ox;
vec3 dy=Pf.y-of+jitter*oy;
vec3 d1=dx*dx+dy*dy;// d11, d12 and d13, squared
p=permute(px.y+Pi.y+oi);// p21, p22, p23
ox=fract(p*K)-Ko;
oy=mod7(floor(p*K))*K-Ko;
dx=Pf.x-.5+jitter*ox;
dy=Pf.y-of+jitter*oy;
vec3 d2=dx*dx+dy*dy;// d21, d22 and d23, squared
p=permute(px.z+Pi.y+oi);// p31, p32, p33
ox=fract(p*K)-Ko;
oy=mod7(floor(p*K))*K-Ko;
dx=Pf.x-1.5+jitter*ox;
dy=Pf.y-of+jitter*oy;
vec3 d3=dx*dx+dy*dy;// d31, d32 and d33, squared
// Sort out the two smallest distances (F1, F2)
vec3 d1a=min(d1,d2);
d2=max(d1,d2);// Swap to keep candidates for F2
d2=min(d2,d3);// neither F1 nor F2 are now in d3
d1=min(d1a,d2);// F1 is now in d1
d2=max(d1a,d2);// Swap to keep candidates for F2
d1.xy=(d1.x<d1.y)?d1.xy:d1.yx;// Swap if smaller
d1.xz=(d1.x<d1.z)?d1.xz:d1.zx;// F1 is in d1.x
d1.yz=min(d1.yz,d2.yz);// F2 is now not in d2.yz
d1.y=min(d1.y,d1.z);// nor in d1.z
d1.y=min(d1.y,d2.x);// F2 is in d1.y, we're done.
return sqrt(d1.xy);
}
float snoise(vec2 v){
const vec4 C=vec4(.211324865405187,// (3.0-sqrt(3.0))/6.0
.366025403784439,// 0.5*(sqrt(3.0)-1.0)
-.577350269189626,// -1.0 + 2.0 * C.x
.024390243902439);// 1.0 / 41.0
// First corner
vec2 i=floor(v+dot(v,C.yy));
vec2 x0=v-i+dot(i,C.xx);
// Other corners
vec2 i1;
i1=(x0.x>x0.y)?vec2(1.,0.):vec2(0.,1.);
vec4 x12=x0.xyxy+C.xxzz;
x12.xy-=i1;
// Permutations
i=mod289(i);// Avoid truncation effects in permutation
vec3 p=permute(permute(i.y+vec3(0.,i1.y,1.))
+i.x+vec3(0.,i1.x,1.));
vec3 m=max(.5-vec3(dot(x0,x0),dot(x12.xy,x12.xy),dot(x12.zw,x12.zw)),0.);
m=m*m;
m=m*m;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x=2.*fract(p*C.www)-1.;
vec3 h=abs(x)-.5;
vec3 ox=floor(x+.5);
vec3 a0=x-ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m*=1.79284291400159-.85373472095314*(a0*a0+h*h);
// Compute final noise value at P
vec3 g;
g.x=a0.x*x0.x+h.x*x0.y;
g.yz=a0.yz*x12.xz+h.yz*x12.yw;
return 130.*dot(m,g);
}
float customEllipse(vec2 p,vec2 ab,float rad,vec2 center){
mat3 H=mat3(
cos(rad),sin(rad),0,
-sin(rad),cos(rad),0,
center.x,center.y,1);
p=(inverse(H)*vec3(p,1.)).xy;
p=abs(p);if(p.x>p.y){p=p.yx;ab=ab.yx;}
float l=ab.y*ab.y-ab.x*ab.x;
float m=ab.x*p.x/l;float m2=m*m;
float n=ab.y*p.y/l;float n2=n*n;
float c=(m2+n2-1.)/3.;float c3=c*c*c;
float q=c3+m2*n2*2.;
float d=c3+m2*n2;
float g=m+m*n2;
float co;
if(d<0.)
{
float h=acos(q/c3)/3.;
float s=cos(h);
float t=sin(h)*sqrt(3.);
float rx=sqrt(-c*(s+t+2.)+m2);
float ry=sqrt(-c*(s-t+2.)+m2);
co=(ry+sign(l)*rx+abs(g)/(rx*ry)-m)/2.;
}
else
{
float h=2.*m*n*sqrt(d);
float s=sign(q+h)*pow(abs(q+h),1./3.);
float u=sign(q-h)*pow(abs(q-h),1./3.);
float rx=-s-u-c*4.+2.*m2;
float ry=(s-u)*sqrt(3.);
float rm=sqrt(rx*rx+ry*ry);
co=(ry/sqrt(rm-rx)+2.*g/rm-m)/2.;
}
vec2 r=ab*vec2(co,sqrt(1.-co*co));
return length(r-p)*sign(p.y-r.y);
}
float customUnevenCapsule(vec2 p,float r1,float r2,float h,float rad,vec2 center){
mat3 H=mat3(
cos(rad),sin(rad),0,
-sin(rad),cos(rad),0,
center.x,center.y,1);
p=(inverse(H)*vec3(p,1.)).xy;
p.x=abs(p.x);
float b=(r1-r2)/h;
float a=sqrt(1.-b*b);
float k=dot(p,vec2(-b,a));
if(k<0.)return length(p)-r1;
if(k>a*h)return length(p-vec2(0.,h))-r2;
return dot(p,vec2(a,b))-r1;
}
float customBlobbyCross(vec2 pos,float he,float rad,vec2 center,float size){
mat3 H=mat3(
cos(rad),sin(rad),0,
-sin(rad),cos(rad),0,
center.x,center.y,1);
pos=(inverse(H)*vec3(pos,1.)).xy;
pos=abs(pos)/size;
pos=vec2(abs(pos.x-pos.y),1.-pos.x-pos.y)/sqrt(2.);
float p=(he-pos.y-.25/he)/(6.*he);
float q=pos.x/(he*he*16.);
float h=q*q-p*p*p;
float x;
if(h>0.){float r=sqrt(h);x=pow(q+r,1./3.)-pow(abs(q-r),1./3.)*sign(r-q);}
else{float r=sqrt(p);x=2.*r*cos(acos(q/(p*r))/3.);}
x=min(x,sqrt(2.)/2.);
vec2 z=vec2(x,he*(1.-2.*x*x))-pos;
return length(z)*sign(z.y);
}
float colour_cellular(vec2 xy){return cellular(xy).x*2.-1.;}
void main(){
vec2 st=(gl_FragCoord.xy/u_resolution.xy)*2.-1.;
vec3 xyz=vec3(st,0);
// light blue (feet)
float light_blue=colour_cellular(xyz.xy*20.);
vec3 colour_light_blue=vec3(.3+.5*vec3(light_blue));
colour_light_blue=1.-colour_light_blue;
// blue (rear legs and the lower part of front legs)
float blue=colour_cellular(xyz.xy*20.);
vec3 colour_blue=vec3(.7+.7*vec3(blue));
colour_blue=1.-colour_blue;
// red (body and the upper part of front legs)
float red=snoise(xyz.xy*7.);
vec3 colour_red=vec3(.3+.6*vec3(red));
// background
float background=colour_cellular(xyz.xy*2.);
vec3 colour_background=vec3(.3+.4*vec3(background));
colour_out=vec4(colour_background.x-.5,colour_background.y,colour_background.z-.5,1.);
// eyes
float mask=1.;
mask*=step(.09,distance(st.xy,vec2(.15,.4)));
mask*=step(.09,distance(st.xy,vec2(-.15,.4)));
if(mask==0.){
colour_out=vec4(0.0, 0.0, 0.0, 1.0);
}
// light blue part
mask=1.;
mask*=step(0.,customBlobbyCross(st.xy,.6,.5,vec2(.55,.25),.1)-.2);// right front feet
mask*=step(0.,customBlobbyCross(st.xy,.6,-.8,vec2(-.44,.25),.1)-.2);// left front feet
mask*=step(0.,customBlobbyCross(st.xy,.6,1.,vec2(.57,-.63),.15)-.2);// right rear feet
mask*=step(0.,customBlobbyCross(st.xy,.6,1.,vec2(-.56,-.77),.15)-.2);// left rear feet
if(mask==0.){
colour_out=vec4(colour_light_blue.x-.6,colour_light_blue.y-.2,colour_light_blue.z,1.);
}
// blue part
mask=1.;
mask*=step(0.,customEllipse(st.xy,vec2(.15,.04),1.2,vec2(.5,.11)));// right front leg
mask*=step(0.,customEllipse(st.xy,vec2(.15,.04),1.5,vec2(-.45,.11)));// left front leg
mask*=step(0.,customEllipse(st.xy,vec2(.25,.11),.5,vec2(.25,-.42)));// right rear leg
mask*=step(0.,customEllipse(st.xy,vec2(.25,.11),-.5,vec2(-.25,-.42)));// left rear leg
mask*=step(0.,customEllipse(st.xy,vec2(.25,.09),1.,vec2(.33,-.5)));// right rear leg
mask*=step(0.,customEllipse(st.xy,vec2(.25,.09),-1.,vec2(-.33,-.5)));// left rear leg
mask*=step(0.,customEllipse(st.xy,vec2(.2,.05),.15,vec2(.38,-.66)));// right rear leg
mask*=step(0.,customEllipse(st.xy,vec2(.2,.05),.25,vec2(-.38,-.73)));// left rear leg
if(mask==0.){
colour_out=vec4(colour_blue.x-.8,colour_blue.y-.2,colour_blue.z,1.);
}
// red part
mask=1.;
mask*=step(0.,customEllipse(st.xy,vec2(.6,.25),1.55,vec2(0)));// body
mask*=step(0.,customUnevenCapsule(st.xy,.04,.05,.25,1.,vec2(.45,0.)));// right front leg
mask*=step(0.,customUnevenCapsule(st.xy,.04,.05,.25,-1.,vec2(-.45,0.)));// left front leg
mask*=step(0.,customEllipse(st.xy,vec2(.11,.09),1.8,vec2(.115,.39)));// right eyelid
mask*=step(0.,customEllipse(st.xy,vec2(.11,.09),-1.8,vec2(-.115,.39)));// left eyelid
if(mask==0.){
colour_out=vec4(colour_red.x,colour_red.y-1.,colour_red.z-1.,1.);
}
// light
colour_out.xyz+=vec3(.04/distance(st,vec2(.15,.43)));
}
Oophaga pumilio by LeeHyeonJoon
// Author: Jingyi Huang 5122FG14
// PseudoName: algaeee
// Title:
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
struct Material
{
vec3 diffuseAlbedo;
vec3 specularAlbedo;
float specularPower;
};
#define AA 1
#define NUM_OCTAVES 20
// dist funcs
// https://iquilezles.org/articles/distfunctions
float dot2(in vec3 v ) { return dot(v,v); }
float sdRoundCone(vec3 p, vec3 a, vec3 b, float r1, float r2)
{
// sampling independent computations (only depend on shape)
vec3 ba = b - a;
float l2 = dot(ba,ba);
float rr = r1 - r2;
float a2 = l2 - rr*rr;
float il2 = 1.0/l2;
// sampling dependant computations
vec3 pa = p - a;
float y = dot(pa,ba);
float z = y - l2;
float x2 = dot2( pa*l2 - ba*y );
float y2 = y*y*l2;
float z2 = z*z*l2;
// single square root!
float k = sign(rr)*rr*rr*x2;
if( sign(z)*a2*z2 > k ) return sqrt(x2 + z2) *il2 - r2;
if( sign(y)*a2*y2 < k ) return sqrt(x2 + y2) *il2 - r1;
return (sqrt(x2*a2*il2)+y*rr)*il2 - r1;
}
float sdSphere( vec3 p, float s )
{
return length(p)-s;
}
float sdCappedTorus(in vec3 p, in vec2 sc, in float ra, in float rb)
{
p.x = abs(p.x);
float k = (sc.y*p.x>sc.x*p.y) ? dot(p.xy,sc) : length(p.xy);
return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb;
}
// http://research.microsoft.com/en-us/um/people/hoppe/ravg.pdf
float det( vec2 a, vec2 b ) { return a.x*b.y-b.x*a.y; }
vec3 getClosest( vec2 b0, vec2 b1, vec2 b2 )
{
float a = det(b0,b2);
float b = 2.0*det(b1,b0);
float d = 2.0*det(b2,b1);
float f = b*d - a*a;
vec2 d21 = b2-b1;
vec2 d10 = b1-b0;
vec2 d20 = b2-b0;
vec2 gf = 2.0*(b*d21+d*d10+a*d20); gf = vec2(gf.y,-gf.x);
vec2 pp = -f*gf/dot(gf,gf);
vec2 d0p = b0-pp;
float ap = det(d0p,d20);
float bp = 2.0*det(d10,d0p);
float t = clamp( (ap+bp)/(2.0*a+b+d), 0.0 ,1.0 );
return vec3( mix(mix(b0,b1,t), mix(b1,b2,t),t), t );
}
vec4 sdBezier( vec3 a, vec3 b, vec3 c, vec3 p )
{
vec3 w = normalize( cross( c-b, a-b ) );
vec3 u = normalize( c-b );
vec3 v = ( cross( w, u ) );
vec2 a2 = vec2( dot(a-b,u), dot(a-b,v) );
vec2 b2 = vec2( 0.0 );
vec2 c2 = vec2( dot(c-b,u), dot(c-b,v) );
vec3 p3 = vec3( dot(p-b,u), dot(p-b,v), dot(p-b,w) );
vec3 cp = getClosest( a2-p3.xy, b2-p3.xy, c2-p3.xy );
return vec4( sqrt(dot(cp.xy,cp.xy)+p3.z*p3.z), cp.z, length(cp.xy), p3.z );
}
float sdEllipsoid( in vec3 p, in vec3 c, in vec3 r )
{
#if 1
return (length( (p-c)/r ) - 1.0) * min(min(r.x,r.y),r.z);
#else
float k0 = length((p-c)/r);
float k1 = length((p-c)/(r*r));
return k0*(k0-1.0)/k1;
#endif
}
vec2 sdSegment( vec3 p, vec3 a, vec3 b )
{
vec3 pa = p-a, ba = b-a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
return vec2( length( pa - ba*h ), h );
}
// https://iquilezles.org/articles/smin
float smin( float a, float b, float k )
{
float h = max(k-abs(a-b),0.0);
return min(a, b) - h*h*0.25/k;
}
float smax( float a, float b, float k )
{
float h = max(k-abs(a-b),0.0);
return max(a, b) + h*h*0.25/k;
}
vec3 smax( vec3 a, vec3 b, float k )
{
vec3 h = max(k-abs(a-b),0.0);
return max(a, b) + h*h*0.25/k;
}
// ------------------------------------------------------------------------
vec2 map( in vec3 pos )
{
float objID = 0.0;
// body
vec3 pa = vec3(-0.180,-0.160,0.100);
vec3 pb = vec3(0.400,0.293,0.316);
float ra = 0.3;
float rb = 0.1;
float d = sdRoundCone(pos, pa, pb, ra, rb );
vec2 res = vec2(d, objID);
// back
pa = vec3(0.32,0.20,0.108);
pb = vec3(0.5,-0.,0.050);
ra = 0.02;
rb = 0.12;
float d1 = sdRoundCone(pos+vec3(0.4, -0.1, 0.0), pa, pb, ra, rb );
d = smin(d, d1, 0.3);
if( d1<res.x ) res = vec2(d1,objID++);
// throat
pa = vec3(0.520,0.015,0.152);
pb = vec3(0.820,0.08,0.3);
ra = 0.1;
rb = 0.03;
d1 = sdRoundCone(pos+vec3(0.4, -0.1, 0.0), pa, pb, ra, rb );
d = smin(d, d1, 0.06);
if( d1<res.x ) res = vec2(d1,objID++);
// mouth
float an = 2.5*(0.428+0.164*sin(1.1+3.0));
vec2 c = vec2(sin(an),cos(an));
float theta1 = -0.968;
float theta2 = 0.056;
float theta3 = -1.164;
mat3 rot_X = mat3(1.0,0.,0.,
0., cos(theta1),-sin(theta1),
0.0, sin(theta1),cos(theta1) );
mat3 rot_Y = mat3(cos(theta2),0.,sin(theta2),
0., 1.0,0.,
-sin(theta2), 0.,cos(theta2) );
mat3 rot_Z = mat3(cos(theta3),-sin(theta3),0.,
sin(theta3), cos(theta3),0.,
0.0, 0.,1. );
d1 = sdCappedTorus(rot_Z*rot_Y*rot_X*(pos+vec3(-0.280,-0.300,-0.380)), c, 0.208, 0.016 );
d = smin(d, d1, 0.06);
if( d1<res.x ) res = vec2(d1,objID++);
// eyes
// eyeframe
d1 = sdSphere( pos+vec3(-0.360,-0.300,-0.4200), 0.08);
d = smin(d, d1, 0.02);
if( d1<res.x ) res = vec2(d1,objID++);
d1 = sdSphere( pos+vec3(-0.440,-0.530,0.200), 0.1);
d = smin(d, d1, 0.02);
mat3 scale = mat3(0.2,0.,0.,
0., 0.224,0.,
0., 0.,0.2);
d1 = sdEllipsoid(pos+vec3(-0.36,-0.3,-0.420),vec3(0.0,0.00,0.00),vec3(0.046,0.030,0.30) );
d = smax(d, -d1, 0.02);
if( d1<res.x ) res = vec2(d1,objID++);
// eye
mat3 rot = mat3(0.8,-0.6,0.0,
0.6, 0.8,0.0,
0.0, 0.0,1.0 );
d1 = sdEllipsoid(rot*(pos+vec3(-0.36,-0.31,-0.430)),vec3(0.0,0.00,0.00),vec3(0.100,0.099,0.099)*0.3 );
d = smin(d, d1, 0.02);
if( d1<res.x ) res = vec2(d1,objID++);
// legs
// front left
pa = vec3(0.22,0.22,0.16);
pb = vec3(0.400,0.023,0.081);
ra = 0.08;
rb = 0.1;
d1 = sdRoundCone(pos+vec3(0.4, 0.36, -0.24), pa, pb, ra, rb );
d = smin(d, d1, 0.05);
if( d1<res.x ) res = vec2(d1,objID++);
pa = vec3(0.220,0.200,0.156);
pb = vec3(0.360,-0.100,0.150);
ra = 0.09;
rb = 0.03;
d1 = sdRoundCone(pos+vec3(0.4, 0.36, -0.24), pa, pb, ra, rb );
d = smin(d, d1, 0.01);
if( d1<res.x ) res = vec2(d1,objID++);
// front right
vec4 d2 = sdBezier( vec3(0.520,-0.200,0.145), vec3(0.432,-0.100+0.1,0.14), vec3(0.460,0.248,0.15), pos +vec3(0.220,0.140,-0.200));
d1 = d2.x - smoothstep(-0.512,0.360,d2.y)*(0.163 - 0.074 *smoothstep(1.8,1.0,d2.y));
d = smin(d, d1, 0.03);
if( d1<res.x ) res = vec2(d1,objID++);
// back right
d2 = sdBezier( vec3(0.540,-0.200,0.050), vec3(0.432,-0.052+0.1,0.14), vec3(0.460,0.248,0.15), pos +vec3(0.1,0.1,0.20));
d1 = d2.x - smoothstep(-0.624,0.280,d2.y)*(0.187 - 0.106 *smoothstep(1.8,1.0,d2.y));
d = smin(d, d1, 0.03);
if( d1<res.x ) res = vec2(d1,objID++);
// paw
vec3 offset = vec3(-0.270,0.360,-0.850);
d2 = sdBezier( vec3(0.159,-0.082,-0.700), vec3(0.120,-0.180+0.1,-0.6), vec3(0.040,0.008,-0.5), pos + offset);
float dd = d2.x - smoothstep(-0.352,0.47,d2.y)*(0.12 - 0.09 *smoothstep(1.8,1.0,d2.y));
d2 = sdBezier( vec3(0.179,-0.102,-0.500), vec3(0.112,-0.212+0.1,-0.5), vec3(0.040,0.008,-0.5), pos + offset);
d1 = d2.x - smoothstep(-0.440,0.470,d2.y)*(0.115 - 0.09 *smoothstep(1.8,1.0,d2.y));
dd = smin( dd, d1, 0.04 );
d2 = sdBezier( vec3(0.019,-0.162,-0.500), vec3(0.080,-0.116+0.1,-0.5), vec3(0.040,0.008,-0.5), pos + offset);
d1 = d2.x - smoothstep(-0.224,0.200,d2.y)*(0.115 - 0.082 *smoothstep(1.8,1.0,d2.y));
dd = smin( dd, d1, 0.04 );
d1 = sdSphere(pos+vec3(-0.420,0.430,-0.200), 0.03);
dd = smin(dd, d1, 0.03);
d1 = sdSphere(pos+vec3(-0.450,0.480,-0.350), 0.02);
dd = smin(dd, d1, 0.03);
d1 = sdSphere(pos+vec3(-0.290,0.520,-0.380), 0.02);
dd = smin(dd, d1, 0.03);
d = smin(d, dd, 0.02);
if( dd<res.x ) res = vec2(dd,objID++);
offset = vec3(-0.40,0.28,-0.40);
d2 = sdBezier( vec3(0.119,-0.182,-0.700), vec3(0.056,-0.244+0.1,-0.6), vec3(0.040,0.008,-0.5), pos + offset);
dd = d2.x - smoothstep(-0.352,0.47,d2.y)*(0.12 - 0.09 *smoothstep(1.8,1.0,d2.y));
d2 = sdBezier( vec3(0.039,-0.122,-0.300), vec3(0.040,-0.212+0.1,-0.5), vec3(0.040,0.008,-0.5), pos + offset);
d1 = d2.x - smoothstep(-0.696,0.470,d2.y)*(0.115 - 0.09 *smoothstep(1.8,1.0,d2.y));
dd = smin( dd, d1, 0.06 );
d2 = sdBezier( vec3(0.219,-0.162,-0.500), vec3(0.136,-0.212+0.1,-0.5), vec3(0.040,0.008,-0.5), pos + offset);
d1 = d2.x - smoothstep(-0.440,0.470,d2.y)*(0.115 - 0.09 *smoothstep(1.512,1.040,d2.y));
dd = smin( dd, d1, 0.06 );
d1 = sdSphere(pos+vec3(-0.14,0.55,-0.40), 0.026);
dd = smin(dd, d1, 0.03);
d1 = sdSphere(pos+vec3(0.03,0.610,-0.40), 0.02);
dd = smin(dd, d1, 0.03);
d1 = sdSphere(pos+vec3(-0.140,0.620,-0.200), 0.03);
dd = smin(dd, d1, 0.03);
d = smin(d, dd, 0.02);
if( dd<res.x ) res = vec2(dd,objID++);
offset = vec3(0.0660,0.450,-0.8800);
d2 = sdBezier( vec3(0.199,-0.162,-0.700), vec3(0.136,-0.268+0.1,-0.6), vec3(0.040,0.008,-0.5), pos + offset);
dd = d2.x - smoothstep(-0.352,0.47,d2.y)*(0.12 - 0.09 *smoothstep(1.8,1.0,d2.y));
d2 = sdBezier( vec3(0.219,-0.102,-0.500), vec3(0.112,-0.212+0.1,-0.5), vec3(0.040,0.008,-0.5), pos + offset);
d1 = d2.x - smoothstep(-0.440,0.470,d2.y)*(0.115 - 0.09 *smoothstep(1.8,1.0,d2.y));
dd = smin( dd, d1, 0.06 );
d2 = sdBezier( vec3(0.019,-0.162,-0.500), vec3(0.040,-0.172+0.1,-0.5), vec3(0.040,0.008,-0.5), pos + offset);
d1 = d2.x - smoothstep(-0.440,0.08,d2.y)*(0.115 - 0.09 *smoothstep(1.8,1.0,d2.y));
dd = smin( dd, d1, 0.06 );
d1 = sdSphere(pos+vec3(-0.620,0.420,0.100), 0.02);
dd = smin(dd, d1, 0.03);
d1 = sdSphere(pos+vec3(-0.440,0.40,-0.080), 0.02);
dd = smin(dd, d1, 0.03);
d = smin(d, dd, 0.02);
if( dd<res.x ) res = vec2(dd,objID++);
return vec2(d, objID);
}
// https://iquilezles.org/articles/normalsSDF
vec3 calcNormal( in vec3 pos )
{
vec2 e = vec2(1.0,-1.0)*0.5773;
const float eps = 0.0005;
return normalize( e.xyy*map( pos + e.xyy*eps ).x +
e.yyx*map( pos + e.yyx*eps ).x +
e.yxy*map( pos + e.yxy*eps ).x +
e.xxx*map( pos + e.xxx*eps ).x );
}
// Description : Array and textureless GLSL 2D/3D/4D simplex
// noise functions.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : stegu
// Lastmod : 20201014 (stegu)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise
// https://github.com/stegu/webgl-noise
//
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 mod289(vec4 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 permute(vec4 x) {
return mod289(((x*34.0)+10.0)*x);
}
// 2D
vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }
vec4 taylorInvSqrt(vec4 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
float snoise(vec3 v)
{
const vec2 C = vec2(1.0/6.0,1.0/3.0);
const vec4 D = vec4(0.211324865405187,
// (3.0-sqrt(3.0))/6.0
0.366025403784439,
// 0.5*(sqrt(3.0)-1.0)
-0.577350269189626,
// -1.0 + 2.0 * C.x
0.024390243902439);
// 1.0 / 41.0
// First corner
vec3 i = floor(v + dot(v, C.yyy) );
vec3 x0 = v - i + dot(i, C.xxx) ;
// Other corners
vec3 g = step(x0.yzx, x0.xyz);
vec3 l = 1.0 - g;
vec3 i1 = min( g.xyz, l.zxy );
vec3 i2 = max( g.xyz, l.zxy );
// x0 = x0 - 0.0 + 0.0 * C.xxx;
// x1 = x0 - i1 + 1.0 * C.xxx;
// x2 = x0 - i2 + 2.0 * C.xxx;
// x3 = x0 - 1.0 + 3.0 * C.xxx;
vec3 x1 = x0 - i1 + C.xxx;
vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
// Permutations
i = mod289(i);
vec4 p = permute( permute( permute(
i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
+ i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
+ i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
float n_ = 0.142857142857; // 1.0/7.0
vec3 ns = n_ * D.wyz - D.xzx;
vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
vec4 x_ = floor(j * ns.z);
vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
vec4 x = x_ *ns.x + ns.yyyy;
vec4 y = y_ *ns.x + ns.yyyy;
vec4 h = 1.0 - abs(x) - abs(y);
vec4 b0 = vec4( x.xy, y.xy );
vec4 b1 = vec4( x.zw, y.zw );
//vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
//vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
vec4 s0 = floor(b0)*2.0 + 1.0;
vec4 s1 = floor(b1)*2.0 + 1.0;
vec4 sh = -step(h, vec4(0.0));
vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
vec3 p0 = vec3(a0.xy,h.x);
vec3 p1 = vec3(a0.zw,h.y);
vec3 p2 = vec3(a1.xy,h.z);
vec3 p3 = vec3(a1.zw,h.w);
//Normalise gradients
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
// Mix final noise value
vec4 m = max(0.5 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
m = m * m;
return 130.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
dot(p2,x2), dot(p3,x3) ) );
}
float snoise(vec2 v) {
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
vec2 i1;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
float random (in vec2 _st) {
return fract(sin(dot(_st.xy,vec2(12.9898,78.633)))*43758.5453123);
}
float noise (in vec2 _st) {
vec2 i = floor(_st);
vec2 f = fract(_st);
float a = random(i);
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
vec2 u = f * f * f * f *(3.0 - 2.0 * f); //+2.0*sin(u_time/10.0)
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
float fbm ( in vec2 _st, in vec2 _mo) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
mat2 rot = mat2(cos(0.5), sin(0.5),
-sin(0.5), cos(0.5));
for (int i = 0; i < NUM_OCTAVES; ++i) {
v += a * noise(_st);
_st = rot * _st * (4.5) + shift;
a *= 0.45;
}
return v;
}
// ------------------------------------------------------------------------
// Translucency: https://www.shadertoy.com/view/3lK3RR
vec3 calculateTransmittance(vec3 ro, vec3 rd, float tmin, float tmax, float atten)
{
const int MAX_DEPTH = 4;
float hitPoints[MAX_DEPTH];
int depth = 0;
for (float t = tmin; t < tmax;)
{
float h = abs(map(ro + t * rd).x);
if (h < 1e-5) { hitPoints[depth++] = t; t += 0.01; };
if (depth >= MAX_DEPTH) break;
t += h;
}
float thickness = 0.0;
for (int i = 0; i < depth - 1; i += 2) thickness += hitPoints[i+1] - hitPoints[i];
return vec3(1.0) * exp(-atten * thickness * thickness);
}
// ------------------------------------------------------------------------
void main() {
// camera movement
float an = 0.7;
vec3 ro = vec3( 0.5*cos(an), 0.0, 2.0*sin(an) );
vec3 ta = vec3( 0.0, 0.0, 0.0 );
// camera matrix
vec3 ww = normalize( ta - ro );
vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) );
vec3 vv = normalize( cross(uu,ww));
// render
vec3 tot = vec3(0.9);
for( int m=0; m<AA; m++ )
for( int n=0; n<AA; n++ )
{
// pixel coordinates
vec2 offset = vec2(float(m)+0.5,float(n)+0.5) / float(AA) - 0.5;
vec2 p = (-u_resolution.xy + 2.0*(gl_FragCoord.xy+offset))/u_resolution.y;
// create view ray
vec3 rd = normalize( p.x*uu + p.y*vv + 1.5*ww );
// raymarch
const float tmax = 2.0;
float t = 0.0;
for( int i=0; i<256; i++ )
{
vec3 pos = ro + t*rd;
float h = map(pos).x;
if( h<0.0001 || t>tmax ) break;
t += h;
}
// shading/lighting
vec3 col = vec3(0.0);
if( t<tmax )
{
vec3 pos = ro + t*rd;
vec3 nor = calcNormal(pos);
vec3 lightDir = normalize(vec3(1.0, 1.5, -1.0));
vec3 lightColor = vec3(1.0);
Material mat = Material(vec3(0.6,0.08,0.0), vec3(0.3), 8.0);
float dif = clamp( dot(nor,vec3(0.57703)), 0.0, 1.0 ); // diffusion
float t = clamp(0.5, 0.2, 1.0);
vec3 light = t * lightColor * calculateTransmittance(pos+nor*vec3(0.01), lightDir, 0.01, 10.0, 2.0);
light += (1.0 - t) * calculateTransmittance(pos+nor*vec3(0.01), rd, 0.01, 10.0, 0.5);
col += light * mat.diffuseAlbedo + mat.specularAlbedo * pow(max(0.0, dot(reflect(lightDir,nor),rd)), 4.0);
// float amb = 0.5 + 0.5*dot(nor,vec3(0.0,1.0,0.0));
// col = vec3(0.2,0.3,0.4)*amb + vec3(0.8,0.7,0.5)*dif;
}
// apply texture
float DF = 0.0;
// Add a random position
DF += snoise(9.0*p)*.25+.25;
// Add a random position
float a = snoise(p*0.1)*3.1415;
vec2 vel = vec2(cos(a),sin(a));
DF += snoise(12.0*p+vel)*.25+.25;
// float n = texture(p * 4.0); // 2D
if( length((p-vec2(0.3, -0.3)).xy) > 0.32 && length(p.xy) < 0.33) { col *= 1.0-smoothstep(.7,.75,fract(DF)); }
else { col*=1.0; }
// gamma
col = sqrt( col );
tot *= col;
}
tot /= float(AA*AA);
vec2 p = (-u_resolution.xy + 2.0*gl_FragCoord.xy)/u_resolution.y;
vec2 m = u_mouse.xy/u_resolution.xy;
vec2 q = vec2(0.);
q.x = fbm( p, m);
q.y = fbm( p + vec2(1.0), m);
vec2 r = vec2(0.);
r.x = fbm( p + 1.0*q + vec2(1.7,9.2), m);
r.y = fbm( p + 1.0*q + vec2(8.3,2.8), m);
float f = fbm(p+r, m);
vec2 g = vec2(f);
vec3 color = vec3(0.0);
color = mix(vec3(0.681,0.858,0.920),
vec3(0.967,0.156,0.573),
clamp((f*f)*4.312,0.992,1.0));
color = mix(color,
vec3(0.300,0.034,0.134),
clamp(length(q),0.0,1.0));
color = mix(color,
vec3(1.000,0.700,0.315),
clamp(length(r.x),0.0,1.0));
tot *= vec3((f*f*f+0.7*f*f*f*f+3.068*f*f)*color*5.0);
tot = pow(tot, vec3(0.4545));
colour_out = vec4(tot, 1.0);
}
unknown by algaeee
// credit: TATyz
// frog: Blue Poison Dart Frog
#define BLADES_SPACING 0.004
#define JITTER_MAX 0.004
// depends on size of grass blades in pixels
#define LOOKUP_DIST 5
#define HASHSCALE1 .1031
#define HASHSCALE3 vec3(.1031, .1030, .0973)
precision mediump float;
uniform vec2 u_resolution;
uniform float u_time;
float msign(in float x) { return (x<0.0)?-1.0:1.0; }
// background grass start
float hash12(vec2 p)
{
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);
p3 += dot(p3, p3.yzx + 19.19);
return fract((p3.x + p3.y) * p3.z);
}
/// 3 out, 2 in...
vec3 hash32(vec2 p)
{
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE3);
p3 += dot(p3, p3.yxz+19.19);
return fract((p3.xxy+p3.yzz)*p3.zyx);
}
/// 2 out, 2 in...
vec2 hash22(vec2 p)
{
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE3);
p3 += dot(p3, p3.yzx+19.19);
return fract((p3.xx+p3.yz)*p3.zy);
}
vec3 getGrassColor(float x) {
vec3 a = vec3(0.2, 0.4, 0.3);
vec3 b = vec3(0.3, 0.5, 0.2);
vec3 c = vec3(0.2, 0.4, 0.2);
vec3 d = vec3(0.66, 0.77, 0.33);
vec3 col = a + b * cos(2. * 3.14 * (c * x + d));
return col;
}
float getGrassBlade(in vec2 position, in vec2 grassPos, out vec4 color) {
// between {-1, -1, -1} and {1, 1, 1}
vec3 grassVector3 = hash32(grassPos * 123512.41) * 2.0 - vec3(1);
// keep grass z between 0 and 0.4
grassVector3.z = grassVector3.z * 0.2 + 0.2;
vec2 grassVector2 = normalize(grassVector3.xy);
float grassLength = hash12(grassPos * 102348.7) * 0.01 + 0.012;
// take coordinates in grass blade frame
vec2 gv = position - grassPos;
float gx = dot(grassVector2, gv);
float gy = dot(vec2(-grassVector2.y, grassVector2.x), gv);
float gxn = gx / grassLength;
// TODO make gy depends to gx
if (gxn >= 0.0 && gxn <= 1.0 && abs(gy) <= 0.0008 * (1. - gxn * gxn)) {
vec3 thisGrassColor = getGrassColor(hash12(grassPos * 2631.6));
color = vec4(thisGrassColor * (0.2 + 0.8 * gxn), 1.0);
return grassVector3.z * gxn;
}
else {
color = vec4(0., 0., 0., 1.);
return -1.0;
}
}
float getPoint(in vec2 position, out vec4 color) {
int xcount = int(1. / BLADES_SPACING);
int ycount = int(1. / BLADES_SPACING);
int ox = int(position.x * float(xcount));
int oy = int(position.y * float(ycount));
float maxz = 0.0;
for (int i = -LOOKUP_DIST; i < LOOKUP_DIST; ++i) {
for (int j = -LOOKUP_DIST; j < LOOKUP_DIST; ++j) {
vec2 upos = vec2(ox + i, oy + j);
vec2 grassPos = (upos * BLADES_SPACING + hash22(upos) * JITTER_MAX);
vec4 tempColor;
float z = getGrassBlade(position, grassPos, tempColor);
if (z > maxz) {
maxz = z;
color = tempColor;
}
}
}
if (maxz == 0.0) {
color = vec4(0.);
}
return maxz;
}
// end
float sdUnion( float d1, float d2 ) {
return min( d1, d2 );
}
float sdDifference( float d1, float d2 ) {
return max( -d1, d2 ); /* Remove d1 from d2 */
}
float sdEllipse( vec2 p, in vec2 ab , in vec2 bias, in float rot)
{
//if( ab.x==ab.y ) return length(p)-ab.x;
vec2 p0 = p;
p.x = p0.x * cos(rot) - p0.y * sin(rot);
p.y = p0.x * sin(rot) + p0.y * cos(rot);
p = abs( p + bias);
if( p.x>p.y ){ p=p.yx; ab=ab.yx; }
float l = ab.y*ab.y - ab.x*ab.x;
float m = ab.x*p.x/l;
float n = ab.y*p.y/l;
float m2 = m*m;
float n2 = n*n;
float c = (m2+n2-1.0)/3.0;
float c3 = c*c*c;
float d = c3 + m2*n2;
float q = d + m2*n2;
float g = m + m *n2;
float co;
if( d<0.0 )
{
float h = acos(q/c3)/3.0;
float s = cos(h) + 2.0;
float t = sin(h) * sqrt(3.0);
float rx = sqrt( m2-c*(s+t) );
float ry = sqrt( m2-c*(s-t) );
co = ry + sign(l)*rx + abs(g)/(rx*ry);
}
else
{
float h = 2.0*m*n*sqrt(d);
float s = msign(q+h)*pow( abs(q+h), 1.0/3.0 );
float t = msign(q-h)*pow( abs(q-h), 1.0/3.0 );
float rx = -(s+t) - c*4.0 + 2.0*m2;
float ry = (s-t)*sqrt(3.0);
float rm = sqrt( rx*rx + ry*ry );
co = ry/sqrt(rm-rx) + 2.0*g/rm;
}
co = (co-m)/2.0;
float si = sqrt( max(1.0-co*co,0.0) );
vec2 r = ab * vec2(co,si);
return length(r-p) * msign(p.y-r.y);
}
float sdEgg( in vec2 p, in float ra, in float rb, in vec2 bias, in float rot)
{
const float k = sqrt(3.0);
vec2 p0 = p;
p.x = p0.x * cos(rot) - p0.y * sin(rot);
p.y = p0.x * sin(rot) + p0.y * cos(rot);
p.y = p.y + bias.y;
p.x = abs(p.x + bias.x);
float r = ra - rb;
return ((p.y<0.0) ? length(vec2(p.x, p.y )) - r :
(k*(p.x+r)<p.y) ? length(vec2(p.x, p.y-k*r)) :
length(vec2(p.x+r,p.y )) - 2.0*r) - rb;
}
float udSegment( in vec2 p, in vec2 a, in vec2 b )
{
vec2 ba = b-a;
vec2 pa = p-a;
float h =clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
return length(pa-h*ba);
}
float sdCircle( in vec2 p, in float r )
{
return length(p)-r;
}
// texture
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec3 permute(vec3 x) {
return mod289(((x*34.0)+10.0)*x);
}
float snoise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
vec3 body_bubble( in vec2 p , in vec2 resolution, in float time)
{
// background
//vec3 color = vec3(0.137, 0.582, 0.836);
vec3 color = vec3(0.008, 0.348, 0.590) + vec3(sin(0.5*p.x));
// bubbles
for( int i=0; i<1000; i++ )
{
// bubble seeds
float pha = sin(float(i)*546.13+5.0)*0.5 + 0.5;
float siz = pow( sin(float(i)*652.74+6.0)*0.5 + 0.5, 9.0 );
if (siz > 0.15){
continue;
}
float pox = sin(float(i)*321.55+6.1) * resolution.x / resolution.y;
// buble size, position and color
float rad = (0.04 + 0.5*siz)+0.03*sin(16.0*p.y)*abs(cos(0.5*time+0.2))-0.03*sin(15.0*p.x)*abs(sin(0.5*time-0.1)) ; // shape of all
vec2 pos = vec2( pox, -1.0-rad + (2.0+2.0*rad)*mod(pha+0.1*(0.2+0.8*siz),1.0));
float dis = length( p - pos -vec2(-.001,.001)); // control circle shape
// vec3 col = mix( vec3(0.94,0.3,0.0), vec3(0.1,0.4,0.8), 0.5+0.5*sin(float(i)*1.2+1.9));
vec3 col = vec3(0.6);
// col+= 8.0*smoothstep( rad*0.95, rad, dis );
// render
float f = length(p-pos)/rad;
f = sqrt(clamp(1.0-f*f,0.0,1.0));
color -= col.zyx *(1.0-smoothstep( rad*0.95, rad, dis )) * f;
}
// vigneting
color *= sqrt(1.5-0.8*length(p));
return color;
}
float turbulence_example( vec2 p ) {
float f = 0.0, scale;
for (int i=0; i<4; i++) {
scale = pow( pow(1.376, 3.952/2.960), float(i) );
f += abs( snoise( p * scale ) ) / scale;
}
return f;
}
vec3 random(vec2 co, vec2 bias) {
const highp float seed = 12.9898;
highp float a = seed;
highp float b = 78.305, c = 47386.098;
highp float dt= dot(co.xy, vec2(a,b));
highp float sn= mod(dt,3.14159265358979323846);
float n = fract(sin(sn) * c)*2.0-1.0;
//vec3 colour_out = vec3(0.133,0.156,0.359)*n*3.0;
vec3 colour = vec3(0.197,0.242,0.510)*n*3.0; // basic color
return colour - 0.9*length(co+bias);
}
void main() {
float PI = 3.14159265358;
vec2 p = (2.0*gl_FragCoord.xy-u_resolution.xy)/u_resolution.y;
vec2 ra = vec2(0.6,0.3);
float d_body = sdEllipse(p, ra, vec2(0.0, 0.1), 135.0 * PI / 180.0); // draw body1
ra = vec2(0.35, 0.2);
float d_head = sdEllipse(p, ra, vec2(0.45, 0.25), 155.0 * PI / 180.0); // draw head
// right leg
float ra_egg = 0.12;
float d_leg_b = sdEgg(p, ra_egg, ra_egg*(3.9+12.9)*cos(2.0), vec2(0.39, 0.2), -90.0*PI / 180.0) - 0.06;
// left leg
ra = vec2(0.3, 0.13);
float d_leg_a = sdEllipse(p, ra, vec2(0.1, -0.53), -80.0 * PI / 180.0);
// arm
vec2 ar_v1 = vec2(0.2, 0.2);
vec2 ar_v2 = vec2(0.4, -0.1);
float d_arm1 = udSegment(p, ar_v1, ar_v2) - 0.08;
ar_v1 = vec2(0.4, -0.1);
ar_v2 = vec2(0.6, -0.1);
float d_arm2 = udSegment(p, ar_v1, ar_v2) - 0.08;
// feet
ra = vec2(0.21, 0.1);
float d_feet = sdEllipse(p, ra, vec2(0.1, 0.53), 15.0 * PI / 180.0);
// eye
float d_eye_b = sdCircle(p + vec2(-0.48, -0.45), 0.07);
float d_eye_center = sdCircle(p + vec2(-0.51+0.015*abs(sin(1.0*u_time+0.3)), -0.45+0.01*cos(1.0*u_time-0.3)), 0.02);
float d_body_com = sdUnion(d_body, d_head);
d_body_com = sdUnion(d_body_com, d_arm1);
d_body_com = sdUnion(d_body_com, d_arm2);
float d_back = sdUnion(d_body_com, d_leg_a);
d_back = sdUnion(d_back, d_leg_b);
d_back = sdUnion(d_back, d_feet);
d_body_com = sdDifference(d_leg_b, d_body_com);
d_body_com = sdDifference(d_eye_b, d_body_com);
d_leg_a = sdDifference(d_body_com, d_leg_a);
d_leg_b = sdUnion(d_leg_b, d_feet);
d_eye_b = sdDifference(d_eye_center, d_eye_b);
// draw texture
//vec3 col = sign(-d_body_com)*vec3(0.1,0.4,0.7);
vec3 col = ((sign(-d_body_com)+1.0)/2.0)*body_bubble(p, u_resolution, u_time);
//vec3 col_head = sign(-d_head)*vec3(0.5,0.4,0.7);
vec3 col_leg_b = ((sign(-d_leg_b)+1.0)/2.0) * random(p, vec2(-0.2, 0.4));
vec3 col_leg_a = ((sign(-d_leg_a)+1.0)/2.0) * random(p, vec2(0.8, 0.15));
vec3 col_eye_b = ((sign(-d_eye_b)+1.0)/2.0) * vec3(0.1,0.1,0.1);
vec3 col_eye_center = ((sign(-d_eye_center)+1.0)/2.0) * vec3(0.9,0.9,0.9);
/* leg 0.133,0.156,0.359 */
vec4 col_back;
float z_back = getPoint(gl_FragCoord.xy/vec2(8000.0, 8000.0), col_back);
col_back = ((sign(d_back)+1.0)/2.0) * col_back;
//vec3 col_back = ((sign(d_back)+1.0)/2.0)*vec3(0.2,0.2,0.2);
//col *= 1.0 - exp(-2.0*abs(d));
//col *= 0.8 + 0.2*cos(120.0*d);
//col = mix( col, vec3(1.0), 1.0 - smoothstep(0.0,0.01,abs(d)) ); // 白边
colour_out = vec4((col+col_leg_b+col_leg_a+col_eye_b+col_eye_center+col_back.xyz), 1.0);
}
Blue Poison Dart Frog by TATyz
// credit: Ziyang Zhang (will show up on website)
// frog: Yellow-band poison dart
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float cro(vec2 a,vec2 b )
{
return a.x*b.y - a.y*b.x;
}
float sdUnevenCapsule(vec2 p,vec2 pa,vec2 pb,float ra,float rb )
{
p -= pa;
pb -= pa;
float h = dot(pb,pb);
vec2 q = vec2( dot(p,vec2(pb.y,-pb.x)), dot(p,pb) )/h;
//-----------
q.x = abs(q.x);
float b = ra-rb;
vec2 c = vec2(sqrt(h-b*b),b);
float k = cro(c,q);
float m = dot(c,q);
float n = dot(q,q);
if( k < 0.0 ) return sqrt(h*(n )) - ra;
else if( k > c.x ) return sqrt(h*(n+1.0-2.0*q.y)) - rb;
return m - ra;
}
float get_body_mask(vec2 p)
{
vec2 v1 = ( vec2(0.0,-0.40) + 0.0 );
vec2 v2 = ( vec2(0.0,0.10) );
float r1 = 0.45;
float r2 = 0.275;
float d = step( 0.01,sdUnevenCapsule( p, v1, v2, r1, r2 ));
return d;
}
float get_leg_mask_left(vec2 p)
{
vec2 v1 = ( vec2(-0.5,-0.40) + 0.0 );
vec2 v2 = vec2(-0.9,0);
float r1 = 0.22;
float r2 = 0.1;
vec2 p2 = vec2(p.x - 0.2f,p.y + 0.3f);
float d = step( 0.01,sdUnevenCapsule( p2, v1, v2, r1, r2 ));
return d;
}
float get_leg_mask_right(vec2 p)
{
vec2 v1 = ( vec2(0.5,-0.40) + 0.0 );
vec2 v2 = vec2(0.9,0);
float r1 = 0.22;
float r2 = 0.1;
vec2 p2 = vec2(p.x + 0.2f,p.y + 0.3f);
float d = step( 0.01,sdUnevenCapsule( p2, v1, v2, r1, r2 ));
return d;
}
float get_arm_body_right(vec2 p)
{
vec2 v1 = ( vec2(0.1,0.30) + 0.0 );
vec2 v2 = vec2(0.35,0);
float r1 = 0.1;
float r2 = 0.05;
vec2 p2 = vec2(p.x - 0.05f,p.y + 0.2f);
float d = step( 0.01,sdUnevenCapsule( p2, v1, v2, r1, r2 ));
return d;
}
float get_arm_body_left(vec2 p)
{
vec2 v1 = ( vec2(-0.1,0.30) + 0.0 );
vec2 v2 = vec2(-0.35,0);
float r1 = 0.1;
float r2 = 0.05;
vec2 p2 = vec2(p.x + 0.05f,p.y + 0.2f);
float d = step( 0.01,sdUnevenCapsule( p2, v1, v2, r1, r2 ));
return d;
}
float get_arm_right(vec2 p)
{
vec2 v1 = ( vec2(0.1,0.40) + 0.0 );
vec2 v2 = vec2(0.35,0.75);
float r1 = 0.1;
float r2 = 0.05;
vec2 p2 = vec2(p.x - 0.15f,p.y + 0.55f);
float d = step( 0.01,sdUnevenCapsule( p2, v1, v2, r1, r2 ));
return d;
}
float get_arm_left(vec2 p)
{
vec2 v1 = ( vec2(-0.1,0.40) + 0.0 );
vec2 v2 = vec2(-0.35,0.75);
float r1 = 0.1;
float r2 = 0.05;
vec2 p2 = vec2(p.x + 0.15f,p.y + 0.55f);
float d = step( 0.01,sdUnevenCapsule( p2, v1, v2, r1, r2 ));
return d;
}
float get_mask(vec2 st, vec2 p)
{
float mask = 1.0;
mask *= step( 0.055, distance( st.xy, vec2(0.6, 0.65) ) );
mask *= step( 0.055, distance( st.xy, vec2(0.4, 0.65) ) );
mask *= get_body_mask(p);
mask *= get_leg_mask_left(p);
mask *= get_leg_mask_right(p);
mask *= get_arm_body_right(p);
mask *= get_arm_body_left(p);
mask *= get_arm_right(p);
mask *= get_arm_left(p);
return mask;
}
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec3 permute(vec3 x) {
return mod289(((x*34.0)+10.0)*x);
}
float snoise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
float marbleturbulence( vec2 p )
{ /* Same as the turbulence before. */
float f = 0.0, scale;
for (int i=0; i<4; i++) {
scale = pow( pow(2.0, 4.0/3.0), float(i) );
f += abs( snoise( p * scale ) ) / scale; }
return f;
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec2 p = st * 2.0f - 1.0f;
float mask = get_mask(st,p);
vec4 leg_c = vec4( 0.94, 0.78, 0.329, 1.0 ) * 0.95f;
leg_c.a = 1.0f;
colour_out = vec4( 0.94, 0.78, 0.329, 1.0 );
colour_out *= 1.0-mask;
float n = marbleturbulence( st );
float t = step(1.0,1.0 + sin( (st.y * u_resolution.y) / 18.556 + 3.2528 * n ) / 2.0);
colour_out *= vec4( vec3(t), 1.0 );
float dot_mask = snoise(st * 9.75f - u_time * 0.1f);
dot_mask = step(0.3 , dot_mask*0.5 + 0.5);
colour_out *= dot_mask;
dot_mask = 1.0f - snoise(st * 1.75f * (5.0f+cos(u_time)));
dot_mask = step(0.5,dot_mask);
float cmask_l = get_leg_mask_left(p);
colour_out *= cmask_l;
colour_out += (1.0f - cmask_l) * leg_c * dot_mask;
float cmask_r = get_leg_mask_right(p);
colour_out *= cmask_r;
colour_out += (1.0f - cmask_r) * leg_c* dot_mask;
colour_out *= step( 0.035, distance( st.xy, vec2(0.6, 0.675) ) );
colour_out *= step( 0.035, distance( st.xy, vec2(0.4, 0.675) ) );
colour_out += 1.0 - step( 0.0085, distance( st.xy, vec2(0.61, 0.6795) ) );
colour_out += 1.0 - step( 0.0085, distance( st.xy, vec2(0.41, 0.6795) ) );
colour_out.a = 1.0f;
//colour_out = vec4(dot_mask,dot_mask,dot_mask,1);
colour_out += step(1.0,mask) * vec4(1,1,1,1);
}
Yellow-band poison dart frog by Ziyang Zhang
//by nagisa
uniform vec2 u_resolution;
uniform float u_time;
vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 mod289(vec4 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
// Permutation polynomial: (34x^2 + 6x) mod 289
vec4 permute(vec4 x) {
return mod289((34.0 * x + 10.0) * x);
}
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
// Permutation polynomial: (34x^2 + 6x) mod 289
vec3 permute(vec3 x) {
return mod289((34.0 * x + 10.0) * x);
}
float snoise(vec2 v) {
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy));
vec2 x0 = v - i + dot(i, C.xx);
// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));
vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);
m = m * m;
m = m * m;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);
// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
vec4 taylorInvSqrt(vec4 r) {
return 1.79284291400159 - 0.85373472095314 * r;
}
vec2 fade(vec2 t) {
return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
}
// Classic Perlin noise
float cnoise(vec2 P) {
vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);
vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);
Pi = mod289(Pi); // To avoid truncation effects in permutation
vec4 ix = Pi.xzxz;
vec4 iy = Pi.yyww;
vec4 fx = Pf.xzxz;
vec4 fy = Pf.yyww;
vec4 i = permute(permute(ix) + iy);
vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0;
vec4 gy = abs(gx) - 0.5;
vec4 tx = floor(gx + 0.5);
gx = gx - tx;
vec2 g00 = vec2(gx.x, gy.x);
vec2 g10 = vec2(gx.y, gy.y);
vec2 g01 = vec2(gx.z, gy.z);
vec2 g11 = vec2(gx.w, gy.w);
vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
float n00 = dot(g00, vec2(fx.x, fy.x));
float n10 = dot(g10, vec2(fx.y, fy.y));
float n01 = dot(g01, vec2(fx.z, fy.z));
float n11 = dot(g11, vec2(fx.w, fy.w));
vec2 fade_xy = fade(Pf.xy);
vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
float n_xy = mix(n_x.x, n_x.y, fade_xy.y);
return 2.3 * n_xy;
}
float random(in vec2 st) {
return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
}
// Value noise by Inigo Quilez - iq/2013
// https://www.shadertoy.com/view/lsf3WH
float noise(vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(mix(random(i + vec2(0.0, 0.0)), random(i + vec2(1.0, 0.0)), u.x), mix(random(i + vec2(0.0, 1.0)), random(i + vec2(1.0, 1.0)), u.x), u.y);
}
mat2 rotate2d(float angle) {
return mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
}
float lines(in vec2 pos, float b) {
float scale = 1.2;
pos *= scale;
return smoothstep(0.1, .5 + b * .5, abs((sin(pos.x * 3.1415) + b * 2.0)) * .5);
}
float dot2(in vec3 v) {
return dot(v, v);
}
float opUnion(float d1, float d2) {
return min(d1, d2);
}
float opSmoothUnion(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);
}
float sdSphere(vec3 p, float s) {
return length(p) - s;
}
float sdCapsule(vec3 p, vec3 a, vec3 b, float r) {
vec3 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
return length(pa - ba * h) - r;
}
float sdRoundCone(vec3 p, vec3 a, vec3 b, float r1, float r2) {
// sampling independent computations (only depend on shape)
vec3 ba = b - a;
float l2 = dot(ba, ba);
float rr = r1 - r2;
float a2 = l2 - rr * rr;
float il2 = 1.0 / l2;
// sampling dependant computations
vec3 pa = p - a;
float y = dot(pa, ba);
float z = y - l2;
float x2 = dot2(pa * l2 - ba * y);
float y2 = y * y * l2;
float z2 = z * z * l2;
// single square root!
float k = sign(rr) * rr * rr * x2;
if(sign(z) * a2 * z2 > k)
return sqrt(x2 + z2) * il2 - r2;
if(sign(y) * a2 * y2 < k)
return sqrt(x2 + y2) * il2 - r1;
return (sqrt(x2 * a2 * il2) + y * rr) * il2 - r1;
}
float sdCappedCylinder(vec3 p, vec3 a, vec3 b, float r) {
vec3 ba = b - a;
vec3 pa = p - a;
float baba = dot(ba, ba);
float paba = dot(pa, ba);
float x = length(pa * baba - ba * paba) - r * baba;
float y = abs(paba - baba * 0.5) - baba * 0.5;
float x2 = x * x;
float y2 = y * y * baba;
float d = (max(x, y) < 0.0) ? -min(x2, y2) : (((x > 0.0) ? x2 : 0.0) + ((y > 0.0) ? y2 : 0.0));
return sign(d) * sqrt(abs(d)) / baba;
}
float sdEllipsoid(vec3 p, vec3 r) {
float k0 = length(p / r);
float k1 = length(p / (r * r));
return k0 * (k0 - 1.0) / k1;
}
vec2 opU(vec2 d1, vec2 d2) {
return (d1.x < d2.x) ? d1 : d2;
}
vec2 map(vec3 pos) {
vec2 res = vec2(2.0, 0.0);
float tree = sdCappedCylinder(pos, vec3(-5.0, 3.0, -3.75), vec3(3.9, -5.0, 2.4), 1.2);
res = opU(res, vec2(tree, 1.0));
float body = sdRoundCone(pos, vec3(0, 0.15, 0.5), vec3(-0.67, 0.04, 0.12), 0.23, 0.28);
float eyes = opUnion(sdSphere(pos - vec3(.10, 0.32, 0.40), 0.14), sdSphere(pos - vec3(-.05, 0.17, 0.63), 0.14));
float eyeball = sdEllipsoid(pos - vec3(-.06, 0.18, 0.70), vec3(0.1, 0.08, 0.11));
float p = 130.0 * 3.1415 / 180.0;
mat3 rotx = mat3(1.0, 0.0, 0.0, 0, cos(p), sin(p), 0, -sin(p), cos(p));
p = -10.0 * 3.1415 / 180.0;
mat3 rotz = mat3(cos(p), sin(p), 0, -sin(p), cos(p), 0, 0, 0, 1);
p = 20.0 * 3.1415 / 180.0;
mat3 roty = mat3(cos(p), 0, -sin(p), 0, 1, 0, sin(p), 0, cos(p));
float mouth = sdEllipsoid(rotx * roty * rotz * (pos - vec3(0.0, 0.15, 0.61)), vec3(0.3, 0.13, 0.18));
p = 80.0 * 3.1415 / 180.0;
rotx = mat3(1.0, 0.0, 0.0, 0, cos(p), sin(p), 0, -sin(p), cos(p));
p = 10.0 * 3.1415 / 180.0;
rotz = mat3(cos(p), sin(p), 0, -sin(p), cos(p), 0, 0, 0, 1);
p = 50.0 * 3.1415 / 180.0;
roty = mat3(cos(p), 0, -sin(p), 0, 1, 0, sin(p), 0, cos(p));
float naka = sdEllipsoid(rotx * roty * rotz * (pos - vec3(-0.46, 0.11, 0.3)), vec3(0.2, 0.22, 0.25));
body = opSmoothUnion(body, naka, 0.14);
body = opSmoothUnion(opSmoothUnion(body, eyes, 0.0001), mouth, 0.05);
float frog = opSmoothUnion(body, eyes, 0.0001);
float legL1 = sdCapsule(pos, vec3(-0.83, -0.1, 0.2), vec3(-.81, -.3, 0.5), 0.07);
float legL2 = sdCapsule(pos, vec3(-.83, -0.31, 0.5), vec3(-1.05, -0.13, 0.27), 0.06);
float legL3 = sdCapsule(pos, vec3(-1.05, -0.1, 0.32), vec3(-.96, -0.43, 0.37), 0.04);
float legR1 = sdCapsule(pos, vec3(-0.2, -0.1, 0.5), vec3(-.26, -0.3, 0.7), 0.04);
float legR2 = sdCapsule(pos, vec3(-.26, -0.33, 0.7), vec3(-.21, -0.6, 0.6), 0.04);
float legL = opSmoothUnion(legL1, opSmoothUnion(legL2, legL3, 0.02), 0.02);
float legR = opSmoothUnion(legR1, legR2, 0.02);
float fingerL1 = sdCapsule(pos, vec3(-.98, -0.43, 0.36), vec3(-.79, -.52, 0.4), 0.02);
float fingerL2 = sdCapsule(pos, vec3(-.98, -0.43, 0.36), vec3(-.76, -.56, 0.6), 0.02);
float fingerL3 = sdCapsule(pos, vec3(-.98, -0.43, 0.36), vec3(-.91, -.55, 0.55), 0.02);
float fingerR1 = sdCapsule(pos, vec3(-.21, -0.63, 0.57), vec3(-.10, -.57, 0.6), 0.02);
float fingerR2 = sdCapsule(pos, vec3(-.21, -0.6, 0.6), vec3(-.01, -.67, 0.6), 0.02);
float fingerR3 = sdCapsule(pos, vec3(-.21, -0.63, 0.6), vec3(-.12, -.72, 0.67), 0.02);
float fingerL = opUnion(fingerL1, opUnion(fingerL2, fingerL3));
float fingerR = opUnion(fingerR1, opUnion(fingerR2, fingerR3));
legL = opSmoothUnion(legL, fingerL, 0.05);
legR = opSmoothUnion(legR, fingerR, 0.05);
float legs = opUnion(legL, legR);
frog = opSmoothUnion(frog, legs, 0.05);
res = opU(res, vec2(frog, 2.0));
res = opU(res, vec2(eyeball, 3.0));
return res;
}
vec3 calcNormal(in vec3 pos) {
vec2 e = vec2(1.0, -1.0) * 0.5773;
const float eps = 0.0005;
return normalize(e.xyy * map(pos + e.xyy * eps).x +
e.yyx * map(pos + e.yyx * eps).x +
e.yxy * map(pos + e.yxy * eps).x +
e.xxx * map(pos + e.xxx * eps).x);
}
const float NEAR_CLIPPING_PLANE = 0.01;
const float FAR_CLIPPING_PLANE = 5.0;
const int MARCHING_STEPS = 100;
const float EPSILON = 0.0001;
const float DISTANCE_BIAS = 1.0;
const vec3 LIGHT_COL = vec3(1.6);
/* We are approximating soft shadows for "free" with raymarching. */
float softshadow(vec3 ro, vec3 rd, float k) {
float res = 1.0;
float ph = 1e20;
float t = NEAR_CLIPPING_PLANE;
for(int i = 0; i < MARCHING_STEPS; i++) {
float h = map(ro + t * rd).x;
if(h < EPSILON)
return 0.0;
float y = h * h / (2.0 * ph);
float d = sqrt(h * h - y * y);
res = min(res, k * d / max(0.0, t - y));
ph = h;
t += h * DISTANCE_BIAS;
if(t > FAR_CLIPPING_PLANE)
break;
}
return res;
}
float fbm_example(vec2 p) {
float f = 0.0, scale;
for(int i = 0; i < 6; i++) {
scale = pow(pow(2.0, 4.0 / 3.0), float(i));
f += snoise(p * scale) / scale;
}
return f;
}
vec2 raymarch(vec3 ro, vec3 rd) {
const float tmax = 5.0;
vec2 t = vec2(-1, 0.0);
for(int i = 0; i < 256; i++) {
vec3 pos = ro + t.x * rd;
vec2 h = map(pos);
if(h.x < 0.0001 || t.x > tmax) {
break;
}
t.x += h.x;
t.y = h.y;
}
return t;
}
void main() {
// camera movement
float an = 1.87 - 0.01 * (1.0 - cos(2.5 * u_time));
vec3 ro = vec3(0.0, 0.0, 1.6) + 1.5 * vec3(cos(an), 0, sin(an));
vec3 ta = vec3(0.11, -0.36, 0.0);
// camera matrix
vec3 ww = normalize(ta - ro);
vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
vec3 vv = normalize(cross(uu, ww));
vec2 p = (2.0 * gl_FragCoord.xy - u_resolution.xy) / u_resolution.y;
// create view ray
vec3 rd = normalize(p.x * uu + p.y * vv + 1.8 * ww);
vec3 tot = vec3(0, 0, 0.0);
vec2 t = raymarch(ro, rd);
vec3 LIGHT_POS = 3.0 * vec3(.6, 1.0, 2.8);
const float tmax = 5.0;
//shading/lighting
vec3 col = vec3(0.0);
if(t.x < tmax) {
vec3 pos = ro + t.x * rd;
vec3 nor = calcNormal(pos);
float dif = clamp(dot(nor, vec3(0.57703)), 0.0, 1.0);
float amb = 0.5 + 0.5 * dot(nor, vec3(0.0, 1.0, 0.0));
vec3 mat = vec3(0.1, 0.6, 0.7);
if(t.y == 1.0) {
vec2 st = pos.xy;
float p = 10.3;
mat2 rot2d = mat2(cos(p), sin(p), -sin(p), cos(p));
vec2 pos = st.xy * rot2d * vec2(7., 4.);
st.y *= u_resolution.y / u_resolution.x;
float pattern = pos.x;
vec2 pos1 = rotate2d(noise(pos) * .45) * pos;
pattern = lines(pos1, 0.3);
mat = vec3(0.33, pattern * 0.55 + 0.09, 0.21) * 0.1 + vec3(0.0, fbm_example(pos.xy * 2.24) * 0.04 + 0.03, 0.0);
}
if(t.y == 2.0) {
if(pos.x > -0.3 && pos.y < -0.23) {
if(pos.y > -0.3) {
mat = mix(vec3(0.99, 0.01, 0.01), vec3(0.001, 0.05, 0.6 * (snoise(pos.xy * 62.00) * 1.4 + 0.9)), snoise(pos.yy) * 1.95 + 0.91);
} else {
mat = vec3(0.001, 0.05, 0.6 * (snoise(pos.yx * 62.00) * 1.4 + 0.9));
}
} else if(0.7 * pos.x + pos.y < -.69) {
mat = mix(vec3(0.001, 0.05, 0.6 * (snoise(pos.xy * 62.00) * 1.4 + 0.9)), vec3(0.99, 0.01, 0.01), 1.5 * pos.x + pos.y + 1.46 + 0.12);
} else {
mat = mix(vec3(0.99, 0.01, 0.01), vec3((snoise((pos.zy + vec2(2.61, 5.4)) * 16.0) * 1.5 + 0.7), 0.01, 0.01), pos.x - pos.y * 0.4 - 0.3);
}
}
if(t.y == 3.0) {
mat = vec3(0.01);
}
col = vec3(0.2, 0.2, 0.2) * amb * 0.1 +
vec3(0.35, 0.55, 0.65) * dif * 0.1 + mat;
vec3 light_dir = normalize(LIGHT_POS - pos);
/* Shadows computed with raymarching. */
float sha = softshadow(pos + nor * 0.001, light_dir, 8.0);
/* Lighting is simple based on a point light. */
float sun = max(dot(nor, light_dir), 0.0);
vec3 lin = sun * LIGHT_COL * pow(vec3(sha), vec3(1.5));
col = col * lin;
// col=col*mat;
} else {
col = vec3(0.15, 0.12 * cnoise(p.xy * 1.2) + 0.21, 0.15);
}
// gamma
col = sqrt(col);
tot += col;
colour_out = vec4(tot, 1.0);
}
unknown by nagisa
その他の学生作品
2022年の学生作品の残りは以下の通りです。なお、一部の作品は非常に計算量が多いため、お使いのブラウザで問題が発生する可能性があります。 全学生の作品を表示
// credit: shouli
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec3 permute(vec3 x) {
return mod(((x * 34.0) + 10.0) * x, 289.0);
}
float snoise(vec2 v) {
const vec4 C = vec4(0.211324865405187, 0.366025403784439,
-0.577350269189626, 0.024390243902439);
vec2 i = floor(v + dot(v, C.yy));
vec2 x0 = v - i + dot(i, C.xx);
vec2 i1;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
i = mod(i, 289.0);
vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))
+ i.x + vec3(0.0, i1.x, 1.0));
vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);
m = m * m;
m = m * m;
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
float fbm(vec2 p) {
float f = 0.0, scale;
for (int i=0; i<4; i++) {
scale = pow( pow(2.0, 4.0/3.0), float(i) );
f += snoise( p * scale ) / scale;
}
return f;
}
void main() {
vec2 p = gl_FragCoord.xy / u_resolution.y;
float n = fbm(p);
float tex = step(5.0, distance(p, vec2(0.47, 0.2)) * 30.0 + 3.0 * n);
tex *= step(4.0, distance(p, vec2(0.27, 0.3)) * 30.0 + 3.0 * n);
tex *= step(5.0, distance(p, vec2(0.68, 0.33)) * 30.0 + 3.0 * n);
tex *= step(3.7, distance(p, vec2(0.31,0.154)) * 30.0 + 3.0 * n);
tex *= step(3.5, distance(p, vec2(0.45,0.44)) * 30.0 + 3.0 * n);
tex *= step(3.0, distance(p, vec2(0.63,0.52)) * 30.0 + 3.0 * n);
tex *= step(2.9, distance(p, vec2(0.43,0.65)) * 30.0 + 3.0 * n);
tex *= step(3.2, distance(p, vec2(0.21,0.49)) * 30.0 + 3.0 * n);
tex *= step(1.0, distance(p, vec2(0.14,0.69)) * 30.0 + 3.0 * n);
tex *= step(2.5, distance(p, vec2(0.20,0.9)) * 30.0 + 3.0 * n);
tex *= step(2.3, distance(p, vec2(0.45,0.95)) * 30.0 + 3.0 * n);
tex *= step(2.0, distance(p, vec2(0.665,0.75)) * 30.0 + 3.0 * n);
tex *= step(4.0, distance(p, vec2(0.82,0.48)) * 30.0 + 3.0 * n);
tex *= step(2.0, distance(p, vec2(0.83,0.7)) * 30.0 + 3.0 * n);
tex *= step(2.0, distance(p, vec2(0.82,0.8)) * 30.0 + 3.0 * n);
tex *= step(2.0, distance(p, vec2(0.76,0.95)) * 30.0 + 3.0 * n);
colour_out = vec4( vec3(0.44,0.795,0.545)*tex, 1.0 );
float mask = 1.0;
mask *= step(0.3, distance(p.xy, vec2(0.5, 0.4)));
mask *= step(0.25, distance(p.xy, vec2(0.6, 0.7)));
mask *= step(0.25, distance(p.xy, vec2(0.4, 0.7)));
colour_out *= 1.0 - mask;
}
unknown by shouli
//name: XIE LIN
//FROG: Dendrobates azureus
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float noise(float value){
return cos(value+cos(value*90.0)*100.0)*0.5+0.5;
}
float sdCircle( in vec2 p, in float r )
{
return length(p)-r;
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
float mask = 1.0;
mask *= step( 0.3, distance( st.xy, vec2(0.5, 0.4) ) );
mask *= step( 0.1, distance( st.xy, vec2(0.6, 0.7) ) );
mask *= step( 0.1, distance( st.xy, vec2(0.4, 0.7) ) );
mask *= step( 0.1, distance( st.xy, vec2(0.3, 0.1) ) );
mask *= step( 0.03, distance( st.xy, vec2(0.2, 0.1) ) );
mask *= step( 0.03, distance( st.xy, vec2(0.2, 0.05) ) );
mask *= step( 0.03, distance( st.xy, vec2(0.25, 0.01) ) );
mask *= step( 0.1, distance( st.xy, vec2(0.7, 0.1) ) );
mask *= step( 0.03, distance( st.xy, vec2(0.8, 0.1) ) );
mask *= step( 0.03, distance( st.xy, vec2(0.8, 0.05) ) );
mask *= step( 0.03, distance( st.xy, vec2(0.75, 0.01) ) );
colour_out = vec4(0.251, 0.251, 0.9216, 1.0);
colour_out *= 1.0-mask;
vec2 p = (2.0 * gl_FragCoord.xy - u_resolution.xy) / u_resolution.y;
vec2 p1 = vec2(p.x-noise(sin(u_time))+0.5,p.y-noise(cos(u_time))+0.55);
if ( sdCircle(p1,0.05)< 0.0)
colour_out = vec4(0.0, 0.0, 0.0, 1.0);
}
Dendrobates azureus by XIE LIN
uniform vec2 u_resolution;
uniform float u_time;
//shape
float dot2(in vec2 v ) { return dot(v,v); }
float sdStar5(in vec2 p, in float r, in float rf, vec2 offset)
{
p -= offset; // 这将从 p.x 中减去 offset.x 并从 p.y 中减去 offset.y
const vec2 k1 = vec2(0.809016994375, -0.587785252292);
const vec2 k2 = vec2(-k1.x,k1.y);
p.x = abs(p.x);
p -= 2.0*max(dot(k1,p),0.0)*k1;
p -= 2.0*max(dot(k2,p),0.0)*k2;
p.x = abs(p.x);
p.y -= r;
vec2 ba = rf*vec2(-k1.y,k1.x) - vec2(0,1);
float h = clamp( dot(p,ba)/dot(ba,ba), 0.0, r );
return length(p-ba*h) * sign(p.y*ba.x-p.x*ba.y);
}
float drop( vec3 p, float r1, float r2, float h )
{
p.x = abs(p.x);
float b = (r1-r2)/h;
float a = sqrt(1.0-b*b);
float k = dot(p.xy,vec2(-b,a));
if( k < 0.0 ) return length(p) - r1;
if( k > a*h ) return length(p.xy-vec2(0.0,h)) - r2;
return dot(p.xy, vec2(a,b) ) - r1;
}
float sdSegment( in vec2 p, in vec2 a, in vec2 b )
{
vec2 pa = p-a, ba = b-a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
return length( pa - ba*h );
}
float sdCircle( vec2 p, float r )
{
return length(p) - r;// 到圆表面的距离
}
float sdPie( in vec2 p, in vec2 c, in float r )
{
p.x = abs(p.x);
float l = length(p) - r;
float m = length(p-c*clamp(dot(p,c),0.0,r)); // c=sin/cos of aperture
return max(l,m*sign(c.y*p.x-c.x*p.y));
}
float sdBox( in vec2 p, in vec2 b )
{
vec2 d = abs(p)-b;
return length(max(d,0.0)) + min(max(d.x,d.y),0.0);
}
mat3 rotate(float _angle){
float angle= radians(_angle);
mat3 rotateMat=mat3(
cos(angle),-sin(angle),0.0,
sin(angle),cos(angle),0.0,
0.0,0.0,1.0);
return rotateMat;
}
// texture
vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0;}
vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0;}
vec3 permute(vec3 x) { return mod289(((x*34.0)+10.0)*x);}
vec4 permute(vec4 x) { return mod((34.0 * x + 1.0) * x, 289.0);}
float snoise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
vec2 cellular2x2(vec2 P) {
#define K 0.142857142857 // 1/7
#define K2 0.0714285714285 // K/2
#define jitter 0.8 // jitter 1.0 makes F1 wrong more often
vec2 Pi = mod(floor(P), 289.0);
vec2 Pf = fract(P);
vec4 Pfx = Pf.x + vec4(-0.5, -1.5, -0.5, -1.5);
vec4 Pfy = Pf.y + vec4(-0.5, -0.5, -1.5, -1.5);
vec4 p = permute(Pi.x + vec4(0.0, 1.0, 0.0, 1.0));
p = permute(p + Pi.y + vec4(0.0, 0.0, 1.0, 1.0));
vec4 ox = mod(p, 7.0)*K+K2;
vec4 oy = mod(floor(p*K),7.0)*K+K2;
vec4 dx = Pfx + jitter*ox;
vec4 dy = Pfy + jitter*oy;
vec4 d = dx * dx + dy * dy; // d11, d12, d21 and d22, squared
// Sort out the two smallest distances
#if 0
// Cheat and pick only F1
d.xy = min(d.xy, d.zw);
d.x = min(d.x, d.y);
return d.xx; // F1 duplicated, F2 not computed
#else
// Do it right and find both F1 and F2
d.xy = (d.x < d.y) ? d.xy : d.yx; // Swap if smaller
d.xz = (d.x < d.z) ? d.xz : d.zx;
d.xw = (d.x < d.w) ? d.xw : d.wx;
d.y = min(d.y, d.z);
d.y = min(d.y, d.w);
return sqrt(d.xy);
#endif
}
#define OCTAVES 4
float ridge(float h, float offset) {
h = abs(h); // create creases
h = offset - h; // invert so creases are at top
h = h * h; // sharpen creases
return h;
}
float ridgedMF(vec2 p) {
float lacunarity = 2.0;
float gain = 0.5;
float offset = 0.9;
float sum = 0.0;
float freq = 1.0, amp = 0.5;
float prev = 1.0;
for(int i=0; i < OCTAVES; i++) {
float n = ridge(snoise(p*freq), offset);
sum += n*amp;
sum += n*amp*prev; // scale by previous octave
prev = n;
freq *= lacunarity;
amp *= gain;
}
return sum;
}
float woodfbm(vec2 p){
float f=0.0,scale;
for (int i=0;i<4;i++){
scale=pow(pow(2.0,4.0/3.0),float(i));
f+=snoise(p*scale)/scale;
}
return f;
}
void main() {
vec2 st2 = gl_FragCoord.xy/u_resolution.xy-0.5;
vec3 st3=vec3(st2,0.0);
vec3 st3Calf=vec3(st2.x+0.004,st2.y+-0.002,0.0);
vec3 st3Calf1=vec3(st2.x+0.116,st2.y+0.030,0.0);
vec3 st3Body=vec3(st2.x-0.1,st2.y-0.15,0.0);
vec3 st3Arm=vec3(st2.x-0.1,st2.y-0.06,0.0);
vec3 stEyeWhite=vec3(vec2(st2.x-0.040,st2.y-0.204),0.0);
mat3 rotateThigh=rotate(67.0);
vec3 pos=rotateThigh*st3;
float thigh=drop(pos,0.008,0.038,0.142);
mat3 rotateCalf=rotate(100.0);
pos=rotateCalf*st3Calf;
float calf=drop(pos,0.016,0.018,0.118);
mat3 rotateCalf1=rotate(250.0);
pos=rotateCalf1*st3Calf1;
float calf1=drop(pos,0.008,0.010,0.070);
float feet1=sdSegment(st2,vec2(-0.050,-0.050),vec2(-0.040,-0.030));
float feet2=sdSegment(st2,vec2(-0.060,-0.050),vec2(-0.020,-0.050));
float feet3=sdSegment(st2,vec2(-0.060,-0.050),vec2(-0.030,-0.080));
mat3 rotateBody=rotate(110.0);
pos=rotateBody*st3Body;
float body=drop(pos,0.05,0.1,0.2);
mat3 rotateArm=rotate(67.0);
pos=rotateArm*st3Arm;
float arm=drop(pos,0.01,0.01,0.1);
mat3 rotateArm1=rotate(275.0);
pos=rotateArm1*st3Arm;
float arm1=drop(pos,0.01,0.0,0.1);
float hand=sdCircle(vec2(st2.x-0.2,st2.y-0.07),0.0);
float finger1=sdSegment(st2,vec2(0.200,0.070),vec2(0.210,0.090));
float finger2=sdSegment(st2,vec2(0.200,0.070),vec2(0.230,0.08));
float finger3=sdSegment(st2,vec2(0.200,0.070),vec2(0.240,0.06));
float eye=sdCircle(vec2(st2.x-0.080,st2.y-0.204),0.040);
mat3 rotateEyeWhite=rotate(220.0);
pos=rotateEyeWhite*stEyeWhite;
float eyeWhie=sdPie(vec2(pos.x+0.026,pos.y+0.041),vec2(0.390,0.710),0.076);
mat3 rotateEyeWhite1=rotate(240.0);
pos=rotateEyeWhite1*stEyeWhite;
float eyeWhie1=sdPie(vec2(pos.x+0.002,pos.y+-0.023),vec2(0.200,0.610),0.052);
float eyePoint=sdCircle(vec2(st2.x-0.088,st2.y-0.196),0.024);
float mouth=sdSegment(st2,vec2(0.110,0.120),vec2(0.140,0.120));
float circle=sdCircle(vec2(st2.x-0.122,st2.y-0.252),0.017);
float rec=sdBox(vec2(st2.x-0.113,st2.y-0.245),vec2(0.01));
float res;
res=min(circle,rec);
float circle1=sdCircle(vec2(st2.x-0.12,st2.y-0.261),0.017);
float rec1=sdBox(vec2(st2.x-0.112,st2.y-0.254),vec2(0.01));
float res1=min(circle1,rec1);
res=max(res,-res1);
res=1.0-step(0.,res);
mat3 rotateStar=rotate(100.0);
vec3 starrr=vec3(st2.x+-0.030,st2.y+-0.26,1.0);
pos=rotateStar*starrr;
float star = sdStar5(pos.xy, 0.024, 0.362, vec2(0.0,0.0)); // 添加偏移量以移动星星的位置
float n=woodfbm(st2);
vec2 st22=vec2(st2.x+0.084,st2.y+-0.348);
float nn=woodfbm(st22);
float n1=snoise(st2);
float t=1.0+sin(length(st2)*50.0+2.0*n)/2.0;
float t1=1.0+sin(length(st2)*52.0+8.0*n)/2.0;
float t2=1.0+sin(length(st2)*120.0+8.0*n)/2.0;
float t3=1.0+sin(length(st2)*120.0+111.0*n)/2.0;
float t4=1.0+sin(length(st22)*6.0+111.0*nn)/0.01;
vec2 F = cellular2x2(st2*20.);
float n2 = 1.0-0.5*F.x;
float ridgedMFV=ridgedMF(st2*15.0);
vec3 lineBody=vec3(0.6392, 0.4706, 0.3569)*ridgedMFV;
vec3 lineArm = vec3(0.6667, 0.6118, 0.5176)*t2;//add texture
vec3 lineEye = vec3(0.0);//add texture
vec3 lineEyeBall=vec3(0.108,0.332,0.470)*t4;
vec3 lineLeg = vec3(0.6941, 0.6863, 0.4392)*t1;//add texture
vec3 lineMouth=vec3(0.050,0.050,0.050);
vec3 line_color4 = vec3(0.0667, 0.0667, 0.0627);//add texture
vec3 bg_color=vec3(0.958,1.000,0.955);
vec3 colorBody=vec3(1.0, 1.0, 1.0);
colorBody=mix(colorBody,lineBody,1.0-step(0.0,body));
vec3 colorLeg=vec3(1.0, 1.0, 1.0);
colorLeg = mix(colorLeg,lineLeg,1.0-step(0.0,thigh));
colorLeg*=mix(colorLeg,lineLeg,1.0-step(0.0,calf));
colorLeg*=mix(colorLeg,lineLeg,1.0-step(0.0,calf1));
colorLeg*=mix(colorLeg,lineLeg,1.0-smoothstep(0.0,0.01,feet1));
colorLeg*=mix(colorLeg,lineLeg,1.0-smoothstep(0.0,0.01,feet2));
colorLeg*=mix(colorLeg,lineLeg,1.0-smoothstep(0.0,0.01,feet3));
vec3 colorArm=vec3(1.0);
colorArm=mix(colorArm,lineArm,1.0-step(0.0,arm));
colorArm*=mix(colorArm,lineArm,1.0-step(0.0,arm1));
colorArm*=mix(colorArm,lineArm,1.0-step(0.0,hand));
colorArm*=mix(colorArm,lineArm,1.0-smoothstep(0.0,0.01,finger1));
colorArm*=mix(colorArm,lineArm,1.0-smoothstep(0.0,0.01,finger2));
colorArm*=mix(colorArm,lineArm,1.0-smoothstep(0.0,0.01,finger3));
vec3 colorEye=vec3(1.0);
// colorEye=mix(colorEye,lineEye,1.0-step(0.0,eye));
//colorEye=mix(colorEye,lineLeg,res);
vec3 coloreyee=mix(vec3(1.0),lineEyeBall,1.0-step(0.0,eyePoint));
colorEye=mix(colorEye,lineEye,1.0-step(0.0,eyeWhie));
vec3 starr=mix(vec3(1.0), vec3(0.0), 1.0-step(0., star));
//colorEye*=mix(colorEye,lineEye,1.0-step(0.0,eyeWhie1));
vec3 colorMouth=mix(bg_color,lineMouth,1.0-smoothstep(0.0,0.01,mouth));
vec3 color=vec3(0.9333, 0.6824, 0.6824);
color=color*colorBody*colorLeg*colorArm*coloreyee*colorEye*starr;
colour_out = vec4(color, 1.0);
}
unknown by anonymous
// author: wbelucky
// Dendrobates tinctorius "azureus"
// noise func from webgl-noise
//
// Description : Array and textureless GLSL 2D simplex noise function.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : stegu
// Lastmod : 20110822 (ijm)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise
// https://github.com/stegu/webgl-noise
//
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec3 permute(vec3 x) {
return mod289(((x*34.0)+10.0)*x);
}
float snoise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
float sdVesica(vec2 p, float r, float d)
{
p = abs(p);
float b = sqrt(r*r-d*d);
return ((p.y-b)*d>p.x*b) ? length(p-vec2(0.0,b))
: length(p-vec2(-d,0.0))-r;
}
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec2 p = 2. * st - vec2(1.);
const float PI = 3.14159;
float theta = PI / 3.;
mat2 r = mat2( cos(theta),-sin(theta),
sin(theta),cos(theta));
p += vec2(0.3, 0.3);
p *= 1. / 2.;
p *= r;
float n = snoise(p * 6. + 0.3 * u_time);
vec4 main_color = mix(vec4(0.001,0.537,0.870,1.000), vec4(0.140,0.140,0.140, 1.), step(0.2, n));
float is_main = step(0.5, step(sdVesica(p, 0.208, 0.344), 0.5) // body
+ step(distance(st, vec2(0.540,0.630)), 0.17)); // left eye
colour_out = mix(vec4(1.),main_color, is_main)
* step(0.094, distance(st, vec2(0.660,0.430))); // right eye
}
Dendrobates tinctorius "azureus" by
wbelucky
//name:ChickenLeg
uniform vec2 u_resolution;
uniform vec2 u_mouse;
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 mod289(vec4 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
// Modulo 7 without a division
vec4 mod7(vec4 x) {
return x - floor(x * (1.0 / 7.0)) * 7.0;
}
// Permutation polynomial: (34x^2 + 6x) mod 289
vec3 permute(vec3 x) {
return mod289((34.0 * x + 10.0) * x);
}
vec4 permute(vec4 x) {
return mod289((34.0 * x + 10.0) * x);
}
// Cellular noise, returning F1 and F2 in a vec2.
// Speeded up by using 2x2x2 search window instead of 3x3x3,
// at the expense of some pattern artifacts.
// F2 is often wrong and has sharp discontinuities.
// If you need a good F2, use the slower 3x3x3 version.
vec2 cellular2x2x2(vec3 P) {
#define K 0.142857142857 // 1/7
#define Ko 0.428571428571 // 1/2-K/2
#define K2 0.020408163265306 // 1/(7*7)
#define Kz 0.166666666667 // 1/6
#define Kzo 0.416666666667 // 1/2-1/6*2
#define jitter 0.8 // smaller jitter gives less errors in F2
P = P*1.8;
vec3 Pi = mod289(floor(P));
vec3 Pf = fract(P);
vec4 Pfx = Pf.x + vec4(0.0, -1.0, 0.0, -1.0);
vec4 Pfy = Pf.y + vec4(0.0, 0.0, -1.0, -1.0);
vec4 p = permute(Pi.x + vec4(0.0, 1.0, 0.0, 1.0));
p = permute(p + Pi.y + vec4(0.0, 0.0, 1.0, 1.0));
vec4 p1 = permute(p + Pi.z); // z+0
vec4 p2 = permute(p + Pi.z + vec4(1.0)); // z+1
vec4 ox1 = fract(p1*K) - Ko;
vec4 oy1 = mod7(floor(p1*K))*K - Ko;
vec4 oz1 = floor(p1*K2)*Kz - Kzo; // p1 < 289 guaranteed
vec4 ox2 = fract(p2*K) - Ko;
vec4 oy2 = mod7(floor(p2*K))*K - Ko;
vec4 oz2 = floor(p2*K2)*Kz - Kzo;
vec4 dx1 = Pfx + jitter*ox1;
vec4 dy1 = Pfy + jitter*oy1;
vec4 dz1 = Pf.z + jitter*oz1;
vec4 dx2 = Pfx + jitter*ox2;
vec4 dy2 = Pfy + jitter*oy2;
vec4 dz2 = Pf.z - 1.0 + jitter*oz2;
vec4 d1 = dx1 * dx1 + dy1 * dy1 + dz1 * dz1; // z+0
vec4 d2 = dx2 * dx2 + dy2 * dy2 + dz2 * dz2; // z+1
// Sort out the two smallest distances (F1, F2)
#if 0
// Cheat and sort out only F1
d1 = min(d1, d2);
d1.xy = min(d1.xy, d1.wz);
d1.x = min(d1.x, d1.y);
return vec2(sqrt(d1.x));
#else
// Do it right and sort out both F1 and F2
vec4 d = min(d1,d2); // F1 is now in d
d2 = max(d1,d2); // Make sure we keep all candidates for F2
d.xy = (d.x < d.y) ? d.xy : d.yx; // Swap smallest to d.x
d.xz = (d.x < d.z) ? d.xz : d.zx;
d.xw = (d.x < d.w) ? d.xw : d.wx; // F1 is now in d.x
d.yzw = min(d.yzw, d2.yzw); // F2 now not in d2.yzw
d.y = min(d.y, d.z); // nor in d.z
d.y = min(d.y, d.w); // nor in d.w
d.y = min(d.y, d2.x); // F2 is now in d.y
return sqrt(d.xy); // F1 and F2
#endif
}
float color(vec3 xyz) { return cellular2x2x2(xyz).x * 2.0 - 1.0; }
// Rotation matrix around the X axis.
mat3 rotateX(float theta) {
float c = cos(theta);
float s = sin(theta);
return mat3(
vec3(1, 0, 0),
vec3(0, c, -s),
vec3(0, s, c)
);
}
// Rotation matrix around the Y axis.
mat3 rotateY(float theta) {
float c = cos(theta);
float s = sin(theta);
return mat3(
vec3(c, 0, s),
vec3(0, 1, 0),
vec3(-s, 0, c)
);
}
// Rotation matrix around the Z axis.
mat3 rotateZ(float theta) {
float c = cos(theta);
float s = sin(theta);
return mat3(
vec3(c, -s, 0),
vec3(s, c, 0),
vec3(0, 0, 1)
);
}
//smooth min
float smin(in float a, in float b, float k)
{
float h = max(k-abs(a-b), 0.0);
return min(a,b)-h*h/(k*4.0);
}
float sdSphere(in vec3 pos, float rad)
{
return length(pos)-rad;
}
float sdElipsoid(in vec3 pos, vec3 rad)
{
float k0 = length(pos/rad);
float k1 = length(pos/(rad*rad));
return k0*(k0-1.0)/k1;
}
float dot2( in vec2 v ) { return dot(v,v); }
float sdRoundCone( vec3 p, float r1, float r2, float h )
{
// sampling independent computations (only depend on shape)
float b = (r1-r2)/h;
float a = sqrt(1.0-b*b);
// sampling dependant computations
vec2 q = vec2( length(p.xz), p.y );
float k = dot(q,vec2(-b,a));
if( k<0.0 ) return length(q) - r1;
if( k>a*h ) return length(q-vec2(0.0,h)) - r2;
return dot(q, vec2(a,b) ) - r1;
}
float frontRightLeg(in vec3 bodyPos)
{
vec3 hum1Pos = bodyPos - vec3(-0.22,-0.03,0.23);
float hum1 = sdRoundCone(hum1Pos*rotateZ(1.3)*rotateX(-.5), 0.04, 0.02, 0.2);
//return hum1;
vec3 leg1Pos = hum1Pos - vec3(0.11,-0.14,0.04);
float leg1 = sdRoundCone(leg1Pos*rotateZ(.2)*rotateX(-.3), 0.04, 0.02, 0.16);
float legPart1 = smin(hum1,leg1,0.05);
//return legPart1;
vec3 foot1Pos = leg1Pos - vec3(-0.02,-0.03,0.0);
vec3 footRad = vec3(0.06,0.01,0.06);
float foot1 = sdElipsoid(foot1Pos*rotateZ(-.2), footRad);
legPart1 = smin(legPart1,foot1,0.02);
//return foot1;
return legPart1;
}
float frontLeftLeg(in vec3 bodyPos)
{
vec3 hum1Pos = bodyPos - vec3(-0.22,-0.03,-0.23);
float hum1 = sdRoundCone(hum1Pos*rotateZ(1.3)*rotateX(.5), 0.04, 0.02, 0.2);
//return hum1;
vec3 leg1Pos = hum1Pos - vec3(0.11,-0.14,-0.04);
float leg1 = sdRoundCone(leg1Pos*rotateZ(.2)*rotateX(.3), 0.04, 0.02, 0.16);
float legPart1 = smin(hum1,leg1,0.05);
//return legPart1;
vec3 foot1Pos = leg1Pos - vec3(-0.02,-0.03,-0.0);
vec3 footRad = vec3(0.06,0.01,0.06);
float foot1 = sdElipsoid(foot1Pos*rotateZ(-.2), footRad);
legPart1 = smin(legPart1,foot1,0.02);
//return foot1;
return legPart1;
}
float backRightLeg(in vec3 bodyPos)
{
vec3 humPos = bodyPos - vec3(0.18,-0.03,0.23);
float hum = sdRoundCone(humPos*rotateZ(0.8)*rotateX(.2), 0.065, 0.045, 0.28);
//return hum;
vec3 legPos = humPos - vec3(0.08,-0.09,0.01);
float leg = sdRoundCone(legPos*rotateZ(0.4)*rotateX(.2), 0.05, 0.03, 0.3);
vec3 footPos = legPos - vec3(-0.04,-0.0,0.);
vec3 footRad = vec3(0.08,0.01,0.08);
float foot = sdElipsoid(footPos*rotateZ(-.2), footRad);
float legPart = smin(hum,leg,0.01);
legPart = smin(legPart,foot,0.01);
return legPart;
}
float backLeftLeg(in vec3 bodyPos)
{
vec3 humPos = bodyPos - vec3(0.18,-0.03,-0.23);
float hum = sdRoundCone(humPos*rotateZ(0.8)*rotateX(-.2), 0.065, 0.045, 0.28);
//return hum;
vec3 legPos = humPos - vec3(0.08,-0.09,-0.01);
float leg = sdRoundCone(legPos*rotateZ(0.4)*rotateX(-.2), 0.05, 0.03, 0.3);
vec3 footPos = legPos - vec3(-0.04,-0.0,-0.);
vec3 footRad = vec3(0.08,0.01,0.08);
float foot = sdElipsoid(footPos*rotateZ(-.2), footRad);
float legPart = smin(hum,leg,0.01);
legPart = smin(legPart,foot,0.01);
return legPart;
}
vec2 sdGuy(in vec3 pos)
{
//return vec2(sdSphere(pos-vec3(0.0,0.1,0.0), 0.3), 2.0);
//body
vec3 cen = vec3(0.0,0.1,0.0);
vec3 rad = vec3(0.15,0.055,0.11 )*2.5;
vec3 bodyPos = pos*rotateZ(0.3)-cen;
float body = sdElipsoid(bodyPos,rad);
//return vec2(body, 2.0);
//head
vec3 headPos = bodyPos*rotateZ(-0.17)-vec3(-0.34,0.07,0.0);
vec3 headRad = vec3(0.08,0.05,0.11)*2.;
float head = sdElipsoid(headPos,headRad);
float main = smin(body, head, 0.05);
//return vec2(head,2.0);
//return vec2(main, 2.0);
//eyebrown
vec3 eb1Pos = bodyPos - vec3(-0.35,0.06,0.16);
vec3 eb2Pos = bodyPos - vec3(-0.35,0.06,-0.16);
float ebsRad = 0.06;
float eb1 = sdSphere(eb1Pos, ebsRad);
float eb2 = sdSphere(eb2Pos, ebsRad);
float ebs = smin(eb1, eb2, 0.05);
main = smin(main, ebs, 0.05);
//return vec2(main, 2.0);
//frontleg
float frontRightLeg = frontRightLeg(bodyPos);
float frontLefttLeg = frontLeftLeg(bodyPos);
main = smin(main, frontRightLeg, 0.03);
main = smin(main, frontLefttLeg, 0.03);
//return vec2(main, 2.0);
//backLeg
float backRightLeg = backRightLeg(bodyPos);
float backLeftLeg = backLeftLeg(bodyPos);
main = smin(main,backLeftLeg,0.03);
main = smin(main,backRightLeg,0.03);
// return vec2(main, 2.0);
vec2 sdid = vec2(main, 2.0);
vec3 eye1Pos = bodyPos - vec3(-0.36,0.05,0.18);
vec3 eye2Pos = bodyPos - vec3(-0.36,0.05,-0.18);
float eyesRad = 0.05;
float eye1 = sdSphere(eye1Pos, eyesRad);
float eye2 = sdSphere(eye2Pos, eyesRad);
float eyes = smin(eye1, eye2, 0.05);
if (eyes < main)
{
sdid = vec2(eyes, 3.0);
}
//float sdid = smin(main, eyes, 0.05);
return sdid;
}
vec2 map( in vec3 pos )
{
// ball
//vec3 cen = vec3( 0.0, 0.1, 0.0 );
//float d1 = sdSphere( pos - cen, 0.3 );
vec2 d1 = sdGuy(pos);
// ground
float fh = -0.1;
float d2 = pos.y - fh;
if (d2<d1.x)
{
return vec2(d2,1.0);
}else
{
return d1;
}
}
vec2 castRay( in vec3 ro, in vec3 rd )
{
float id = -1.0;
vec2 res = vec2(-1.0,-1.0);
float tmin = 0.5;
float tmax = 20.0;
float t = tmin;
for( int i=0; i<512 && t<tmax; i++ )
{
vec2 h = map( ro+rd*t );
id = h.y;
if( h.x<0.001 ) break;
t += h.x;
}
if( t>tmax ) t=-1.0;
return vec2(t,id);
}
vec3 calcNormal( in vec3 pos )
{
vec2 e = vec2(0.0005,0.0);
return normalize( vec3(
map( pos + e.xyy ).x - map( pos - e.xyy ).x,
map( pos + e.yxy ).x - map( pos - e.yxy ).x,
map( pos + e.yyx ).x - map( pos - e.yyx ).x ) );
}
float calcOcclusion( in vec3 pos, in vec3 nor, float time )
{
float occ = 0.0;
float sca = 1.0;
for( int i=0; i<5; i++ )
{
float h = 0.01 + 0.11*float(i)/4.0;
vec3 opos = pos + h*nor;
float d = map( opos ).x;
occ += (h-d)*sca;
sca *= 0.95;
}
return clamp( 1.0 - 2.0*occ, 0.0, 1.0 );
}
// color render
vec3 render( in vec3 ro, in vec3 rd, in vec2 p )
{
// sky dome
vec3 col = vec3(0.5, 0.8, 0.9) ;
float t = castRay(ro,rd).x;
if( t>0.0 )
{
vec3 pos = ro + t*rd;
vec3 nor = calcNormal( pos );
vec3 ref = reflect( rd, nor );
col = vec3(0.15);
float ks = 1.0;
vec3 mate = vec3(.18);
float id = castRay(ro,rd).y;
if (id < 1.5)
{
mate = vec3(0.05,0.1,0.02);
}else if (id > 1.5 && id < 2.5)
{
vec3 xyz = vec3(p, -sqrt(t));
float n = color(xyz*4.0);
mate = (vec3(1.0,1.0,1.0)-mix(0.0, 0.7 + 0.5 * n, step(0.0, t))) * vec3(1.0 ,0.26,0.0);
//mate = vec3(0.5);
}else if (id > 2.5)
{
mate = vec3(0.05, 0.4, 0.9) ;
}
// lighting
vec3 sun_lig = normalize( vec3(0.6, 0.35, 0.5) );
float sun_dif = clamp(dot( nor, sun_lig ), 0.0, 1.0 );
vec3 sun_hal = normalize( sun_lig-rd );
float sun_sha = step(castRay( pos+0.001*nor, sun_lig ).x,0.0);
float sun_spe = ks*pow(clamp(dot(nor,sun_hal),0.0,1.0),8.0)*sun_dif*(0.04+0.96*pow(clamp(1.0+dot(sun_hal,rd),0.0,1.0),5.0));
float sky_dif = sqrt(clamp( 0.5+0.5*nor.y, 0.0, 1.0 ));
float bou_dif = sqrt(clamp( 0.1-0.9*nor.y, 0.0, 1.0 ))*clamp(1.0-0.1*pos.y,0.0,1.0);
vec3 lin = vec3(0.0);
lin += mate*sun_dif*vec3(8.10,6.00,4.20)*sun_sha;
lin += mate*sky_dif*vec3(0.50,0.70,1.00);
lin += mate*bou_dif*vec3(0.60,0.40,0.30);
col = col*lin;
col += mate*sun_spe*vec3(8.10,6.00,4.20)*sun_sha;
col = mix( col, vec3(0.5,0.7,0.9), 1.0-exp( -0.0001*t*t*t ) );
}
return col;
}
void main()
{
vec2 p = (-u_resolution.xy + 2.0*gl_FragCoord.xy)/u_resolution.y;
// ray marching
// camera
float an = 10.57*u_mouse.x/u_resolution.x;
vec3 ta = vec3( 0.0, 0.6, 0.);
vec3 ro = ta + vec3( 1.8*cos(an), -0.1, 1.8*sin(an) ); // ray origin
// viewpoint to object
vec3 cw = normalize(ta-ro);
vec3 cp = vec3(0.0, 1.0,0.0);
vec3 cu = normalize( cross(cw,cp) );
vec3 cv = ( cross(cu,cw) );
vec3 rd = normalize( p.x*cu + p.y*cv + 1.8*cw ); // ray direction
vec3 col = render( ro, rd, p );
col = pow( col, vec3(0.4545) );
colour_out = vec4( col, 1.0 );
}
unknown by ChickenLeg
// credit: jikihakase (will show up on website)
// frog: Epipedobates tricolor
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float random (in vec2 st) {
return fract(sin(dot(st.xy,vec2(-0.130,-0.030)))* 43758.945);
}
float noise(vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f*f*(3.0-2.0*f);
return mix( mix( random( i + vec2(0.0,0.0) ),random( i + vec2(1.0,0.0) ), u.x),
mix( random( i + vec2(0.0,1.0) ),random( i + vec2(1.0,1.0) ), u.x), u.y);
}
mat2 rotate2d(float angle){
return mat2(cos(angle),-sin(angle),sin(angle),cos(angle));
}
float lines(in vec2 pos, float b){
float scale = 3.2;
pos *= scale;
return smoothstep(1.0,1.044+b*.5,abs((sin(pos.x*2.787)+b*0.968))*1.012);
}
float ndot(vec2 a, vec2 b ) { return a.x*b.x - a.y*b.y; }
float sdRhombus( in vec2 p, in vec2 b )
{
p = abs(p);
float h = clamp( ndot(b-2.0*p,b)/dot(b,b), -1.0, 1.0 );
float d = length( p-0.5*b*vec2(1.0-h,1.0+h) );
return d * sign( p.x*b.y + p.y*b.x - b.x*b.y );
}
float sdCircle( vec2 p, float r )
{
return length(p) - r;
}
mat3 rotation(float r){
float r1 = radians(r);mat3 m = mat3(cos(r1), -sin(r1),0.0,sin(r1),cos(r1),0.0,0.0,0.0,1.0);return m;}
float sdUnevenCapsule( vec2 p, float r1, float r2, float h )
{
p.x = abs(p.x);
float b = (r1-r2)/h;
float a = sqrt(1.0-b*b);
float k = dot(p,vec2(-b,a));
if( k < 0.0 ) return length(p) - r1;
if( k > a*h ) return length(p-vec2(0.0,h)) - r2;
return dot(p, vec2(a,b) ) - r1;
}
void main() {
vec2 st = (gl_FragCoord.xy * 2. - u_resolution) / u_resolution.y;
vec3 pos = vec3(st,0.0);
vec3 color = vec3(0.6);
float body = sdRhombus(st,vec2(0.290,0.530));
float eye_right = sdCircle(vec2(st.x-0.108,st.y-0.372),0.028);
float eye_left = sdCircle(vec2(st.x+0.108,st.y-0.372),0.028);
vec3 pos1 = pos*rotation(43.0);
float leg_r = sdUnevenCapsule(vec2(pos1.x-0.396,pos1.y+0.228),0.036,0.128,0.312);
vec3 pos2= pos*rotation(-43.0);
float leg_l = sdUnevenCapsule(vec2(pos2.x+0.396,pos2.y+0.228),0.036,0.128,0.312);
vec3 pos3= pos*rotation(90.0);
float leg_l_s = sdUnevenCapsule(vec2(pos3.x-0.460,pos3.y-0.196),0.084,0.040,0.192);
vec3 pos4= pos*rotation(-90.0);
float leg_r_s = sdUnevenCapsule(vec2(pos4.x+0.460,pos4.y-0.196),0.084,0.040,0.192);
//pattern
vec2 pos_t = st.xy*vec2(10.,3.);
float pattern = pos_t.x;
pos_t = rotate2d( noise(pos_t) ) * pos_t;
pattern = lines(pos_t,0.824);
vec3 pattern_leg = vec3(0.479,0.500,0.478);
float t_l = 0.008;
pattern_leg = vec3(1.000,0.237,0.304) * smoothstep(-0.284,0.312,noise(st));
pattern_leg += smoothstep(-0.146,0.264,noise(st*10.176));
pattern_leg -= smoothstep(.35,.4,noise(st*10.));
color = mix(color,vec3(1, st.y, abs(sin(-0.048)))+vec3(pattern),1.0-smoothstep(0.0,0.01,body));
color = mix(color,vec3(0.0,0.0,0.0),1.0-smoothstep(0.0,0.01,eye_right));
color = mix(color,vec3(0.0,0.0,0.0),1.0-smoothstep(0.0,0.01,eye_left));
color = mix(color,vec3(1.-pattern_leg),1.0-smoothstep(0.0,0.0,leg_r));
color = mix(color,vec3(1.-pattern_leg),1.0-smoothstep(0.0,0.01,leg_l));
color = mix(color,vec3(1.-pattern_leg),1.0-smoothstep(0.0,0.01,leg_l_s));
color = mix(color,vec3(1.-pattern_leg),1.0-smoothstep(0.0,0.01,leg_r_s));
colour_out = vec4(color, 1.0);
}
unknown by anonymous
// credit: Yoooo
// frog: Dendrobates azureus
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec2 mod289(vec2 x) {
return x - floor(x * (1. / 289.)) * 289.;
}
vec4 mod289(vec4 x) {
return x - floor(x * (1. / 289.)) * 289.;
}
vec4 mod7(vec4 x) {
return x - floor(x * (1. / 7.)) * 7.;
}
vec4 permute(vec4 x) {
return mod289((34. * x + 10.) * x);
}
vec2 cellular2x2(vec2 P) {
#define K.142857142857// 1/7
#define K2.0714285714285// K/2
#define jitter.8// jitter 1.0 makes F1 wrong more often
vec2 Pi = mod289(floor(P));
vec2 Pf = fract(P);
vec4 Pfx = Pf.x + vec4(-.5, -1.5, -.5, -1.5);
vec4 Pfy = Pf.y + vec4(-.5, -.5, -1.5, -1.5);
vec4 p = permute(Pi.x + vec4(0., 1., 0., 1.));
p = permute(p + Pi.y + vec4(0., 0., 1., 1.));
vec4 ox = mod7(p) * K + K2;
vec4 oy = mod7(floor(p * K)) * K + K2;
vec4 dx = Pfx + jitter * ox;
vec4 dy = Pfy + jitter * oy;
vec4 d = dx * dx + dy * dy;// d11, d12, d21 and d22, squared
// Sort out the two smallest distances
#if 0
// Cheat and pick only F1
d.xy = min(d.xy, d.zw);
d.x = min(d.x, d.y);
return vec2(sqrt(d.x));// F1 duplicated, F2 not computed
#else
// Do it right and find both F1 and F2
d.xy = (d.x < d.y) ? d.xy : d.yx;// Swap if smaller
d.xz = (d.x < d.z) ? d.xz : d.zx;
d.xw = (d.x < d.w) ? d.xw : d.wx;
d.y = min(d.y, d.z);
d.y = min(d.y, d.w);
return sqrt(d.xy);
#endif
}
float arm( vec2 p, float r1, float r2, float h )
{
p.x = abs(p.x);
float b = (r1-r2)/h;
float a = sqrt(1.0-b*b);
float k = dot(p,vec2(-b,a));
if( k < 0.0 ) return length(p) - r1;
if( k > a*h ) return length(p-vec2(0.0,h)) - r2;
return dot(p, vec2(a,b) ) - r1;
}
float arm1(vec2 p, float offset){
float A_length = 0.2;
float A_up = 0.1;
float A_down = 0.049;
vec2 coord = p.xy-offset;
float theta = 4.644;
float c = cos(theta);
float s = sin(theta);
mat3 R = mat3(c, -s, 0,
s, c, 0,
0, 0, 1.0);
float a = arm(coord.xy-vec2(-0.168, offset/2.5),A_up, A_down,A_length);
for (int i=0; i<1; i++){
coord = (R*vec3(coord.xy, 1.0)).xy;
a = min(a,arm(coord.xy-vec2(0.184, offset/2.5),A_up, A_down,A_length));
}
return a;
}
float arm2(vec2 p, float theta,float offset){
float A_length = 0.25;
float A_up = 0.040;
float A_down = 0.02;
vec2 coord = p.xy-offset;
float c = cos(theta);
float s = sin(theta);
mat3 R = mat3(c, -s, 0,
s, c, 0,
0, 0, 1.0);
coord = (R*vec3(coord.xy, 1.0)).xy;
float a = arm(coord.xy-vec2(-0.072, offset/2.5),A_up, A_down,A_length);
return a;
}
float arm3(vec2 p, float theta,float offset){
float A_length = 0.2;
float A_up = 0.0;
float A_down = 0.1;
vec2 coord = p.xy-offset;
float c = cos(theta);
float s = sin(theta);
mat3 R = mat3(c, -s, 0,
s, c, 0,
0, 0, 1.0);
coord = (R*vec3(coord.xy, 1.0)).xy;
float a = arm(coord.xy-vec2(0.008, offset/2.5),A_up, A_down,A_length);
return a;
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec2 F = cellular2x2(st*20.952);
vec2 pos = st-.5;
float a = dot(pos,pos)-u_time*0.0;
float n = step(abs(sin(a*3.494*30.284)),F.x*2.488);
float mask = 1.0;
//mask *= step( 0.28, distance( st.xy, vec2(0.410,0.380) ) );
mask *= step( 0.1,arm3(st,-0.716,0.228));
mask *= step( 0.17, distance( st.xy, vec2(0.570,0.590) ) );
mask *= step( 0.08, distance( st.xy, vec2(0.710,0.560) ) );
mask *= step( 0.08, distance( st.xy, vec2(0.530,0.730) ) );
mask *= step( 0.02, distance( st.xy, vec2(0.260,0.840) ) );
mask *= step( 0.02, distance( st.xy, vec2(0.330,0.890) ) );
mask *= step( 0.02, distance( st.xy, vec2(0.420,0.890) ) );
mask *= step( 0.02, distance( st.xy, vec2(0.450,0.830) ) );
mask *= step( 0.02, distance( st.xy, vec2(0.860,0.410) ) );
mask *= step( 0.02, distance( st.xy, vec2(0.880,0.340) ) );
mask *= step( 0.02, distance( st.xy, vec2(0.850,0.300) ) );
mask *= step( 0.02, distance( st.xy, vec2(0.790,0.270) ) );
//mask *= step(0.1,arm(st,0.1,0.1,0.1));
mask *= step( 0.01,arm1(st,0.324));
mask *= step( 0.01,arm2(st,-0.124,0.388));
mask *= step( 0.01,arm2(st,-1.820,0.388));
colour_out = vec4(a, a, n, 1.0);
colour_out *= 1.0-mask;
}
Dendrobates azureus by Yoooo
// credit: Chouchou
uniform vec2 u_resolution;uniform vec2 u_mouse;uniform float u_time;
float random (in vec2 st) {
return fract(sin(dot(st.xy,vec2(1345,78.5)))* 43758.6);
}
vec2 truchetPattern(in vec2 st, in float index){
index = fract(((index-0.5)*1.5));
if (index > 0.75) {
st = vec2(1.0) - st;
} else if (index > 0.5) {
st = vec2(1.0-st.x,st.y);
} else if (index > 0.25) {
st = 1.0-vec2(1.0-st.x,st.y);
}
return st;
}
float cro(in vec2 a, in vec2 b ) { return a.x*b.y - a.y*b.x; }
float sdUnevenCapsule( in vec2 p, in vec2 pa, in vec2 pb, in float ra, in float rb )
{
p -= pa;
pb -= pa;
float h = dot(pb,pb);
vec2 q = vec2( dot(p,vec2(pb.y,-pb.x)), dot(p,pb) )/h;
q.x = abs(q.x);
float b = ra-rb;
vec2 c = vec2(sqrt(h-b*b),b);
float k = cro(c,q);
float m = dot(c,q);
float n = dot(q,q);
if( k < 0.0 ) return sqrt(h*(n)) - ra;
else if( k > c.x ) return sqrt(h*(n+1.0-2.0*q.y)) - rb;
return m - ra;
}
void main() {
vec2 st = (2.0 * gl_FragCoord.xy -u_resolution.xy) /u_resolution.y;
st *= 6.5;
vec2 integer_pos = floor(st); // integer
vec2 fraction_pos = fract(st); // fraction
vec2 tile = truchetPattern(fraction_pos, random( integer_pos ));
float color = (step(length(tile),0.68) -
step(length(tile),0.32) ) +
(step(length(tile-vec2(1.0)),0.68) -
step(length(tile-vec2(1.0)),0.32));
colour_out = vec4(0, color, 0, 1.0);
float mask = 1.0;
vec2 v1 = cos( vec2(0.950,1.010) + -0.984 );
vec2 v2 = cos( vec2(-0.960,0.670) + 1.5 );
float r1 = 0.372;
float r2 = 0.964;
vec2 v3 = cos( vec2(-1.010,0.550) + -1.360 );
vec2 v4 = cos( vec2(-0.680,0.800) + 1.5 );
float r3 = -0.396;
float r4 = 0.260;
vec2 v5 = cos( vec2(-0.570,0.320) + -1.360 );
vec2 v6 = cos( vec2(-1.000,-1.000) + 1.012 );
vec2 v7 = cos( vec2(-0.940,0.510) + -1.176 );
vec2 v8 = cos( vec2(-0.240,-0.990) + 1.492 );
vec2 v9 = cos( vec2(-1.000,0.990) + -1.176 );
vec2 v10 = cos( vec2(0.170,-0.660) + 1.492 );
float r5 = -0.396;
float r6 = -0.396;
mask*= step(0.6, min(1.0f,max(0.0f, sdUnevenCapsule( st, v1, v2, r1, r2))));
mask*= step(0.6, min(1.0f,max(0.0f, sdUnevenCapsule( st+vec2(0.900,0.340), v3, v4, r3, r4))));
mask*= step(0.6, min(1.0f,max(0.0f, sdUnevenCapsule( st+vec2(-2.510,1.270), v5, v6, r4, r3))));
mask*= step(0.6, min(1.0f,max(0.0f, sdUnevenCapsule( st+vec2(0.300,-0.500), v9, v10, r5, r6))));
mask*= step(0.6, min(1.0f,max(0.0f, sdUnevenCapsule( st+vec2(-2.510,-0.270), v7, v8, r6, r3))));
colour_out*= 1.0f - mask;
}
unknown by Chouchou
// credit: a
// frog: Dendrobates auratus (Green and black poison dart frog)
// noise from https://github.com/stegu/webgl-noise/
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 mod289(vec4 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 permute(vec4 x) {
return mod289(((x*34.0)+10.0)*x);
}
vec3 permute(vec3 x) {
return mod289(((x*34.0)+10.0)*x);
}
vec4 taylorInvSqrt(vec4 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
float snoise(vec3 v)
{
const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
// First corner
vec3 i = floor(v + dot(v, C.yyy) );
vec3 x0 = v - i + dot(i, C.xxx) ;
// Other corners
vec3 g = step(x0.yzx, x0.xyz);
vec3 l = 1.0 - g;
vec3 i1 = min( g.xyz, l.zxy );
vec3 i2 = max( g.xyz, l.zxy );
// x0 = x0 - 0.0 + 0.0 * C.xxx;
// x1 = x0 - i1 + 1.0 * C.xxx;
// x2 = x0 - i2 + 2.0 * C.xxx;
// x3 = x0 - 1.0 + 3.0 * C.xxx;
vec3 x1 = x0 - i1 + C.xxx;
vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
// Permutations
i = mod289(i);
vec4 p = permute( permute( permute(
i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
+ i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
+ i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
float n_ = 0.142857142857; // 1.0/7.0
vec3 ns = n_ * D.wyz - D.xzx;
vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
vec4 x_ = floor(j * ns.z);
vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
vec4 x = x_ *ns.x + ns.yyyy;
vec4 y = y_ *ns.x + ns.yyyy;
vec4 h = 1.0 - abs(x) - abs(y);
vec4 b0 = vec4( x.xy, y.xy );
vec4 b1 = vec4( x.zw, y.zw );
//vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
//vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
vec4 s0 = floor(b0)*2.0 + 1.0;
vec4 s1 = floor(b1)*2.0 + 1.0;
vec4 sh = -step(h, vec4(0.0));
vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
vec3 p0 = vec3(a0.xy,h.x);
vec3 p1 = vec3(a0.zw,h.y);
vec3 p2 = vec3(a1.xy,h.z);
vec3 p3 = vec3(a1.zw,h.w);
//Normalise gradients
vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
// Mix final noise value
vec4 m = max(0.5 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
m = m * m;
return 105.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
dot(p2,x2), dot(p3,x3) ) );
}
float snoise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
// sdf from https://iquilezles.org/articles/distfunctions2d/
float cro(in vec2 a, in vec2 b ) { return a.x*b.y - a.y*b.x; }
float sdUnevenCapsule( in vec2 p, in vec2 pa, in vec2 pb, in float ra, in float rb )
{
p -= pa;
pb -= pa;
float h = dot(pb,pb);
vec2 q = vec2( dot(p,vec2(pb.y,-pb.x)), dot(p,pb) )/h;
//-----------
q.x = abs(q.x);
float b = ra-rb;
vec2 c = vec2(sqrt(h-b*b),b);
float k = cro(c,q);
float m = dot(c,q);
float n = dot(q,q);
if( k < 0.0 ) return sqrt(h*(n )) - ra;
else if( k > c.x ) return sqrt(h*(n+1.0-2.0*q.y)) - rb;
return m - ra;
}
float sdSegment( in vec2 p, in vec2 a, in vec2 b )
{
vec2 pa = p-a, ba = b-a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
return length( pa - ba*h );
}
////////////////////////
float turb_fract( vec3 p ) {
float f = -0.2, scale;
for (int i=0; i<4; i++) {
scale = pow( pow(3.0, 1.75), float(i) );
f += abs(snoise( p * scale )) / scale;
}
return f;
}
float turb_fract( vec2 p ) {
float f = -0.2, scale;
for (int i=0; i<4; i++) {
scale = pow( pow(5.0, 1.75), float(i) );
f += abs(snoise( p * scale )) / scale;
}
return f;
}
////////////////////////
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec2 mt = u_mouse.xy/u_resolution.xy;
// smoke affect
vec3 uv = vec3( .5 * st - 0.5, 0.1*u_time );
float noise = 0.6*turb_fract( uv )+0.2;
colour_out = vec4( vec3(0.063,0.188,0.230), noise );
// main body
vec3 co_dark = vec3(0.15);
vec3 co_pat = vec3(0.314, 0.706, 0.706);
float mask = 1.0;
float n = turb_fract( st / 0.25 + 0.025 * mt.x);
mask *= step( 0.0, sdUnevenCapsule(st - vec2(0.55, 0.5), vec2(-0.3, 0.20), vec2(0.0), 0.1, .2) );
mask *= step( 0.0, sdUnevenCapsule(st - vec2(0.55, 0.5), vec2(0.25, -0.15), vec2(0.0), 0.1, .2) );
mask *= step( 0.11, distance( st.xy, vec2(0.30, 0.72) ) );
vec3 co = mix(co_dark, co_pat, vec3(step(0.7, n * 0.5 + 0.5)));
colour_out += mix(vec4(co, 1.0), vec4(0.589 , 0.589, 0.196, 1.0), mask);
// shadow
mask = 1.0;
mask *= smoothstep( .05, .30, sdUnevenCapsule(st - vec2(0.80, 0.15), vec2(-0.5, 0.02), vec2(0.0), 0.01, 0.03) );
colour_out *= mix(vec4(0.7), vec4(1.0), mask);
// legs
mask = 1.0;
n = turb_fract( st / 0.15 + 0.025 * mt.y);
co = mix(vec3(0.00), vec3(1.,5.,7.), vec3(step(0.7, n * 0.5 + 0.5)));
mask *= step( 0.05, sdSegment(st, vec2(0.70, 0.31), vec2(0.90, 0.35)) );
mask *= step( 0.05, sdSegment(st, vec2(0.70, 0.31), vec2(0.90, 0.30)) );
mask *= step( 0.04, sdSegment(st, vec2(0.90, 0.30), vec2(0.89, 0.25)) );
mask *= step( 0.04, sdSegment(st, vec2(0.89, 0.25), vec2(0.60, 0.20)) );
mask *= step( 0.03, sdSegment(st, vec2(0.40, 0.45), vec2(0.42, 0.30)) );
mask *= step( 0.02, sdSegment(st, vec2(0.42, 0.30), vec2(0.35, 0.25)) );
colour_out *= mix(vec4(co, 1.0), vec4(1.0, 1.0, 1.0, 1.0), mask);
//eye
mask = 1.0;
mask *= step( 0.06, distance( st.xy, vec2(0.3, 0.7) ) );
colour_out *= mix(vec4(0.0), vec4(1.0), mask);
// iris + mouse trackin+
mask = 1.0;
mask *= step( 0.03, distance( st - 0.03 * (mt - vec2(.3, .7)), vec2(.3, .7) ) );
colour_out += mix(vec4(.9), vec4(0.0), mask);
}
Dendrobates auratus by a
//Wen Ruijia,
//relevant frog : https://wallup.net/wp-content/uploads/2016/07/20/22940-frog-amphibian-poison_dart_frogs.jpg
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec3 permute(vec3 x) {
return mod289(((x*34.0)+10.0)*x);
}
float snoise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
// Permutations
i = mod289(i); // Avoid truncation effects in permutation
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.684 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.152);
m = m*m ;
m = m*m ;
// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.753 - 2.102 * ( a0*a0 + h*h );
// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
// demo code:
float color(vec2 xy) { return snoise(xy); }
void main() {
vec2 p = (gl_FragCoord.xy/u_resolution.y) * 4.264;
vec3 xyz = vec3(p, 0);
float n = color(xyz.xy * 4.984);
colour_out = vec4(vec3(0.5 - 0.5 * vec3(n, n, n)),1.0);
}
unknown by Wen
Ruijia
// credit: NemoSencho (will show up on website)
// frog: Bumblebee Dart Frog
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
//
// GLSL textureless classic 2D noise "cnoise",
// with an RSL-style periodic variant "pnoise".
// Author: Stefan Gustavson (stefan.gustavson@liu.se)
// Version: 2011-08-22
//
// Many thanks to Ian McEwan of Ashima Arts for the
// ideas for permutation and gradient selection.
//
// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
// Distributed under the MIT license. See LICENSE file.
// https://github.com/stegu/webgl-noise
//
vec4 mod289(vec4 x)
{
return x - floor(x * (1.0 / 289.0)) * 289.0;
}
vec4 permute(vec4 x)
{
return mod289(((x*34.0)+10.0)*x);
}
vec4 taylorInvSqrt(vec4 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}
vec2 fade(vec2 t) {
return t*t*t*(t*(t*6.0-15.0)+10.0);
}
// Classic Perlin noise
float cnoise(vec2 P)
{
vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);
vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);
Pi = mod289(Pi); // To avoid truncation effects in permutation
vec4 ix = Pi.xzxz;
vec4 iy = Pi.yyww;
vec4 fx = Pf.xzxz;
vec4 fy = Pf.yyww;
vec4 i = permute(permute(ix) + iy);
vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
vec4 gy = abs(gx) - 0.5 ;
vec4 tx = floor(gx + 0.5);
gx = gx - tx;
vec2 g00 = vec2(gx.x,gy.x);
vec2 g10 = vec2(gx.y,gy.y);
vec2 g01 = vec2(gx.z,gy.z);
vec2 g11 = vec2(gx.w,gy.w);
vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
float n00 = dot(g00, vec2(fx.x, fy.x));
float n10 = dot(g10, vec2(fx.y, fy.y));
float n01 = dot(g01, vec2(fx.z, fy.z));
float n11 = dot(g11, vec2(fx.w, fy.w));
vec2 fade_xy = fade(Pf.xy);
vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
float n_xy = mix(n_x.x, n_x.y, fade_xy.y);
return 2.3 * n_xy;
}
// Classic Perlin noise, periodic variant
float pnoise(vec2 P, vec2 rep)
{
vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);
vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);
Pi = mod(Pi, rep.xyxy); // To create noise with explicit period
Pi = mod289(Pi); // To avoid truncation effects in permutation
vec4 ix = Pi.xzxz;
vec4 iy = Pi.yyww;
vec4 fx = Pf.xzxz;
vec4 fy = Pf.yyww;
vec4 i = permute(permute(ix) + iy);
vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
vec4 gy = abs(gx) - 0.5 ;
vec4 tx = floor(gx + 0.5);
gx = gx - tx;
vec2 g00 = vec2(gx.x,gy.x);
vec2 g10 = vec2(gx.y,gy.y);
vec2 g01 = vec2(gx.z,gy.z);
vec2 g11 = vec2(gx.w,gy.w);
vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
float n00 = dot(g00, vec2(fx.x, fy.x));
float n10 = dot(g10, vec2(fx.y, fy.y));
float n01 = dot(g01, vec2(fx.z, fy.z));
float n11 = dot(g11, vec2(fx.w, fy.w));
vec2 fade_xy = fade(Pf.xy);
vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
float n_xy = mix(n_x.x, n_x.y, fade_xy.y);
return 2.3 * n_xy;
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
float mask = 1.0;
float PI = 3.141592;
vec2 LL_coord = st*4.0 + u_time;
float pn1 = cnoise(LL_coord);
float pn2 = cnoise(LL_coord);
float pn = (pn1 + pn2) / 2.0;
pn *= pow((1.0 + sin((LL_coord.x+LL_coord.y)*PI)) / 2.0, 2.0);
if (sqrt(pn) > 0.07 && sqrt(pn) < 0.55) {
mask = 0.0;
} else {
mask = 1.0;
}
colour_out = vec4( 1.0, 0.95, 0.1, 1.0 );
colour_out *= 1.0-mask;
}
Bumblebee Dart Frog by NemoSencho