Welcome aboard!
What you want is to make the calculation relative to the origin of the mesh coordinate system, so that it is independent of the camera position. You can obtain this origin thanks to the world matrix, in the translation part (last row of the matrix):
https://cyos.babylonjs.com/#MUA2IU#5
distInsideSphere
computes the distance between the intersection of a ray AB with a sphere and point B. Here, A is the position of the camera and B is the position of the vertex (in world space). The position of the sphere is the origin of the mesh coordinate system and the radius of this sphere must be chosen so that it surrounds the mesh.
Note: I got the sphIntersect
function from Shader - Shadertoy BETA