Advertisement
Nefrace

Untitled

May 18th, 2025
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 330
  2.  
  3. // Input vertex attributes (from vertex shader)
  4. in vec3 fragPosition;
  5. in vec2 fragTexCoord;
  6. in vec4 fragColor;
  7. in vec3 fragNormal;
  8.  
  9. // Input uniform values
  10. uniform sampler2D texture0; // Screen texture
  11. uniform sampler2D texture1; // Palette
  12. uniform vec4 colDiffuse;
  13.  
  14. out vec4 finalColor;
  15.  
  16. const int bayer16[16] = int[16](0,  8,  2,  10,
  17.                                 12, 4,  14, 6,
  18.                                 3,  11, 1,  9,
  19.                                 15, 7,  13, 5);
  20.  
  21.  
  22. void main() {
  23.     vec4 texelColor = texture(texture0, fragTexCoord);
  24.     float grey = 0.21 * texelColor.r + 0.71 * texelColor.g + 0.07 * texelColor.b;
  25.     int col = int(mod(gl_FragCoord.x, 4));
  26.     int row = int(mod(gl_FragCoord.y, 4));
  27.     float threshold = float(bayer16[col + 4 * row]) / 16.0 - 0.5;
  28.     grey = clamp(grey + threshold * 0.1 , 0.01, 0.99); // Apply bayer pattern to the color
  29.  
  30.     vec2 paluv = vec2(grey, 0.5);
  31.     vec4 paletteValue = texture(texture1, paluv);
  32.     finalColor.a = 1.0;
  33.     finalColor.rgb = paletteValue.rgb;
  34. }
  35.  
  36.  
Tags: glsl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement