update: save ram by trace ray one by one

This commit is contained in:
2025-04-08 21:15:15 -04:00
parent 7fb4669c4b
commit 1057a7c3e9

View File

@@ -18,7 +18,7 @@ r = 1
# disk = Disk(center, r, n) # disk = Disk(center, r, n)
N = 100000 N = 100000
min_intensity = 0.00001 min_intensity = 0.00001
max_ray = 100*N max_ray = 100
stack = [] stack = []
result = [] result = []
@@ -109,31 +109,31 @@ def modified_trace(wavelength, temp, center, r, N, n_theta, d_theta, min_intensi
n = water_refraction_index(temp, wavelength) n = water_refraction_index(temp, wavelength)
disk = Disk(center, r, n) disk = Disk(center, r, n)
stack = [] stack = []
for u in np.linspace(0, 1, N, endpoint=False):
stack.append(Ray([r*np.sqrt(u), 2*r], [0,-1], 1))
ray_count = 0
XYZ = colorspace.wavelength2XYZ(wavelength)*sun_spectral(wavelength) XYZ = colorspace.wavelength2XYZ(wavelength)*sun_spectral(wavelength)
own_angle_XYZ = np.zeros((n_theta, 3)) own_angle_XYZ = np.zeros((n_theta, 3))
while stack and ray_count < max_ray: for u in np.linspace(0, 1, N, endpoint=False):
ray = stack.pop() stack=[Ray([r*np.sqrt(u), 2*r], [0,-1], 1)]
ray_count += 1 ray_count = 0
if ray is None: while stack and ray_count < max_ray:
continue ray = stack.pop()
if isinstance(ray, Ray): ray_count += 1
if ray.intensity < min_intensity: if ray is None:
continue continue
direction = ray.direction if isinstance(ray, Ray):
t,intersection_point = disk.find_intersection(ray) if ray.intensity < min_intensity:
if intersection_point is not None: continue
points.append(np.concatenate((ray.origin, intersection_point,[ray.intensity]))) direction = ray.direction
normal = disk.get_normal(intersection_point) t,intersection_point = disk.find_intersection(ray)
stack.extend(reflection_and_refraction(ray, intersection_point, normal, disk.refractive_index)) if intersection_point is not None:
else: points.append(np.concatenate((ray.origin, intersection_point,[ray.intensity])))
points.append(np.concatenate((ray.origin, ray.origin+ray.direction,[ray.intensity]))) normal = disk.get_normal(intersection_point)
if direction[1] > 0: stack.extend(reflection_and_refraction(ray, intersection_point, normal, disk.refractive_index))
angle = np.arccos(direction[1]) else:
if angle < max_angle: points.append(np.concatenate((ray.origin, ray.origin+ray.direction,[ray.intensity])))
own_angle_XYZ[int(angle/d_theta)] += XYZ*ray.intensity*direction[1] if direction[1] > 0:
angle = np.arccos(direction[1])
if angle < max_angle:
own_angle_XYZ[int(angle/d_theta)] += XYZ*ray.intensity*direction[1]
return own_angle_XYZ return own_angle_XYZ
def rainbow(n_theta, max_theta, temp): def rainbow(n_theta, max_theta, temp):