Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array of Structs #18

Closed
makeartandgames opened this issue Nov 13, 2020 · 3 comments
Closed

Array of Structs #18

makeartandgames opened this issue Nov 13, 2020 · 3 comments

Comments

@makeartandgames
Copy link

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?

@krauthaufen
Copy link
Owner

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.

@makeartandgames
Copy link
Author

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....

  1. 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).

  2. 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.

@krauthaufen
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants