three.js: [Enhancement] onBeforeCompile may break material's .clone() method

Description of the problem

onBeforeCompile seems to be ignored when cloning materials:

https://codepen.io/anon/pen/yjPLrJ?editors=1010

Expected result is equal amount of yellow and red cubes.

Proposing to either:

  1. consider Material.onBeforeCompile when cloning
  2. document that there should be no cloning happening after setting this callback
  3. document that .clone() is non deterministic, it’s going to be a different clone depending on the presence of onBeforeCompile
Three.js version
  • Dev
  • r92
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I guess I’m wondering whether we should try to keep improving hooks for replacement into shaders and onBeforeCompile, or whether we should be spending time on that instead. For example, implement glTF’s spec/gloss materials as THREE.NodeStandardSGMaterial.

I agree, focusing on NodeMaterial would be a much better use of our time – and we could follow that up with a graphical API to go with it.

As of 2015 there was the idea that NodeMaterial might eventually be in src/*… I guess I’m wondering whether we should try to keep improving hooks for replacement into shaders and onBeforeCompile, or whether we should be spending time on that instead. For example, implement glTF’s spec/gloss materials as THREE.NodeStandardSGMaterial.