Function to extend Materials

So here are a lot more important changes. I optimized the concept for shared and mixed uniforms, as with different sources for uniforms and possibly wanted references there are many scenarios to consider.

Demo: Creating new materials based on MeshStandardMaterial and custom depth material for shadows

All needed to create a depth material for shadows with the custom transforms:

myMaterial.customDepthMaterial = THREE.extendMaterial( THREE.MeshDepthMaterial, {

	template: myMaterial

} );
  • Big reduction of uniforms to defined and necessary ones
  • class property in options to use another material class than ShaderMaterial (e.g CustomMaterial)
  • mixed property in uniforms to pass them from templates
  • linked property in uniforms to share them when used as template but not when extending them, this ensures you don’t have to sync. uniforms from your original material with the depth material for shadows for example
  • customDepthMaterial and customDistanceMaterial can be defined on materials now instead only on the mesh, cloning a material also automatically clones these if defined and links uniforms to the new material (see Demo)
  • Cloning materials will respect shared uniforms
  • Templates (see Demo)
  • Extending a instance of a built-in material is improved to inherit the properties
  • New THREE.CustomMaterial based on ShaderMaterial for extending in-built materials, it ensures better compatibility with the in-built features, for example when using envMap (which requires THREE to setup constants internally)