Skip to content

Instantly share code, notes, and snippets.

@crearo
Last active August 11, 2018 06:09
Show Gist options
  • Save crearo/c1a68b168e530f52c830524d94962d3b to your computer and use it in GitHub Desktop.
Save crearo/c1a68b168e530f52c830524d94962d3b to your computer and use it in GitHub Desktop.
GLES shaders for look up table texture - false colorizing a greyscale image
// Simple vertex shader
private static final String VERTEX_SHADER =
"uniform mat4 uMVPMatrix;\n" +
"uniform mat4 uTexMatrix;\n" +
"attribute vec4 aPosition;\n" +
"attribute vec4 aTextureCoord;\n" +
"varying vec2 vTextureCoord;\n" +
"void main() {\n" +
" gl_Position = uMVPMatrix * aPosition;\n" +
" vTextureCoord = (uTexMatrix * aTextureCoord).xy;\n" +
"}\n";
// Fragment shader for use with external 2D textures + an lut texture
private static final String FRAGMENT_SHADER_EXT =
"#extension GL_OES_EGL_image_external : require\n" +
"precision mediump float;\n" +
"varying vec2 vTextureCoord;\n" +
"uniform samplerExternalOES sTexture;\n" +
"uniform sampler2D lutTexture;\n" +
"void main() {\n" +
" float lum = texture2D(sTexture, vTextureCoord).r;" +
" lum = clamp(lum, 0.0, 1.0);" +
" gl_FragColor = texture2D(lutTexture, vec2(lum, 0.5));\n" +
"}\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment