042bb43b37
- cpp/functions/gfx: gl_shader, gl_framebuffer, fullscreen_quad, shader_canvas - cpp/apps/shaders_lab: main + 3 seed shaders (plasma, circle, checker) - ImGui docking layout: Code | Canvas | Controls Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
96 lines
2.5 KiB
C
96 lines
2.5 KiB
C
#pragma once
|
|
|
|
// GLSL 330 fragment shader bodies (no #version, no out, no uniform declarations).
|
|
// compile_fragment() prepends those automatically.
|
|
|
|
static const char* PLASMA = R"glsl(
|
|
void main() {
|
|
vec2 uv = gl_FragCoord.xy / u_resolution;
|
|
float t = u_time * 0.5;
|
|
|
|
float v1 = sin(uv.x * 10.0 + t);
|
|
float v2 = sin(uv.y * 10.0 + t * 1.3);
|
|
float v3 = sin((uv.x + uv.y) * 10.0 + t * 0.7);
|
|
float v4 = sin(length(uv - 0.5) * 20.0 - t * 2.0);
|
|
|
|
float v = (v1 + v2 + v3 + v4) * 0.25;
|
|
|
|
vec3 col = vec3(
|
|
sin(v * 3.14159 + 0.0) * 0.5 + 0.5,
|
|
sin(v * 3.14159 + 2.094) * 0.5 + 0.5,
|
|
sin(v * 3.14159 + 4.188) * 0.5 + 0.5
|
|
);
|
|
|
|
fragColor = vec4(col, 1.0);
|
|
}
|
|
)glsl";
|
|
|
|
static const char* CIRCLE = R"glsl(
|
|
void main() {
|
|
vec2 uv = gl_FragCoord.xy / u_resolution;
|
|
vec2 center = vec2(0.5);
|
|
float t = u_time;
|
|
|
|
// Animated center
|
|
center += vec2(sin(t * 0.7), cos(t * 0.5)) * 0.2;
|
|
|
|
float d = length(uv - center);
|
|
|
|
// Concentric rings
|
|
float rings = sin(d * 40.0 - t * 3.0) * 0.5 + 0.5;
|
|
|
|
// Radial glow
|
|
float glow = exp(-d * 4.0);
|
|
|
|
vec3 col = mix(
|
|
vec3(0.05, 0.1, 0.3),
|
|
vec3(0.2, 0.7, 1.0),
|
|
rings * glow + glow * 0.4
|
|
);
|
|
|
|
fragColor = vec4(col, 1.0);
|
|
}
|
|
)glsl";
|
|
|
|
static const char* CHECKER = R"glsl(
|
|
void main() {
|
|
vec2 uv = gl_FragCoord.xy / u_resolution;
|
|
float t = u_time;
|
|
|
|
// Animated scale and rotation
|
|
float scale = 8.0 + sin(t * 0.4) * 3.0;
|
|
float angle = t * 0.2;
|
|
float ca = cos(angle), sa = sin(angle);
|
|
vec2 p = uv - 0.5;
|
|
p = vec2(ca * p.x - sa * p.y, sa * p.x + ca * p.y);
|
|
p = p * scale + 0.5;
|
|
|
|
vec2 cell = floor(p);
|
|
float checker = mod(cell.x + cell.y, 2.0);
|
|
|
|
// Color gradient per cell
|
|
float hue = fract((cell.x + cell.y) * 0.1 + t * 0.05);
|
|
vec3 col_a = vec3(hue, 0.7, 0.9);
|
|
vec3 col_b = vec3(fract(hue + 0.5), 0.5, 0.7);
|
|
|
|
// Simple HSV to RGB
|
|
vec3 col = mix(col_b, col_a, checker);
|
|
// hue is already [0,1], apply saturation/value manually
|
|
float h = col.x * 6.0;
|
|
int i = int(h);
|
|
float f = h - float(i);
|
|
float p2 = col.z * (1.0 - col.y);
|
|
float q2 = col.z * (1.0 - col.y * f);
|
|
float t2 = col.z * (1.0 - col.y * (1.0 - f));
|
|
vec3 rgb;
|
|
if (i == 0) rgb = vec3(col.z, t2, p2);
|
|
else if (i == 1) rgb = vec3(q2, col.z, p2);
|
|
else if (i == 2) rgb = vec3(p2, col.z, t2);
|
|
else if (i == 3) rgb = vec3(p2, q2, col.z);
|
|
else if (i == 4) rgb = vec3(t2, p2, col.z);
|
|
else rgb = vec3(col.z, p2, q2);
|
|
|
|
fragColor = vec4(rgb, 1.0);
|
|
}
|
|
)glsl";
|