summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Braendli <matthias.braendli@u-blox.com>2013-12-03 09:01:40 +0100
committerMatthias Braendli <matthias.braendli@u-blox.com>2013-12-03 09:01:40 +0100
commitdc2de954b63d9ff4eac201e7be7e7be2520d1304 (patch)
treeedd463684f174f41d68bd92bb5528477f811357c
parent2d704858c4c5259493db0e31c4ee1de7b16409ee (diff)
downloadhaskell-dc2de954b63d9ff4eac201e7be7e7be2520d1304.tar.gz
haskell-dc2de954b63d9ff4eac201e7be7e7be2520d1304.tar.bz2
haskell-dc2de954b63d9ff4eac201e7be7e7be2520d1304.zip
correct skycolor
-rw-r--r--raytracer.hs11
1 files changed, 6 insertions, 5 deletions
diff --git a/raytracer.hs b/raytracer.hs
index fe873e0..3b6a8fa 100644
--- a/raytracer.hs
+++ b/raytracer.hs
@@ -32,7 +32,7 @@ filename num = "foo/foo" ++ show num ++ ".ppm"
--spherepos = take 1 [0,20..]
--spherepos = take 10 [0,36..]
-spherepos = [36]
+spherepos = [72]
spheres num = [ trace ("Sphere at " ++
show (round (80 * sin(num * degrees))) ++ "," ++
@@ -58,7 +58,7 @@ floorscale = 4
w = 600 * 2
h = 330 * 2
-oversampling = 2 -- each pixel is oversampling^2 rays
+oversampling = 4 -- each pixel is oversampling^2 rays
black :: Color
black = (0,0,0)
@@ -153,9 +153,10 @@ intersect_floor source (alpha, beta)
-- blue is beautiful, but a green tint is nice too
skycolor :: Coord -> ScreenCoord -> Color
-skycolor source (alpha, beta) = (60,
- round ((sqrt (alpha/6)) / (sqrt (90 * degrees)) * 128),
- round ((sqrt (-beta+90*degrees)) / (sqrt (90 * degrees)) * 255) )
+skycolor source (alpha, beta) = (r,g,b)
+ where r = 60
+ g = max 0 $ round $ (sqrt (alpha/6)) / (sqrt (90 * degrees)) * 128
+ b = max 0 $ round $ (sqrt (-beta+90*degrees)) / (sqrt (90 * degrees)) * 255
data SphereIntersect = SphereIntersect Double Color deriving (Eq, Show) -- distance color
instance Ord SphereIntersect where