use uneven sample points

This commit is contained in:
Yingjie Wang 2023-11-10 13:41:01 -05:00
parent 10770f26a9
commit c9aca677d7

View File

@ -16,8 +16,7 @@ center = [0,0]
r = 1 r = 1
# n = 1.3 # n = 1.3
# disk = Disk(center, r, n) # disk = Disk(center, r, n)
dx = 0.00001 N = 10000
N = int(2*r /dx - 1)
min_intensity = 0.00001 min_intensity = 0.00001
max_ray = 1000000 max_ray = 1000000
@ -25,11 +24,11 @@ stack = []
result = [] result = []
points = [] points = []
def init(): # def init():
stack = [] # stack = []
for x in np.linspace(-r + dx, r-dx, N): # for x in np.linspace(-r + dx, r-dx, N):
stack.append(Ray([x, 2*r], [0,-1], 10*np.abs(x))) # stack.append(Ray([x, 2*r], [0,-1], 10*np.abs(x)))
return stack # return stack
def reflection_and_refraction(ray:Ray, intersection_point, normal, n): def reflection_and_refraction(ray:Ray, intersection_point, normal, n):
# print("reflection/refraction at the point:", intersection_point) # print("reflection/refraction at the point:", intersection_point)
@ -110,8 +109,8 @@ def modified_trace(wavelength, temp, center, r, dx, N, n_theta, d_theta, min_int
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 x in np.linspace(-r + dx, r-dx, N): for u in np.linspace(0, 1, N, endpoint=False):
stack.append(Ray([x, 2*r], [0,-1], 10*np.abs(x))) stack.append(Ray([r*np.sqrt(u), 2*r], [0,-1], 1))
ray_count = 0 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))
@ -163,8 +162,8 @@ def rainbow(n_theta, max_theta, temp):
maxRGB = np.max(angle_sRGB) maxRGB = np.max(angle_sRGB)
angle_sRGB/= maxRGB angle_sRGB/= maxRGB
angle_sRGB = np.clip(angle_sRGB, 0, 1)
colorspace.vectorized_gamma_correct(angle_sRGB) colorspace.vectorized_gamma_correct(angle_sRGB)
np.clip(angle_sRGB, 0, 1)
return angles,angle_sRGB return angles,angle_sRGB
def bin_find(x, list, start): def bin_find(x, list, start):
@ -221,10 +220,12 @@ def take_picture(angles, angle_sRGB, w, h, distance, filename="image.png"):
image.save(filename) image.save(filename)
if __name__=="__main__": if __name__=="__main__":
w = 7680 w = 7680 *2
h = 4320 h = 4320 *2
dis = 2400 dis = 2400 *2
max_angle = 1.1*np.arctan(np.sqrt(1+(h*h+w*w/4)/(dis*dis))) max_angle = 1.1*np.arctan(np.sqrt(1+(h*h+w*w/4)/(dis*dis)))
angles,sRGB=rainbow(10000, max_angle, 10) # angles,sRGB=rainbow(10000, max_angle, 10)
np.savez_compressed("saved.npz", a=angles, b=sRGB) # np.savez_compressed("saved.npz", a=angles, b=sRGB)
take_picture(angles,sRGB, 7680, 4320, 2400, "image.png") loaded = np.load("saved.npz")
angles, sRGB = loaded['a'], loaded['b']
take_picture(angles,sRGB, w, h, dis, "image16k.png")