Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JettMonstersGoBoom/89901f6cfdbf3ea215609eefb08e5da0 to your computer and use it in GitHub Desktop.
Save JettMonstersGoBoom/89901f6cfdbf3ea215609eefb08e5da0 to your computer and use it in GitHub Desktop.
4 bit source texture shader . for OpenGL
#version 130
in vec2 out_uv;
out vec4 out_0;
uniform sampler2D vramimage;
uniform sampler1D vrampalette;
void main(void)
{
vec2 uv = out_uv;
uv.x *=0.5; // force read twice.
vec4 tex = texture(vramimage, uv); // grab texel
int index = int(tex.r*255.0); // convert the index to 0x00-0xff range
int U = int(uv.x * 1024.0); // our texture is 512 so we need to double it
if ((U&1)==1) // ODD pixel
index = index & 0xf;
else // EVEN pixel
index = index>>4 & 0xf;
out_0 = texture(vrampalette,index/255.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment