From 0fc4f3de01b6ef63e1fc8d36d581a542b3c27a42 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Wed, 30 Sep 2026 01:08:35 +0530 Subject: Add night vista --- src/main/kotlin/vista_night/VistaNightProgram.kt | 39 +++++++++++ src/main/resources/shaders/vista_night.glsl | 84 ++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/main/kotlin/vista_night/VistaNightProgram.kt create mode 100644 src/main/resources/shaders/vista_night.glsl (limited to 'src/main') diff --git a/src/main/kotlin/vista_night/VistaNightProgram.kt b/src/main/kotlin/vista_night/VistaNightProgram.kt new file mode 100644 index 0000000..dcd97b4 --- /dev/null +++ b/src/main/kotlin/vista_night/VistaNightProgram.kt @@ -0,0 +1,39 @@ +package vista_night + +import org.openrndr.application +import org.openrndr.color.* +import org.openrndr.draw.* +import org.openrndr.extra.noise.filters.SimplexNoise3D +import org.openrndr.math.Vector3 +import phenax.utils.* + +fun main() = application { + recordDuration(5.seconds()) + + if (recordingEnabled || screenshotEnabled) { + configure { + width = 1920 + height = 1080 + windowResizable = false + } + } else { + configure { + width = 640 + height = 360 + windowResizable = false + } + } + + oliveProgram { + val cs by liveComputeShader("vista_night") + + 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/vista_night.glsl b/src/main/resources/shaders/vista_night.glsl new file mode 100644 index 0000000..3cabd15 --- /dev/null +++ b/src/main/resources/shaders/vista_night.glsl @@ -0,0 +1,84 @@ +#version 430 +layout(local_size_x = 1, local_size_y = 1) in; + +#include +#include +#include + +uniform float seconds = 0; +layout(rgba8) uniform writeonly image2D output_image; + +uniform float antialiasing = 0.28; +uniform bool enable_antialiasing = true; + +vec3 image(vec2 uv) { + const vec3 mooncolor = srgb(1, 0.86, 0.99); + const vec3 starcolor = srgb(1, 0.86, 0.99); + const vec3 m1color = srgb(0.1, 0.1, 0.2); + const vec3 m2color = srgb(0.15, 0.16, 0.3); + const vec3 m3color = srgb(0.16, 0.18, 0.36); + const vec3 m4color = srgb(0.21, 0.23, 0.42); + + vec3 color = srgb(0.06, 0.07, 0.1); + + { + vec2 p = uv; + float gap = 0.06; + vec2 id = round(p / gap); + p -= id * gap; + float starry = sdf_circle(p - 0.06 * vec2(fbm(id * 100), fbm(id * 200)), 0.0015); + color = mix(color, starcolor, step(starry, 0)); + } + + { + vec2 p = uv - vec2(-0.26, 0.2); + float moon = sdf_circle(p, 0.06); + float moonshadow = sdf_circle(p - 0.02, 0.06); + color = mix(color, mooncolor, step(max(-moonshadow, moon), 0)); + } + + float yoff = 0; + { + yoff -= 0.10; + float v = yoff + uv.y - sin(smoothstep(uv.x, 1.6, 0.6) * (20 - 4 * fbm(uv * 2))) * (0.01 + 0.02 * fbm(uv * 3)); + color = mix(color, m1color, step(v, 0)); + } + { + yoff += 0.08; + float v = yoff + uv.y - sin(smoothstep(-uv.x + 0.09, 1.1, 0.5) * 18) * 0.02; + color = mix(color, m2color, step(v, 0)); + } + { + yoff += 0.08; + float v = yoff + uv.y - sin(smoothstep(uv.x - 0.06, 1.1, 0.8) * 20) * 0.03; + color = mix(color, m3color, step(v, 0)); + } + { + yoff += 0.12; + float v = yoff + uv.y - sin(smoothstep(-uv.x + 0.03, 1.1, 0.8) * 20) * 0.02; + color = mix(color, m4color, step(v, 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 = enable_antialiasing ? antialiased_image(uv) : image(uv); + + imageStore(output_image, ivec2(gl_GlobalInvocationID.xy), vec4(color, 1)); +} -- cgit v1.3.1