Inventory management focused game written in Godot / C#
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
1010 B

shader_type spatial;
uniform sampler2D palette : filter_nearest;
uniform sampler2D albedo_texture : filter_nearest;
uniform float min_brightness = 0.0; // This is calculated for the
uniform float max_brightness = 1.0; // provided albedo texture.
// vec3 rgb2hsv(vec3 c) {
// vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
// vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
// vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
//
// float d = q.x - min(q.w, q.y);
// const float e = 1.0e-10;
// return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
// }
void fragment() {
ivec2 size = textureSize(palette, 0);
vec3 color = texture(albedo_texture, UV).rgb;
float brightness = max(color.r, max(color.g, color.b));
brightness = (brightness - min_brightness) / (max_brightness - min_brightness);
float palette_u = (0.5 + (brightness * float(size.r - 1))) / float(size.r);
ALBEDO = texture(palette, vec2(palette_u, 0.5)).rgb;
}