做什么
WebGL API 开发专家指南,包括3D图形,遮蔽器(GLSL),渲染管道,纹理,缓冲器,性能优化和画布渲染
技能库 智客分类:Agent 工作流 webgl-expert
WebGL API开发专家指南,包括3D图形,遮光镜(GLSL),渲染管道,纹理,缓冲,性能优化,和画布渲染. 在与WebGL,3D图形,画布渲染,遮蔽器,GPU编程合作时使用,或者用户提及WebGL,OpenGL ES,GLSL,顶点遮蔽器,碎片遮蔽器,纹理映射,或3D网络图形时使用.
官方网址:skills.sh
先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。
WebGL API 开发专家指南,包括3D图形,遮蔽器(GLSL),渲染管道,纹理,缓冲器,性能优化和画布渲染
与 WebGL, 三维图形, 画布渲染, 遮蔽器, GPU 编程工作, 或当用户提及 WebGL, OpenGL ES, GLSL, 顶点遮蔽器, 碎片遮蔽器, 纹理映射, 或 三维网络图形
按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:WebGL Expert、Overview、Core Interfaces、WebGLRenderingContext (WebGL 1.0)、WebGL2RenderingContext (WebGL 2.0)、Rendering Pipeline。
文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。
Expert guide for WebGL API development including 3D graphics, shaders (GLSL), rendering pipeline, textures, buffers, performance optimization, and canvas rendering. Use when working with WebGL, 3D graphics, canvas rendering, shaders, GPU programming, or when user mentions WebGL, OpenGL ES, GLSL, vertex shaders, fragment shaders, texture mapping, or 3D web graphics.
WebGL ExpertOverviewCore InterfacesWebGLRenderingContext (WebGL 1.0)WebGL2RenderingContext (WebGL 2.0)Rendering Pipeline1. Shader Creation and Compilation2. Buffer Management3. Texture Handling4. Rendering LoopMatrix MathematicsPerformance Optimization
来源分类:skills.sh agent-skill
namewebgl-expertdescription具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗
先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。
复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。
把 Agent Skill「webgl-expert」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-9646a1ff1da0e5fc-Webgl-%E4%B8%93%E5%AE%B6.html 请存为 .cursor/skills/webgl-expert/SKILL.md 或 .claude/skills/webgl-expert/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。
npx skills add 'https://github.com/ronnycoding/.claude' --list
npx skills add 'https://github.com/ronnycoding/.claude' --skill 'webgl-expert'
CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。
Expert guide for WebGL (Web Graphics Library) API development, covering both WebGL 1.0 and WebGL 2.0 for high-performance 2D and 3D graphics rendering in web browsers.
WebGL is a JavaScript API that enables hardware-accelerated 3D graphics rendering within HTML canvas elements without requiring plugins. It closely conforms to OpenGL ES 2.0 (WebGL 1.0) and OpenGL ES 3.0 (WebGL 2.0) standards.
Key capabilities:
The foundational interface for WebGL operations, obtained via canvas context:
const canvas = document.querySelector('canvas');
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
if (!gl) {
console.error('WebGL not supported');
}
Enhanced interface with advanced features:
const gl = canvas.getContext('webgl2');
if (!gl) {
console.log('WebGL 2 not supported, falling back to WebGL 1');
gl = canvas.getContext('webgl');
}
WebGL 2 exclusive features:
Shaders are programs written in GLSL (OpenGL Shading Language) that run on the GPU:
Vertex Shader - Processes each vertex:
attribute vec3 aPosition;
attribute vec2 aTexCoord;
uniform mat4 uModelViewProjection;
varying vec2 vTexCoord;
void main() {
gl_Position = uModelViewProjection * vec4(aPosition, 1.0);
vTexCoord = aTexCoord;
}
Fragment Shader - Determines pixel colors:
precision mediump float;
varying vec2 vTexCoord;
uniform sampler2D uTexture;
void main() {
gl_FragColor = texture2D(uTexture, vTexCoord);
}
JavaScript shader setup:
function createShader(gl, type, source) {
const shader = gl.createShader(type);
gl.shaderSource(shader, source);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
console.error('Shader compilation error:', gl.getShaderInfoLog(shader));
gl.deleteShader(shader);
return null;
}
return shader;
}
function createProgram(gl, vertexShader, fragmentShader) {
const program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
console.error('Program linking error:', gl.getProgramInfoLog(program));
gl.deleteProgram(program);
return null;
}
return program;
}
Buffers store vertex data (positions, colors, normals, texture coordinates):
// Create buffer
const positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
// Upload data
const positions = new Float32Array([
-1.0, -1.0, 0.0,
1.0, -1.0, 0.0,
0.0, 1.0, 0.0
]);
gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
// Set up attribute pointer
const positionLocation = gl.getAttribLocation(program, 'aPosition');
gl.enableVertexAttribArray(positionLocation);
gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
Buffer usage patterns:
gl.STATIC_DRAW - Data doesn't changegl.DYNAMIC_DRAW - Data changes occasionallygl.STREAM_DRAW - Data changes every framefunction loadTexture(gl, url) {
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
// Placeholder until image loads
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,
new Uint8Array([255, 0, 255, 255]));
const image = new Image();
image.onload = () => {
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
// Generate mipmaps if power of 2
if (isPowerOf2(image.width) && isPowerOf2(image.height)) {
gl.generateMipmap(gl.TEXTURE_2D);
} else {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
}
};
image.src = url;
return texture;
}
function isPowerOf2(value) {
return (value & (value - 1)) === 0;
}
function render(gl, program) {
// Clear canvas
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
// Enable depth testing
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
// Use program
gl.useProgram(program);
// Set uniforms
const projectionMatrix = mat4.create();
mat4.perspective(projectionMatrix, Math.PI / 4, canvas.width / canvas.height, 0.1, 100.0);
const uniformLocation = gl.getUniformLocation(program, 'uModelViewProjection');
gl.uniformMatrix4fv(uniformLocation, false, projectionMatrix);
// Draw
gl.drawArrays(gl.TRIANGLES, 0, 3);
// Animation loop
requestAnimationFrame(() => render(gl, program));
}
WebGL uses column-major matrices for transformations. Recommended libraries:
Common transformations:
// Model matrix (object transform)
const modelMatrix = mat4.create();
mat4.translate(modelMatrix, modelMatrix, [x, y, z]);
mat4.rotate(modelMatrix, modelMatrix, angle, [0, 1, 0]);
mat4.scale(modelMatrix, modelMatrix, [sx, sy, sz]);
// View matrix (camera)
const viewMatrix = mat4.create();
mat4.lookAt(viewMatrix, eyePosition, targetPosition, upVector);
// Projection matrix
const projectionMatrix = mat4.create();
mat4.perspective(projectionMatrix, fov, aspect, near, far);
// Combined MVP matrix
const mvpMatrix = mat4.create();
mat4.multiply(mvpMatrix, projectionMatrix, viewMatrix);
mat4.multiply(mvpMatrix, mvpMatrix, modelMatrix);
const ext = gl.getExtension('ANGLE_instanced_arrays'); // WebGL 1
// or use gl.drawArraysInstanced directly in WebGL 2
// Set up per-instance attribute
const instanceOffsetBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, instanceOffsetBuffer);
gl.bufferData(gl.ARRAY_BUFFER, offsetData, gl.STATIC_DRAW);
const offsetLocation = gl.getAttribLocation(program, 'aInstanceOffset');
gl.enableVertexAttribArray(offsetLocation);
gl.vertexAttribPointer(offsetLocation, 3, gl.FLOAT, false, 0, 0);
gl.vertexAttribDivisor(offsetLocation, 1); // Advance per instance
// Draw multiple instances
gl.drawArraysInstanced(gl.TRIANGLES, 0, vertexCount, instanceCount);
Check for and use extensions to access advanced features:
function getExtension(gl, name) {
const ext = gl.getExtension(name);
if (!ext) {
console.warn(`Extension ${name} not supported`);
}
return ext;
}
// Common extensions
const anisotropic = getExtension(gl, 'EXT_texture_filter_anisotropic');
const floatTextures = getExtension(gl, 'OES_texture_float');
const depthTexture = getExtension(gl, 'WEBGL_depth_texture');
const drawBuffers = getExtension(gl, 'WEBGL_draw_buffers');
const loseContext = getExtension(gl, 'WEBGL_lose_context'); // for testing
Important extension categories:
canvas.addEventListener('webglcontextlost', (event) => {
event.preventDefault();
console.log('WebGL context lost');
cancelAnimationFrame(animationId);
}, false);
canvas.addEventListener('webglcontextrestored', () => {
console.log('WebGL context restored');
initWebGL(); // Recreate all resources
render();
}, false);
const gl = canvas.getContext('webgl2', {
alpha: false, // No alpha channel (better performance)
antialias: true, // Antialiasing (performance cost)
depth: true, // Depth buffer
stencil: false, // Stencil buffer
premultipliedAlpha: true, // Alpha premultiplication
preserveDrawingBuffer: false, // Keep buffer after render
powerPreference: 'high-performance', // GPU preference
failIfMajorPerformanceCaveat: false // Fallback to software
});
const framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
const targetTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, targetTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, targetTexture, 0);
// Render to framebuffer
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.viewport(0, 0, width, height);
// ... render scene ...
// Render to canvas
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.viewport(0, 0, canvas.width, canvas.height);
const ext = gl.getExtension('WEBGL_draw_buffers'); // WebGL 1
// Fragment shader outputs to multiple targets
gl.drawBuffers([
gl.COLOR_ATTACHMENT0,
gl.COLOR_ATTACHMENT1,
gl.COLOR_ATTACHMENT2
]);
gl.enableVertexAttribArray()Float32Array, Uint16Array, etc.gl.clear() each frame// Error checking
const error = gl.getError();
if (error !== gl.NO_ERROR) {
console.error('WebGL error:', error);
}
See reference.md for:
See examples for:
When supporting both WebGL 1 and 2:
function initWebGL(canvas) {
const gl = canvas.getContext('webgl2');
let version = 2;
if (!gl) {
gl = canvas.getContext('webgl');
version = 1;
console.log('Using WebGL 1');
}
// Feature detection
const hasVAO = version === 2 || gl.getExtension('OES_vertex_array_object');
const hasInstancing = version === 2 || gl.getExtension('ANGLE_instanced_arrays');
return { gl, version, hasVAO, hasInstancing };
}
When helping users with WebGL:
Agent 工作流
创造有效技能指南。 当用户想创造出新的技能(或更新现有的技能),以专业知识,工作流程,或工具集成来扩展克洛德的能力时,应该使用这种技能.
Agent 工作流
使用ClawdHub CLI搜索,安装,更新并发布从taladhub.com的代理技能. 需要获取苍蝇上的新技能时使用,将安装的技能同步到最新版本或特定版本,或者发布 npm-instainddhub CLI 的新/更新的技能文件夹.
Agent 工作流
管弦乐团多代理团队,任务设定周期,交接协议,审查工作流程. 使用时间: (1)建立2+特派员队伍,具有不同专业,(2)确定任务路线和生命周期(收录框_ spec_建设_审查_完成),(3)在特派员之间制定交接协议,(4)建立审查和质量关口,(5)管理特派员之间的交流和文物共享.
Agent 工作流
Spec-first,TDD,子代理驱动的软件开发工作流程. 当:(1)构建任何新功能或应用——触发脑暴_计划_子代理执行回路,(2)调试出一个bug或测试失败——触发系统性的根起过程,(3)用户说"让我们构建","帮助我计划","我想添加X",或"这个被打破",(4)完成一个功…