Created
August 8, 2023 11:48
-
-
Save N-Carter/a5613f8fa50a40d34aab63b5ada000e8 to your computer and use it in GitHub Desktop.
A Godot 4 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. | |
// | |
// This version is for Godot 4. | |
shader_type canvas_item; | |
render_mode blend_disabled, unshaded, skip_vertex_transform; | |
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; | |
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