diff options
Diffstat (limited to 'themes/src/shaders')
| -rw-r--r-- | themes/src/shaders/snowflake_frag.cpp | 76 | ||||
| -rw-r--r-- | themes/src/shaders/snowflake_frag.h | 4 | ||||
| -rw-r--r-- | themes/src/shaders/snowflake_vert.cpp | 33 | ||||
| -rw-r--r-- | themes/src/shaders/snowflake_vert.h | 4 |
4 files changed, 117 insertions, 0 deletions
diff --git a/themes/src/shaders/snowflake_frag.cpp b/themes/src/shaders/snowflake_frag.cpp new file mode 100644 index 0000000..52d535d --- /dev/null +++ b/themes/src/shaders/snowflake_frag.cpp @@ -0,0 +1,76 @@ +#include "snowflake_frag.h" + +const char* shader_snowflake_frag = "// Procedural star fragment shader \n" +"varying lowp vec2 vUV; \n" +"varying lowp float vSeed; \n" +"varying lowp float vScale; \n" +" \n" +"const lowp float PI = 3.14159265359; \n" +" \n" +"// Simple hash function for deterministic randomness \n" +"lowp float hash(lowp float n) { \n" +" return fract(sin(n) * 43758.5453123); \n" +"} \n" +" \n" +"// Generate star pattern procedurally \n" +"lowp float starPattern(lowp vec2 uv) { \n" +" lowp float dist = length(uv); \n" +" lowp float angle = atan(uv.y, uv.x); \n" +" \n" +" // Number of star points (4 or 5) \n" +" lowp float numPoints = 4.0 + floor(hash(vSeed) * 2.0); \n" +" \n" +" // Create sharp star with triangular points \n" +" lowp float angleStep = 2.0 * PI / numPoints; \n" +" lowp float currentAngle = mod(angle + PI / numPoints, angleStep) - angleStep * 0.5; \n" +" \n" +" // Create triangular points - distance from center to edge varies linearly with angle \n" +" lowp float normalizedAngle = abs(currentAngle) / (angleStep * 0.5); \n" +" \n" +" // Outer tip radius and inner valley radius \n" +" lowp float tipRadius = 0.5; \n" +" lowp float valleyRadius = 0.15; \n" +" \n" +" // Linear interpolation creates sharp triangular points \n" +" lowp float rayEdge = mix(tipRadius, valleyRadius, normalizedAngle); \n" +" \n" +" // Hard cutoff for sharp edges \n" +" lowp float star = step(dist, rayEdge); \n" +" \n" +" return star; \n" +"} \n" +" \n" +"void main() { \n" +" lowp float pattern = starPattern(vUV); \n" +" \n" +" // Color variation based on seed - white and blue tints \n" +" lowp float colorVar = hash(vSeed * 3.0); \n" +" lowp vec3 starColor; \n" +" \n" +" if (colorVar < 0.5) { \n" +" // Pure white \n" +" starColor = vec3(1.0, 1.0, 1.0); \n" +" } else if (colorVar < 0.75) { \n" +" // Light blue tint \n" +" starColor = vec3(0.9, 0.95, 1.0); \n" +" } else { \n" +" // Stronger blue tint \n" +" starColor = vec3(0.85, 0.92, 1.0); \n" +" } \n" +" \n" +" // Scale alpha based on size - smaller stars are more transparent \n" +" // Normalize scale from range [16, 48] to [0, 1] \n" +" lowp float sizeRatio = (vScale - 16.0) / (48.0 - 16.0); \n" +" // Map to alpha range [0.3, 1.0] - smaller stars at 30% opacity, larger at 100% \n" +" lowp float alpha = mix(0.3, 1.0, sizeRatio); \n" +" \n" +" lowp vec4 color = vec4(starColor, pattern * alpha); \n" +" \n" +" // Discard fully transparent pixels for performance \n" +" if (color.a < 0.01) { \n" +" discard; \n" +" } \n" +" \n" +" gl_FragColor = color; \n" +"} \n" +" \n"; diff --git a/themes/src/shaders/snowflake_frag.h b/themes/src/shaders/snowflake_frag.h new file mode 100644 index 0000000..b34328f --- /dev/null +++ b/themes/src/shaders/snowflake_frag.h @@ -0,0 +1,4 @@ +#ifndef SHADER_SNOWFLAKE_FRAG +#define SHADER_SNOWFLAKE_FRAG +extern const char* shader_snowflake_frag; +#endif diff --git a/themes/src/shaders/snowflake_vert.cpp b/themes/src/shaders/snowflake_vert.cpp new file mode 100644 index 0000000..199009d --- /dev/null +++ b/themes/src/shaders/snowflake_vert.cpp @@ -0,0 +1,33 @@ +#include "snowflake_vert.h" + +const char* shader_snowflake_vert = "// Instanced snowflake vertex shader \n" +"attribute vec2 position; // Base quad vertex position \n" +"attribute vec2 instancePos; // Per-instance: snowflake center position \n" +"attribute float instanceRot; // Per-instance: rotation angle \n" +"attribute float instanceScale; // Per-instance: size scale \n" +"attribute float instanceSeed; // Per-instance: random seed for variation \n" +" \n" +"uniform mat4 projection; \n" +"uniform mat4 model; \n" +" \n" +"varying lowp vec2 vUV; // UV coordinates for fragment shader \n" +"varying lowp float vSeed; // Pass seed to fragment shader \n" +"varying lowp float vScale; // Pass scale to fragment shader \n" +" \n" +"void main() { \n" +" // Rotate and scale the base quad \n" +" float c = cos(instanceRot); \n" +" float s = sin(instanceRot); \n" +" mat2 rotation = mat2(c, s, -s, c); \n" +" \n" +" vec2 rotatedPos = rotation * (position * instanceScale); \n" +" vec2 worldPos = instancePos + rotatedPos; \n" +" \n" +" gl_Position = projection * model * vec4(worldPos, 0.0, 1.0); \n" +" \n" +" // Pass UV in range [-1, 1] for procedural generation \n" +" vUV = position; \n" +" vSeed = instanceSeed; \n" +" vScale = instanceScale; \n" +"} \n" +" \n"; diff --git a/themes/src/shaders/snowflake_vert.h b/themes/src/shaders/snowflake_vert.h new file mode 100644 index 0000000..36bf8b0 --- /dev/null +++ b/themes/src/shaders/snowflake_vert.h @@ -0,0 +1,4 @@ +#ifndef SHADER_SNOWFLAKE_VERT +#define SHADER_SNOWFLAKE_VERT +extern const char* shader_snowflake_vert; +#endif |
