Skip to content
Johan Verwey edited this page May 24, 2018 · 67 revisions

SharpShaders - A library for crafting GPU shaders in F#.

ColoredCube Golfball Marbled Lumpy Crinkled

Why write shaders in F#?

Examples

Limitations

SharpShaders is still in its infancy and there are many F# features which cannot be translated to HLSL yet. Keep in mind though that the hardware architecture of GPUs have some limitations of its own. Even something as simple as an if then else statement is expensive on GPUs. For this reason, advanced F# features such as such as pattern matching will probably not be supported any time soon.

Future Work

  • Runtime code compilation
    • It should be possible to edit an F# shader and immediately see the result at runtime.
  • Geometry, Hull, Domain, Compute Shaders
  • Translate tail recursive functions into while statements.
  • Dynamic Shader Linking
    • The Dynamic attribute on shader functions should indicate that this function can be swapped at runtime
let marble = ...
let lumpy = ...
let crinkled = ...

[<Dynamic>]
member m.surface = marble

[<PixelShader>]
member m.pixel(input:PSInput) =
    surface input

At runtime the surface shader can be swapped:

ps.surface <- ps.crinkled