|
1 | 1 | from geom3 import Point3, Vector3, Ray3, cross, dot, unit, length
|
2 | 2 | from colour import Colour
|
3 | 3 | from math import sqrt
|
| 4 | +import random |
4 | 5 |
|
5 | 6 | class NoAA(object):
|
6 | 7 | def __init__(self, eyepoint, rayfunc):
|
@@ -37,3 +38,42 @@ def getPixel(self, pixelBox):
|
37 | 38 | return colour / count
|
38 | 39 |
|
39 | 40 |
|
| 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 | + |
0 commit comments