diff options
Diffstat (limited to '')
| -rw-r--r-- | src/main/kotlin/mitosis/MitosisProgram.kt | 37 | ||||
| -rw-r--r-- | src/main/resources/shaders/mitosis.glsl | 60 | ||||
| -rw-r--r-- | video/mitosis.MitosisProgram.mp4 | bin | 0 -> 14496986 bytes |
3 files changed, 97 insertions, 0 deletions
diff --git a/src/main/kotlin/mitosis/MitosisProgram.kt b/src/main/kotlin/mitosis/MitosisProgram.kt new file mode 100644 index 0000000..a1cfc3f --- /dev/null +++ b/src/main/kotlin/mitosis/MitosisProgram.kt @@ -0,0 +1,37 @@ +package mitosis + +import org.openrndr.application +import org.openrndr.color.* +import org.openrndr.draw.* +import phenax.utils.* + +fun main() = application { + recordDuration(10.seconds()) + + if (captureEnabled) { + configure { + width = 1920 + height = 1440 + windowResizable = false + } + } else { + configure { + width = 640 + height = 480 + windowResizable = false + } + } + + oliveProgram { + val cs by liveComputeShader("mitosis") + + val outputBuffer = colorBuffer(width, height, type = ColorType.UINT8) + + extend { + cs.uniform("seconds", seconds) + cs.image("output_image", 0, outputBuffer.imageBinding(0, ImageAccess.WRITE)) + cs.execute(outputBuffer.width, outputBuffer.height, 1) + drawer.image(outputBuffer) + } + } +} diff --git a/src/main/resources/shaders/mitosis.glsl b/src/main/resources/shaders/mitosis.glsl new file mode 100644 index 0000000..7d0d373 --- /dev/null +++ b/src/main/resources/shaders/mitosis.glsl @@ -0,0 +1,60 @@ +#version 430 +layout(local_size_x = 1, local_size_y = 1) in; + +#include <utils> + +uniform float seconds = 0; +layout(rgba8) uniform readonly image2D noise_texture; +layout(rgba8) uniform writeonly image2D output_image; + +uniform float antialiasing = 0.28; +uniform bool enable_antialiasing = true; + +float sample_noise(in vec2 p) { + vec4 noise = imageLoad(noise_texture, ivec2(p * imageSize(noise_texture))); + return noise.x; +} + +vec3 image(vec2 uv) { + const vec3 bg_color = srgb(0.16, 0.16, 0.21); + const vec3 color1 = srgb(0.09, 0.57, 0.6); + const vec3 color2 = srgb(0.31, 0.23, 0.64); + const vec3 color3 = srgb(0.82, 0.06, 0.22); + + float duration = 10.0; + float t = mod(seconds, duration) - duration / 2; + t *= 0.5; + + vec3 color = bg_color; + vec2 p = uv * 11.6; + float v = 1 - (sin(p.x * p.x) - sin(p.y * p.y) - sin(t * p.x * p.y)); + color = mix(color, color1, step(v, 1.4)); + color = mix(color, color2, step(v, 1.1)); + color = mix(color, color3, step(v, 0.84)); + color = mix(color, color2, step(v, 0.6)); + color = mix(color, color1, step(v, 0.3)); + color = mix(color, bg_color, step(v, 0.1)); + + return color; +} + +vec3 antialiased_image(vec2 uv) { + vec2 resolution = vec2(imageSize(output_image).xy); + float s = antialiasing / max(resolution.x, resolution.y); + vec3 sum = vec3(0); + int count = 0; + for (int i = -2; i < 2; i++) + for (int j = -2; j < 2; j++, count++) + sum += image(uv + vec2(i, j) * s); + return sum / count; +} + +void main() { + vec2 resolution = vec2(imageSize(output_image).xy); + float aspect_ratio = resolution.y / resolution.x; + vec2 uv = (gl_GlobalInvocationID.xy - resolution / 2.) * vec2(1.0, aspect_ratio) / resolution; + + vec3 color = enable_antialiasing ? antialiased_image(uv) : image(uv); + + imageStore(output_image, ivec2(gl_GlobalInvocationID.xy), vec4(color, 1)); +} diff --git a/video/mitosis.MitosisProgram.mp4 b/video/mitosis.MitosisProgram.mp4 Binary files differnew file mode 100644 index 0000000..97fde41 --- /dev/null +++ b/video/mitosis.MitosisProgram.mp4 |
