Skip to content

Commit 74447e2

Browse files
phirephire
phire
authored and
phire
committed
Added Jitter algrothems
1 parent f29e824 commit 74447e2

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

antiAlaising.py

+40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from geom3 import Point3, Vector3, Ray3, cross, dot, unit, length
22
from colour import Colour
33
from math import sqrt
4+
import random
45

56
class NoAA(object):
67
def __init__(self, eyepoint, rayfunc):
@@ -37,3 +38,42 @@ def getPixel(self, pixelBox):
3738
return colour / count
3839

3940

41+
class Jitter(object):
42+
def __init__(self, eyepoint, rayfunc, subPixels=4):
43+
self.eye = eyepoint
44+
self.rayfunc = rayfunc
45+
self.subPixels= int(sqrt(subPixels))
46+
47+
def getPixel(self, pixelBox):
48+
(x, y, x2, y2) = pixelBox
49+
pitch = (x2 - x)/ self.subPixels
50+
xx = x
51+
yy = y
52+
count = 0
53+
colour = Colour(0,0,0)
54+
for col in range(self.subPixels):
55+
for row in range(self.subPixels):
56+
colour += self.rayfunc(Ray3(self.eye, (Point3(xx + random.uniform(0, pitch) ,yy + random.uniform(0, pitch),1) - self.eye)))
57+
count += 1
58+
yy += pitch
59+
yy = y
60+
xx += pitch
61+
assert count == self.subPixels * self.subPixels
62+
return colour / count
63+
64+
class Jitter2(object):
65+
def __init__(self, eyepoint, rayfunc, subPixels=4):
66+
self.eye = eyepoint
67+
self.rayfunc = rayfunc
68+
self.subPixels= subPixels
69+
70+
def getPixel(self, pixelBox):
71+
(x, y, x2, y2) = pixelBox
72+
pixSize = x2 - x
73+
colour = Colour(0,0,0)
74+
for i in range(self.subPixels):
75+
colour += self.rayfunc(Ray3(self.eye, (Point3(random.uniform(x,x2) ,random.uniform(y,y2),1) - self.eye)))
76+
return colour / self.subPixels
77+
78+
79+

rayCaster.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def rayColour(self, ray, depth=0):
8080
# Main body. Set up an image then compute colour at each pixel
8181
def trace(self):
8282
img = Image.new("RGB", (WIN_SIZE, WIN_SIZE))
83-
aa = SuperSampling(EYEPOINT, self.rayColour, 16)
83+
aa = Jitter(EYEPOINT, self.rayColour, 16)
8484
print "Tracing Rays:"
8585
count = 0
8686
max = float(WIN_SIZE**2)

0 commit comments

Comments
 (0)