diff options
| author | Matt Kosarek <matt.kosarek@canonical.com> | 2026-07-08 09:07:55 -0400 |
|---|---|---|
| committer | Matt Kosarek <matt.kosarek@canonical.com> | 2026-07-08 09:07:55 -0400 |
| commit | c8938fe29132a11126013ed1b010c3092f5645e4 (patch) | |
| tree | f6a6cd0603f25d51c08e302cc4342c28f9e10806 /themes/src/shaders/water_vert.cpp | |
| parent | 418396ee5100eda8f6bc036ea35dbbe44db2f91a (diff) | |
feature: improved summer scene
Diffstat (limited to 'themes/src/shaders/water_vert.cpp')
| -rw-r--r-- | themes/src/shaders/water_vert.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/themes/src/shaders/water_vert.cpp b/themes/src/shaders/water_vert.cpp new file mode 100644 index 0000000..44dabd8 --- /dev/null +++ b/themes/src/shaders/water_vert.cpp @@ -0,0 +1,66 @@ +#include "water_vert.h" + +const char* shader_water_vert = "precision highp float; \n" +" \n" +"attribute vec2 position; // local (x, z) on the plane \n" +" \n" +"uniform mat4 projection; \n" +"uniform mat4 view; \n" +"uniform mat4 model; \n" +"uniform float time; \n" +"uniform float amplitude; \n" +" \n" +"varying vec3 vWorldPos; \n" +"varying vec3 vNormal; \n" +" \n" +"float hash(vec2 p) { \n" +" p = fract(p * vec2(123.34, 456.21)); \n" +" p += dot(p, p + 45.32); \n" +" return fract(p.x * p.y); \n" +"} \n" +" \n" +"float valueNoise(vec2 p) { \n" +" vec2 i = floor(p); \n" +" vec2 f = fract(p); \n" +" float a = hash(i); \n" +" float b = hash(i + vec2(1.0, 0.0)); \n" +" float c = hash(i + vec2(0.0, 1.0)); \n" +" float d = hash(i + vec2(1.0, 1.0)); \n" +" vec2 u = f * f * (3.0 - 2.0 * f); \n" +" return mix(mix(a, b, u.x), mix(c, d, u.x), u.y); \n" +"} \n" +" \n" +"// Irregular height: non-harmonic directional sines plus two octaves of \n" +"// scrolling value noise so it never reads as a single clean wave. \n" +"float waveHeight(vec2 p, float t) { \n" +" float h = 0.0; \n" +" h += 0.30 * sin(dot(p, vec2(0.90, 0.30)) * 0.35 + t * 1.1); \n" +" h += 0.20 * sin(dot(p, vec2(-0.40, 1.00)) * 0.55 - t * 1.7); \n" +" h += 0.12 * sin(dot(p, vec2(0.70, -0.80)) * 0.90 + t * 2.3); \n" +" h += 0.08 * sin(dot(p, vec2(1.00, 0.60)) * 1.60 - t * 3.1); \n" +" h += 0.18 * (valueNoise(p * 0.25 + vec2(t * 0.15, t * 0.10)) - 0.5); \n" +" h += 0.09 * (valueNoise(p * 0.70 - vec2(t * 0.20, 0.0)) - 0.5); \n" +" return h; \n" +"} \n" +" \n" +"void main() { \n" +" vec2 p = position; \n" +" float t = time; \n" +" \n" +" float h = waveHeight(p, t) * amplitude; \n" +" \n" +" // Analytic normal via central differences of the same height function. \n" +" float e = 2.0; \n" +" float hL = waveHeight(p - vec2(e, 0.0), t) * amplitude; \n" +" float hR = waveHeight(p + vec2(e, 0.0), t) * amplitude; \n" +" float hD = waveHeight(p - vec2(0.0, e), t) * amplitude; \n" +" float hU = waveHeight(p + vec2(0.0, e), t) * amplitude; \n" +" vec3 N = normalize(vec3(hL - hR, 2.0 * e, hD - hU)); \n" +" \n" +" vec4 worldPos = model * vec4(p.x, h, p.y, 1.0); \n" +" vWorldPos = worldPos.xyz; \n" +" vNormal = N; // model is translation-only, so no normal matrix needed \n" +" \n" +" gl_Position = projection * view * worldPos; \n" +"} \n" +" \n"; |
