I was able to get a very very similar shader working on LibGDX some months back. This being my very second shader ever, I'm not sure what could be wrong.
I have verified my palette texture is filled with the colors I want to use as a lookup.
I have verified that the current rendering canvas, without the shader applied, is monochrome red (all shades of 0 to 1 in the red component. as you can see from the shader code, this is used to look up the color to replace with).
Yet, the pixels are all white, or all black.
I'm thinking there must be something with the underlying opengl system that I do not understand that is affecting the behavior of the shader. For example, I do not understand why I have to do a setColor(1, 1, 1) right before my last setCanvas() in order to see the colors as I drew them (without the shader applied).
Code: Select all
uniform sampler2D u_paletteTexture;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
{
vec4 pixelColor = texture2D(texture, texture_coords);
float paletteIndex = pixelColor.r;
vec2 paletteTextureCoords = vec2(paletteIndex, 0);
vec3 outputPixelColor = texture2D(u_paletteTexture, paletteTextureCoords).rgb;
return vec4(outputPixelColor,pixelColor.a);
}