Communitygithub.com

GLSL 片段着色器

编写用于程序化图形处理的 GLSL 片段着色器。主题涵盖:形状(SDF)、图案、噪声(Perlin/Simplex/Cellular)、fBm、颜色(HSB/RGB)、矩阵、渐变、动画。适用于生成艺术、纹理、视觉效果、WebGL 和 Three.js 着色器。

GLSL 片段着色器 是什么?

该技能旨在帮助开发者高效编写 GPU 加速的片段着色器,用于生成程序化纹理、形状(基于 SDF 距离场)、图案、噪声(如 Perlin、Simplex、Cellular)以及颜色混合等视觉效果。它支持多种平台,包括 WebGL、Three.js、Processing 以及 ShaderToy 等在线工具,并且提供了从基础概念到高级模式的渐进式学习路径。技能内容涵盖了核心概念(如像素并行执行、标准化坐标)、常用 uniform 变量(如 u_time、u_resolution)、必备数学函数(如 mix、step、smoothstep、fract)以及常见图案的快速实现示例(如圆形、矩形、平铺、动画)。此外,还通过引用文档的方式提供了更深入的专题讨论(如 SDF 形状、分形布朗运动、细胞噪声等),方便开发者按需深入学习。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/majiayu000/claude-skill-registry-data/tree/HEAD/creative/shader-hoanghd218-landing-page-ai-kien-2

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

GLSL 片段着色器 是做什么的?

为程序化图形、纹理和视觉效果编写 GPU 加速的片段着色器。

何时使用

  • 创建程序化纹理(木纹、大理石、云朵、地形)
  • 使用距离场(SDF)绘制形状
  • 生成图案、噪声、渐变
  • 构建视觉效果和动画
  • 为 Three.js、WebGL、Processing 编写自定义着色器

核心概念

片段着色器 同时在每个像素上执行。每个线程:

  • 通过 gl_FragCoord 接收像素位置
  • 通过 gl_FragColor 返回颜色(vec4:RGBA 0.0-1.0)
  • 不能与其他线程通信(无状态)

标准 Uniform 变量

uniform float u_time;       // 已过去的秒数
uniform vec2 u_resolution;  // 画布尺寸(宽度,高度)
uniform vec2 u_mouse;       // 鼠标位置(像素)

标准化坐标:vec2 st = gl_FragCoord.xy / u_resolution;

常用函数

函数用途示例
mix(a,b,t)线性插值mix(red, blue, 0.5)
step(edge,x)硬阈值step(0.5, st.x)
smoothstep(e0,e1,x)平滑阈值smoothstep(0.2, 0.8, st.x)
fract(x)小数部分fract(st * 3.0) 用于平铺
mod(x,y)取模mod(st.x, 0.25)
clamp(x,min,max)限制值范围clamp(col, 0.0, 1.0)
length(v)向量长度length(st - 0.5)
distance(a,b)欧几里得距离distance(st, center)
dot(a,b)点积dot(normal, lightDir)
normalize(v)单位向量normalize(direction)
atan(y,x)角度(弧度)atan(st.y-0.5, st.x-0.5)
sin/cos/pow/abs数学运算硬件加速

快速模式

圆形:

float d = distance(st, vec2(0.5));
float circle = 1.0 - smoothstep(0.2, 0.21, d);

矩形:

vec2 bl = step(vec2(0.1), st);
vec2 tr = step(vec2(0.1), 1.0 - st);
float rect = bl.x * bl.y * tr.x * tr.y;

平铺:

st = fract(st * 4.0);  // 4x4 网格

动画:

float wave = sin(st.x * 10.0 + u_time) * 0.5 + 0.5;

参考资料(渐进式查阅)

基础

  • references/glsl-fundamentals-data-types-vectors-precision-coordinates.md
  • references/glsl-shaping-functions-step-smoothstep-curves-interpolation.md

绘制

  • references/glsl-colors-rgb-hsb-gradients-mixing-color-spaces.md
  • references/glsl-shapes-sdf-circles-rectangles-polar-distance-fields.md
  • references/glsl-shapes-polygon-star-polar-sdf-combinations.md

