-
-
Notifications
You must be signed in to change notification settings - Fork 36.3k
Description
Description
I'm currently investigating the inner workings of how TSL generates and applies instance matrices to positionLocal, in the hopes that I can submit a PR that allows a user to get the position of an InstancedMesh instance immediately after it has been transformed by its matrix.
I'm under the impression that the toStack() method (previously append()) runs a node instantly, as described in this post.
In the following code however, notice how instancedMesh.toStack() is called before positionLocal.assign():
three.js/src/materials/nodes/NodeMaterial.js
Lines 832 to 842 in b59b5e7
| if ( ( object.isInstancedMesh && object.instanceMatrix && object.instanceMatrix.isInstancedBufferAttribute === true ) ) { | |
| instancedMesh( object ).toStack(); | |
| } | |
| if ( this.positionNode !== null ) { | |
| positionLocal.assign( subBuild( this.positionNode, 'POSITION', 'vec3' ) ); | |
| } |
However, when shader code is generated, the shader code generated by instancedMesh.toStack() is placed after the shader code generated by positionLocal.assign().
This results in material.positionNode TSL running before the instance matrix is applied to the instance.
Is it a bug that the shader code generated by instancedMesh.toStack() is placed after the shader code positionLocal.assign(), even though the setup appears to have it otherwise? If not, and toStack() is "lazy" or deferred, when does toStack() actually generate the code?
Version
r182