What section of a sphere does the camera 'see'? Intersection of camera viewport and sphere

Blender 2.8

Scene: A sphere and a camera.

The camera can be moved, but it will always show a part of the sphere. Later on, textures should be loaded onto the sphere BUT ONLY for the part of the sphere that is actually in the camera frame. Thereby avoiding to load data that is not necessary.

I have defined the problem as an intersection of and arbitrary number of camera vectors (red dots in the left panel of the screenshot) with the sphere.

Question: How do I project those points onto the sphere? And how to deal with the horizon?

If I have a list of XYZ vectors that are on the sphere I can create a polygon (in polar coordinates) as illustrated in the right panel of the screenshot. That polygon can than be used to select the mentioned textures.

Any code, advice, or keywords of how to better title this question are much appreciated.

Update 29/01/2020: I found this tutorial that describes how to calculate the intersection between a sphere and a ray (I called it camera vector before). This is the code for blender to calculate one ray only, i.e. the center of the camera frame

import bpy
from  mathutils import Vector
import numpy as np
from math import acos

R = 2.0

scene = bpy.data.scenes["Scene"]
ro = scene.camera.location  # ray origin
s = Vector([0,0,0])  # sphere center
rd = scene.camera.matrix_world.to_quaternion() @ Vector((0.0,0.0,-1.0))  # ray direction
t = np.dot(s-ro, rd)  # time, i.e. point along ray
p = ro + rd * t  # vector between sphere center and ray
y = (s-p).length  # distance between sphere center and ray
if y<R:
x = np.sqrt((R*R)-(y*y))
t1 = t-x  # time to t1
result = ro + rd * t1
print('result: ',  result)
else:
print('camera not looking onto sphere')


result is a vector that describes the point on the sphere

• Couple of answers that may be of some use blender.stackexchange.com/a/91019/15543 and blender.stackexchange.com/a/160388/15543 There is also something from ideasman42 that makes the four planes for camera but cannot find atm. – batFINGER Jan 28 '20 at 13:55
• If you're looking for a way to reduce the required memory, wouldn't it be easier to use a downscaled texture that is still detailed enough for the output resolution of your render? – Robert Gützkow Jan 28 '20 at 13:57
• Camera as planes blender.stackexchange.com/a/45324/15543 in conjunction with blender.stackexchange.com/a/118908/15543 – batFINGER Jan 28 '20 at 14:04
• @RobertGützkow, it is actually not one texture, but many different. There are also objects that will be loaded onto the sphere and I have to make a preselection first. – Michael Jan 29 '20 at 7:33
• @batFINGER, thanks this is a lot of input. – Michael Jan 29 '20 at 7:33