worked a bit further
This commit is contained in:
parent
89a83a1579
commit
551685e131
@ -63,7 +63,9 @@ executable raytrace
|
|||||||
attoparsec >= 0.12,
|
attoparsec >= 0.12,
|
||||||
bytestring >= 0.10,
|
bytestring >= 0.10,
|
||||||
linear >= 1.10,
|
linear >= 1.10,
|
||||||
JuicyPixels >= 3.1
|
JuicyPixels >= 3.1,
|
||||||
|
parallel >= 3.2,
|
||||||
|
vector >= 0.10
|
||||||
|
|
||||||
-- Directories containing source files.
|
-- Directories containing source files.
|
||||||
-- hs-source-dirs:
|
-- hs-source-dirs:
|
||||||
|
38
src/Main.hs
38
src/Main.hs
@ -6,12 +6,16 @@ import Codec.Picture.Png
|
|||||||
import Codec.Picture.Types
|
import Codec.Picture.Types
|
||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
import qualified Data.ByteString.Char8 as B8
|
import qualified Data.ByteString.Char8 as B8
|
||||||
|
import Data.Vector hiding ((++),map)
|
||||||
|
import Data.Word (Word8)
|
||||||
|
|
||||||
import Data.Attoparsec
|
import Data.Attoparsec
|
||||||
|
|
||||||
import Scene.Parser
|
import Scene.Parser
|
||||||
import Scene.Types
|
import Scene.Types
|
||||||
|
|
||||||
|
import Debug.Trace
|
||||||
|
|
||||||
findCamera :: [ObjectParser] -> Either String Camera
|
findCamera :: [ObjectParser] -> Either String Camera
|
||||||
findCamera [] = Left "No camera found"
|
findCamera [] = Left "No camera found"
|
||||||
findCamera (a:as) = case a of
|
findCamera (a:as) = case a of
|
||||||
@ -50,8 +54,9 @@ filterObjects (a:as) = case a of
|
|||||||
OpP p -> P p:filterObjects as
|
OpP p -> P p:filterObjects as
|
||||||
_ -> filterObjects as
|
_ -> filterObjects as
|
||||||
|
|
||||||
validateScene :: [ObjectParser] -> Either String Scene
|
validateAndParseScene :: B8.ByteString -> Either String Scene
|
||||||
validateScene obs = do
|
validateAndParseScene f = do
|
||||||
|
obs <- parseScene f
|
||||||
cam <- findCamera obs
|
cam <- findCamera obs
|
||||||
depth <- findDepth obs
|
depth <- findDepth obs
|
||||||
amb <- findAmbience obs
|
amb <- findAmbience obs
|
||||||
@ -67,21 +72,30 @@ validateScene obs = do
|
|||||||
, sceneObjects = objects
|
, sceneObjects = objects
|
||||||
}
|
}
|
||||||
|
|
||||||
render :: Scene -> Image PixelRGB8
|
render :: Int -> Int -> Scene -> Int -> PixelRGB8
|
||||||
render s = generateImage pixelRenderer 250 300
|
render w h s index = trace (show (x,y)) PixelRGB8 255 (fromIntegral x) (fromIntegral y)
|
||||||
where pixelRenderer x y = PixelRGB8 128 128 128
|
where
|
||||||
|
y = index `mod` w
|
||||||
|
x = index `div` w
|
||||||
|
|
||||||
|
data Ray = Ray (V3 Float) (V3 Float)
|
||||||
|
|
||||||
|
data Collision = Collision (V3 Float) Float Collidable
|
||||||
|
|
||||||
|
intersect :: Ray -> Collidable -> Maybe Collision
|
||||||
|
intersect (Ray ro rd) (S (Sphere sc sr _) = undefined
|
||||||
|
intersect _ = undefined
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
f <- B.readFile "scenes/test.sce"
|
f <- B.readFile "scenes/test.sce"
|
||||||
rawScene <- return $ parseScene f
|
case validateAndParseScene f of
|
||||||
case rawScene of
|
|
||||||
Left error -> putStrLn $ "error Parsing: " ++ error
|
|
||||||
Right raw -> do
|
|
||||||
scene <- return $ validateScene raw
|
|
||||||
case scene of
|
|
||||||
Left error -> putStrLn $ "Error: " ++ error
|
Left error -> putStrLn $ "Error: " ++ error
|
||||||
Right s -> do
|
Right s -> do
|
||||||
|
let (w,h) = (width . sceneCamera $ s, height . sceneCamera $ s)
|
||||||
|
imdata = map (render w h s) [0..w*h-1]
|
||||||
|
imvec = fromList imdata
|
||||||
|
im = generateImage (\x y -> imvec ! (x*w+y)) w h
|
||||||
print s
|
print s
|
||||||
im <- return $ render s
|
print (w,h)
|
||||||
writePng "out.png" im
|
writePng "out.png" im
|
||||||
|
Loading…
Reference in New Issue
Block a user