jpskill.com
💬 コミュニケーション コミュニティ

shadertoy

Shadertoy環境でGLSL ESのコードを記述し、Web用のプロシージャルなグラフィックや視覚効果、ジェネラティブアートを作成する際に、構文やパターン、Shadertoy特有の規則を参考にしながら効率的に開発を進めるSkill。

📜 元の英語説明(参考)

This skill should be used when working with Shadertoy shaders, GLSL fragment shaders, or creating procedural graphics for the web. Use when writing .glsl files, implementing visual effects, creating generative art, or working with WebGL shader code. This skill provides GLSL ES syntax reference, common shader patterns, and Shadertoy-specific conventions.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Shadertoy環境でGLSL ESのコードを記述し、Web用のプロシージャルなグラフィックや視覚効果、ジェネラティブアートを作成する際に、構文やパターン、Shadertoy特有の規則を参考にしながら効率的に開発を進めるSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o shadertoy.zip https://jpskill.com/download/23589.zip && unzip -o shadertoy.zip && rm shadertoy.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/23589.zip -OutFile "$d\shadertoy.zip"; Expand-Archive "$d\shadertoy.zip" -DestinationPath $d -Force; ri "$d\shadertoy.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して shadertoy.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → shadertoy フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
4

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

[スキル名] Shadertoy

Shadertoy シェーダー開発

概要

Shadertoy は、WebGL を使用してブラウザで実行される GLSL フラグメントシェーダーを作成・共有するためのプラットフォームです。このスキルは、GLSL ES 構文、一般的なパターン、数学的テクニック、リアルタイムプロシージャラルグラフィックスに特化したベストプラクティスなど、シェーダー作成のための包括的なガイダンスを提供します。

このスキルを使用するタイミング

以下の状況でこのスキルをアクティブ化してください。

  • .glsl シェーダーファイルを記述または編集する場合
  • プロシージャルグラフィックス、ジェネレーティブアート、または視覚効果を作成する場合
  • Shadertoy.com プロジェクトまたは WebGL フラグメントシェーダーを扱う場合
  • レイマーチング、距離フィールド、またはプロシージャルテクスチャを実装する場合
  • シェーダーコードのデバッグまたはシェーダーパフォーマンスの最適化を行う場合
  • GLSL ES 構文リファレンスまたは Shadertoy の入力変数が必要な場合

コアコンセプト

シェーダーのエントリーポイント

すべての Shadertoy シェーダーは mainImage 関数を実装します。

void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
    // fragCoord: ピクセル座標 (0 から iResolution.xy)
    // fragColor: 出力色 (RGBA、通常アルファは 1.0)

    vec2 uv = fragCoord / iResolution.xy;
    fragColor = vec4(uv, 0.0, 1.0);
}

Shadertoy の組み込み入力

シェーダー内で常に利用可能です。

名前 説明
vec3 iResolution ビューポートの解像度 (x, y, アスペクト比)
float iTime 現在の時刻 (秒単位、主要なアニメーションドライバー)
float iTimeDelta 1フレームのレンダリングにかかる時間
int iFrame 現在のフレーム番号
vec4 iMouse マウス: xy = 現在の位置、zw = クリック位置
sampler2D iChannel0-iChannel3 入力テクスチャ/バッファ
vec3 iChannelResolution[4] 各入力チャンネルの解像度
vec4 iDate 年、月、日、時刻 (秒単位) (.xyzw)

座標系の設定

座標を正規化するための標準的なパターンです。

// 原点中心のアスペクト比補正済み UV (-1 から 1、アスペクト比を保持)
vec2 uv = (fragCoord.xy - 0.5 * iResolution.xy) / min(iResolution.y, iResolution.x);

// 代替のコンパクトな形式:
vec2 uv = (fragCoord * 2.0 - iResolution.xy) / min(iResolution.x, iResolution.y);

// シンプルな正規化 (0 から 1)
vec2 uv = fragCoord / iResolution.xy;

一般的なシェーダーパターン

1. プロシージャルカラーパレット

滑らかなカラーグラデーションには Inigo Quilez のコサインパレットを使用します。

vec3 palette(float t, vec3 a, vec3 b, vec3 c, vec3 d) {
    return a + b * cos(6.28318 * (c * t + d));
}

