Search code examples
three.jsshader

Duplicate existing Three.js materials to add displacement calculations


I need to do vertex displacements using a texture map in Three.js.

  1. Is there an existing material that supports that?
  2. If not, what is the best way to duplicate an existing Three.js shader so that I can add in some vertex displacement calculations? I would like to keep existing functionalities such as shadows and wireframe on the material.

Solution

  • Vertex displacements using a texture map are supported by THREE.ShaderTerrain[ "terrain" ] and THREE.ShaderLib[ "normalmap" ].

    Examples of their use can be found in http://threejs.org/examples/webgl_terrain_dynamic.html and http://threejs.org/examples/webgl_materials_normalmap.html.

    If these do not suit your needs, then you will have to write your own shader. Doing so is not easy. It is best to modify an existing shader.

    three.js r.61