faculaganymede
03-16-2005, 01:12 PM
Shader Experts.
I am trying to implement a fragment shader that converts the texture RGB to intensity using a look-up table:
RGB -> fragment shader (use look-up table) -> intensity
Note: the intensity value need to be mapped from the look-up table (i.e. it should not be computed in the shader with something like 0.299 * R + 0.587 * G + 0.114 * B).
The look-up table needs to be a 3D array for the 3 color components (i.e. tbl[R][G][B]=intensity). This is what I had in mind of going about it:
1. In application program -> create look-up table -> float tbl[256][256][256]
2. In application program -> call shader programs
3. In fragment shader program -> read look-up table
4. In fragment shader program -> get texture RGB
5. In fragment shader program -> do intensity look-up -> gl_FragColor = intensity
So, I'll need a 3D array variable in the shader program. But, from what I learned, GLSL seems to only support 1D arrays. If I do something like this:
uniform float tbl[256][256][256];
I get a compiler error:
Ready for GLSL
ERROR: 0:4: '[' : syntax error parse error
Link failed. All shader objects have not been successfully compiled."
I came up with another idea, which is to use a sampler2D or sampler3D variable to store the look-up table data, but accessing the data inside the shader seem cumbersome. Does anyone have a better idea?
I am trying to implement a fragment shader that converts the texture RGB to intensity using a look-up table:
RGB -> fragment shader (use look-up table) -> intensity
Note: the intensity value need to be mapped from the look-up table (i.e. it should not be computed in the shader with something like 0.299 * R + 0.587 * G + 0.114 * B).
The look-up table needs to be a 3D array for the 3 color components (i.e. tbl[R][G][B]=intensity). This is what I had in mind of going about it:
1. In application program -> create look-up table -> float tbl[256][256][256]
2. In application program -> call shader programs
3. In fragment shader program -> read look-up table
4. In fragment shader program -> get texture RGB
5. In fragment shader program -> do intensity look-up -> gl_FragColor = intensity
So, I'll need a 3D array variable in the shader program. But, from what I learned, GLSL seems to only support 1D arrays. If I do something like this:
uniform float tbl[256][256][256];
I get a compiler error:
Ready for GLSL
ERROR: 0:4: '[' : syntax error parse error
Link failed. All shader objects have not been successfully compiled."
I came up with another idea, which is to use a sampler2D or sampler3D variable to store the look-up table data, but accessing the data inside the shader seem cumbersome. Does anyone have a better idea?