Skip to content

Instantly share code, notes, and snippets.

@SheatNoisette
Last active June 5, 2020 13:04
Show Gist options
  • Save SheatNoisette/29dbdb2095ae96ff200450fd6add7af0 to your computer and use it in GitHub Desktop.
Save SheatNoisette/29dbdb2095ae96ff200450fd6add7af0 to your computer and use it in GitHub Desktop.
Gameboy shader made in shadertoy
// Simple GameBoy style shader in ShaderToy
// This require a texture/Webcam input on Channel0 in ShaderToy
// SheatNoisette (2020) - GNU GPL 3.0 Licensed
vec3 gameboy_palette[4];
vec3 gameboyify(vec3 color) {
// Create palette
gameboy_palette[0] = vec3(51, 44, 80);
gameboy_palette[1] = vec3(70, 135, 143);
gameboy_palette[2] = vec3(148, 227, 68);
gameboy_palette[3] = vec3(226, 243, 228);
// Gameboy shader
float diff = 256.;
float current_diff = 0.;
int min_index = 0;
int index;
for (index = 0; index < 4; index++) {
current_diff = sqrt(
pow((color.x) - gameboy_palette[index].x, 2.) +
pow((color.y) - gameboy_palette[index].y, 2.) +
pow((color.z) - gameboy_palette[index].z, 2.)
);
if (current_diff < diff) {
diff = current_diff;
min_index = index;
}
}
return gameboy_palette[min_index];
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Output to screen
for (int posY = -1; posY <= 1; posY++) {
for (int posX = -1; posX <= 1; posX++) {
float x = (fragCoord.x + float(posX))/iResolution.x;
float y = (fragCoord.y + float(posY))/iResolution.y;
fragColor.xyz = gameboyify(texture( iChannel0, vec2(x, y)).xyz * 255.) / 255.;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment