Shader look at behaviour with instances

For the sake of sharing I paste here the solution to a problem I had in retrieving camera_position in the shader builder, while trying to implement a look at behaviour with instances.

the amazing @gui helped me clarify the issue:

The camera position is indeed not updated internally for the meshLambertBuilder material,
easy solution is to use the MeshStandardBuilder node instead (or MeshPhysicalBuilder), for which the camera position is updated as expected.

I share also interesting suggestions about implementing look at behaviours with shader vs actor node:

  • look at in the shader is the fastest.
  • the actor node, which is still quite fast. Even though it is executed on the CPU and not the GPU, it only changes matrices. If you have only 100 objects, it shouldn’t impact the performance too much.

But there may be cases where method 1 could end up slower than method 2. if the geometry was to have many points (say 100k+), it may be heavy for the vertex shader, while updating 100 matrices would be cheap. And using the setGeometry node would allow each object to share the same geometry.
In short, in those situations, there are always many factors that impact performance, it’s always good to test and compare.

1 Like