three-projected-material icon indicating copy to clipboard operation
three-projected-material copied to clipboard

setting `.camera` does not update `ORTHOGRAPHIC` define.

Open trusktr opened this issue 3 years ago • 0 comments

onBeforeCompile only ever runs once, initially, and never again. Therefore if someone does this:

const mat = new ProjectedMaterial()
renderer.render(scene, camera) // runs onBeforeCompile

// ...later...
mat.camera = new OrthographicCamera 

renderer.render(scene, camera) // does NOT run onBeforeCompile again, ORTHOGRAPHIC is undefined.

mat.needsUpdate = true // even this doesn't help
renderer.render(scene, camera) // does NOT run onBeforeCompile again, ORTHOGRAPHIC is undefined.

the shader's ORTHOGRAPHIC define will not be defined.

And conversely, if the user starts with an OrthographicCamera then later switches to a PerspectiveCamera, ORTHOGRAPHIC will still be defined.

This leads to the shader's conditional branches running the wrong code, not matching the camera that is used.

The issue with onBeforeCompile, and how to make it work, is described here:

https://discourse.threejs.org/t/onbeforecompile-fires-only-once-although-i-set-needsupdate-true/38614

trusktr avatar May 28 '22 21:05 trusktr