// 使用例:
vec3 col = palette(
    t,
    vec3(0.5, 0.5, 0.5),    // base
    vec3(0.5, 0.5, 0.5),    // amplitude
    vec3(1.0, 1.0, 0.5),    // frequency
    vec3(0.8, 0.90, 0.30)   // phase
);

2. ハッシュ関数 (擬似乱数)

ノイズとランダム性のためのシンプルな 2D ハッシュです。

float hash21(vec2 p) {
    p = fract(p * vec2(234.34, 435.345));
    p += dot(p, p + 34.23);
    return fract(p.x * p.y);
}

3. レイマーチング

スフィアトレーシングによる 3D レンダリングの標準的なパターンです。

// 距離フィールド関数
float map(vec3 p) {
    return length(p) - 1.0;  // 原点に半径 1 の球
}

// 法線計算
vec3 calcNormal(vec3 p) {
    vec2 e = vec2(0.001, 0.0);
    return normalize(vec3(
        map(p + e.xyy) - map(p - e.xyy),
        map(p + e.yxy) - map(p - e.yxy),
        map(p + e.yyx) - map(p - e.yyx)
    ));
}

// レイマーチングループ
vec3 render(vec3 ro, vec3 rd) {
    float t = 0.0;
    for (int i = 0; i < 100; i++) {
        vec3 p = ro + rd * t;
        float d = map(p);
        if (d < 0.001) {
            // ヒット - ライティングを計算
            vec3 n = calcNormal(p);
            return n * 0.5 + 0.5;  // 法線の可視化
        }
        if (t > 10.0) break;
        t += d * 0.5;  // ステップ (安全のため 0.5 倍)
    }
    return vec3(0.0);  // ミス
}

4. 回転

2D 回転:

mat2 rot2d(float a) {
    float c = cos(a), s = sin(a);
    return mat2(c, -s, s, c);
}
// 使用法: p.xy *= rot2d(iTime);

3D 軸角度回転 (インプレースで変更):

void rot(inout vec3 p, vec3 axis, float angle) {
    axis = normalize(axis);
    float s = sin(angle), c = cos(angle), oc = 1.0 - c;
    mat3 m = mat3(
        oc * axis.x * axis.x + c,           oc * axis.x * axis.y - axis.z * s,  oc * axis.z * axis.x + axis.y * s,
        oc * axis.x * axis.y + axis.z * s,  oc * axis.y * axis.y + c,           oc * axis.y * axis.z - axis.x * s,
        oc * axis.z * axis.x - axis.y * s,  oc * axis.y * axis.z + axis.x * s,  oc * axis.z * axis.z + c
    );
    p = m * p;
}

5. ドメインの繰り返しと折りたたみ

フラクタル状の構造を作成します。

vec3 foldRotate(vec3 p, float timeOffset) {
    for (int i = 0; i < 5; i++) {
        p = abs(p);  // ミラーフォールド
        rot(p, vec3(0.707, 0.707, 0.0), 0.785);
        p -= 0.5;    // 平行移動
    }
    return p;
}

6. ポストプロセス

ビネット:

float vignette(vec2 uv) {
    uv *= 1.0 - uv.yx;
    return pow(uv.x * uv.y * 15.0, 0.25);
}

フィルムグレイン/ディザリング (バンディングを軽減):

float dither = hash21(fragCoord + iTime) * 0.001;
finalCol += dither;

ガンマ補正:

finalCol = pow(finalCol, vec3(0.45));  // ~1/2.2

マルチパスレンダリング

時間的なフィードバックや複数のレンダリングステージを必要とする複雑なエフェクトの場合:

バッファ A (計算):

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord / iResolution.xy;
    // 値を生成または計算
    fragColor = vec4(computedColor, 1.0);
}

バッファ B (フィードバック/ブレンド):

#define BUFFER_A iChannel0
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord / iResolution.xy;
    vec4 current = texture(BUFFER_A, uv);
    vec4 previous = texture(iChannel1, uv);  // 自己参照
    fragColor = mix(previous, current, 0.1);  // 時間的ブレンド
}

メイン (最終出力):

#define BUFFER_B iChannel1
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord / iResolution.xy;
    fragColor = texture(BUFFER_B, uv);
}
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Shadertoy Shader Development

Overview

Shadertoy is a platform for creating and sharing GLSL fragment shaders that run in the browser using WebGL. This skill provides comprehensive guidance for writing shaders including GLSL ES syntax, common patterns, mathematical techniques, and best practices specific to real-time procedural graphics.

When to Use This Skill

Activate this skill when:

  • Writing or editing .glsl shader files
  • Creating procedural graphics, generative art, or visual effects
  • Working with Shadertoy.com projects or WebGL fragment shaders
  • Implementing ray marching, distance fields, or procedural textures
  • Debugging shader code or optimizing shader performance
  • Need GLSL ES syntax reference or Shadertoy input variables

Core Concepts

Shader Entry Point

Every Shadertoy shader implements the mainImage function:

void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
    // fragCoord: pixel coordinates (0 to iResolution.xy)
    // fragColor: output color (RGBA, typically alpha = 1.0)

    vec2 uv = fragCoord / iResolution.xy;
    fragColor = vec4(uv, 0.0, 1.0);
}

Shadertoy Built-in Inputs

Always available in shaders:

Type Name Description
vec3 iResolution Viewport resolution (x, y, aspect ratio)
float iTime Current time in seconds (primary animation driver)
float iTimeDelta Time to render one frame
int iFrame Current frame number
vec4 iMouse Mouse: xy = current position, zw = click position
sampler2D iChannel0-iChannel3 Input textures/buffers
vec3 iChannelResolution[4] Resolution of each input channel
vec4 iDate Year, month, day, time in seconds (.xyzw)

Coordinate System Setup

Standard patterns for normalizing coordinates:

// Aspect-corrected UV centered at origin (-1 to 1, aspect-preserved)
vec2 uv = (fragCoord.xy - 0.5 * iResolution.xy) / min(iResolution.y, iResolution.x);

// Alternative compact form:
vec2 uv = (fragCoord * 2.0 - iResolution.xy) / min(iResolution.x, iResolution.y);

// Simple normalized (0 to 1)
vec2 uv = fragCoord / iResolution.xy;

Common Shader Patterns

1. Procedural Color Palettes

Use Inigo Quilez's cosine palette for smooth color gradients:

vec3 palette(float t, vec3 a, vec3 b, vec3 c, vec3 d) {
    return a + b * cos(6.28318 * (c * t + d));
}

// Example usage:
vec3 col = palette(
    t,
    vec3(0.5, 0.5, 0.5),    // base
    vec3(0.5, 0.5, 0.5),    // amplitude
    vec3(1.0, 1.0, 0.5),    // frequency
    vec3(0.8, 0.90, 0.30)   // phase
);

2. Hash Functions (Pseudo-Random)

Simple 2D hash for noise and randomness:

float hash21(vec2 p) {
    p = fract(p * vec2(234.34, 435.345));
    p += dot(p, p + 34.23);
    return fract(p.x * p.y);
}

3. Ray Marching

Standard pattern for 3D rendering via sphere tracing:

// Distance field function
float map(vec3 p) {
    return length(p) - 1.0;  // Sphere at origin, radius 1
}

// Normal calculation
vec3 calcNormal(vec3 p) {
    vec2 e = vec2(0.001, 0.0);
    return normalize(vec3(
        map(p + e.xyy) - map(p - e.xyy),
        map(p + e.yxy) - map(p - e.yxy),
        map(p + e.yyx) - map(p - e.yyx)
    ));
}

// Ray marching loop
vec3 render(vec3 ro, vec3 rd) {
    float t = 0.0;
    for (int i = 0; i < 100; i++) {
        vec3 p = ro + rd * t;
        float d = map(p);
        if (d < 0.001) {
            // Hit - calculate lighting
            vec3 n = calcNormal(p);
            return n * 0.5 + 0.5;  // Normal visualization
        }
        if (t > 10.0) break;
        t += d * 0.5;  // Step (0.5 factor for safety)
    }
    return vec3(0.0);  // Miss
}

4. Rotations

2D rotation:

mat2 rot2d(float a) {
    float c = cos(a), s = sin(a);
    return mat2(c, -s, s, c);
}
// Usage: p.xy *= rot2d(iTime);

3D axis-angle rotation (modifies in-place):

