Im trying to figure out when a vertex is visible from the main camera. I have this function:
bool in_frustum(float4x4 M, float4 p) {
float4 Pclip = mul(M, float4(p.x, p.y, p.z, 1.0));
return abs(Pclip.x) < Pclip.w &&
abs(Pclip.y) < Pclip.w &&
0 < Pclip.z &&
Pclip.z < Pclip.w;
}
I call it in the vertex shader, and it works fine. The problem is when I have multiple cameras, and I only want to know if it is within the frustum on one of the cameras. If the vertex is not visible from my target camera, I want all other cameras to render it (if it is visible) a particular way (for example red).
I am a little rusty on matrix transformations and the graphics pipeline, but maybe instead of passing UNITY_MVP_MATRIX into the in_frustum function, I need to pass in the MVP matrix of the target camera? Or maybe just the View of the target camera needs to be replaced in.