I tried using the camera extension 'IsInFOV'. In the unity editor it was clear that the points being returned included points behind the camera, so long as they were still within the angles of the FOV.
/// <summary>
/// Returns if a point will be rendered on the screen in either eye
/// </summary>
/// <param name="camera">The camera to check the point against</param>
/// <param name="position"></param>
/// <returns></returns>
public static bool IsInFOV(this Camera camera, Vector3 position)
{
float verticalFovHalf = camera.fieldOfView * 0.5f;
float horizontalFovHalf = camera.GetHorizontalFieldOfViewRadians() * Mathf.Rad2Deg * 0.5f;
Vector3 deltaPos = position - camera.transform.position;
Vector3 headDeltaPos = MathUtilities.TransformDirectionFromTo(null, camera.transform, deltaPos).normalized;
# ********** I added this to fix the bug for me
if (headDeltaPos.z < camera.nearClipPlane || headDeltaPos.z > camera.farClipPlane)
{
return false;
}
# **********
float yaw = Mathf.Asin(headDeltaPos.x) * Mathf.Rad2Deg;
float pitch = Mathf.Asin(headDeltaPos.y) * Mathf.Rad2Deg;
return (Mathf.Abs(yaw) < horizontalFovHalf && Mathf.Abs(pitch) < verticalFovHalf);
}
Steps to reproduce the behavior:
things behind the camera shouldn't render.
bad:

good:

You could directly create a PullRequest for this. Makes total sense not to include objects behind the camera.
@keveleigh, when you make this change, can you plz add a test for this as part of your PR?
@davidkline-ms and @keveleigh I actually already just did this :P Opening PR now
Fixed via #6128
Most helpful comment
You could directly create a PullRequest for this. Makes total sense not to include objects behind the camera.