Advertisement
Guest User

Untitled

a guest
Jun 11th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type canvas_item;
  2.  
  3. uniform sampler2D palette; // The palette texture.
  4. uniform float shift; // The shift amount on the palette texture.
  5.  
  6.  
  7. // Rounds a value.
  8. float roundval(float value){
  9.     float frac = value - floor(value);
  10.     float result;
  11.    
  12.     if(frac  < 0.5) { result = floor(value); }
  13.     if(frac >= 0.5) { result = ceil(value); }
  14.    
  15.     return result;
  16. }
  17.  
  18. void fragment()
  19. {
  20. vec4 pixcol;
  21. // The pixel coordinate being operated on.
  22. vec2 pixpos = SCREEN_UV;
  23.  
  24. float over_x = ceil(UV.x * 16.0);
  25. float over_y = ceil(UV.y * 16.0);
  26.  
  27. // Get dither pixel
  28. vec2 overlayCoord = vec2(over_x, over_y);
  29. // Get 1 or 0 based on the pixel location.
  30. float overlayPixelColor = mod(overlayCoord.x + overlayCoord.y, 2.0);
  31. // Dither is black and white every other pixel.
  32. vec4 overlayPixel = vec4(overlayPixelColor, overlayPixelColor, overlayPixelColor, 1);
  33.  
  34. // Get base color.
  35. pixcol = vec4(texture(SCREEN_TEXTURE, SCREEN_UV).rgb, 0);
  36.  
  37. // Mix dither texture.
  38. pixcol = mix(pixcol, overlayPixel, 0.1);
  39.  
  40. // Determine the brightness of the pixel in a dumb way.
  41. float gray = (pixcol.r + pixcol.g + pixcol.b) / 3.0;
  42.  
  43. // Round it to the nearest 0.25.
  44. gray = roundval(gray / 0.25) * 0.25;
  45.  
  46. // Map the palette to the pixel based on the brightness and shift.
  47. pixcol = texture(palette, vec2(gray, shift));
  48.  
  49. // Multiply through the gl_Color for final output.
  50. COLOR = pixcol;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement