Advertisement
Zunesha

Shader Pallet Swap Godot 4 (ColorRect)

Sep 11th, 2024
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 1.51 KB | Gaming | 0 0
  1. Shader Pallet Swap  Godot 4 (ColorRect)
  2.  
  3. shader_type canvas_item;
  4.  
  5. uniform vec4 whiteColor : source_color = vec4(0.961, 0.980, 0.937, 1.0);
  6. uniform vec4 lightGreyColor : source_color = vec4(0.549, 0.749, 0.039, 1.0);
  7. uniform vec4 darkGreyColor : source_color = vec4(0.18, 0.451, 0.125, 1.0);
  8. uniform vec4 blackColor : source_color = vec4(0.0, 0.247, 0.0, 1.0);
  9. uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
  10.  
  11. float min4(float a, float b, float c, float d){
  12.     return min(a, min(b, min(c, d)));
  13. }
  14.  
  15. void fragment(){
  16.     vec4 currentColor = texture(SCREEN_TEXTURE, SCREEN_UV);
  17.    
  18.     float blackDistance = distance(currentColor, vec4(vec3(0.0), 1.0));
  19.     float whiteDistance = distance(currentColor, vec4(vec3(1.0), 1.0));
  20.     float lightGrayDistance = distance(currentColor, vec4(vec3(0.666, 0.666, 0.666), 1.0));
  21.     float darkGrayDistance = distance(currentColor, vec4(vec3(0.333, 0.333, 0.333), 1.0));
  22.    
  23.     if (
  24.         whiteDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)
  25.     )
  26.     {
  27.         COLOR = whiteColor;
  28.     }
  29.     else if (
  30.         blackDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)
  31.     )
  32.     {
  33.         COLOR = blackColor;
  34.     }
  35.     else if (
  36.         darkGrayDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)
  37.     )
  38.     {
  39.         COLOR = darkGreyColor;
  40.     }
  41.     else if (
  42.         lightGrayDistance == min4(whiteDistance, lightGrayDistance, darkGrayDistance, blackDistance)
  43.     )
  44.     {
  45.         COLOR = lightGreyColor;
  46.     }
  47.     else{
  48.         COLOR = whiteColor;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement