Last active
August 8, 2023 11:46
-
-
Save N-Carter/087ef2f04d898718a07e48c0d685e452 to your computer and use it in GitHub Desktop.
A Godot shader which reads the lowest four bits from the input's blue channel and uses them to pick a substitute colour from a palette texture.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reads the lowest four bits from the input's blue channel and uses them to | |
// pick a substitute colour from a palette texture. | |
// | |
// The palette texture should be 16 pixels wide and 1 pixel high, with the | |
// colours arranged with index 0 at the left and index 15 at the right. | |
shader_type canvas_item; | |
render_mode blend_disabled, unshaded, skip_vertex_transform; | |
uniform sampler2D palette; | |
void fragment() { | |
float blue = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).b; | |
int index = min(int(blue * 256.0), 255) & 0xF; | |
vec3 colour = textureLod(palette, vec2(float(index) / 16.0, 0.0), 0.0).rgb; | |
COLOR.rgb = colour; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment