-- parallel tiled rendering, scanline order
-- currently image must be power of two
{-
renderScene3 :: S.Scene -> Render -> Image
renderScene3 s r@(Render (resX, resY)) = ImageRGBF resX resY (V.update initImg (V.concat tiles))
        where initImg = V.replicate (resX*resY) (EXR.PixelRGBF 0 0 0)
              tiles = [renderTile (Tile (x*tileW) (y*tileH) tileW tileH) | y <- [0..nTilesH], x <- [0..nTilesW]] `using` parList rdeepseq
              tileW = 16
              tileH = 16
              nTilesW = (resX - 1) `quot` tileW
              nTilesH = (resY - 1) `quot` tileH
              renderTile t = V.fromList px
                where px = [(index x y, trace s (ray (offsetX t + x) (offsetY t + y))) | y <- [0..height t - 1], x <- [0..width t - 1]]
                      index x y = offsetX t + x + (offsetY t + y) * resX
                      ray x y = C.mkRayDiff (S.camera s) $ mkSample r (fromIntegral x) (fromIntegral y)
-}



main = do
        [sceneFile] <- getArgs
        (scene, render) <- fmap (fromJust . SP.parse) (BL.readFile sceneFile)
        EXR.writeFile "image.exr" (renderScene1 scene render) EXR.ZipCompression
main = do
        [sceneFile] <- getArgs
        (scene, render) <- fmap (fromJust . SP.parse) (BL.readFile sceneFile)
        EXR.writeFile "image.exr" (renderScene1 scene render) EXR.ZipCompression
main = do
        [sceneFile] <- getArgs
        (scene, render) <- fmap (fromJust . SP.parse) (BL.readFile sceneFile)
        EXR.writeFile "image.exr" (renderScene1 scene render) EXR.ZipCompression