程序化

  • references/glsl-patterns-tiling-fract-matrices-transformations.md
  • references/glsl-pattern-symmetry-truchet-domain-warping.md
  • references/glsl-noise-random-perlin-simplex-cellular-voronoi.md
  • references/glsl-cellular-voronoi-worley-noise-patterns.md
  • references/glsl-fbm-fractional-brownian-motion-turbulence-octaves.md
  • references/glsl-procedural-textures-clouds-marble-wood-terrain.md

API 参考

  • references/glsl-shader-builtin-functions-complete-api-reference.md

工具

  • 在线编辑器: editor.thebookofshaders.com
  • glslViewer: 运行 .frag 文件的命令行工具
  • glslCanvas: 用于实时着色器的 HTML 嵌入
  • ShaderToy: 使用 iTime、iResolution、iMouse 等 uniform 变量

外部资源

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

majiayu000/claude-skill-registry-data

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry-data

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry-data

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry-data

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry-data

Analyzes current state and user query to answer BMad questions or recommend the next workflow or agent. Use when user says what should I do next, what do I do now, or asks a question about BMad

majiayu000/claude-skill-registry-data

Build AI agents with Google ADK Python (Agent Development Kit). Use for multi-agent systems, workflow agents (sequential/parallel/loop), Vertex AI deployment, tool integration, human-in-the-loop.

majiayu000/claude-skill-registry-data

Build AI agents with Google ADK Python (Agent Development Kit). Use for multi-agent systems, workflow agents (sequential/parallel/loop), Vertex AI deployment, tool integration, human-in-the-loop.

majiayu000/claude-skill-registry-data

Portfolio allocation and rebalancing optimizer. Manages asset allocation across stocks/cash/bonds, performs periodic rebalancing, and ensures diversification according to market regime and risk tolerance.

majiayu000/claude-skill-registry-data

Create a hilarious and ultra-realistic video of an anthropomorphic animal acting like a human vlogger in a real-world setting.

majiayu000/claude-skill-registry-data

Speech-to-text transcription and translation via OpenAI Audio API -- models, response formats, timestamps, prompting, streaming, chunking, and diarization

majiayu000/claude-skill-registry-data

This skill should be used when the user asks about libraries, frameworks, API references, or needs code examples. Activates for setup questions, code generation involving libraries, or mentions of specific frameworks like React, Vue, Next.js, Prisma, Supabase, etc.

majiayu000/claude-skill-registry-data

小省导购员数字人带货版即梦视频提示词生成系统,基于四大智能体协同(提示词生成师、质量管控师、知识库运维师、跨环节适配师),按照"主体+运动+场景+(镜头语言+光影+氛围)"公式输出中英文双版提示词,适配5s短视频。确保人物一致性、视觉连贯性、情绪连贯性,支持知识库智能复用和跨工具适配(Suno音乐、AI绘画),为数字人带货视频提供高质量提示词生成服务。

majiayu000/claude-skill-registry-data

Upload and manage files using Google Gemini File API via scripts/. Use for uploading images, audio, video, PDFs, and other files for use with Gemini models. Supports file upload, status checking, and file management. Triggers on "upload file", "file API", "upload image", "upload PDF", "upload video", "file management".

majiayu000/claude-skill-registry-data

Analyze images/audio/video with Gemini API (better vision than Claude). Generate images (Imagen 4), videos (Veo 3). Use for vision analysis, transcription, OCR, design extraction, multimodal AI.

majiayu000/claude-skill-registry-data

Analyze images/audio/video with Gemini API (better vision than Claude). Generate images (Imagen 4), videos (Veo 3). Use for vision analysis, transcription, OCR, design extraction, multimodal AI.

majiayu000/claude-skill-registry-data

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

majiayu000/claude-skill-registry-data

Conduct domain and industry research. Use when the user says "lets create a research report on [domain or industry]

majiayu000/claude-skill-registry-data

Conduct market research on competition and customers. Use when the user says "create a market research report about [business idea]".

majiayu000/claude-skill-registry-data

Conduct technical research on technologies and architecture. Use when the user says "create a technical research report on [topic]".

majiayu000/claude-skill-registry-data

Builds, edit or validate Agent Skill through conversational discovery. Use when the user requests to "Create an Agent", "Optimize an Agent" or "Edit an Agent".

相关技能