Advertisement
Guest User

Untitled

a guest
Nov 20th, 2021
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 450
  2.  
  3. /*
  4.     by Rere
  5.     license: public domain
  6. */
  7.  
  8. layout(push_constant) uniform Push
  9. {
  10.     vec4 SourceSize;
  11.     vec4 OriginalSize;
  12.     vec4 OutputSize;
  13.     uint FrameCount;
  14.     float thickness;
  15.     float glow;
  16.     float sGamma;
  17.     float tGamma;
  18.     float highlights;
  19.     float boost;
  20. } params;
  21.  
  22. #pragma parameter thickness  "Scanline thickness"        0.50 0.00 1.00 0.01
  23. #pragma parameter glow       "Scanline glow"             0.75 0.00 1.00 0.01
  24. #pragma parameter highlights "Scanline highlights"       0.75 0.00 1.00 0.01
  25. #pragma parameter boost      "Luminance boost"           0.25 0.00 1.00 0.01
  26. #pragma parameter sGamma     "Source gamma"              2.40 1.00 3.00 0.01
  27. #pragma parameter tGamma     "Target gamma"              2.20 1.00 3.00 0.01
  28.  
  29. layout(std140, set = 0, binding = 0) uniform UBO
  30. {
  31.     mat4 MVP;
  32. } global;
  33.  
  34. #define pi 3.141592654
  35. #define luminance(c) (0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b)
  36.  
  37. vec3 gammaFn(vec3 c, float gamma) {
  38.   return vec3(pow(c.x, gamma), pow(c.y, gamma), pow(c.z, gamma));
  39. }
  40.  
  41. #pragma stage vertex
  42. layout(location = 0) in vec4 Position;
  43. layout(location = 1) in vec2 TexCoord;
  44. layout(location = 0) out vec2 vTexCoord;
  45. layout(location = 1) out float thickness;
  46. layout(location = 2) out float glow;
  47. layout(location = 3) out float highlights;
  48. layout(location = 4) out float boost;
  49.  
  50. void main()
  51. {
  52.    gl_Position = global.MVP * Position;
  53.    vTexCoord = TexCoord;
  54.    thickness = 0.5 + mix(0.0, 2.0, params.thickness);
  55.    glow = mix(-0.5, 0.5, params.glow);
  56.    highlights = mix(0.0, 1.0, params.highlights);
  57.    boost = mix(0.0, 5.0, params.boost);
  58. }
  59.  
  60. #pragma stage fragment
  61. layout(location = 0) in vec2 vTexCoord;
  62. layout(location = 1) in float thickness;
  63. layout(location = 2) in float glow;
  64. layout(location = 3) in float highlights;
  65. layout(location = 4) in float boost;
  66. layout(location = 0) out vec4 FragColor;
  67. layout(set = 0, binding = 2) uniform sampler2D Source;
  68.  
  69. void main()
  70. {
  71.     vec2 uv = vTexCoord.xy;
  72.     vec3 col = texture(Source, uv).rgb;
  73.     col = gammaFn(col, params.sGamma);
  74.     float L = luminance(col);
  75.     float y = fract(uv.y * params.SourceSize.y * 1.0);
  76.     y = pow(sin(y * pi), thickness);
  77.     y = (y + glow) / (1.0 + glow);
  78.     float g = 1.0 + L * (1.0 - L) * boost;
  79.     col = mix(col, col * g * y, 1.0 - L * highlights);
  80.     FragColor = vec4(gammaFn(col, 1.0 / params.tGamma), 1.0);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement