views:

50

answers:

2

I have a fragment shader with the following:

const lowp float colors[8] = float[8]( // line 12
    0,0,0,1,
    1,0,0,1
);

but it fails to compile:

ERROR: 0:12: 'array of float' : array type not supported here in glsl < 120 
ERROR: 0:12: 'array of float' : constructor not supported for type 
ERROR: 0:15: 'array of float' : no matching overloaded function found 
ERROR: 0:12: 'const lowp float' : cannot declare arrays of this type 
ERROR: 0:12: 'colors' : redefinition 

How can I define a lookup table in GLSL? The input texture has values from an enum, each value of which I want to be mapped to a different color.

+1  A: 

Read the spec, section 4.1.9:

"There is no mechanism for initializing arrays at declaration time from within a shader."

genpfault
+2  A: 

You can use a 1D texture as a lookup table.

Matias Valdenegro
GLES2.0 doesn't support 1D textures, but I used a 2D texture of height 1.
nornagon