Shader using View Projection matrix in Scene View

I have a shader that needs to know the View Projection matrix (the vertex shader needs to do some work in world space and pass on the results of that to the fragment shader)

I’m currently achieving this by calculating the VP matrix myself and setting it as a shader variable. I do this once using SetGlobalMatrix as there can be 100 or so instances that all need the results. So each Update() I do this:

Matrix4x4 vp = new Matrix4x4();
vp = cam.projectionMatrix * cam.worldToCameraMatrix;
Shader.SetGlobalMatrix(“_VPTransform”,vp);

Problem I have is that ‘cam’ is the camera for my game view, so it is the wrong VP for the scene view. Is there a better way I should be doing this. I don’t want to sacrifice any performance just so it works in Scene View, but would be really nice to have it work in the Scene View.

You can get the cameras for all open scene views with:

var sceneCameras:Camera[] = SceneView.GetAllSceneCameras();