Guest User

img_mod_mod.slang

a guest
Jul 7th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | Source Code | 0 0
  1. #version 450
  2.  
  3. // Modular Image Adjustment
  4. // Author: hunterk
  5. // License: Public domain
  6.  
  7. layout(push_constant) uniform Push
  8. {
  9. vec4 SourceSize;
  10. uint FrameCount;
  11. vec4 OutputSize;
  12. } registers;
  13.  
  14. layout(std140, set = 0, binding = 0) uniform UBO
  15. {
  16. mat4 MVP;
  17. #include "../include/img/param_floats.h"
  18. } global;
  19.  
  20. #include "../include/img/helper_macros.h"
  21.  
  22. /////////////////////////////// INCLUDES ////////////////////////////////
  23. // comment the #include and corresponding line to remove functionality //
  24. /////////////////////////////////////////////////////////////////////////
  25.  
  26. // Flip image vertically or horizontally
  27. // #include "../include/img/image_flip.h"
  28.  
  29. // Stretching, Zooming, Panning
  30. // #include "../include/img/stretch_zoom_pan.h"
  31.  
  32. // Film grain effect
  33. #include "../include/img/film_grain.h"
  34.  
  35. // Sharp, antialiased pixels; use with linear filtering
  36. // #include "../include/img/sharpening.h"
  37.  
  38. // Saturation and Luminance
  39. //#include "../include/img/sat_lum.h"
  40. // #include "../include/img/lum_chrom.h"
  41.  
  42. // Gamma correction
  43. // exp_gamma is basic pow function
  44. //#include "../include/img/exp_gamma.h"
  45. // #include "../include/img/gamma_srgb.h"
  46.  
  47. // Mask edges to hide unsightly garbage
  48. #include "../include/img/border_mask.h"
  49.  
  50. // Change the whitepoint to warmer/cooler
  51. // #include "../include/img/white_point.h"
  52.  
  53. // Add a phosphor mask effect onto the image
  54. // #include "../include/img/subpx_masks.h"
  55.  
  56. // Force integer scaling and custom aspect ratio
  57. #include "../include/img/int_ar.h"
  58.  
  59. // Vignette; Darkens image around edges
  60. //#include "../include/img/vignette.h"
  61.  
  62.  
  63. // Black level
  64. // uncomment only one of the next 2 lines to set black level method
  65. //#include "../include/img/black_lvl.h"
  66. // #include "../include/img/black_lvl_dogway.h"
  67.  
  68. // Brightness and Contrast control
  69. // uncomment only one of the next 2 lines to set contract complexity;
  70. // sigmoidal_con is advanced, bright_con is basic
  71. // #include "../include/img/sigmoidal_con.h"
  72. //#include "../include/img/bright_con.h"
  73.  
  74. // Adjust color balance and tint
  75. // uncomment only one of the next 2 lines to set color channel complexity;
  76. // color mangler is advanced, channel mixer is basic
  77. //#include "../include/img/col_mangler.h"
  78. // #include "../include/img/channel_mix.h"
  79.  
  80. // 2D screen curvature
  81. //#include "../include/img/gristle_warp.h"
  82. //#include "../include/img/lottes_warp.h"
  83. // #include "../include/img/cgwg_warp.h"
  84.  
  85. // Rounded corners
  86. #include "../include/img/corner.h"
  87.  
  88. ////////////////////////////// END INCLUDES //////////////////////////////
  89.  
  90. #pragma stage vertex
  91. layout(location = 0) in vec4 Position;
  92. layout(location = 1) in vec2 TexCoord;
  93. layout(location = 0) out vec2 vTexCoord;
  94.  
  95. void main()
  96. {
  97. vec4 pos = Position;
  98.  
  99. // apply axis flip
  100. pos = flip_pos(pos);
  101.  
  102. gl_Position = global.MVP * pos;
  103.  
  104. vec2 coord = TexCoord.st;
  105.  
  106. // apply crop/zoom/pan
  107. coord = crop_zoom_pan(TexCoord);
  108.  
  109. // apply integer scaling and aspect ratio
  110. // coord = int_ar(coord, registers.SourceSize, registers.OutputSize);
  111.  
  112. vTexCoord = coord;
  113. }
  114.  
  115. #pragma stage fragment
  116. layout(location = 0) in vec2 vTexCoord;
  117. layout(location = 0) out vec4 FragColor;
  118. layout(set = 0, binding = 2) uniform sampler2D Source;
  119.  
  120. //////////////////////////////// LUTS ///////////////////////////////////
  121. // Use either 1 or 2 color-grading LUTs
  122. // uncomment only one of the next 2 lines
  123. //#include "../include/img/lut1.h"
  124. //#include "../include/img/lut2.h"
  125. ////////////////////////////// END LUTS /////////////////////////////////
  126.  
  127. void main()
  128. {
  129. // declare texture coordinates
  130. vec2 coord = vTexCoord.xy;
  131.  
  132. // apply sharpening to coords
  133. // coord = sharp(vTexCoord, registers.SourceSize);
  134.  
  135. // apply screen curvature
  136. // coord = warp(coord);
  137.  
  138. // sample the texture
  139. vec3 res = texture(Source, coord).rgb;
  140.  
  141. // apply grain (expects to run in gamma space)
  142. // res = luma_grain(res, vTexCoord.xy, ia_GRAIN_STR, registers.FrameCount);
  143. res = rgb_grain(res, vTexCoord.xy, ia_GRAIN_STR, registers.FrameCount);
  144.  
  145. // saturation and luminance (expects to run in gamma space)
  146. // res = sat_lum(res);
  147.  
  148. // contrast
  149. // res = cntrst(res);
  150.  
  151. // apply first gamma transform (linearize)
  152. // (whether LUT or gamma should come first depends on LUT)
  153. // res = gamma_in(res);
  154.  
  155. // apply LUT1
  156. // res = lut1(res);
  157.  
  158. // apply white point adjustment
  159. // res = white_point(res);
  160.  
  161. // black level
  162. // res = black_level(res);
  163.  
  164. // channel mix
  165. // res = channel_mix(res);
  166.  
  167. // overscan mask
  168. res = border_mask(res, coord.xy);
  169.  
  170. // apply LUT2 (whether LUT or gamma should come first depends on LUT)
  171. // res = lut2(res);
  172.  
  173. // apply gamma curve
  174. // res = gamma_out(res);
  175.  
  176. // apply mask effect
  177. // res *= mask_weights(gl_FragCoord.xy, mask_strength, mask);
  178.  
  179. // apply vignette effect
  180. // res = vignette(res, vTexCoord.xy);
  181.  
  182. // apply rounded corners
  183. res *= corner(coord);
  184.  
  185. FragColor = vec4(res, 1.0);
  186. }
  187.  
Advertisement
Add Comment
Please, Sign In to add comment