Index of every page on this site: llms.txt
All skills
impertio-studio avatar

/threejs-syntax-shaders

@6c190f0
Run it yourself

Use when writing custom GLSL shaders, creating ShaderMaterial or RawShaderMaterial, defining uniforms, or patching built-in materials with onBeforeCompile. Prevents the common mistake of wrong uniform format, missing needsUpdate on uniforms, or not including required defines. Covers ShaderMaterial, RawShaderMaterial, GLSL, uniforms, ShaderChunk, onBeforeCompile, defines, GLSL3. Keywords: ShaderMaterial, RawShaderMaterial, GLSL, vertex shader, fragment shader, uniform, varying, ShaderChunk, onBeforeCompile, custom shader, write shader, custom visual effect, GPU programming.

Use this Skill: https://skilld.dev/gh/impertio-studio/three.js-claude-skill-package/threejs-syntax-shaders

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesmethods.md

≈1.6k tokens on demand. Your agent reads this file only when SKILL.md points to it.

threejs-syntax-shaders -- Methods Reference

ShaderMaterial Constructor

new THREE.ShaderMaterial(parameters?: {
  uniforms?: { [name: string]: { value: any } },
  uniformsGroups?: THREE.UniformsGroup[],
  vertexShader?: string,
  fragmentShader?: string,
  defines?: { [name: string]: string | number },
  extensions?: {
    clipCullDistance?: boolean,
    multiDraw?: boolean,
  },
  wireframe?: boolean,
  wireframeLinewidth?: number,
  lights?: boolean,
  fog?: boolean,
  clipping?: boolean,
  glslVersion?: null | typeof THREE.GLSL3,
  defaultAttributeValues?: { [name: string]: number[] },
  // Inherited from Material:
  side?: THREE.Side,
  transparent?: boolean,
  opacity?: number,
  depthTest?: boolean,
  depthWrite?: boolean,
  blending?: THREE.Blending,
})

RawShaderMaterial Constructor

new THREE.RawShaderMaterial(parameters?: {
  // Same parameters as ShaderMaterial
  // Difference: NO built-in uniforms, attributes, or precision injected
  uniforms?: { [name: string]: { value: any } },
  vertexShader?: string,
  fragmentShader?: string,
  defines?: { [name: string]: string | number },
  glslVersion?: null | typeof THREE.GLSL3,
  // ...all Material base properties
})

ShaderMaterial Properties

Property Type Default Description
uniforms Object {} Map of { name: { value: any } }
uniformsGroups THREE.UniformsGroup[] [] Uniform buffer objects
vertexShader string default vertex shader GLSL vertex shader source
fragmentShader string default fragment shader GLSL fragment shader source
defines Object {} Preprocessor defines
extensions Object {} WebGL extensions to enable
wireframe boolean false Render as wireframe
wireframeLinewidth number 1 Line width (limited to 1 on most platforms)
lights boolean false If true, passes light data as uniforms
fog boolean false If true, passes fog data as uniforms
clipping boolean false If true, enables clipping planes
glslVersion string | null null null = GLSL1, THREE.GLSL3 = GLSL 3.0 ES
defaultAttributeValues Object { color: [1,1,1], uv: [0,0], uv2: [0,0] } Fallback values for missing geometry attributes
isShaderMaterial boolean true Read-only type flag

ShaderMaterial Methods (Inherited from Material)

Method Signature Returns Description
clone (): ShaderMaterial new instance Deep clone the material
copy (source: ShaderMaterial): this this Copy properties from another material
dispose (): void void Free GPU resources
toJSON (meta?: object): object JSON Serialize to JSON
onBeforeCompile (shader: object, renderer: WebGLRenderer): void void Callback before shader compilation
customProgramCacheKey (): string string Return custom key for shader program caching

Built-in Uniforms (Injected by ShaderMaterial)

Transform Matrices

Uniform GLSL Type Description
modelMatrix mat4 Object-to-world transform
modelViewMatrix mat4 Object-to-camera (viewMatrix * modelMatrix)
projectionMatrix mat4 Camera-to-clip projection
viewMatrix mat4 World-to-camera transform
normalMatrix mat3 Transpose inverse of modelViewMatrix

Camera

Uniform GLSL Type Description
cameraPosition vec3 Camera position in world space

Lighting (when lights: true)

Uniform GLSL Type Description
ambientLightColor vec3 Combined ambient light color
directionalLights struct array Direction, color for each directional light
pointLights struct array Position, color, distance, decay for each point light
spotLights struct array Position, direction, color, distance, decay, angle, penumbra
hemisphereLights struct array Sky color, ground color, direction

Built-in Attributes (Injected by ShaderMaterial)

Attribute GLSL Type Source
position vec3 geometry.attributes.position
normal vec3 geometry.attributes.normal
uv vec2 geometry.attributes.uv
uv2 vec2 geometry.attributes.uv2
tangent vec4 geometry.attributes.tangent (if present)
color vec3 geometry.attributes.color (if present)

ShaderChunk API

// Access any internal shader chunk by name
THREE.ShaderChunk['common']          // Returns string with source code
THREE.ShaderChunk['fog_pars_vertex'] // Returns fog vertex pars source

Usage in GLSL (ShaderMaterial only)

#include <common>
#include <fog_pars_vertex>

onBeforeCompile Callback Signature

material.onBeforeCompile = (shader: {
  uniforms: { [name: string]: { value: any } },
  vertexShader: string,
  fragmentShader: string,
  defines: { [name: string]: string | number },
}, renderer: THREE.WebGLRenderer) => void;

customProgramCacheKey Signature

material.customProgramCacheKey = (): string => {
  return 'unique-key-for-this-variant';
};

UniformsLib

Three.js groups commonly-used uniforms into libraries:

THREE.UniformsLib.common    // diffuse map, opacity, alphaMap, UV transform
THREE.UniformsLib.envmap    // environment map uniforms
THREE.UniformsLib.normalmap // normal map uniforms
THREE.UniformsLib.fog       // fogColor, fogNear, fogFar, fogDensity
THREE.UniformsLib.lights    // all light type uniforms

UniformsUtils

// Merge multiple uniform objects (deep clone)
const merged = THREE.UniformsUtils.merge([
  THREE.UniformsLib.common,
  THREE.UniformsLib.lights,
  { uCustom: { value: 1.0 } },
]);

// Clone uniforms (deep copy of values)
const cloned = THREE.UniformsUtils.clone(someUniforms);

Official Sources

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5mo3 checks · Risk SAFE
  • Gen Agent Trust Hub5mo

    This skill provides instructions and reference material for writing custom Three.js shaders. It consists entirely of markdown documentation and code examples. No security risks were identified.

  • Socket5mo

    No alerts

  • Snyk5mo

    Risk: LOW · No issues

Signed by skilld at 6c190f0. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 8 months ago
compatibility
Designed for Claude Code. Requires Three.js r160+.
metadata
{
  "author": "OpenAEC-Foundation",
  "version": "1.0"
}

README badge

README badge for impertio-studio/three.js-claude-skill-package/threejs-syntax-shaders