1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import numpy
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
config = {
'size_x': 1000,
'size_y': 1000,
'ray_samples': 16,
'light_samples': 8,
'exposure': 20.0,
'zoom': 2.0,
'eye_pos': numpy.array([0, -3, 1.1]),
'eye_dir': numpy.array([0, 1, -0.35])
}
sun_range = (0, 360, 1)
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*numpy.float64(0).nbytes)
program = None
with open('raymarch.cl') as f:
program = cl.Program(cl_context, Template(f.read()).substitute(
{**config, **earth}
)).build()
for i in numpy.arange(*sun_range):
sun = make_double3(numpy.cos(i*2*numpy.pi/360),numpy.sin(i*2*numpy.pi/360),0)
print(sun)
program.render(
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 = numpy.ndarray(shape=(config['size_y'], config['size_x'], 3), dtype=numpy.float64)
cl.enqueue_copy(cl_queue, np_picture, cl_picture).wait();
plt.imsave("bluedot_%05.1f.png" % i, np_picture, origin='lower')
|