forked from deermichel/raytracer.py
-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer_gpu.py
39 lines (33 loc) · 1.22 KB
/
renderer_gpu.py
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
import os
import threading
from Queue import Queue
from tracer import Tracer
from tracer_gpu import Tracer_gpu
from vector3 import Vector3
class Renderer_gpu:
"""
: Renderer coordinating the tracing process
: GPU version
"""
def __init__(self, tilesize=32, threads=2):
"""Creates a new renderer"""
self.__tilesize = tilesize
self.__threads = threads
def render(self, scene, camera, width, height, super_sampling=1, logging=True):
"""Renders a scene"""
tracer = Tracer_gpu()
ray_array = []
ray_from_array = []
# generate ray array
for y in range(0, height):
for x in range(0, width):
sum_color = Vector3()
# calculate ray using Camera class
ray = camera.calcRay(x, y, width, height)
# put ray into an array for further processing
ray_array.append([ray.origin.x, ray.origin.y, ray.origin.z,
ray.direction.x, ray.direction.y, ray.direction.z, ray.current_ior])
ray_from_array.append([x, y])
# call GPU tracer
rendered = tracer.trace(ray_array, ray_from_array, scene)
return rendered