Why does texture1d() in GLSL return a vec4?
-
29-09-2019 - |
Question
I'm trying to use a 1D array as a lookup table in my vertex shader.. so why when I call
texture1D(tex,gl_TexCoord[0].s);
does it return a vec4? I mean I know that's what it does, but what do the 4 values represent? All I want is the one value from the texture based on the coordinate.
Solution
Because the texture1D can/has RGBA values (red, green, blue, alpha). If you store the 1D texture data in the red channel (GL_RED) you can access that data with:
texture1D(tex,gl_TexCoord[0].s)
.r
;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow