aboutsummaryrefslogtreecommitdiff
path: root/local_sunrise.py
diff options
context:
space:
mode:
authorAdrian Kummerlaender2020-01-20 22:40:44 +0100
committerAdrian Kummerlaender2020-01-20 22:40:44 +0100
commitabbdbe64d12af732983bc11aac772d3d32682bb5 (patch)
treefb89bd9818e33588cf295036c6feb681b92d0ff4 /local_sunrise.py
parentb0b52925fb96e417802f4b390fafc15c8536df2d (diff)
downloadfirmament-abbdbe64d12af732983bc11aac772d3d32682bb5.tar
firmament-abbdbe64d12af732983bc11aac772d3d32682bb5.tar.gz
firmament-abbdbe64d12af732983bc11aac772d3d32682bb5.tar.bz2
firmament-abbdbe64d12af732983bc11aac772d3d32682bb5.tar.lz
firmament-abbdbe64d12af732983bc11aac772d3d32682bb5.tar.xz
firmament-abbdbe64d12af732983bc11aac772d3d32682bb5.tar.zst
firmament-abbdbe64d12af732983bc11aac772d3d32682bb5.zip
Extract OpenCL setup into Renderer
Diffstat (limited to 'local_sunrise.py')
-rw-r--r--local_sunrise.py36
1 files changed, 7 insertions, 29 deletions
diff --git a/local_sunrise.py b/local_sunrise.py
index 7032847..b413579 100644
--- a/local_sunrise.py
+++ b/local_sunrise.py
@@ -1,17 +1,12 @@
import numpy as np
import matplotlib.pyplot as plt
-from string import Template
-import pyopencl as cl
-from pyopencl.cltypes import make_double3
-
-mf = cl.mem_flags
-
-from planets import earth
-
-from sun import sun_direction
from datetime import datetime
+from firmament import Renderer
+from firmament.planets import earth
+from firmament.sun import sun_direction
+
fish_eye = False
config = {
@@ -37,36 +32,19 @@ config = {
time_range = (6, 20, 0.5)
-cl_platform = cl.get_platforms()[0]
-cl_context = cl.Context(properties=[(cl.context_properties.PLATFORM, cl_platform)])
-cl_queue = cl.CommandQueue(cl_context)
-
-cl_picture = cl.Buffer(cl_context, mf.WRITE_ONLY, size=config['size_x']*config['size_y']*3*np.float64(0).nbytes)
-program = None
-
-with open('raymarch.cl') as f:
- program = cl.Program(cl_context, Template(f.read()).substitute(
- {**config, **earth}
- )).build()
+renderer = Renderer(config, earth)
for time in np.arange(*time_range):
pit = datetime(*config['date'], int(np.floor(time)), int((time-np.floor(time))*60), 0)
sun_dir = sun_direction(config['latitude'], config['longitude'], pit, config['timezone'], 1.0 if config['summertime'] else 0.0)
- sun = make_double3(
+ sun =(
np.cos(sun_dir[0])*np.sin(sun_dir[1]),
np.cos(sun_dir[0])*np.cos(sun_dir[1]),
np.sin(sun_dir[0])
)
print(sun_dir)
- (program.render_fisheye if fish_eye else program.render_pinhole)(
- cl_queue, (config['size_x'], config['size_y']), None, cl_picture,
- make_double3(*(config['eye_pos'] * earth['earth_radius'])),
- make_double3(*(config['eye_dir'] * earth['earth_radius'])),
- sun)
-
- np_picture = np.ndarray(shape=(config['size_y'], config['size_x'], 3), dtype=np.float64)
- cl.enqueue_copy(cl_queue, np_picture, cl_picture).wait();
+ np_picture = (renderer.render_fisheye if fish_eye else renderer.render_pinhole)(sun)
plt.imsave("sky_%05.1f.png" % time, np_picture, origin='lower')