Solving 3D Problems With F#
Olya Samusik | @w0lya | w0lya.s@gmail.com
Agenda
3D basics
Vertex a point in the 3D space (x, y, z)
Edge a line connecting two points
Face a surface defined by at least 3 points
(aka polygon)
Wireframe a shape consisting of vertices
and edges
Mesh a set of polygons forming a shape
Magic of Matrices
Representing Objects
Placing Objects: Coordinates
3D basics - continued
Graphics Pipeline
Geometry Pipeline
Rendering Pipeline
(*) - Programmable. Languages: GLSL / HLSL / Cg …
Shader Examples
Shader Pipeline
Alternative approach: Raytracing
Very realistic resulting images
GPUs
Forms:
Challenges besides 3D rendering
Domains: Game Development
Domains: Movie Making
Domains: All Kinds of Design
Domains: Architecture, Landscape Design
Domains: Medical, Scientific - All Kinds of Visualizations
Also, pretty much anything can be 3D Printed
VR / AR / MR
3D Graphics (Development) Challenges
Technical
Organizational
Can F# help to address (at least some of) these?
Prototyping
Prototyping - continued
Prototyping - pattern matching
Here and in the previous 2 slides: great examples from Beginning F# book by Robert Pickering
Taking it all to a higher level - a 3D DSL!
A sample made by Tomas Petricek using his OpenGL-based Fun3D library.
See the full demo here.
Shaders in F#
Diffuse shader. Computes the general color of a material when light shines on it. Thanks to SharpShaders.
Interactive and interop example: Quake 3 to F#
Will Smith, a.k.a. @TIHan, attempted porting Quake 3 to F#.
Interactive Scripting - 3D Geometry of Abu-Dhabi
Goswin Rothenthal, Architect, used F# to represent and organize all the cladding elements of the Abu-Dhabi Dome.
Running F# in Tsunami IDE inside Rhino
3D Model Manipulation with F# for real-time rendering on mobile
Wael El Oraiby has chosen F# for 3D graphics dev and never regretted it. His Talk at F# Exchange 2018
F# look at Shaders
F# and Augmented Reality
The magic of Xamarin, ARKit and F#
Graphics tools: where is F# scripting possible?
3D Modelling
CAD Software
3Ds Max | MAXScript |
MAYA | MEL, Python, C++ |
Blender | Python |
AutoCAD | LISP routines (?!); F# - possible |
FreeCAD | Python |
Rhino3D | RhinoScript, C++, Python; F# - go here or ask Goswin |
Integration of Graphics libraries & tools with F#
General 3D Graphics
OpenGL | OpenTK (C# bindings available), sample in F# |
Open Scene Graph | Can either try PInvoke or SWIG |
DirectX / Direct3D | Supported |
Vulkan | .NET bindings available |
Unity | Somewhat supported but no native support officially. However, F# Unity Kit is available. F# + Unity Tutorial. UnityScript deprecated, so no JS option. |
Unreal | Officially possible thanks to MonoUE. Also, web integration (Unreal.js via Fable bindings) is possible. |
Urhosharp | |
RayLib | C# bindings currently available, need to try F# :) |
MonoGame |
Game Development
Graphics with F# on the Web
How to call JS graphics libraries from F#? Through Fable bindings.
F#, 3D Graphics and Fable - example
Generating a Terrain using Three.js, WebGL and a Perlin Noise generator lib.
Summary. Which challenges can F# help to solve?
| Interactive REPL and F#’s expressiveness: data types, composing, creating DSLs F# ‘tricks’ you into creating code where you can see the data / transformation flow clearly. |
| Functional approach itself helps. Not covered here but Functional Reactive Programming style for graphics or game development is very promising. A FRP game engine has been developed by Bryan Edds in F#! Check it out |
| Scenes: F# interactive helps Shaders: write shaders in F#, transpile to shader languages. Try FShade or SharpShaders. Unit testing and friendly IDEs as a bonus. |
| Being able to easily prototype will help Nicely written domain logic could help to communicate complex things |
Bonus: a much, much better refactoring and maintenance experience.
3D & Gamedev in F#: 3D Graphics Programming and Game Development in F#
Apps and Games in F#: Guide - Mobile App and Game Programming with F#
Graphics & GameDev in other FP languages: Functional Programming In Games
General Computer Graphics Resources: Awesome Graphics
General Game Development Resources: Awesome Gamedev
Useful Resources
The end.
Questions?