git.haldean.org
Woo hoo dox Will Brown 10 years ago
14 changed file(s) with 202 addition(s) and 22 deletion(s).
 2 2 import Data.Vect.Double 3 3 import ArtRay.Primitives 4 4 5 -- | Solve a quadratic. Returns NaN for non-real roots, and two equal values for 6 -- double roots. 5 7 quadSolve :: Double -> Double -> Double -> (Double, Double) 6 8 quadSolve a b c = 7 9 ((-b + disc) / (2 * a), (-b - disc) / (2 * a)) 8 10 where disc = sqrt (b * b - 4 * a * c) 9 11 12 -- | Find the first intersection between a primitive and a ray. Returns Nothing 13 -- if the ray never intersects the primitive. 10 14 firstIntersection :: Ray -> Primitive -> Maybe (Double, Vec3, Primitive) 15 11 16 firstIntersection (Ray dir pos) prim@(Sphere center radius _) = 12 17 let (s1, s2) = quadSolve 13 18 (normsqr dir) 23 28 let s = (x `dotprod` n - pos `dotprod` n) / (dir `dotprod` n) 24 29 in if s > 0 then Just (s, pos &+ scalarMul s dir, p) else Nothing 25 30 31 -- | Find the ray for a point on the image plane 26 32 pointToRay' :: Viewer -> Point2D -> Ray 27 33 pointToRay' (Viewer location u v f) (RelPoint2D hu hv) = 28 34 Ray (normalize (p &- location)) location 34 40 where f_hat = normalize onto 35 41 s = (dist - dotprod pos f_hat) / dotprod dir f_hat 36 42 43 -- | Deform a ray by (i, j) in the image plane, maintaining the focal point of 44 -- the ray. 37 45 deformRay :: Scene -> Ray -> (Double, Double) -> Ray 38 46 deformRay scene ray@(Ray dir pos) (i, j) = 39 47 let farpt = farpoint ray (f \$ viewer scene) (dofdepth scene) 42 50 newdir = normalize (farpt &- newpos) 43 51 in Ray newdir newpos 44 52 53 -- | Find a family of rays that converge at the focal distance for a point in 54 -- the image plane. 45 55 pointToRay :: Scene -> Viewer -> Point2D -> [Ray] 46 56 pointToRay scene viewer point = 47 57 if not \$ dofenabled scene then [pointToRay' viewer point] 51 61 samplesize = ap / fromIntegral (dofsamples scene) 52 62 range = [-ap, (-ap) + samplesize .. ap] 53 63 64 -- | Reflect the first vector about the second 54 65 reflectAbout :: Vec3 -> Vec3 -> Vec3 55 66 reflectAbout vec norm = vec &- scalarMul (2 * dotprod norm vec) norm 56 67 68 -- | Refract the second vector around the first with the provided refraction 69 -- index. 57 70 refractVector :: Double -> Vec3 -> Vec3 -> Vec3 58 71 refractVector refind norm incident = 59 72 refract refind (mkNormal norm) (neg incident) 60 73 74 -- | Find the normal vector at a point on a primitive. Note that this function 75 -- does not require that the point be actually incident to the primitive. 61 76 normal :: Primitive -> Vec3 -> Vec3 62 77 normal (Sphere center _ _) vec = normalize (vec &- center) 63 78 normal (Plane n _ _) vec = normalize n
 0 module Main where 1 0 2 import Data.Vect.Double 1 3 import ArtRay.Primitives 2 4 import ArtRay.Render 3 5 import System (getArgs) 4 6 import System.IO 5 7 8 -- | Read a scene from a file 6 9 readScene :: FilePath -> IO Scene 7 10 readScene path = 8 11 do 10 13 contents <- hGetContents infile 11 14 return (read contents::Scene) 12 15 16 -- | Artificially inflate my Haddock coverage. 17 main :: IO () 13 18 main = getArgs >>= \args -> 14 19 if length args /= 2 then putStrLn "Must supply input and output file names" 15 20 else do
 4 4 import Debug.Trace 5 5 import Graphics.GD 6 6 7 -- | The root object of any rendered scene in ArtRay 7 8 data Scene = 8 9 Scene { 9 10 background :: ColorTriple, 11 -- ^ The background color of the scene -- displayed whenever a ray doesn't 12 -- intersect any geometry. 10 13 options :: [Option], 14 -- ^ A list of rendering options 11 15 geom :: [Primitive], 16 -- ^ The geometry of the scene 12 17 lights :: [Light], 18 -- ^ The lights in the scene 13 19 viewer :: Viewer 20 -- ^ Camera information 14 21 } deriving (Show, Read) 15 22 23 -- | Rendering-related options for scenes 16 24 data Option 25 -- | The global ambient light. If provided, this will illuminate all 26 -- primitives with nonzero ambient material response at all points. 17 27 = GlobalAmbient ColorTriple 18 28 29 -- | Antialiasing options. When the Antialiased option is provided with 30 -- msaaSamples > 1, ArtRay will use MSAA subpixel sampling to antialias the 31 -- image. Note that multiplying msaaSamples by n increases runtime by O(n^2). 19 32 | Antialiased { 20 33 msaaSamples :: Double 21 34 } 22 35 36 -- | Depth of field options. If this option is not provided, the camera has 37 -- infinite depth of field. When this option is provided, the camera simulates 38 -- a real camera with focal length and aperture. Aperture is a number, usually 39 -- on the order of 1, which controls how tight the depth of field is -- higher 40 -- aperture values lead to narrower areas in focus. The focal length option 41 -- determines how far away from the camera's location is in focus. The samples 42 -- parameter is the square root of the number of rays shot out to determine 43 -- the color at each pixel. For simple scenes, this can be as low as 2. The 44 -- run time scales as O(samples^2). 23 45 | DepthOfField { 24 46 focalLength :: Double, 25 47 aperture :: Double, 32 54 center :: Vec3, radius :: Double, material :: Material } 33 55 | Plane { 34 56 pnorm :: Vec3, point :: Vec3, material :: Material } 35 | RectPrism { 36 corner :: Vec3, x :: Vec3, y :: Vec3, z :: Vec3, material :: Material } 37 57 deriving (Show, Read, Eq) 38 58 39 59 data Ray = Ray { direction :: Vec3, position :: Vec3 } deriving (Show) 47 67 loclight :: Vec3 48 68 } deriving (Show, Read) 49 69 70 -- | Combination models determine how materials on an object are combined. 50 71 data CombinationModel 72 -- | Sum the two colors after multiplying the primary by weight and the 73 -- secondary by (1-weight). The weighting term should be in [0,1]. 51 74 = WeightSum { weight::Double } 75 -- | Sum the colors, truncating if any component goes over the maximum. 52 76 | FlatSum 77 -- | Take the product of the two colors. This creates weird effects which you 78 -- almost certainly do not want, but it's interesting to look at. 53 79 | Multiply 54 80 deriving (Show, Eq, Read) 55 81 56 82 data Material 83 -- | A material where every point on the material has the same color. 57 84 = ColorMaterial { 58 85 basecolor :: ColorTriple 59 86 } 60 87 88 -- | A material which reflects rays. Optionally, the material can have a base 89 -- material, whose color is blended with the reflections using the 90 -- reflectivity parameter. 91 -- TODO: Use a combination model here. 61 92 | ReflectiveMaterial { 62 93 base :: Material, 63 94 reflectivity :: Double 64 95 } 65 96 97 -- | A Phong-reflectance based material. 66 98 | PhongMaterial { 67 99 specular :: ColorTriple, 68 100 diffuse :: ColorTriple, 70 102 phongexp :: Int 71 103 } 72 104 105 -- | A transparent material with a refractive index. This can be blended with 106 -- a base material using the provided combination model. 73 107 | TransparentMaterial { 74 108 base :: Material, 75 109 cmodel :: CombinationModel, 76 110 refindex :: Double 77 111 } 78 112 113 -- | A material that doesn't exist. This can be convenient for a placeholder 114 -- when you don't want to provide an actual material (like as the base 115 -- material of a TransparentMaterial that is fully transparent). 79 116 | NullMaterial 80 117 deriving (Show, Read, Eq) 81 118 92 129 93 130 data Point2D = 94 131 -- | Describes a point in the image using pixel coordinates, allowing for 95 -- | fractional pixels for subpixel sampling. 132 -- fractional pixels for subpixel sampling. 96 133 Point2D Double Double 97 134 -- | Describes a point in the image using offsets from the center, where each 98 -- field goes from zero to one. 135 -- field goes from zero to one. 99 136 | RelPoint2D Double Double 100 137 deriving (Show) 101 138 102 139 -- | Returns the transmittance (1 minus the opacity) of any material. 103 140 transmittance :: Material -> Double 104 141 transmittance (TransparentMaterial _ (WeightSum op) _) = op 105 142 transmittance _ = 0 106 143 144 -- | Returns the global ambient of the scene 107 145 glambient :: Scene -> ColorTriple 108 146 glambient scene = 109 147 case mapMaybe 112 150 amb:_ -> amb 113 151 otherwise -> (0, 0, 0) 114 152 153 -- | Returns the number of subpixels used for MSAA, or Nothing if no 154 -- antialiasing is to be performed. 115 155 subpixels :: Scene -> Maybe Double 116 156 subpixels scene = 117 157 case mapMaybe 120 160 subp:_ -> Just subp 121 161 otherwise -> Nothing 122 162 163 -- | Returns the DepthOfField option, or nothing if no depth of field is to be 164 -- used. 123 165 dofinfo :: Scene -> Maybe Option 124 166 dofinfo scene = 125 167 case mapMaybe 130 172 dofs:_ -> Just dofs 131 173 otherwise -> Nothing 132 174 175 -- | Returns True if depth of field is to be simulated, and false otherwise. 133 176 dofenabled :: Scene -> Bool 134 177 dofenabled = isJust . dofinfo 135 178 179 -- | Returns the number of samples to use for calculating depth of field. This 180 -- will throw an exception if depth of field is not enabled for the provided 181 -- scene. 136 182 dofsamples :: Scene -> Int 137 183 dofsamples = dofSamples . fromJust . dofinfo 138 184 185 -- | Returns the focal length of the camera. This will throw an exception if 186 -- depth of field is not enabled for the provided scene. 139 187 dofdepth :: Scene -> Double 140 188 dofdepth = focalLength . fromJust . dofinfo 141 189 190 -- | Returns the aperture size of the camera. This will throw an exception if 191 -- depth of field is not enabled for the provided scene. 142 192 dofaperture :: Scene -> Double 143 193 dofaperture = aperture . fromJust . dofinfo 144 194 195 -- | Convenience method for turning a pair of integers into a Point2D. 145 196 p2d :: Int -> Int -> Point2D 146 197 p2d x y = Point2D (fromIntegral x) (fromIntegral y) 147 198 199 -- | Convenience method for creating colors 148 200 color :: Double -> Double -> Double -> ColorTriple 149 201 color r g b = (r, g, b) 150 202 203 -- | Convenience method for creating ColorMaterials. 151 204 colorm :: Double -> Double -> Double -> Material 152 205 colorm r g b = ColorMaterial (r, g, b) 153 206 207 -- | Converts pixel locations into relative locations in [-1,1], where -1 208 -- corresponds to the left or bottom edge, and 1 corresponds to the right or top 209 -- edge. 154 210 toRelPoint :: Size -> Point2D -> Point2D 155 211 toRelPoint size (Point2D x y) = 156 212 RelPoint2D ((x - xc) / xc) ((y - yc) / yc) 157 213 where xc = fromIntegral (fst size) / 2 158 214 yc = fromIntegral (snd size) / 2 159 215 160 -- |Creates a viewer 216 -- | Creates a viewer 161 217 view :: Vec3 -- ^ The location of the viewer 162 218 -> Double -- ^ The field of view of the viewer, in radians 163 219 -> Vec3 -- ^ The vector from viewer to center of image plane 170 226 instance Eq Vec3 where 171 227 (Vec3 x1 y1 z1) == (Vec3 x2 y2 z2) = (x1 == x2) && (y1 == y2) && (z1 == z2) 172 228 229 -- | Convert an ArtRay color to a GD color. 173 230 colorFrom :: ColorTriple -> Color 174 231 colorFrom (r, g, b) = 175 232 rgb (round (r * 255)) (round (g * 255)) (round (b * 255)) 176 233 234 -- | Take the product of two colors 177 235 combine :: ColorTriple -> ColorTriple -> ColorTriple 178 236 combine (r1, g1, b1) (r2, g2, b2) = (r1 * r2, g1 * g2, b1 * b2) 179 237 238 -- | Multiply a color by a scalar 180 239 scale :: ColorTriple -> Double -> ColorTriple 181 240 scale (r, g, b) s = (s * r, s * g, s * b) 182 241 242 -- | Weight two colors with the provided weighting factor. The first color is 243 -- multiplied by the weight, the second by one minus the weight. 183 244 weightedCombine :: Double -> ColorTriple -> ColorTriple -> ColorTriple 184 245 weightedCombine w (r1, g1, b1) (r2, g2, b2) = 185 246 (mul w r1 r2, mul w g1 g2, mul w b1 b2) 186 247 where mul w a b = w * a + (1 - w) * b 187 248 249 -- | Ensure that each component of the color is in [0, 1]. 188 250 normalizeColor (r, g, b) = (n r, n g, n b) 189 251 where n x = max 0 (min 1 x) 190 252 253 -- | Take the sum of a list of colors 191 254 sumLight :: [ColorTriple] -> ColorTriple 192 255 sumLight = foldl1 sumColor 193 256 257 -- | Take the sum of a pair of colors, truncating if it results in a value 258 -- outside [0, 1]. 194 259 sumColor :: ColorTriple -> ColorTriple -> ColorTriple 195 260 sumColor (r1, g1, b1) (r2, g2, b2) = normalizeColor (r1 + r2, g1 + g2, b1 + b2) 261 262 -- | Take the sum of a pair of colors without normalizing. 263 sumColor' :: ColorTriple -> ColorTriple -> ColorTriple 196 264 sumColor' (r1, g1, b1) (r2, g2, b2) = (r1 + r2, g1 + g2, b1 + b2) 197 265 266 -- | Find the mean value of a list of colors. 198 267 meanColor :: [ColorTriple] -> ColorTriple 199 268 meanColor colors = div \$ foldl1 sumColor' colors 200 269 where l = fromIntegral \$ length colors
 22 22 where inc = (-0.5) + 1 / subpixels 23 23 otherwise -> rayTraceImage' scene size (p2d x y) 24 24 25 -- | Turn a function into a pretty picture 25 26 applyToImage :: (Size -> Point -> ColorTriple) -> Image -> IO() 26 27 applyToImage imFunc im = 27 28 do 29 30 sequence_ [setPixel (i,j) (colorFrom \$ imFunc size (i,j)) im 30 31 | i <- [0..(fst size)], j <- [0..(snd size)]] 31 32 32 render :: Scene -> Int -> String -> IO() 33 -- | Render a square image and save it to the given file. 34 render :: Scene -> Int -> FilePath -> IO() 33 35 render scene size outfile = 34 36 do 35 37 im <- newImage (size, size)
 0 0 ArtRay.Geometry

ArtRay.Geometry

Documentation

quadSolve :: Double -> Double -> Double -> (Double, Double)

firstIntersection :: Ray -> Primitive -> Maybe (Double, Vec3, Primitive)

reflectAbout :: Vec3 -> Vec3 -> Vec3

refractVector :: Double -> Vec3 -> Vec3 -> Vec3

normal :: Primitive -> Vec3 -> Vec3

⏎ 3

ArtRay.Geometry

Synopsis

Documentation

quadSolve :: Double -> Double -> Double -> (Double, Double)

Solve a quadratic. Returns NaN for non-real roots, and two equal values for 4 double roots. 5

firstIntersection :: Ray -> Primitive -> Maybe (Double, Vec3, Primitive)

Find the first intersection between a primitive and a ray. Returns Nothing 6 if the ray never intersects the primitive. 7

pointToRay' :: Viewer -> Point2D -> Ray

Find the ray for a point on the image plane 8

farpoint :: Ray -> Vec3 -> Double -> Vec3

Finds the point on a ray whose projection on a vector has a specific length. 9

deformRay :: Scene -> Ray -> (Double, Double) -> Ray

Deform a ray by (i, j) in the image plane, maintaining the focal point of 10 the ray. 11

pointToRay :: Scene -> Viewer -> Point2D -> [Ray]

Find a family of rays that converge at the focal distance for a point in 12 the image plane. 13

reflectAbout :: Vec3 -> Vec3 -> Vec3

Reflect the first vector about the second 14

refractVector :: Double -> Vec3 -> Vec3 -> Vec3

Refract the second vector around the first with the provided refraction 15 index. 16

normal :: Primitive -> Vec3 -> Vec3

Find the normal vector at a point on a primitive. Note that this function 17 does not require that the point be actually incident to the primitive. 18

 0 0 ArtRay.Primitives

ArtRay.Primitives

Synopsis

Documentation

data Scene

Constructors

Scene

Instances

Show Scene

data Option

Constructors

Antialiased Double
GlobalAmbient ColorTriple

Instances

Show Option

data Primitive

Constructors

Sphere

Fields

center :: Vec3

material :: Material

Plane

Fields

pnorm :: Vec3

point :: Vec3

material :: Material

RectPrism

Fields

corner :: Vec3

x :: Vec3

y :: Vec3

z :: Vec3

material :: Material

Instances

Eq Primitive
Show Primitive

data Ray

Constructors

Ray

Fields

direction :: Vec3

position :: Vec3

Instances

Show Ray

type ColorTriple = (Double, Double, Double)

data Light

Constructors

PhongLight

Instances

Show Light

data CombinationModel

Constructors

WeightSum

Fields

weight :: Double

FlatSum
Multiply

Instances

Eq CombinationModel
Show CombinationModel

data Material

Constructors

ColorMaterial
ReflectiveMaterial

Fields

base :: Material

reflectivity :: Double

PhongMaterial
TransparentMaterial

Fields

base :: Material

cmodel :: CombinationModel

refindex :: Double

NullMaterial

Instances

Eq Material
Show Material

data Viewer

Constructors

Viewer

Fields

location :: Vec3

The location of the viewer 3

ArtRay.Primitives

Synopsis

Documentation

data Scene

The root object of any rendered scene in ArtRay 4

Constructors

Scene

Fields

background :: ColorTriple

The background color of the scene -- displayed whenever a ray doesn't 5 intersect any geometry. 6

options :: [Option]

A list of rendering options 7

geom :: [Primitive]

The geometry of the scene 8

lights :: [Light]

The lights in the scene 9

viewer :: Viewer

Camera information 10

Instances

Show Scene

data Option

Rendering-related options for scenes 11

Constructors

GlobalAmbient ColorTriple

The global ambient light. If provided, this will illuminate all 12 primitives with nonzero ambient material response at all points. 13

Antialiased

Antialiasing options. When the Antialiased option is provided with 14 msaaSamples > 1, ArtRay will use MSAA subpixel sampling to antialias the 15 image. Note that multiplying msaaSamples by n increases runtime by O(n^2). 16

Fields

msaaSamples :: Double

DepthOfField

Depth of field options. If this option is not provided, the camera has 17 infinite depth of field. When this option is provided, the camera simulates 18 a real camera with focal length and aperture. Aperture is a number, usually 19 on the order of 1, which controls how tight the depth of field is -- higher 20 aperture values lead to narrower areas in focus. The focal length option 21 determines how far away from the camera's location is in focus. The samples 22 parameter is the square root of the number of rays shot out to determine 23 the color at each pixel. For simple scenes, this can be as low as 2. The 24 run time scales as O(samples^2). 25

Fields

focalLength :: Double

aperture :: Double

dofSamples :: Int

Instances

Show Option

data Primitive

Constructors

Sphere

Fields

center :: Vec3

material :: Material

Plane

Fields

pnorm :: Vec3

point :: Vec3

material :: Material

Instances

Eq Primitive
Show Primitive

data Ray

Constructors

Ray

Fields

direction :: Vec3

position :: Vec3

Instances

Show Ray

type ColorTriple = (Double, Double, Double)

data Light

Constructors

PhongLight

Instances

Show Light

data CombinationModel

Combination models determine how materials on an object are combined. 26

Constructors

WeightSum

Sum the two colors after multiplying the primary by weight and the 27 secondary by (1-weight). The weighting term should be in [0,1]. 28

Fields

weight :: Double

FlatSum

Sum the colors, truncating if any component goes over the maximum. 29

Multiply

Take the product of the two colors. This creates weird effects which you 30 almost certainly do not want, but it's interesting to look at. 31

data Material

Constructors

ColorMaterial

A material where every point on the material has the same color. 32

ReflectiveMaterial

A material which reflects rays. Optionally, the material can have a base 33 material, whose color is blended with the reflections using the 34 reflectivity parameter. 35 TODO: Use a combination model here. 36

Fields

base :: Material

reflectivity :: Double

PhongMaterial

A Phong-reflectance based material. 37

TransparentMaterial

A transparent material with a refractive index. This can be blended with 38 a base material using the provided combination model. 39

Fields

base :: Material

cmodel :: CombinationModel

refindex :: Double

NullMaterial

A material that doesn't exist. This can be convenient for a placeholder 40 when you don't want to provide an actual material (like as the base 41 material of a TransparentMaterial that is fully transparent). 42

Instances

Eq Material
Show Material

data Viewer

Constructors

Viewer

Fields

location :: Vec3

The location of the viewer 4 43

u :: Vec3

A vector pointing horizontally along the image plane 5 44

v :: Vec3

A vector pointing vertically along the image plane 6 45

f :: Vec3

A vector pointing from the viewer to the center of the image plane 7 46

Instances

Show Viewer

data Point2D

Constructors

Point2D Double Double

Describes a point in the image using pixel coordinates, allowing for 8 | fractional pixels for subpixel sampling. 47 fractional pixels for subpixel sampling. 9 48

RelPoint2D Double Double

Describes a point in the image using offsets from the center, where each 10 field goes from zero to one. 11

Instances

Show Point2D

transmittance :: Material -> Double

subpixels :: Scene -> Maybe Double

p2d :: Int -> Int -> Point2D

color :: Double -> Double -> Double -> ColorTriple

colorm :: Double -> Double -> Double -> Material

toRelPoint :: Size -> Point2D -> Point2D

view

Arguments

:: Vec3

The location of the viewer 49 field goes from zero to one. 50

Instances

Show Point2D

transmittance :: Material -> Double

Returns the transmittance (1 minus the opacity) of any material. 51

glambient :: Scene -> ColorTriple

Returns the global ambient of the scene 52

subpixels :: Scene -> Maybe Double

Returns the number of subpixels used for MSAA, or Nothing if no 53 antialiasing is to be performed. 54

dofinfo :: Scene -> Maybe Option

Returns the DepthOfField option, or nothing if no depth of field is to be 55 used. 56

dofenabled :: Scene -> Bool

Returns True if depth of field is to be simulated, and false otherwise. 57

dofsamples :: Scene -> Int

Returns the number of samples to use for calculating depth of field. This 58 will throw an exception if depth of field is not enabled for the provided 59 scene. 60

dofdepth :: Scene -> Double

Returns the focal length of the camera. This will throw an exception if 61 depth of field is not enabled for the provided scene. 62

dofaperture :: Scene -> Double

Returns the aperture size of the camera. This will throw an exception if 63 depth of field is not enabled for the provided scene. 64

p2d :: Int -> Int -> Point2D

Convenience method for turning a pair of integers into a Point2D. 65

color :: Double -> Double -> Double -> ColorTriple

Convenience method for creating colors 66

colorm :: Double -> Double -> Double -> Material

Convenience method for creating ColorMaterials. 67

toRelPoint :: Size -> Point2D -> Point2D

Converts pixel locations into relative locations in [-1,1], where -1 68 corresponds to the left or bottom edge, and 1 corresponds to the right or top 69 edge. 70

view

Arguments

:: Vec3

The location of the viewer 12 71

-> Double

The field of view of the viewer, in radians 13 72

-> Vec3

The vector from viewer to center of image plane 14 73

-> Vec3

Unit vector pointing vertically along the image plane 15 74

-> Viewer

Creates a viewer 16

scale :: ColorTriple -> Double -> ColorTriple

⏎ 75

colorFrom :: ColorTriple -> Color

Convert an ArtRay color to a GD color. 76

combine :: ColorTriple -> ColorTriple -> ColorTriple

Take the product of two colors 77

scale :: ColorTriple -> Double -> ColorTriple

Multiply a color by a scalar 78

weightedCombine :: Double -> ColorTriple -> ColorTriple -> ColorTriple

Weight two colors with the provided weighting factor. The first color is 79 multiplied by the weight, the second by one minus the weight. 80

sumLight :: [ColorTriple] -> ColorTriple

Ensure that each component of the color is in [0, 1]. 81

Take the sum of a list of colors 82

sumColor :: ColorTriple -> ColorTriple -> ColorTriple

Take the sum of a pair of colors, truncating if it results in a value 83 outside [0, 1]. 84

sumColor' :: ColorTriple -> ColorTriple -> ColorTriple

Take the sum of a pair of colors without normalizing. 85

meanColor :: [ColorTriple] -> ColorTriple

Find the mean value of a list of colors. 86

 7 7

-> Vec3

The location of intersection 8 8

-> Int

The stack depth 9 9

-> ColorTriple

The color at that point 10

occluded :: Scene -> Primitive -> Vec3 -> Vec3 -> Double

sortTuples :: (Double, Vec3, Primitive) -> (Double, Vec3, Primitive) -> Ordering

geomAtRay :: Scene -> Ray -> [Primitive] -> Maybe (Vec3, Primitive)

intersectWithScene :: Scene -> Ray -> [Primitive] -> [(Double, Vec3, Primitive)]

⏎ 10

occluded :: Scene -> Primitive -> Vec3 -> Vec3 -> Double

sortTuples :: (Double, Vec3, Primitive) -> (Double, Vec3, Primitive) -> Ordering

geomAtRay :: Scene -> Ray -> [Primitive] -> Maybe (Vec3, Primitive)

intersectWithScene :: Scene -> Ray -> [Primitive] -> [(Double, Vec3, Primitive)]

 0 0 ArtRay.Render

ArtRay.Render

Synopsis

Documentation

rayTraceImage' :: Scene -> Size -> Point2D -> ColorTriple

Raytrace an image without antialiasing 3

ArtRay.Render

Synopsis

Documentation

rayTraceImage' :: Scene -> Size -> Point2D -> ColorTriple

Raytrace an image without antialiasing 4 4

rayTraceImage :: Scene -> Size -> Point -> ColorTriple

Raytrace an image with antialiasing by subpixel sampling 5

applyToImage :: (Size -> Point -> ColorTriple) -> Image -> IO ()

render :: Scene -> Int -> String -> IO ()

⏎ 5

applyToImage :: (Size -> Point -> ColorTriple) -> Image -> IO ()

Turn a function into a pretty picture 6

render :: Scene -> Int -> FilePath -> IO ()

Render a square image and save it to the given file. 7

 0 0 Main

Main

Documentation

main :: IO ()

⏎ 3

Main

Synopsis

Documentation

readScene :: FilePath -> IO Scene

Read a scene from a file 4

main :: IO ()

Artificially inflate my Haddock coverage. 5

 0 0 ArtRay: A Haskell Raytracer (Index)

Index

ambientArtRay.Primitives
AntialiasedArtRay.Primitives
applyToImageArtRay.Render
backgroundArtRay.Primitives
baseArtRay.Primitives
basecolorArtRay.Primitives
centerArtRay.Primitives
cmodelArtRay.Primitives
colorArtRay.Primitives
colorAtRayArtRay.RayTrace
colorAtRay'ArtRay.RayTrace
colorForArtRay.RayTrace
colorFromArtRay.Primitives
colormArtRay.Primitives
ColorMaterialArtRay.Primitives
ColorTripleArtRay.Primitives
CombinationModelArtRay.Primitives
combineArtRay.Primitives
cornerArtRay.Primitives
difflightArtRay.Primitives
diffuseArtRay.Primitives
directionArtRay.Primitives
fArtRay.Primitives
firstIntersectionArtRay.Geometry
FlatSumArtRay.Primitives
geomArtRay.Primitives
geomAtRayArtRay.RayTrace
glambientArtRay.Primitives
GlobalAmbientArtRay.Primitives
intersectWithSceneArtRay.RayTrace
LightArtRay.Primitives
lightsArtRay.Primitives
locationArtRay.Primitives
loclightArtRay.Primitives
mainMain
MaterialArtRay.Primitives
materialArtRay.Primitives
meanColorArtRay.Primitives
MultiplyArtRay.Primitives
normalArtRay.Geometry
normalizeColorArtRay.Primitives
NullMaterialArtRay.Primitives
occludedArtRay.RayTrace
OptionArtRay.Primitives
optionsArtRay.Primitives
p2dArtRay.Primitives
phongexpArtRay.Primitives
PhongLightArtRay.Primitives
phongLightArtRay.RayTrace
PhongMaterialArtRay.Primitives
pixelColorArtRay.RayTrace
PlaneArtRay.Primitives
pnormArtRay.Primitives
pointArtRay.Primitives
Point2D
1 (Type/Class)ArtRay.Primitives
2 (Data Constructor)ArtRay.Primitives
pointToRayArtRay.Geometry
positionArtRay.Primitives
PrimitiveArtRay.Primitives
Ray
1 (Type/Class)ArtRay.Primitives
2 (Data Constructor)ArtRay.Primitives
rayTraceImageArtRay.Render
rayTraceImage'ArtRay.Render
RectPrismArtRay.Primitives
refindexArtRay.Primitives
ReflectiveMaterialArtRay.Primitives
reflectivityArtRay.Primitives
refractVectorArtRay.Geometry
RelPoint2DArtRay.Primitives
renderArtRay.Render
scaleArtRay.Primitives
Scene
1 (Type/Class)ArtRay.Primitives
2 (Data Constructor)ArtRay.Primitives
sortTuplesArtRay.RayTrace
speclightArtRay.Primitives
specularArtRay.Primitives
SphereArtRay.Primitives
subpixelsArtRay.Primitives
sumColorArtRay.Primitives
sumColor'ArtRay.Primitives
sumLightArtRay.Primitives
toRelPointArtRay.Primitives
traceiArtRay.RayTrace
transmittanceArtRay.Primitives
TransparentMaterialArtRay.Primitives
uArtRay.Primitives
vArtRay.Primitives
viewArtRay.Primitives
Viewer
1 (Type/Class)ArtRay.Primitives
2 (Data Constructor)ArtRay.Primitives
viewerArtRay.Primitives
weightArtRay.Primitives
weightedCombineArtRay.Primitives
WeightSumArtRay.Primitives
xArtRay.Primitives
yArtRay.Primitives
zArtRay.Primitives
⏎ 3

Index

ambientArtRay.Primitives
AntialiasedArtRay.Primitives
apertureArtRay.Primitives
applyToImageArtRay.Render
backgroundArtRay.Primitives
baseArtRay.Primitives
basecolorArtRay.Primitives
centerArtRay.Primitives
cmodelArtRay.Primitives
colorArtRay.Primitives
colorAtRayArtRay.RayTrace
colorAtRay'ArtRay.RayTrace
colorForArtRay.RayTrace
colorFromArtRay.Primitives
colormArtRay.Primitives
ColorMaterialArtRay.Primitives
ColorTripleArtRay.Primitives
CombinationModelArtRay.Primitives
combineArtRay.Primitives
deformRayArtRay.Geometry
DepthOfFieldArtRay.Primitives
difflightArtRay.Primitives
diffuseArtRay.Primitives
directionArtRay.Primitives
dofapertureArtRay.Primitives
dofdepthArtRay.Primitives
dofenabledArtRay.Primitives
dofinfoArtRay.Primitives
dofSamplesArtRay.Primitives
dofsamplesArtRay.Primitives
fArtRay.Primitives
farpointArtRay.Geometry
firstIntersectionArtRay.Geometry
FlatSumArtRay.Primitives
focalLengthArtRay.Primitives
geomArtRay.Primitives
geomAtRayArtRay.RayTrace
glambientArtRay.Primitives
GlobalAmbientArtRay.Primitives
intersectWithSceneArtRay.RayTrace
LightArtRay.Primitives
lightsArtRay.Primitives
locationArtRay.Primitives
loclightArtRay.Primitives
mainMain
MaterialArtRay.Primitives
materialArtRay.Primitives
meanColorArtRay.Primitives
msaaSamplesArtRay.Primitives
MultiplyArtRay.Primitives
normalArtRay.Geometry
normalizeColorArtRay.Primitives
NullMaterialArtRay.Primitives
occludedArtRay.RayTrace
OptionArtRay.Primitives
optionsArtRay.Primitives
p2dArtRay.Primitives
phongexpArtRay.Primitives
PhongLightArtRay.Primitives
phongLightArtRay.RayTrace
PhongMaterialArtRay.Primitives
pixelColorArtRay.RayTrace
PlaneArtRay.Primitives
pnormArtRay.Primitives
pointArtRay.Primitives
Point2D
1 (Type/Class)ArtRay.Primitives
2 (Data Constructor)ArtRay.Primitives
pointToRayArtRay.Geometry
pointToRay'ArtRay.Geometry
positionArtRay.Primitives
PrimitiveArtRay.Primitives
Ray
1 (Type/Class)ArtRay.Primitives
2 (Data Constructor)ArtRay.Primitives
rayTraceImageArtRay.Render
rayTraceImage'ArtRay.Render
refindexArtRay.Primitives
ReflectiveMaterialArtRay.Primitives
reflectivityArtRay.Primitives
refractVectorArtRay.Geometry
RelPoint2DArtRay.Primitives
renderArtRay.Render
scaleArtRay.Primitives
Scene
1 (Type/Class)ArtRay.Primitives
2 (Data Constructor)ArtRay.Primitives
sortTuplesArtRay.RayTrace
speclightArtRay.Primitives
specularArtRay.Primitives
SphereArtRay.Primitives
subpixelsArtRay.Primitives
sumColorArtRay.Primitives
sumColor'ArtRay.Primitives
sumLightArtRay.Primitives
toRelPointArtRay.Primitives
traceiArtRay.RayTrace
transmittanceArtRay.Primitives
TransparentMaterialArtRay.Primitives
uArtRay.Primitives
vArtRay.Primitives
viewArtRay.Primitives
Viewer
1 (Type/Class)ArtRay.Primitives
2 (Data Constructor)ArtRay.Primitives
viewerArtRay.Primitives
weightArtRay.Primitives
weightedCombineArtRay.Primitives
WeightSumArtRay.Primitives
 0 0 ArtRay.Geometry

ArtRay.Geometry

⏎ 3

ArtRay.Geometry

 0 0 Main

Main

⏎ 3

Main

 4 4 DepthOfField { 5 5 focalLength = 10, 6 6 aperture = 2, 7 dofSamples = 4 7 dofSamples = 2 8 8 } 9 9 ], 10 10