How to determine if a sun lamp is "visible" to the camera

Hello, all. I’m old to Blender, but new to scripting in Blender. I was hoping someone knows of a novel way to determine in Python if a sun lamp is “visible” to the active camera.

I say “visible” for two reason. First, unless it is a mesh light, the Blender camera can’t “see” the lamp, only the light it casts. So sun, point, hemi are are all technically invisible to the camera. And second, with a point lamp, it is simple enough to convert the lamp’s location to camera space, and if it is between 0 and 1 in X and Y and has a positive Z, the camera can “see” it. With the sun lamp, the lamps location doesn’t matter, only the lamp’s rotation. I suppose with some advanced raycasting, I could shoot rays from the sun lamp along its rotation (both forward and backward because the lamp could be behind the camera and still be shining light into the camera) and test if the rays intersect at two points between the camera front plane and image plane, but that is all quite over my head programmatically.

My next thought would be to compare the sun lamp’s rotation with the camera’s rotation to see if they are pointing in opposite directions (i.e., the closer to 180 degrees rotated from each other, the more likely the sun is shining into the camera), but I still want to know the sun lamp’s apparent camera space location (i.e., if sun lamp and camera are at exactly 180 degrees rotated away from each other, the sun would be at (.5, .5, 92.9million) in camera space).

I have searched the API, but it is along the lines of “I don’t know what I don’t know.” If I don’t know how to do it, I’m not exactly sure I’m looking up the right keywords to find out if the question has already been answered.

I appreciate anyone’s help on this. Happy Blending.

in general lamp are invisible except emission plane

do you mean if the lamp is in the field of view of the camera ?
that takes some calculations to determine that
function of camera location rotation get the angle for field of view

then determine location of lamps and if they are inside the camera field of view !

happy bl