elm-explorations / webgl

Functional rendering with WebGL in Elm
https://package.elm-lang.org/packages/elm-explorations/webgl/latest/
BSD 3-Clause "New" or "Revised" License
117 stars 17 forks source link

Workaround for uniform array type inference failure #37

Open costructuralist opened 3 years ago

costructuralist commented 3 years ago

I have the following Elm type for uniforms:

type alias Uniforms = { cellColors : List Vec3 }

In a vertex shader I have the following declaration for an array of vec3 uniform:

uniform vec3 cellColors[9];

The GLSL parser, however, is inferring/parsing the type of the cellColors variable to be Vec3, and not Array Vec3.

It seems as if this is a bug in the underlying GLSL parsing library: https://github.com/noteed/language-glsl/issues/19

Is there a way to work around this bug?

w0rm commented 3 years ago

Hi. Array uniforms are not supported in the elm compiler. This is not a bug, but a missing feature. The supported shader types are listed in the package docs: Int, Float, Texture and Vec2, Vec3, Vec4, Mat4 from the linear-algebra package.

This bit in the compiler derives the type signature for shaders https://github.com/elm/compiler/blob/master/compiler/src/Parse/Shader.hs#L170

w0rm commented 3 years ago

Maybe you could use a few Mat4 uniforms to pass the same amount of data.

Or a texture image, if the data is constant