Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a function that returns an array in glsl es (version 100)

The following shader method:

float[1] GetArray()
{
    float array[1];
    array[0] = 1.0;
    return array;
}

Gives me: ERROR: 0:1: 'GetArray' : syntax error: Array size must appear after variable name

like image 936
SeismicSquall Avatar asked Dec 01 '15 21:12

SeismicSquall


1 Answers

I found a way to work around this limitation. You can return an array by modifying the passed in array by reference. Here is a sample fragment shader:

void GetArray(inout vec4 array[1])
{
    array[0] = vec4(.5,.2,.1,1.0);
} 

void main()
{
    vec4 test[1];
    GetArray(test);
    gl_FragColor = test[0];
}
like image 121
SeismicSquall Avatar answered Oct 12 '22 12:10

SeismicSquall