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
Renormalize rot2 so rotations preserve distances on every GPU
Gökaya5fb9ab6f14b
diff --git a/gallery/raymarch-sdf.glsl b/gallery/raymarch-sdf.glslindex 66f6614..c338e54 100644--- a/gallery/raymarch-sdf.glsl+++ b/gallery/raymarch-sdf.glsl@@ -11,10 +11,10 @@// ---- shader-skills library: common ----const float PI = 3.14159265358979;const float TAU = 6.28318530717959;-// 2D rotation matrix. `rot2(a) * v` rotates v counter-clockwise by a radians.+// 2D rotation matrix. `rot2(a) * v` rotates v counter-clockwise by a radians. (cos, sin) is renormalized because GLSL ES leaves trig precision undefined: on SwiftShader and some mobile GPUs a raw cos/sin pair is far enough from unit length that rotations stop preserving distances.mat2 rot2(float a) {- float c = cos(a), s = sin(a);- return mat2(c, s, -s, c);+ vec2 cs = normalize(vec2(cos(a), sin(a)));+ return mat2(cs.x, cs.y, -cs.y, cs.x);}// ---- shader-skills library: hash ----diff --git a/gallery/sdf-2d-poster.glsl b/gallery/sdf-2d-poster.glslindex 84fdbc0..9e1c27f 100644--- a/gallery/sdf-2d-poster.glsl+++ b/gallery/sdf-2d-poster.glsl@@ -11,10 +11,10 @@ const float TAU = 6.28318530717959;// Squared length.float dot2(vec2 v) { return dot(v, v); }float dot2(vec3 v) { return dot(v, v); }-// 2D rotation matrix. `rot2(a) * v` rotates v counter-clockwise by a radians.+// 2D rotation matrix. `rot2(a) * v` rotates v counter-clockwise by a radians. (cos, sin) is renormalized because GLSL ES leaves trig precision undefined: on SwiftShader and some mobile GPUs a raw cos/sin pair is far enough from unit length that rotations stop preserving distances.mat2 rot2(float a) {- float c = cos(a), s = sin(a);- return mat2(c, s, -s, c);+ vec2 cs = normalize(vec2(cos(a), sin(a)));+ return mat2(cs.x, cs.y, -cs.y, cs.x);}// ---- shader-skills library: hash ----diff --git a/skills/shader-art-coding/glsl/common.glsl b/skills/shader-art-coding/glsl/common.glslindex ede0b50..ce62c27 100644--- a/skills/shader-art-coding/glsl/common.glsl+++ b/skills/shader-art-coding/glsl/common.glsl@@ -15,10 +15,12 @@ float dot2(vec2 v) { return dot(v, v); }float dot2(vec3 v) { return dot(v, v); }/// 2D rotation matrix. `rot2(a) * v` rotates v counter-clockwise by a radians.+/// (cos, sin) is renormalized because GLSL ES leaves trig precision undefined: on SwiftShader and some mobile+/// GPUs a raw cos/sin pair is far enough from unit length that rotations stop preserving distances./// @use spinning parts, posing limbs, rotating octaves, camera rollmat2 rot2(float a) {- float c = cos(a), s = sin(a);- return mat2(c, s, -s, c);+ vec2 cs = normalize(vec2(cos(a), sin(a)));+ return mat2(cs.x, cs.y, -cs.y, cs.x);}/// Linear remap of x from [a,b] to [c,d] (unclamped).diff --git a/skills/shader-art-coding/references/formula-code-couples-sdf.md b/skills/shader-art-coding/references/formula-code-couples-sdf.mdindex 0430c93..028391c 100644--- a/skills/shader-art-coding/references/formula-code-couples-sdf.md+++ b/skills/shader-art-coding/references/formula-code-couples-sdf.md@@ -333,8 +333,8 @@ GLSL:```glslmat2 rot2(float a) {- float c = cos(a), s = sin(a);- return mat2(c, s, -s, c);+ vec2 cs = normalize(vec2(cos(a), sin(a)));+ return mat2(cs.x, cs.y, -cs.y, cs.x);}float posedEllipsoid(vec3 p, vec3 c, vec3 r, float yaw) {diff --git a/skills/shader-art-coding/references/library-index.md b/skills/shader-art-coding/references/library-index.mdindex 08bbfca..a2dbb61 100644--- a/skills/shader-art-coding/references/library-index.md+++ b/skills/shader-art-coding/references/library-index.md@@ -39,7 +39,7 @@ common: constants, rotation, remapping and shaping functions. Target: GLSL ES 3.- `const float TAU = 6.28318530717959;`- `float saturate(float x)` / `vec3 saturate(vec3 x)` - Clamp to [0,1]. *Use: masks, weights, colors.*- `float dot2(vec2 v)` / `float dot2(vec3 v)` - Squared length. *Use: cheap distance comparisons, SDF internals.*-- `mat2 rot2(float a)` - 2D rotation matrix. `rot2(a) * v` rotates v counter-clockwise by a radians. *Use: spinning parts, posing limbs, rotating octaves, camera roll.*+- `mat2 rot2(float a)` - 2D rotation matrix. `rot2(a) * v` rotates v counter-clockwise by a radians. (cos, sin) is renormalized because GLSL ES leaves trig precision undefined: on SwiftShader and some mobile GPUs a raw cos/sin pair is far enough from unit length that rotations stop preserving distances. *Use: spinning parts, posing limbs, rotating octaves, camera roll.*- `float remap(float x, float a, float b, float c, float d)` - Linear remap of x from [a,b] to [c,d] (unclamped). *Use: converting ranges, rescaling noise.*- `float linearstep(float a, float b, float x)` - Linear ramp from 0 at a to 1 at b, clamped. *Use: masks whose falloff should not ease in or out.*- `float cubicPulse(float c, float w, float x)` - Smooth bump: 1 at x == c, falling to 0 at |x - c| >= w (cubic). *Use: stripes, rings, highlights at one height, pulses in time.*