Last active
January 26, 2016 10:08
-
-
Save co3moz/4abd3c0576100fff321f to your computer and use it in GitHub Desktop.
Cake Fragment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HAPPY BIRTHDAY TO YOU :) | |
// co3moz (Dogan Derya) | |
// https://gist.github.com/co3moz/4abd3c0576100fff321f | |
#define CAKE_LENGTH 10. | |
#define CAKE_WIDTH 10. | |
#define CAKE_COLOR 0, i / CAKE_LENGTH, 1 | |
#define CANDLE_LENGTH 9. | |
#define CANDLE_COUNT 9. | |
#define CANDLE_COLOR z / CANDLE_LENGTH * c(2., 2.), 0, 0 | |
#define FIRE_LENGTH 6. | |
#define FIRE_COLOR 1. * z / FIRE_LENGTH, .15 + 1. * z / FIRE_LENGTH, .5 + (FIRE_LENGTH - z - 10.) / FIRE_LENGTH | |
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
uniform float time; | |
uniform vec2 resolution; | |
#extension GL_OES_standard_derivatives : enable | |
#define rad .0174532925 | |
#define s(i, a) i + sin(time) / a | |
#define c(i, a) i + cos(time) / a | |
void main(void) { | |
vec2 position = (gl_FragCoord.xy / resolution.xy); | |
vec3 color = vec3(0); | |
for (float i = 0.; i < CAKE_LENGTH; i += 1.) if (distance(position, vec2(s(.5, 7.), c(.5, 7.) + .01 * i)) < 0.01 * CAKE_WIDTH) color = vec3(CAKE_COLOR); | |
if (distance(position, vec2(s(.5, 7.), c(.5, 7.) + .009 * CAKE_LENGTH)) < .009 * CAKE_WIDTH) color = vec3(.9, .7, 0); | |
for (float i = 0.; i < 360.; i += 360. / CANDLE_COUNT) { | |
for (float z = 0.; z < CANDLE_LENGTH; z += 1.) if (distance(position, vec2(s(.5, 7.) + sin(i * rad + time)/(120. / CAKE_WIDTH), c(.5, 7.) + cos(i * rad + time)/(120. / CAKE_WIDTH) + .009 * CAKE_LENGTH + 0.0045 * z)) < .006 - (z / 700. / CANDLE_LENGTH)) color = vec3(CANDLE_COLOR); | |
for (float z = 0.; z < FIRE_LENGTH; z += 1.) if (distance(position, vec2(s(.5, 7.) + sin(i * rad + time)/(120. / CAKE_WIDTH) - .0005 * sin(time * (i + 1.)) * z, c(.5, 7.) + cos(i * rad + time)/(120. / CAKE_WIDTH) + .009 * CAKE_LENGTH + .0045 * CANDLE_LENGTH + .002 * z)) < .006 - (CANDLE_LENGTH / 4000.) - sin(z * 3.) * .0005 - (z / 900. / FIRE_LENGTH)) color = vec3(FIRE_COLOR); | |
} | |
gl_FragColor = vec4(color, 1.); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment