Advertisement
Guest User

Untitled

a guest
Mar 19th, 2024
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #version 450
  2.  
  3. /*
  4. Shader Modified: Pokefan531
  5. Color Mangler
  6. Author: hunterk
  7. License: Public domain
  8. */
  9. // Shader that replicates the LCD Colorspace from Gameboy Color --
  10.  
  11. layout(push_constant) uniform Push
  12. {
  13. float lighten_screen;
  14. } params;
  15.  
  16. layout(std140, set = 0, binding = 0) uniform UBO
  17. {
  18. mat4 MVP;
  19. vec4 OutputSize;
  20. vec4 OriginalSize;
  21. vec4 SourceSize;
  22. float mode;
  23. } global;
  24.  
  25. #pragma parameter mode "Color Profile (1=sRGB, 2=DCI, 3=Rec2020)" 1.0 1.0 3.0 1.0
  26. int color_mode = int(global.mode);
  27.  
  28. #pragma parameter lighten_screen "Lighten Screen" 0.5 0.0 1.0 0.05
  29.  
  30. #define target_gamma 2.2
  31. #define display_gamma 2.2
  32.  
  33. /*
  34. We'll define our color weights in this pattern:
  35. r, rg, rb, 0.0, //red channel
  36. gr, g, gb, 0.0, //green channel
  37. br, bg, b, 0.0, //blue channel
  38. blr, blg, blb, lum //alpha channel; we'll hide lum at the end, too
  39. */
  40.  
  41. const mat4 GBC_sRGB = mat4(
  42. 0.88, 0.0725, 0.025, 0.0, //red channel
  43. 0.05, 0.6, 0.05, 0.0, //green channel
  44. -0.03, 0.35, 1.2, 0.0, //blue channel
  45. 0.0, 0.0, 0.0, 1.0 //alpha channel
  46. );
  47.  
  48. const mat4 GBC_DCI = mat4(
  49. 0.685, 0.16, 0.20, 0.0, //red channel
  50. 0.34, 0.629, 0.19, 0.0, //green channel
  51. -0.025, 0.211, 0.61, 0.0, //blue channel
  52. 0.0, 0.0, 0.0, 0.975 //alpha channel
  53. );
  54.  
  55. const mat4 GBC_Rec2020 = mat4(
  56. 0.555, 0.1825, 0.20, 0.0, //red channel
  57. 0.395, 0.61, 0.195, 0.0, //green channel
  58. 0.05, 0.2075, 0.605, 0.0, //blue channel
  59. 0.0, 0.0, 0.0, 1.0 //alpha channel
  60. );
  61.  
  62. #pragma stage vertex
  63. layout(location = 0) in vec4 Position;
  64. layout(location = 1) in vec2 TexCoord;
  65. layout(location = 0) out vec2 vTexCoord;
  66. layout(location = 1) out mat4 profile;
  67.  
  68. void main()
  69. {
  70. gl_Position = global.MVP * Position;
  71. vTexCoord = TexCoord;
  72.  
  73. if (color_mode == 1) profile = GBC_sRGB;
  74. else if (color_mode == 2) profile = GBC_DCI;
  75. else if (color_mode == 3) profile = GBC_Rec2020;
  76. }
  77.  
  78. #pragma stage fragment
  79. layout(location = 0) in vec2 vTexCoord;
  80. layout(location = 1) in mat4 profile;
  81. layout(location = 0) out vec4 FragColor;
  82. layout(set = 0, binding = 2) uniform sampler2D Source;
  83.  
  84. void main()
  85. {
  86. // bring out our stored luminance value
  87. float lum = profile[3].w;
  88.  
  89. // our adjustments need to happen in linear gamma
  90. vec4 screen = pow(texture(Source, vTexCoord), vec4(target_gamma + (params.lighten_screen * -1.0))).rgba;
  91.  
  92. screen = clamp(screen * lum, 0.0, 1.0);
  93. screen = profile * screen;
  94. FragColor = pow(screen, vec4(1.0 / display_gamma));
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement