SHARE
TWEET

SpritePalettizer godot shader example

nezvers May 26th, 2020 (edited) 929 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type canvas_item;                    //2D shader
  2. render_mode unshaded, blend_disabled;       // no bells and wistles
  3. uniform sampler2D palette;                  //Use palletes in collum with colors in rows
  4. uniform float palette_count = 1.0;          //Tells the shader how many palettes you have
  5. uniform float palette_index = 0.0;          //Telss the shader which palette to choose
  6.  
  7. void fragment(){
  8.     float increment = 1.0/palette_count;                    //Value for getting palette index
  9.     float y = increment * palette_index + increment * 0.5;  // + safety measure for floating point imprecision
  10.     vec4 color = texture(TEXTURE, UV);                      //Original graysscale color used as collumn index
  11.     vec4 new_collor = texture(palette, vec2(color.r, y));   //get color from palette texture
  12.     float a = step(0.00392, color.a);                       //check if transparent color is less than 1/255 for backgrounds
  13.     new_color.a *= a;                                       //if BG is transparent, then alpha is multiplied by 0
  14.    
  15.     COLOR = new_color;                                      //set new color from palette
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top