Vertex Shader
varying vec2 pos;
void main(void) {
pos = vec2(gl_Vertex.xy);
gl_Position = ftransform();
}
Fragment Shader
uniform sampler2D image;
uniform sampler3D lookup;
uniform float imageWidth;
uniform float imageHeight;
varying vec2 pos;
void main(void)
{
//find the texture coordinate corresponding to this fragment
vec2 texCoord = vec2(pos.x/imageWidth, pos.y/imageHeight);
//get the corresponding color
vec4 colorIn = texture2D(image, texCoord);
//apply look up tables
vec4 colorOut;
colorOut.rgb = texture3D(lookup, colorIn.rgb).rgb;
//final color
gl_FragColor = colorOut;
}
Multitexturing
glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, imageName); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_3D, lutName);
Set Texture in Shader Program
texLoc = glGetUniformLocation(programObj, "image"); glUniform1i(texLoc, 0); //texture0 texLoc = glGetUniformLocation(programObj, "lookup"); glUniform1i(texLoc, 1); //texture1
Note:
- Test in orthographic mode is more easier
- Easy GLUT base code
- Easy GLSL wrapper
- Good OpenGL book RedBook and OrangeBook