GLSL and Shadertoy shader skills for Claude Code, Codex, Cursor, Copilot and Gemini CLI. 186 functions, SDF raymarching, procedural terrain, water, clouds and generative art, with a bundler, checker and 11 examples.
Python agent-skillsclaude-codecodexcomputer-graphicscursorgemini-cligenerative-artgithub-copilotglslnoiseprocedural-artprocedural-generationraymarchingshadersshadertoysigned-distance-functionsterrain-generationwebglwebgl2
//! tonemap: map scene-linear HDR to display range. Every function here takes linear input (after exposure) and
//! returns LINEAR [0,1]. Then apply linearToSrgb exactly once.
//! Recommended chain: col *= exposure; col = tonemapAgX(col); col = linearToSrgb(col); add dither.
//! Choosing: AgX (default) for 3D scenes, glows, fire, suns and volumes; its highlights roll off to white without
//! hue skews. tonemapNeutral for 2D, product shots and palette-faithful work. ACES for the saturated filmic look.
/// AgX: log encoding plus a sigmoid inside an inset/outset gamut. Mid-grey 0.18 maps to about 0.5 display.
/// Minimal implementation after Troy Sobotka's AgX and Benjamin Wrensch's polynomial fit (both MIT).
/// @use default tonemapper for 3D, emissive glows, fire, neon, skies, clouds
/// @see https://iolite-engine.com/blog_posts/minimal_agx_implementation
vec3 tonemapAgX(vec3 c) {
const mat3 inset = mat3(0.842479062253094, 0.0423282422610123, 0.0423756549057051,
0.0784335999999992, 0.878468636469772, 0.0784336,
0.0792237451477643, 0.0791661274605434, 0.879142973793104);
const mat3 outset = mat3(1.19687900512017, -0.0528968517574562, -0.0529716355144438,
-0.0980208811401368, 1.15190312990417, -0.0980434501171241,
-0.0990297440797205, -0.0989611768448433, 1.15107367264116);
const float minEv = -12.47393, maxEv = 4.026069;
c = inset * max(c, 0.0);
c = clamp((log2(max(c, 1e-10)) - minEv) / (maxEv - minEv), 0.0, 1.0);
vec3 x2 = c * c, x4 = x2 * x2;
c = 15.5 * x4 * x2 - 40.14 * x4 * c + 31.96 * x4 - 6.868 * x2 * c + 0.4298 * x2 + 0.1191 * c - 0.00232;
c = outset * c;
return pow(max(c, 0.0), vec3(2.2));
}
/// AgX with the "punchy" look (more contrast and saturation) for stylized art.
/// @use stylized 3D, saturated sunsets, toy-like renders
vec3 tonemapAgXPunchy(vec3 c) {
const mat3 inset = mat3(0.842479062253094, 0.0423282422610123, 0.0423756549057051,
0.0784335999999992, 0.878468636469772, 0.0784336,
0.0792237451477643, 0.0791661274605434, 0.879142973793104);
const mat3 outset = mat3(1.19687900512017, -0.0528968517574562, -0.0529716355144438,
-0.0980208811401368, 1.15190312990417, -0.0980434501171241,
-0.0990297440797205, -0.0989611768448433, 1.15107367264116);
const float minEv = -12.47393, maxEv = 4.026069;
c = inset * max(c, 0.0);
c = clamp((log2(max(c, 1e-10)) - minEv) / (maxEv - minEv), 0.0, 1.0);
vec3 x2 = c * c, x4 = x2 * x2;
c = 15.5 * x4 * x2 - 40.14 * x4 * c + 31.96 * x4 - 6.868 * x2 * c + 0.4298 * x2 + 0.1191 * c - 0.00232;
c = pow(max(c, 0.0), vec3(1.35));
float luma = dot(c, vec3(0.2126, 0.7152, 0.0722));
c = luma + 1.4 * (c - luma);
c = outset * c;
return pow(max(c, 0.0), vec3(2.2));
}
/// Khronos PBR Neutral: leaves [0, ~0.76] almost untouched and compresses only highlights, preserving hue.
/// @use 2D art, palette-faithful scenes, product renders, UI glow
/// @see https://github.com/KhronosGroup/ToneMapping
vec3 tonemapNeutral(vec3 c) {
const float startCompression = 0.76;
const float desaturation = 0.15;
c = max(c, 0.0);
float x = min(c.r, min(c.g, c.b));
float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
c -= offset;
float peak = max(c.r, max(c.g, c.b));
if (peak < startCompression) return c;
const float d = 1.0 - startCompression;
float newPeak = 1.0 - d * d / (peak + d - startCompression);
c *= newPeak / peak;
float g = 1.0 - 1.0 / (desaturation * (peak - newPeak) + 1.0);
return mix(c, vec3(newPeak), g);
}
/// Stephen Hill's ACES fit (RRT + ODT, sRGB primaries). Contrasty and saturated; blues drift purple when very bright.
/// Darker than AgX at the same exposure: multiply the input by about 1.6 to compensate.
/// @use the classic "filmic game" look
/// @see https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl
vec3 tonemapACES(vec3 c) {
c = max(c, 0.0) * mat3(0.59719, 0.35458, 0.04823,
0.07600, 0.90834, 0.01566,
0.02840, 0.13383, 0.83777);
c = (c * (c + 0.0245786) - 0.000090537) / (c * (0.983729 * c + 0.4329510) + 0.238081);
c = c * mat3(1.60475, -0.53108, -0.07367,
-0.10208, 1.10813, -0.00605,
-0.00327, -0.07276, 1.07602);
return clamp(c, 0.0, 1.0);
}
/// Extended Reinhard on luminance: maps `white` to 1 and preserves hue. Simple and predictable.
/// @use quick previews, soft low-contrast looks
vec3 tonemapReinhard(vec3 c, float white) {
c = max(c, 0.0);
float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
float lt = l * (1.0 + l / (white * white)) / (1.0 + l);
return clamp(c * (lt / max(l, 1e-6)), 0.0, 1.0);
}