webgl
БесплатноБез исполняемых скриптовНе проверенRender 3D graphics in the browser with WebGL — set up rendering pipelines, write vertex and fragment shaders in GLSL, manage buffers and textures, handle…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
WebGL
Overview
WebGL 2 is the browser's low-level 3D graphics API (OpenGL ES 3.0 semantics, GLSL ES 3.00 shaders), available through canvas.getContext("webgl2") in all current browsers. You supply the shaders, buffers, textures and matrices yourself; for scenes with models, lights and loaders, use a library such as three.js instead. WebGPU is the successor API but WebGL remains the portable default.
Instructions
Initializing a WebGL Context
// src/webgl/init.ts — Get a WebGL2 rendering context and configure it.
// Throws when WebGL2 is unavailable (no silent WebGL1 fallback).
export function initWebGL(canvas: HTMLCanvasElement): WebGL2RenderingContext {
const gl = canvas.getContext("webgl2", { antialias: true });
if (!gl) throw new Error("WebGL2 not supported");
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.enable(gl.DEPTH_TEST);
resizeCanvasToDisplaySize(gl);
return gl;
}
// Match the drawing buffer to the CSS size times devicePixelRatio, then set the viewport.
// Call it every frame (cheap when nothing changed) or from a ResizeObserver.
export function resizeCanvasToDisplaySize(gl: WebGL2RenderingContext): boolean {
const canvas = gl.canvas as HTMLCanvasElement;
const width = Math.round(canvas.clientWidth * devicePixelRatio);
const height = Math.round(canvas.clientHeight * devicePixelRatio);
const changed = canvas.width !== width || canvas.height !== height;
if (changed) {
canvas.width = width;
canvas.height = height;
}
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
return changed;
}
Compiling Shaders
// src/webgl/shaders.ts — Compile vertex and fragment shaders, link into a program.
// Shaders run on the GPU and control how vertices and pixels are processed.
export function createShaderProgram(
gl: WebGL2RenderingContext,
vertexSrc: string,
fragmentSrc: string
): WebGLProgram {
const vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexSrc);
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSrc);
const program = gl.createProgram()!;
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
throw new Error(`Link error: ${gl.getProgramInfoLog(program)}`);
}
return program;
}
function compileShader(
gl: WebGL2RenderingContext,
type: number,
source: string
): WebGLShader {
const shader = gl.createShader(type)!;
gl.shaderSource(shader, source);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
const info = gl.getShaderInfoLog(shader);
gl.deleteShader(shader);
throw new Error(`Shader compile error: ${info}`);
}
return shader;
}
GLSL Shaders
#version 300 es
// shaders/vertex.glsl — Transform vertex positions and pass data to fragment shader.
// "#version 300 es" must stay the very first line of the shader string.
layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec3 aNormal;
layout(location = 2) in vec2 aTexCoord;
uniform mat4 uModelView;
uniform mat4 uProjection;
uniform mat3 uNormalMatrix; // inverse-transpose of the model-view's upper 3x3
out vec3 vNormal;
out vec2 vTexCoord;
void main() {
vNormal = mat3(uNormalMatrix) * aNormal;
vTexCoord = aTexCoord;
gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);
}
#version 300 es
// shaders/fragment.glsl — Calculate pixel color using lighting and texture.
precision highp float;
in vec3 vNormal;
in vec2 vTexCoord;
uniform sampler2D uTexture;
uniform vec3 uLightDir;
out vec4 fragColor;
void main() {
vec3 normal = normalize(vNormal);
float diffuse = max(dot(normal, normalize(uLightDir)), 0.0);
vec4 texColor = texture(uTexture, vTexCoord);
fragColor = vec4(texColor.rgb * (0.3 + 0.7 * diffuse), texColor.a);
}
Buffers and VAOs
// src/webgl/geometry.ts — Create vertex buffer objects and vertex array objects
// to upload geometry data to the GPU.
export function createTriangle(gl: WebGL2RenderingContext) {
const vertices = new Float32Array([
// x, y, z
0.0, 0.5, 0.0,
-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
]);
const vao = gl.createVertexArray()!;
gl.bindVertexArray(vao);
const vbo = gl.createBuffer()!;
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.bindVertexArray(null);
return { vao, vertexCount: 3 };
}
Textures
// src/webgl/texture.ts — Upload an image to the GPU. Call after the image has loaded.
export async function loadTexture(gl: WebGL2RenderingContext, url: string): Promise<WebGLTexture> {
const response = await fetch(url);
const bitmap = await createImageBitmap(await response.blob(), { imageOrientation: "flipY" });
const texture = gl.
Установить webgl в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл webgl?
Render 3D graphics in the browser with WebGL — set up rendering pipelines, write vertex and fragment shaders in GLSL, manage buffers and textures, handle camera transformations, and build interactive 3D scenes. Use when tasks involve 3D visualization, GPU-accelerated rendering, custom shaders, or building graphics-intensive web applications.
Как установить скилл webgl?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл webgl запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic