Skip to content

TSL: toStack() doesn't always run a node instantly? #32872

@PoseidonEnergy

Description

@PoseidonEnergy

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():

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSLThree.js Shading Language

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions