Passing an array as parameter to shader

Hi,

There is any way to pass an array as a parameter to a shader? I need to pass an array of vec3, but I could not make it work.

Thanks!

Does it work if you specify a matrix type? A matrix should be a set of multiple vec types

http://api.openfl.org/openfl/display/ShaderParameterType.html

I could not, I even tried to pass a float array but all the values are 0 within the shader.

How should I pass the parameters? I tried:

var param:ShaderParameter<Array> = new ShaderParameter<Array>();

How can I set the ShaderParameterType.MATRIX3X3?

Ah, I forgot. We parse your GLSL shader source code, and generate a Shader instance based on that. As a result, it works something like…

Shader

attribute vec4 myVec;

Parameter

shader.data.myVec = [ 0, 1, 2, 3 ];

I think it’s possible it would work like this, then, for matrices

Shader

attribute mat4 myMat4;

Parameter

shader.data.myMat4 = [ 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 ];

Here is where we parse the GLSL source to assign parameter types:

Mmmm I can´t make that work. This feature is avalable for all platforms? I’m porting to HTML5.

To my knowledge, it should work for HTML5 as well as other targets. We use for our core display shader internally.

However, it is possible to define GLSL shaders using shader.glFragmentSource = "(source)"; as well as extending openfl.display.Shader and using @:glFragmentSource in meta-data. Using the meta-data / extended class approach allows this macro to run, so perhaps that is necessary for this to work as intended.

I can not make it work with either of the two approaches :frowning:

Hello!
I wonder if this attribute functionality works just like uniforms in OpenFL (I used uniforms successfully, but consider attributes too)? So it’s not possible to provide different attribute values per different sprites in drawQuads? :thinking:
Or does one need to create a separate shader per sprite with custom attributes, which would be still weird?

Custom shader uniform:

shader.uMyInt.value = [ 1 ];

Custom shader attribute (treated as a uniform):

shader.aMyInt.value = [ 1 ];

Custom shader attribute:

shader.aMyInt.value [ 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, ... ];

One value only if you are making it constant, or four values (one for each vertex) on drawQuads, or one for each vertex if you are using drawTriangles

2 Likes

Thank you, that makes sense now!

So it figures out automatically based on how many values I pass or how it’s declared in shader code?
And what about the “shader.data.NAME” mentioned above? Is it deprecated now in favour of using “shader.NAME.value” for everything?

I think both work, but one is strongly typed

1 Like