安装方式
命令行安装
在项目根目录执行以下命令,完成 Skill 安装。
npx bzskills add MiniMax-AI/skills --skill shader-dev 全面的GLSL着色器技术,用于创建惊艳的视觉效果——光线步进、SDF建模、流体模拟、粒子系统、程序化生成、光照、后期处理等等。
43
下载量
命令行安装
在项目根目录执行以下命令,完成 Skill 安装。
npx bzskills add MiniMax-AI/skills --skill shader-dev name: shader-dev
description: 全面的GLSL着色器技术,用于创建惊艳的视觉效果——光线步进、SDF建模、流体模拟、粒子系统、程序化生成、光照、后期处理等等。
license: MIT
metadata:
version: "1.0"
category: graphics一个覆盖36种GLSL着色器技术(兼容ShaderToy)的统一技能,用于实时视觉效果。
/shader-dev <请求>
$ARGUMENTS 包含用户的请求(例如“创建一个带柔和阴影的光线步进SDF场景”)。
shader-dev/
├── SKILL.md # 核心技能(本文件)
├── techniques/ # 实现指南(根据路由表读取)
│ ├── ray-marching.md # 使用SDF进行球体追踪
│ ├── sdf-3d.md # 3D符号距离函数
│ ├── lighting-model.md # PBR、Phong、卡通着色
│ ├── procedural-noise.md # Perlin、Simplex、FBM
│ └── ... # 另外34个技术文件
└── reference/ # 详细指南(按需读取)
├── ray-marching.md # 数学推导与高级模式
├── sdf-3d.md # 扩展SDF理论
├── lighting-model.md # 光照数学深度解析
├── procedural-noise.md # 噪声函数理论
└── ... # 另外34个参考文件
techniques/ 目录中读取相关文件——每个文件包含核心原理、实现步骤和完整的代码模板reference/| 用户想要创建... | 主要技术 | 结合使用 |
|---|---|---|
| 基于数学的3D物体/场景 | [ray-marching](techniques/ray-marching.md) + [sdf-3d](techniques/sdf-3d.md) | lighting-model, shadow-techniques |
| 复杂3D形状(布尔运算、混合) | [csg-boolean-operations](techniques/csg-boolean-operations.md) | sdf-3d, ray-marching |
| 无限重复的3D图案 | [domain-repetition](techniques/domain-repetition.md) | sdf-3d, ray-marching |
| 有机/扭曲形状 | [domain-warping](techniques/domain-warping.md) | procedural-noise |
| 流体/烟雾/墨水效果 | [fluid-simulation](techniques/fluid-simulation.md) | multipass-buffer |
| 粒子效果(火焰、火花、雪) | [particle-system](techniques/particle-system.md) | procedural-noise, color-palette |
| 基于物理的模拟 | [simulation-physics](techniques/simulation-physics.md) | multipass-buffer |
| 生命游戏/反应扩散 | [cellular-automata](techniques/cellular-automata.md) | multipass-buffer, color-palette |
| 海洋/水面 | [water-ocean](techniques/water-ocean.md) | atmospheric-scattering, lighting-model |
| 地形/景观 | [terrain-rendering](techniques/terrain-rendering.md) | atmospheric-scattering, procedural-noise |
| 云/雾/体积火焰 | [volumetric-rendering](techniques/volumetric-rendering.md) | procedural-noise, atmospheric-scattering |
| 天空/日落/大气 | [atmospheric-scattering](techniques/atmospheric-scattering.md) | volumetric-rendering |
| 真实光照(PBR、Phong) | [lighting-model](techniques/lighting-model.md) | shadow-techniques, ambient-occlusion |
| 阴影(柔和/硬) | [shadow-techniques](techniques/shadow-techniques.md) | lighting-model |
| 环境光遮蔽 | [ambient-occlusion](techniques/ambient-occlusion.md) | lighting-model, normal-estimation |
| 路径追踪/全局光照 | [path-tracing-gi](techniques/path-tracing-gi.md) | analytic-ray-tracing, multipass-buffer |
| 精确射线-几何体相交 | [analytic-ray-tracing](techniques/analytic-ray-tracing.md) | lighting-model |
| 体素世界(类Minecraft) | [voxel-rendering](techniques/voxel-rendering.md) | lighting-model, shadow-techniques |
| 噪声/FBM纹理 | [procedural-noise](techniques/procedural-noise.md) | domain-warping |
| 平铺2D图案 | [procedural-2d-pattern](techniques/procedural-2d-pattern.md) | polar-uv-manipulation |
| 沃罗诺伊/细胞图案 | [voronoi-cellular-noise](techniques/voronoi-cellular-noise.md) | color-palette |
| 分形(曼德勃罗、朱利亚、3D) | [fractal-rendering](techniques/fractal-rendering.md) | color-palette, polar-uv-manipulation |
| 调色/调色板 | [color-palette](techniques/color-palette.md) | — |
| 辉光/色调映射/故障效果 | [post-processing](techniques/post-processing.md) | multipass-buffer |
| 多通乒乓缓冲 | [multipass-buffer](techniques/multipass-buffer.md) | — |
| 纹理/采样技术 | [texture-sampling](techniques/texture-sampling.md) | — |
| 相机/矩阵变换 | [matrix-transform](techniques/matrix-transform.md) | — |
| 表面法线 | [normal-estimation](techniques/normal-estimation.md) | — |
| 极坐标/万花筒 | [polar-uv-manipulation](techniques/polar-uv-manipulation.md) | procedural-2d-pattern |
| 来自SDF的2D形状/UI | [sdf-2d](techniques/sdf-2d.md) | color-palette |
| 程序化音频/音乐 | [sound-synthesis](techniques/sound-synthesis.md) | — |
| SDF技巧/优化 | [sdf-tricks](techniques/sdf-tricks.md) | sdf-3d, ray-marching |
| 抗锯齿渲染 | [anti-aliasing](techniques/anti-aliasing.md) | sdf-2d, post-processing |
| 景深/运动模糊/镜头效果 | [camera-effects](techniques/camera-effects.md) | post-processing, multipass-buffer |
| 高级纹理映射/无平铺纹理 | [texture-mapping-advanced](techniques/texture-mapping-advanced.md) | terrain-rendering, texture-sampling |
| WebGL2着色器错误/调试 | [webgl-pitfalls](techniques/webgl-pitfalls.md) | — |
fragCoord、main()包装器、函数顺序、宏限制、uniform空值所有技术文件使用ShaderToy GLSL风格。生成独立HTML页面时,应用以下适配:
canvas.getContext("webgl2")#version 300 es,片元着色器添加 precision highp float;out vec4 fragColor;attribute → in,varying → outvarying → in,gl_FragColor → fragColor,texture2D() → texture()gl_FragCoord.xy 代替 fragCoord(WebGL2没有内置fragCoord)// 错误
vec2 uv = (2.0 * fragCoord - iResolution.xy) / iResolution.y;
// 正确
vec2 uv = (2.0 * gl_FragCoord.xy - iResolution.xy) / iResolution.y;
void mainImage(out vec4 fragColor, in vec2 fragCoord)void main() 入口点——始终包装mainImage:void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// 着色器代码...
fragColor = vec4(col, 1.0);
}
void main() {
mainImage(fragColor, gl_FragCoord.xy);
}
// 错误 — getAtmosphere() 调用了尚未定义的 getSunDirection()
vec3 getAtmosphere(vec3 dir) { return getSunDirection(); } // 错误!
vec3 getSunDirection() { return normalize(vec3(1.0)); }
// 正确 — 先定义被调用函数
vec3 getSunDirection() { return normalize(vec3(1.0)); }
vec3 getAtmosphere(vec3 dir) { return getSunDirection(); } // 正常
#define 不能使用函数调用——改用 const:// 错误
#define SUN_DIR normalize(vec3(0.8, 0.4, -0.6))
// 正确
const vec3 SUN_DIR = vec3(0.756, 0.378, -0.567); // 预计算归一化值
<script>标签提取着色器源码时,确保#version是第一个字符——使用.trim():const fs = document.getElementById('fs').text.trim();
gl.getUniformLocation()返回null——始终以编译器无法优化掉的方式使用uniform#define宏terrainM(vec2)这样的函数需要XZ分量——使用terrainM(pos.xz + offset)而不是terrainM(pos + offset)生成独立HTML页面时:
body { margin: 0; overflow: hidden; background: #000; }iTime、iResolution、iMouse、iFramelet/const变量必须在<script>块的顶部声明,在所有引用它们的函数之前:
// 1. 状态变量放在最前面
let frameCount = 0;
let startTime = Date.now();
// 2. Canvas/GL初始化、着色器编译、FBO创建
const canvas = document.getElementById('canvas');
const gl = canvas.getContext('webgl2');
// ...
// 3. 函数和事件绑定放在最后
function resize() { /* 现在可以安全引用frameCount */ }
function render() { /* ... */ }
window.addEventListener('resize', resize);
原因:let/const存在暂时性死区——在声明前引用它们会抛出ReferenceError,导致白屏。
float fbm(vec3 p),则不能使用 vec2 调用 fbm(uv)patch、cast、sample、filter、input、output、common、partition、activevec3 x = 1.0 是非法的——应使用 vec3 x = vec3(1.0);不能使用 .z 访问 vec2if/else部署环境可能使用有限的GPU能力的头端软件渲染。请保持在以下限制内:
常见效果组合——由技术模块组装完成的渲染管线。
可视化调试方法——临时替换输出来诊断问题。
| 检查项 | 代码 | 观察内容 |
|---|---|---|
| 表面法线 | col = nor * 0.5 + 0.5; | 平滑渐变 = 法线正确;条带 = epsilon过大 |
| 光线步进步数 | col = vec3(float(steps) / float(MAX_STEPS)); | 红色热点 = 性能瓶颈;均匀 = 浪费迭代 |
| 深度/距离 | col = vec3(t / MAX_DIST); | 验证正确击中距离 |
| UV坐标 | col = vec3(uv, 0.0); | 检查坐标映射 |
| SDF距离场 | col = (d > 0.0 ? vec3(0.9,0.6,0.3) : vec3(0.4,0.7,0.85)) * (0.8 + 0.2*cos(150.0*d)); | 可视化SDF带状和过零点 |
| 棋盘格图案(UV) | col = vec3(mod(floor(uv.x*10.)+floor(uv.y*10.), 2.0)); | 验证UV扭曲、接缝 |
| 仅光照 | col = vec3(shadow); 或 col = vec3(ao); | 隔离阴影/AO贡献 |
| 材质ID | col = palette(matId / maxMatId); | 验证材质分配 |