void rot(inout vec3 p, vec3 axis, float angle) {
    axis = normalize(axis);
    float s = sin(angle), c = cos(angle), oc = 1.0 - c;
    mat3 m = mat3(
        oc * axis.x * axis.x + c,           oc * axis.x * axis.y - axis.z * s,  oc * axis.z * axis.x + axis.y * s,
        oc * axis.x * axis.y + axis.z * s,  oc * axis.y * axis.y + c,           oc * axis.y * axis.z - axis.x * s,
        oc * axis.z * axis.x - axis.y * s,  oc * axis.y * axis.z + axis.x * s,  oc * axis.z * axis.z + c
    );
    p = m * p;
}

5. Domain Repetition and Folding

Create fractal-like structures:

vec3 foldRotate(vec3 p, float timeOffset) {
    for (int i = 0; i < 5; i++) {
        p = abs(p);  // Mirror fold
        rot(p, vec3(0.707, 0.707, 0.0), 0.785);
        p -= 0.5;    // Translate
    }
    return p;
}

6. Post-Processing

Vignette:

float vignette(vec2 uv) {
    uv *= 1.0 - uv.yx;
    return pow(uv.x * uv.y * 15.0, 0.25);
}

Film grain/dithering (reduces banding):

float dither = hash21(fragCoord + iTime) * 0.001;
finalCol += dither;

Gamma correction:

finalCol = pow(finalCol, vec3(0.45));  // ~1/2.2

Multi-Pass Rendering

For complex effects requiring temporal feedback or multiple rendering stages:

Buffer A (Computation):

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord / iResolution.xy;
    // Generate or compute values
    fragColor = vec4(computedColor, 1.0);
}

Buffer B (Feedback/Blending):

#define BUFFER_A iChannel0
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord / iResolution.xy;
    vec4 current = texture(BUFFER_A, uv);
    vec4 previous = texture(iChannel1, uv);  // Self-reference
    fragColor = mix(previous, current, 0.1);  // Temporal blend
}

Main (Final Output):

#define BUFFER_B iChannel1
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord / iResolution.xy;
    fragColor = texture(BUFFER_B, uv);
}

Critical GLSL ES Rules

ALWAYS follow these rules to avoid compilation errors:

  1. NO f suffix: Use 1.0 NOT 1.0f
  2. NO saturate(): Use clamp(x, 0.0, 1.0) instead
  3. Protect pow/sqrt: Wrap arguments: pow(max(x, 0.0), p), sqrt(abs(x))
  4. Avoid division by zero: Check denominators or add epsilon
  5. Initialize variables: Don't assume default values
  6. Avoid name conflicts: Don't name functions like variables
  7. NO interactive commands: Avoid find, grep - use Glob/Grep tools instead

Workflow Guide

Creating a New Shader

  1. Set up coordinate system - Choose appropriate UV normalization
  2. Define core effect - Implement main visual algorithm
  3. Add animation - Use iTime for temporal variation
  4. Apply color palette - Use cosine palette or custom scheme
  5. Add post-processing - Vignette, dither, gamma correction
  6. Optimize - Reduce iterations, use early exits, minimize branches

Common Tasks

Visualizing complex numbers:

  • Use the complex math functions in references/common-patterns.md
  • Plot with cx_log(), cx_pow(), or polynomial evaluation
  • Map complex results to color via palette

Ray marching 3D scenes:

  • Define distance field in map() function
  • Set up camera (ray origin ro, ray direction rd)
  • March using standard loop pattern
  • Calculate normals with tetrahedron method
  • Apply lighting and material properties

Creating noise/organic effects:

  • Use hash21() for random values
  • Implement fbm() (fractional Brownian motion) for natural variation
  • Combine with sin()/cos() for structured patterns
  • Apply domain warping for organic distortion

Multi-layer composition:

  • Render multiple passes with different parameters
  • Blend layers using mix() or custom blend modes
  • Add interference patterns by comparing layer differences
  • Use smoothstep() for soft transitions

Debugging Strategies

Visualize intermediate values:

fragColor = vec4(vec3(distanceField), 1.0);  // Show distance
fragColor = vec4(normal * 0.5 + 0.5, 1.0);   // Show normals
fragColor = vec4(fract(uv), 0.0, 1.0);       // Show UV tiling

