Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
made it work. Now the image is properly rendered
Browse files Browse the repository at this point in the history
It is useful to point out the rendering is _very_ slow.
I guess we can improve the situation, but soon we will have to switch to C
  • Loading branch information
stefanoborini committed Jun 23, 2011
1 parent e618a02 commit 00de858
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions raytrace/World.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from . import ViewPlane
from . import Ray
from . import Tracer
from . import samplers
from PIL import Image
import pygame
import itertools
import math
import numpy
import sys
Expand All @@ -12,9 +14,9 @@

class World(object):
def __init__(self):
self.viewplane = ViewPlane.ViewPlane(resolution=(500,200), pixel_size=1.0)
self.viewplane = ViewPlane.ViewPlane(resolution=(100,100), pixel_size=1.0)
self.background_color = (0.0,0.0,0.0)
self.sampler = samplers.Regular(1)
self.sampler = samplers.Regular(9,10)
self.objects=[]

def set_bgcolor(self,bgcolor):
Expand All @@ -28,17 +30,18 @@ def render(self):
tracer = Tracer.Tracer(self)
for row in self.viewplane:
for pixel in row:
print pixel
imagePxPos = (pixel[0], self.viewplane.resolution[1]-pixel[1]-1)
color = numpy.array([0.0, 0.0, 0.0])
for subsample in sampler:
for subsample in itertools.islice(self.sampler,self.sampler.num_samples_per_set()):
origin = numpy.zeros(3)
origin[0] = self.viewplane.pixel_size*(column - self.viewplane.resolution[0] / 2 + subsample[0])
origin[1] = self.viewplane.pixel_size*(row - self.viewplane.resolution[1] / 2 + subsample[1])
origin[0] = self.viewplane.pixel_size*(pixel[0] - self.viewplane.resolution[0] / 2 + subsample[0])
origin[1] = self.viewplane.pixel_size*(pixel[1] - self.viewplane.resolution[1] / 2 + subsample[1])
origin[2] = 100.0
ray = Ray.Ray(origin = origin, direction = (0.0,0.0,-1.0))

color += numpy.array(tracer.trace_ray(ray))
color /= sampler.num_samples
color /= self.sampler.num_samples_per_set()

im.putpixel(imagePxPos, (int(color[0]*255), int(color[1]*255), int(color[2]*255)))
pxarray[imagePxPos[0]][imagePxPos[1]] = (int(color[0]*255), int(color[1]*255), int(color[2]*255))
Expand Down Expand Up @@ -70,10 +73,6 @@ def f(o):
return None

return foremost



self.sampler = sampler.Regular(1)

def set_sampler(self, sampler):
self.sampler = sampler
Expand Down

0 comments on commit 00de858

Please sign in to comment.