Don’t use the “model” matrix, it’s meaningless here as the camera doesn’t really have one. Using the transform.localToWorldMatrix for anything rendering related is actually wrong as it does not necessarily match the model space used for rendering, but it’s doubly wrong here. You’re trying to get a ray in world space, and the camera’s cameraToWorldMatrix (or the inverse of the worldToCameraMatrix like you’re using) is all that’s needed for getting a camera space ray into world space.
Thanks for replying, @bgolus . In the end I got it working with the following code should it interest anyone. If there’s a better/quicker way let me know.
fyi this was handy so that I could call it from a bursted job using the new DOTs packages.