Simplify progressively:

  • Comment out post-processing
  • Reduce iteration counts
  • Replace complex functions with simple placeholders
  • Check coordinate transformations step-by-step

Check for NaN/Inf:

  • Add guards: if (isnan(value) || isinf(value)) return vec3(1.0, 0.0, 0.0);
  • Validate divisions and roots

Performance Optimization

  1. Fixed iteration counts - Avoid dynamic loops
  2. Early exit conditions - Break when threshold met
  3. Step multiplier tuning - Balance quality vs speed (0.5 to 1.0)
  4. Minimize texture reads - Cache repeated lookups
  5. Avoid conditionals - Use mix(), step(), smoothstep() instead of if
  6. Reduce precision - Use mediump or lowp where appropriate (mobile)

Naming Conventions

Based on observed patterns in creative work:

  • Poetic/evocative names - "alien-water", "heavenly-wisp", "comprehension"
  • Technical descriptors - "complex-plot", "noise-circuits", "ray-marching-demo"
  • Compound phrases - "coming-apart-at-the-seams", "form-without-form"
  • Lowercase with hyphens - my-shader-name.glsl

Attribution and Forking

When forking or remixing shaders:

// Fork of "Original Name" by AuthorName. https://shadertoy.com/view/XxXxXx
// Date: YYYY-MM-DD
// License: Creative Commons (CC BY-NC-SA 4.0) [or other]

Resources

references/glsl-reference.md

Complete GLSL ES syntax reference including:

  • Built-in functions (trig, math, vectors, matrices, textures)
  • Shadertoy input variables specification
  • Type conversions and swizzling
  • Common pitfalls and corrections

Search with: Read /references/glsl-reference.md for complete language reference.

references/common-patterns.md

Comprehensive pattern library including:

  • Complex number mathematics (cx_mul, cx_div, cx_sin, cx_cos, cx_log, cx_pow)
  • Color palette functions (cosine palette, multi-layer palettes)
  • Hash functions (hash21, PCG hash)
  • Ray marching templates (render loop, normal calculation)
  • 3D transformations (rotations, domain folding)
  • Distance fields (sphere, box, octahedron)
  • Noise functions (simplex, FBM)
  • Post-processing (vignette, blur, film grain, gamma)
  • Blend modes (soft light, hard light, vivid light)
  • Multi-pass rendering patterns

Search with: Grep "pattern" references/common-patterns.md for specific techniques.

references/example-compact-shader.glsl

Reference implementation showing:

  • Compact, algorithmic shader coding style
  • Efficient ray marching in minimal code
  • Advanced matrix operations and transformations
  • Creative Commons licensed example

Quick Reference

#define PI 3.1415926535897932384626433832795

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    // 1. Normalize coordinates
    vec2 uv = (fragCoord * 2.0 - iResolution.xy) / min(iResolution.x, iResolution.y);

    // 2. Compute effect
    float d = length(uv) - 0.5;  // Circle distance field
    vec3 col = vec3(smoothstep(0.01, 0.0, d));  // Sharp edge

    // 3. Animate with time
    col *= 0.5 + 0.5 * sin(iTime + uv.xyx * 3.0);

    // 4. Apply palette
    col = palette(col.x, vec3(0.5), vec3(0.5), vec3(1.0), vec3(0.0));

    // 5. Post-process
    col = pow(col, vec3(0.45));  // Gamma
    col *= vignette(fragCoord / iResolution.xy);

    // 6. Output
    fragColor = vec4(col, 1.0);
}

Common Shader Types in Collection

  1. Mathematical Visualizations - Complex number plots, function graphs
  2. Ray Marched 3D - Distance field rendering, folded geometries
  3. Procedural Textures - Noise-based patterns, organic effects
  4. Multi-Pass Effects - Temporal feedback, buffer composition
  5. Particle Systems - Point-based simulations
  6. 2D Patterns - Geometric, kaleidoscopic, interference effects

Tips for Creative Coding

  • Start simple - Get basic structure working, then iterate
  • Use time creatively - sin(iTime), mod(iTime, period), smoothstep() transitions
  • Layer effects - Combine multiple techniques for richness
  • Embrace accidents - Bugs often lead to interesting visuals
  • Study references - Learn from existing shaders, understand techniques
  • Optimize later - Prioritize visual quality first, then performance

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。