Skip to content

A ray tracer in F# for fun. Includes Phong lighting, soft shadows, reflections, ambient occlusion, and depth of field.

License

Notifications You must be signed in to change notification settings

afritz1/FSharpRayTracer

Repository files navigation

F# Ray Tracer

By Aaron Fritz

This particular ray tracer was a success, and currently has neat features like soft shadows, ambient occlusion, and depth of field. It's nice that the .NET framework allows simple parallelization of code with the Parallel.For function, too.

Image 4

One more thing to note is that I seem to have circular dependencies in nearly all of my ray tracers in the past, but this is the first one to have zero of them. This is in part because the Visual F# project enforces sorting files from top to bottom according to their compilation order, and it seems no forward declarations are allowed, unlike other languages. Because of this restriction, I changed my ray tracer design a bit, and I think it was for the better, though now the World type has much more of the shading code that was originally in the Material type.

About F#

F# is a functional language derived from OCaml that also allows for some imperative and object-oriented style. I really like that values are immutable by default in F#; it's a nice break from having to write const all the time in C++. Some other interesting traits of the language, like only allowing a type to be nullable if it should be nullable, are much appreciated, and they frequently lead to code being easier to prove correct. I think that, since F# and C# both compile to the same intermediate language, F# should theoretically be usable in every scenario that C# is.

If C++ can be considered "mostly imperative, and a little functional", then F# is "mostly functional, and a little imperative". It isn't always practical to write purely functional code, and it isn't always smart to write purely imperative code, so I feel F# manages to provide the most useful elements of both paradigms.

About

A ray tracer in F# for fun. Includes Phong lighting, soft shadows, reflections, ambient occlusion, and depth of field.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages