Array of Structs
Is it possible to simulate or create an Arr of a product type?
type Shape =
{ctr : V3d; size : V2d; _type : int}
let shapes : Arr<4 N, Shape> = Arr.ofList([{ ctr = V3d(0.2, 0.0, 0.0); size = V2d(0.3, 0.0); _type = 1}]); // size = V2d(0.3, 0.0); _type = Sphere} ])
for shape in shapes do
texColor.Y <- shape.size.X
Gives
Unhandled exception. System.Exception: [FShade] encountered recursive type Microsoft.FSharp.Collections.FSharpList`1[Program+Shape]
Is there a way to use an f-sharp list and unroll it in the glsl, or the like?
Hey, yes that should be possible, as long as you use array literals (instead of lists) if memory serves.
In that case the Arr wrapping should be unnecessary, since FShade will turn the array into a constant.
Another option would be to create an Arr using Unchecked.defaultof<_> as initial value and then set the elements via mutation.
I would like to contribute to the documentation and with an example, but I have been struggling due to #17 and some obscure runtime exceptions. For example, if I attempt to initialize an Arr like Arr([1.0, 2.0]) but forget to annotate with a type, I get a runtime exception about INatural being invalid. I am trying to track these as I go.
But I can initialize arrays, and I found IntrinsicFunctions.fs which helps with #17. I'm not sure I get what's going on though. These seem to be overriding the functions in Aardvark.Base.Fun. But....
-
Is there a way to import only those functions which are actually defined for FShade? (for example,
stepis not defined, but is in Aardvar.Base.Fun). -
How would I go about adding a function? Either one which is built-in, or one which I include from a glsl library. I would like to add the
stepfunction, which I assume is not in their because Aardvark has astepfunction with a different meaning and type signature.
Is there a way to import only those functions which are actually defined for FShade? (for example, step is not defined, but is in Aardvar.Base.Fun).
Sadly not atm. but this would certainly make sense. maybe a new namespace FShade.Base re-exporting all the available functions could help there.
How would I go about adding a function? Either one which is built-in, or one which I include from a glsl library. I would like to add the step function, which I assume is not in their because Aardvark has a step function with a different meaning and type signature.
Adding an intrinsic function can be done via the GLSLIntrinsic attribute like:
[<GLSLIntrnsic("mix({0}, {1}, {2})")>]
let mix (a : float) (b : float) (t : float) : float = onlyInShaderCode "mix"
Hope that helps.