Collision with gradient color proximation

Hi all, my goal is in collisions between meshes add a gradient color (red with total collision and green closest collisions) like this: http://www.youtube.com/watch?v=7PsM-LGLXiQ&t=1m55s
Is possible do this ?

Thank you very much!

Hey, to achieve that, you can leverage depth buffer eg.:

  • render mesh one
  • set depth buffer to “equal” and render mesh two with the material you want for the “collision zone”
  • set depth buffer to “less” and render mesh two again with its material

Hi @Deltakosh you have some sample where i can learne more about this approach ?

Thanks a lot!

Would there be any playground that I can refer to?
I would like to color code the overlapping regions of mesh with gradient based on how far the face penetrated into the other mesh. I’ve looked at documentation here but couldn’t quite get how to use it…

Also is shader necessary for this to work?

Using stencil would be better thand depth due to precision issue in this particular case I guess https://playground.babylonjs.com/#FNEGC1#1 ?

1 Like