You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we can't access the "final" position of a vertex in a batch mesh.
The result is we have to rewrite the whole vertex node from batchmesh and then add our Custom logic, something like this :
returnFn((builder)=>{letbatchingIdNode=null// WebGL fallback ifif(batchingIdNode===null){// check if https://github.com/mrdoob/three.js/blob/841ea631018e0bf40c7de1b54811101f77f1e1b3/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js#L626if(builder.getDrawIndex()===null){batchingIdNode=instanceIndex}else{batchingIdNode=drawIndex}}constgetIndirectIndex=Fn(([id])=>{constsize=textureSize(textureLoad(builder.object._indirectTexture),0)constx=int(id).modInt(int(size))consty=int(id).div(int(size))returntextureLoad(builder.object._indirectTexture,ivec2(x,y)).x}).setLayout({name: 'getIndirectIndex',type: 'uint',inputs: [{name: 'id',type: 'int'}]})constmatriceTexture=builder.object._matricesTextureconstsize=textureSize(textureLoad(matriceTexture),0)constj=float(getIndirectIndex(int(batchingIdNode))).mul(4).toVar()constx=int(j.mod(size))consty=int(j).div(int(size))constbatchingMatrix=mat4(textureLoad(matriceTexture,ivec2(x,y)),textureLoad(matriceTexture,ivec2(x.add(1),y)),textureLoad(matriceTexture,ivec2(x.add(2),y)),textureLoad(matriceTexture,ivec2(x.add(3),y)))constbm=mat3(batchingMatrix)letbatchPos=batchingMatrix.mul(positionLocal).xyz.toVar()// -- > DO CUSTOM STUFF ON MESH POSITION HERE// example : batchPos.z.addAssign( time.mul( -3 ) )// --> OR : // if( builder.material.batchPositionNode ) {// batchPos = builder.material.batchPositionNode( batchPos )//}// positionWorld is broken by vertexNode, had to recalculate herevaryingTransformBatch.assign(modelWorldMatrix.mul(batchPos))consttransformed=modelViewMatrix.mul(batchPos).toVar()positionView.assign(transformed)// <------- fix point lightsconstmvPosition=transformed// NormalsconsttransformedNormal=normalLocal.div(vec3(bm[0].dot(bm[0]),bm[1].dot(bm[1]),bm[2].dot(bm[2])))constbatchingNormal=bm.mul(transformedNormal).xyznormalLocal.assign(batchingNormal)// -- > ASSIGN FINAL POSITION / NORMAL// to be used in other node ( outputNode / normalNode / ... )varyingTransformNormal.assign(normalLocal)if(builder.hasGeometryAttribute('tangent')){tangentLocal.mulAssign(bm)}returncameraProjectionMatrix.mul(mvPosition)})()
Solution
I would love to see batchPosition to get the position of the bach (batchPos in the previous code) but also a batchPositionNode in material so we can add logic to it without having to rewrite it all.
Similar features for normal would be great
Alternatives
Rewrite all as above but it didnt seems good for maintenance.
The text was updated successfully, but these errors were encountered:
gkjohnson
changed the title
Fast access to transformed / normal for Batch and possibility to custom it
TSL: Fast access to transformed / normal for Batch and possibility to custom it
Feb 6, 2025
Currently we can't access the "final" position of a vertex in a batch mesh.
Like with InstanceNode, MorphNode or SkinningNode, BatchNode updates the TSL object positionLocal. So positionLocal should reflect the changes that have been applied to the vertex positions (the same holds for normalLocal and tangentLocal btw).
Description
Currently we can't access the "final" position of a vertex in a batch mesh.
The result is we have to rewrite the whole vertex node from batchmesh and then add our Custom logic, something like this :
Solution
I would love to see
batchPosition
to get the position of the bach (batchPos
in the previous code) but also abatchPositionNode
in material so we can add logic to it without having to rewrite it all.Similar features for normal would be great
Alternatives
Rewrite all as above but it didnt seems good for maintenance.
The text was updated successfully, but these errors were encountered: