From f8fa4402bb7e1421c5219a93e86a73cf06bab389 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Tue, 29 Sep 2026 11:36:20 +0530 Subject: Add cloak --- src/main/kotlin/cloak/CloakProgram.kt | 37 ++++++++++++++++++ src/main/resources/shaders/cloak.glsl | 74 +++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/main/kotlin/cloak/CloakProgram.kt create mode 100644 src/main/resources/shaders/cloak.glsl (limited to 'src') diff --git a/src/main/kotlin/cloak/CloakProgram.kt b/src/main/kotlin/cloak/CloakProgram.kt new file mode 100644 index 0000000..9f96e29 --- /dev/null +++ b/src/main/kotlin/cloak/CloakProgram.kt @@ -0,0 +1,37 @@ +package cloak + +import org.openrndr.application +import org.openrndr.color.* +import org.openrndr.draw.* +import phenax.utils.* + +fun main() = application { + recordDuration(5.seconds()) + + if (recordingEnabled || screenshotEnabled) { + configure { + width = 1920 + height = 1440 + windowResizable = false + } + } else { + configure { + width = 640 + height = 480 + windowResizable = false + } + } + + oliveProgram { + val cs by liveComputeShader("cloak") + + 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/cloak.glsl b/src/main/resources/shaders/cloak.glsl new file mode 100644 index 0000000..c249760 --- /dev/null +++ b/src/main/resources/shaders/cloak.glsl @@ -0,0 +1,74 @@ +#version 430 +layout(local_size_x = 1, local_size_y = 1) in; + +#include +#include + +#define PI 3.14159265358979323 + +const float antialiasing = 0.28; +uniform float seconds = 0; +layout(rgba8) uniform writeonly image2D output_image; + +vec3 background = srgb(1, 0.99, 0.91); +vec3 body = srgb(0.15, 0.19, 0.30); +vec3 bodyaccent1 = srgb(0.099, 0.099, 0.16); +vec3 bodyaccent2 = srgb(0.83, 0.69, 0.22); +vec3 bgaccent1 = srgb(0.15, 0.19, 0.30); +vec3 bgaccent2 = srgb(0.4, 0.1, 0.18); +vec3 bgaccent3 = srgb(0.31, 0.78, 0.41); + +vec3 image(vec2 uv) { + vec2 p = uv * 7 - vec2(0, 0); + + vec3 color = background; + + float overhood = 2.4 - p.y - 0.86 * p.x * p.x; + float bodycut = 0.0 + p.y + 0.12 * p.x * p.x * p.x * p.x; + + float cloak = cos(atan(p.x * p.x + p.y, p.y) * 24 + 8 * p.y) - 0.4; + float clothtexture = sin(240 * (p.x - 1)) * cos(240 * (p.y - 1)) * (fbm(400 * p) - 0.42); + vec3 patterncolor = mix(bodyaccent2, bodyaccent1, smoothstep(cloak - 0.01 * fbm(uv * 100), 0.6, 0.594)); + color = mix(color, patterncolor, step(bodycut, 0)); + color = mix(color, mix(mix(body, vec3(0), step(-cloak, 0.34)), mix(body, vec3(0), 0.6), step(clothtexture, 0)), step(cloak, 0)); + + float yoff = 2.951; + float cutshape = abs(cos(0.18 * (p.y + yoff) * (p.y + yoff))) + 1.37; + float xc = 1.10; + float overhoodcut = min(cutshape - xc * p.x, cutshape + xc * p.x); + overhood = min(overhood, max(-cloak, 2.1 - p.y - 1.06 * p.x * p.x)); + overhood = min(overhood, overhoodcut); + vec2 noisep = p; + float noisy1 = fbm(8 * noisep * fbm(0.8 * noisep * fbm(2.2 * noisep))) - 0.36; + float noisy2 = fbm(8 * noisep * fbm(noisep * fbm(2.2 * noisep))) - 0.38; + float noisy3 = fbm(8 * noisep * fbm(0.8 * noisep * fbm(2.2 * noisep))) - 0.39; + vec3 bgcolor = background; + bgcolor = mix(bgcolor, bgaccent3, step(noisy3, 0)); + bgcolor = mix(bgcolor, bgaccent1, step(noisy1, 0)); + bgcolor = mix(bgcolor, bgaccent2, step(noisy2, 0)); + color = mix(color, bgcolor, step(overhood, 0)); + color = mix(color, mix(bgcolor, mix(bgcolor, body, 0.70), step(cloak, 0)), step(overhood, 0)); + + 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 = image(uv); + vec3 color = antialiased_image(uv); + imageStore(output_image, ivec2(gl_GlobalInvocationID.xy), vec4(color, 1)); +} -- cgit v1.3.1