Atlaslog
Atlaslog / three.js / API reference / ShaderMaterial
three.js · API reference

ShaderMaterial

Quick answer

ShaderMaterial runs your own GLSL vertex and fragment code while three.js handles compilation, uniforms, and built-in matrices. Provide vertexShader, fragmentShader, and a uniforms object whose entries use a value field, and enable lights, fog, or clipping flags when the shader needs them.

Last verified 2026-11-03 · three.js 0.160.0 · Cite this page
new THREE.ShaderMaterial ( parameters )
Key points
Example
const uniforms = {
  uTime: { value: 0 },
  uColor: { value: new THREE.Color('#4aa3df') },
  uAmplitude: { value: 1.4 }
};

const material = new THREE.ShaderMaterial({
  uniforms: uniforms,
  vertexShader: `
    uniform float uTime;
    uniform float uAmplitude;
    varying float vHeight;

    void main() {
      vec3 p = position;
      float h = sin(p.x * 0.8 + uTime) * cos(p.z * 0.8 + uTime) * uAmplitude;
      p.y += h;
      vHeight = h;
      gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
    }
  `,
  fragmentShader: `
    uniform vec3 uColor;
    varying float vHeight;

    void main() {
      vec3 c = mix(uColor, vec3(1.0), clamp(vHeight * 0.4 + 0.4, 0.0, 1.0));
      gl_FragColor = vec4(c, 1.0);
    }
  `,
  side: THREE.DoubleSide
});

function animate(t) {
  uniforms.uTime.value = t * 0.001;
  renderer.render(scene, camera);
}
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). ShaderMaterial. https://www.jingweizhi.com/en/three/api/shader-material.html (accessed 2026-11-03).