From fbc5d7dd1a9192c29daccdf12a7a067037ff2c2a Mon Sep 17 00:00:00 2001 From: Matt Kosarek Date: Mon, 29 Dec 2025 10:02:38 -0500 Subject: Improve the sun shader with the help of AI --- themes/src/shaders/sun_frag.cpp | 40 +++++++++++++++++++++++++++++++++++++++- themes/src/shaders/sun_vert.cpp | 27 ++++++++++++++++++--------- 2 files changed, 57 insertions(+), 10 deletions(-) (limited to 'themes/src/shaders') diff --git a/themes/src/shaders/sun_frag.cpp b/themes/src/shaders/sun_frag.cpp index d1ea160..30553e0 100644 --- a/themes/src/shaders/sun_frag.cpp +++ b/themes/src/shaders/sun_frag.cpp @@ -1,8 +1,46 @@ #include "sun_frag.h" const char* shader_sun_frag = "varying lowp vec4 VertexColor; \n" +"varying lowp vec2 TexCoord; \n" +"uniform lowp float time; \n" +" \n" +"// Simple noise function for edge distortion \n" +"lowp float noise(lowp vec2 p) { \n" +" return sin(p.x * 10.0 + time) * cos(p.y * 10.0 + time * 0.5) * 0.5 + 0.5; \n" +"} \n" " \n" "void main() { \n" -" gl_FragColor = VertexColor; \n" +" // TexCoord is now normalized: center is (0,0), edges are at distance ~1 \n" +" lowp float dist = length(TexCoord); \n" +" \n" +" // Add animated noise to the edge \n" +" lowp float angle = atan(TexCoord.y, TexCoord.x); \n" +" lowp float wave = sin(angle * 8.0 + time * 2.0) * 0.05 + sin(angle * 4.0 - time * 1.5) * 0.03; \n" +" lowp float noiseValue = noise(TexCoord + time * 0.1) * 0.02; \n" +" \n" +" // Create soft edge using smoothstep - ensure fade reaches zero at the actual edge \n" +" lowp float innerEdge = 0.2; \n" +" lowp float outerEdge = 1.0; \n" +" lowp float alpha = 1.0 - smoothstep(innerEdge, outerEdge, dist); \n" +" \n" +" // Apply wave distortion to the edge \n" +" alpha *= 1.0 - smoothstep(0.85 + wave + noiseValue * 2.0, 1.0, dist); \n" +" \n" +" // Make edges even more transparent with additional fade \n" +" alpha = alpha * alpha * alpha; \n" +" \n" +" // Add slight glow effect at the edge \n" +" lowp float glow = smoothstep(0.5, 0.8, dist) * (1.0 - smoothstep(0.8, 1.0, dist)); \n" +" \n" +" // Create orange gradient from center \n" +" lowp vec3 orangeColor = vec3(1.0, 0.5, 0.1); \n" +" lowp float centerGradient = smoothstep(0.6, 0.0, dist); \n" +" lowp vec3 baseColor = mix(VertexColor.rgb, orangeColor, centerGradient * 0.6); \n" +" \n" +" // Mix in the glow with a brighter color \n" +" lowp vec3 glowColor = baseColor * 1.3; \n" +" lowp vec3 finalColor = mix(baseColor, glowColor, glow * 0.5); \n" +" \n" +" gl_FragColor = vec4(finalColor, VertexColor.a * alpha); \n" "} \n" " \n"; diff --git a/themes/src/shaders/sun_vert.cpp b/themes/src/shaders/sun_vert.cpp index ca617c0..bacf3a6 100644 --- a/themes/src/shaders/sun_vert.cpp +++ b/themes/src/shaders/sun_vert.cpp @@ -1,16 +1,25 @@ #include "sun_vert.h" const char* shader_sun_vert = " \n" -"attribute vec2 position; \n" -"attribute vec4 color; \n" -"attribute mat4 vMatrix; \n" -"uniform mat4 projection; \n" -"uniform mat4 model; \n" +"attribute vec2 position; \n" +"attribute vec4 color; \n" +"attribute mat4 vMatrix; \n" +"uniform mat4 projection; \n" +"uniform mat4 model; \n" "varying lowp vec4 VertexColor; \n" +"varying lowp vec2 TexCoord; \n" " \n" -"void main() { \n" -" vec4 fragmentPosition = projection * model * vMatrix * vec4(position.x, position.y, 0, 1); \n" -" gl_Position = fragmentPosition; \n" -" VertexColor = color; \n" +"void main() { \n" +" vec4 fragmentPosition = projection * model * vMatrix * vec4(position.x, position.y, 0, 1); \n" +" gl_Position = fragmentPosition; \n" +" VertexColor = color; \n" +" // Normalize the position - the center is at (0,0) and edge vertices are at distance 'radius' \n" +" // We want TexCoord to be in the range roughly [-1, 1] at the edges \n" +" lowp float maxDist = length(position); \n" +" if (maxDist > 0.1) { \n" +" TexCoord = position / maxDist; \n" +" } else { \n" +" TexCoord = vec2(0.0, 0.0); \n" +" } \n" "} \n" " \n"; -- cgit v1.2.1