Get the rays from the camera

Hey everyone,

Is there a way to get the infos from the 4 rays the camera casts to determine the frustrum planes ? I want to use those rays to detect when they collide with the floor so I can get the 4 points on my plane between the camera can see.
Or is there another way do achieve this than using rays ? I wanna do this to split my floor into multiple areas and detect with areas are seen by the camera.

You can’t get those rays, because they don’t exist. Real-time rendering normally uses the painter’s algorithm and not raytracing. You can calculate them yourself and cast the rays pretty easily since you have the camera’s position, fov and aspect ratio.

Ouch my ego. No idea how to do that.

I don’t know what you mean by " the 4 rays the camera casts to determine the frustrum planes", but you don’t need to do any math at all. You can get any rays coming out from the camera using that function.

@StarManta
What function are you talking about ?

Sorry I was not clear and it was also wrong. What I’m looking for are these 4 rays (camera gizmos) :


I need the intersection points with the floor so that I can determine which area the camera has the vision into.

There’s a link in my comment, follow that link.

Sorry, I’m tired. I managed to do it thanks.

Heres the code I used to debug :

    void Update ()
    {
        Camera cam = GetComponent<Camera>();

        RaycastHit[] hits = new RaycastHit[4];
        List<Ray> rays = new List<Ray>();
        rays.Add(cam.ViewportPointToRay(Vector3.zero));
        rays.Add(cam.ViewportPointToRay(new Vector3(1, 0)));
        rays.Add(cam.ViewportPointToRay(new Vector3(0, 1)));
        rays.Add(cam.ViewportPointToRay(new Vector3(1, 1)));

        for (int i = 0; i < rays.Count; i++)
        {
            Debug.DrawRay(rays[i].origin, rays[i].direction, Color.red);
            if (Physics.Raycast(rays[i], out hits[i]))
                Debug.Log(hits[i].point);
        }
    }