diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-09-26 01:53:26 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-09-28 01:48:05 +0530 |
| commit | a4c35a815a2aceeea2f127a5b506a133a602df8e (patch) | |
| tree | cc5cb826c68cb0cd4ed3e29fdffa05249b31f786 /src/main/resources | |
| parent | e9613fcaa547dababd02c58b89abcebab6945c8f (diff) | |
| download | art-playground-openrndr-a4c35a815a2aceeea2f127a5b506a133a602df8e.tar.gz art-playground-openrndr-a4c35a815a2aceeea2f127a5b506a133a602df8e.zip | |
Vacation scene
Diffstat (limited to 'src/main/resources')
| -rw-r--r-- | src/main/resources/shaders/modules/sdf.glsl | 9 | ||||
| -rw-r--r-- | src/main/resources/shaders/vacation.glsl | 73 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/main/resources/shaders/modules/sdf.glsl b/src/main/resources/shaders/modules/sdf.glsl index 9051339..c6787c9 100644 --- a/src/main/resources/shaders/modules/sdf.glsl +++ b/src/main/resources/shaders/modules/sdf.glsl @@ -2,6 +2,10 @@ float sdf_circle(in vec3 p, in float radius) { return length(p) - radius; } +float sdf_circle(in vec2 p, in float radius) { + return length(p) - radius; +} + float sdf_plane(in vec3 p, in vec3 normal, in float offset) { return dot(p, normal) + offset; } @@ -11,6 +15,11 @@ float sdf_box(in vec3 p, in vec3 dimens, in float rounding) { return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0) - rounding; } +float sdf_box(in vec2 p, in vec2 dimens, in float rounding) { + vec2 q = abs(p) - dimens + rounding; + return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - rounding; +} + float sd_ellipsoid(vec3 p, vec3 r) { float k0 = length(p / r); float k1 = length(p / (r * r)); diff --git a/src/main/resources/shaders/vacation.glsl b/src/main/resources/shaders/vacation.glsl new file mode 100644 index 0000000..0a9838a --- /dev/null +++ b/src/main/resources/shaders/vacation.glsl @@ -0,0 +1,73 @@ +#version 430 +layout(local_size_x = 1, local_size_y = 1) in; + +#include <sdf> + +uniform float seconds = 0; +layout(rgba8) uniform readonly image2D noise_texture; +layout(rgba8) uniform writeonly image2D output_image; + +float sample_noise(in vec2 p) { + vec4 noise = imageLoad(noise_texture, ivec2(p * imageSize(noise_texture))); + return noise.x; +} + +const vec3 sky_color = vec3(0.4, 0.65, 1); +const vec3 water_color = vec3(0.02, 0.1, 0.9); +const vec3 sand_color = vec3(0.7, 0.6, 0.4); +const vec3 sun_color = vec3(1, 0.4, 0.2); +const vec3 tree_trunk_color = vec3(0.3, 0.13, 0.06); + +vec3 image(vec2 uv) { + vec3 color = vec3(0); + + vec2 sunpos = vec2(0.2, 0.1); + float sun = sdf_circle(uv - sunpos, 0.04); + color = mix(clamp(sun_color * 1.6, 0., 1.), sky_color, clamp(sun * 6, 0, 1)); + color = mix(color, sun_color, step(sun, 0.04)); + + float water = uv.y; + color = mix(color, water_color, step(water, -0.04)); + + float sand = uv.y + sin(uv.x * 3 + 0.) * 0.07; + color = mix(color, sand_color, step(sand, -0.23)); + + float trunk = sdf_box(uv - vec2(-0.35 + sin(uv.y * 4 - 0.2) * 0.08, -0.06), vec2(0.01 + abs(uv.y * 0.2 - 0.1) * 0.3, 0.28), 0.0); + color = mix(color, tree_trunk_color, step(trunk, 0)); + + float leafbranchcurve = sin(-uv.x * 8 + 0.2) * 0.06; + float leafsizecurve = sin(uv.x * 8 - 6.8) * 0.06; + + vec2 leafpos = uv; + leafpos -= vec2(-0.26 + sin(uv.y * 8 + 0.5) * 0.06, 0.18 + leafbranchcurve + leafsizecurve); + float leafgap = 0.012; + float leafindex = clamp(round(leafpos.x / leafgap), -7, 21); + leafpos.x = leafpos.x - leafgap * leafindex; + float leaf = sdf_box(leafpos, vec2(abs(leafpos.y * 0.1 + 0.014) * 0.26, 0.02 - leafsizecurve), 0.0); + color = mix(color, vec3(0.0, 0.3, 0.0), step(leaf, 0)); + + float leaf_stick = sdf_box(uv - vec2(-0.13, 0.20 + leafbranchcurve), vec2(0.19, 0.008), 0.02); + color = mix(color, vec3(0.0, 0.06, 0.0), step(leaf_stick, 0)); + + return color; +} + +vec3 antialiased_image(vec2 uv) { + float anti_aliasing = 0.0006; + 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) * anti_aliasing); + 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 * 0.5) * vec2(1.0, aspect_ratio) / resolution; + + // vec3 color = antialiased_image(uv); + vec3 color = image(uv); + imageStore(output_image, ivec2(gl_GlobalInvocationID.xy), vec4(color, 1)); +} |
