Passing an array as parameter to shader


#1

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!


#2

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


#3

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


#4

How should I pass the parameters? I tried:

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

How can I set the ShaderParameterType.MATRIX3X3?


#5

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:


#6

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


#7

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.


#8

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