Advertisement
Guest User

broken nonsense

a guest
Jun 18th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.83 KB | None | 0 0
  1. /*
  2. CRT-Champloo: by Syh
  3. Licenses: GPL, BSD-3-Clause
  4. Copyrights for BSD-3-Clause: Ryan Holtz, ImJezze
  5. Credits: Easymode, guest.r, hunterk
  6. Special Thanks To: guest.r and hunterk
  7. */
  8.  
  9. #pragma parameter TATE "[Toggle] TATE Mode: (Off/On)" 0.0 0.0 1.0 1.0
  10. #pragma parameter GAMMA_CRT "[Gamma] CRT:" 2.4 1.0 5.0 0.1
  11. #pragma parameter SCAN_STYLE "[Scanline] Style:" 1.0 0.0 2.0 1.0
  12. #pragma parameter SCAN_SHAPE "[Scanline] Shape:" 7.0 1.0 10.0 1.0
  13. #pragma parameter SCAN_EDGE_SHAPE "[Scanline] Edge Shape:" 9.0 6.0 22.0 1.0
  14. #pragma parameter SCAN_BEAM_MIN "[Scanline] Dark Strength:" 1.35 0.5 2.0 0.05
  15. #pragma parameter SCAN_BEAM_MAX "[Scanline] Light Strength:" 1.10 0.5 2.0 0.05
  16. #pragma parameter SCAN_BEAM_SIZE "[Scanline] Bright Beam Boost:" 0.65 0.0 1.0 0.05
  17. #pragma parameter h_sharp "[Display] Horizontal Sharpness:" 5.25 1.5 20.0 0.25
  18. #pragma parameter s_sharp "[Display] Subtractive Sharpness:" 0.05 0.0 0.20 0.01
  19. #pragma parameter h_smart "[Display] Horizontal Smoothing:" 0.0 0.0 1.0 0.1
  20. #pragma parameter MASK_SCALE "[Mask] Scale: (HD/4k)" 1.0 1.0 2.0 1.0
  21. #pragma parameter MASK_STYLE "[Mask] Style:" 2.0 -1.0 7.0 1.0
  22. #pragma parameter MASK_DARK "[Mask] Dark Phosphor:" 0.7 0.0 2.0 0.1
  23. #pragma parameter MASK_LIGHT "[Mask] Light Phosphor:" 1.1 0.0 2.0 0.1
  24. #pragma parameter MASK_CUT "[Mask] Style 5&6 Cutoff:" 0.2 0.0 0.5 0.05
  25. #pragma parameter SLOT_MASK "[Slot-Mask] Strength:" 0.0 0.0 1.0 0.05
  26. #pragma parameter SLOT_WIDTH "[Slot-Mask] Width:" 2.0 2.0 6.0 0.5
  27. #pragma parameter DOUBLE_SLOT "[Slot-Mask] Height: (HD/4k)" 1.0 1.0 2.0 1.0
  28. #pragma parameter BLOOM_WIDTH "[Bloom] Width:" 0.65 0.05 1.0 0.05
  29. #pragma parameter BLOOM_HEIGHT "[Bloom] Height:" 0.65 0.05 1.0 0.05
  30. #pragma parameter BLOOM_HALATION "[Bloom] Halation:" 0.10 0.0 1.0 0.01
  31. #pragma parameter BLOOM_DIFFUSION "[Bloom] Diffusion:" 0.10 0.0 1.0 0.01
  32. #pragma parameter DPS_BRIGHTNESS "[Display] Brightness:" 1.5 0.0 2.0 0.05
  33. #pragma parameter GAMMA_DISPLAY "[Gamma] Display:" 2.2 1.0 5.0 0.1
  34. #pragma parameter CURVE_CORNER "[Curvature] Corner Size:" 0.0 0.0 0.05 0.01
  35. #pragma parameter CURVE_X "[Curvature] Horizontal:" 0.0 0.0 0.125 0.01
  36. #pragma parameter CURVE_Y "[Curvature] Vertical:" 0.0 0.0 0.125 0.01
  37. #pragma parameter XFX_STATIC "[Effect] Static:" 0.0 0.0 18.0 3.0
  38. #pragma parameter XFX_HUMBAR "[Effect] Humbar:" 0.0 0.0 1.0 0.01
  39. #pragma parameter XFX_VIGNETTE "[Effect] Vignette:" 0.0 0.0 1.0 0.01
  40. #pragma parameter XFX_PVM_COLOR "[Effect] PVM-ish Color Shift:" 0.0 0.0 0.25 0.01
  41. #pragma parameter OS "R. Bloom Overscan Mode" 2.0 0.0 2.0 1.0
  42. #pragma parameter R_BLOOM "Raster bloom %" 0.0 0.0 20.0 1.0
  43.  
  44. #define Coord TEX0
  45.  
  46. #if defined(VERTEX)
  47.  
  48. #if __VERSION__ >= 130
  49. #define OUT out
  50. #define IN in
  51. #define tex2D texture
  52. #else
  53. #define OUT varying
  54. #define IN attribute
  55. #define tex2D texture2D
  56. #endif
  57.  
  58. #ifdef GL_ES
  59. #define PRECISION mediump
  60. #else
  61. #define PRECISION
  62. #endif
  63.  
  64. IN vec4 VertexCoord;
  65. IN vec4 Color;
  66. IN vec2 TexCoord;
  67. OUT vec4 color;
  68. OUT vec2 Coord;
  69.  
  70. uniform mat4 MVPMatrix;
  71. uniform PRECISION int FrameDirection;
  72. uniform PRECISION int FrameCount;
  73. uniform PRECISION vec2 OutputSize;
  74. uniform PRECISION vec2 TextureSize;
  75. uniform PRECISION vec2 InputSize;
  76.  
  77. void main()
  78. {
  79. gl_Position = MVPMatrix * VertexCoord;
  80. color = Color;
  81. Coord = TexCoord;
  82. }
  83.  
  84. #elif defined(FRAGMENT)
  85.  
  86. #if __VERSION__ >= 130
  87. #define IN in
  88. #define tex2D texture
  89. out vec4 FragColor;
  90. #else
  91. #define IN varying
  92. #define FragColor gl_FragColor
  93. #define tex2D texture2D
  94. #endif
  95.  
  96. #ifdef GL_ES
  97. #ifdef GL_FRAGMENT_PRECISION_HIGH
  98. precision highp float;
  99. #else
  100. precision mediump float;
  101. #endif
  102. #define PRECISION mediump
  103. #else
  104. #define PRECISION
  105. #endif
  106.  
  107. uniform PRECISION int FrameDirection;
  108. uniform PRECISION int FrameCount;
  109. uniform PRECISION vec2 OutputSize;
  110. uniform PRECISION vec2 TextureSize;
  111. uniform PRECISION vec2 InputSize;
  112. uniform sampler2D Texture;
  113. uniform sampler2D PassPrev3Texture;
  114. uniform sampler2D PassPrev4Texture;
  115. IN vec2 Coord;
  116.  
  117. #ifdef PARAMETER_UNIFORM
  118. uniform PRECISION float TATE;
  119. uniform PRECISION float GAMMA_CRT, GAMMA_DISPLAY, DPS_BRIGHTNESS;
  120. uniform PRECISION float h_sharp, s_sharp, h_smart;
  121. uniform PRECISION float SCAN_STYLE, SCAN_SHAPE, SCAN_EDGE_SHAPE, SCAN_BEAM_MIN, SCAN_BEAM_MAX, SCAN_BEAM_SIZE;
  122. uniform PRECISION float MASK_SCALE, MASK_STYLE, MASK_DARK, MASK_LIGHT, MASK_CUT;
  123. uniform PRECISION float SLOT_MASK, SLOT_WIDTH, DOUBLE_SLOT;
  124. uniform PRECISION float BLOOM_WIDTH, BLOOM_HEIGHT, BLOOM_HALATION, BLOOM_DIFFUSION;
  125. uniform PRECISION float CURVE_CORNER, CURVE_X, CURVE_Y;
  126. uniform PRECISION float XFX_STATIC, XFX_HUMBAR, XFX_VIGNETTE, XFX_PVM_COLOR;
  127. uniform PRECISION float OS;
  128. uniform PRECISION float R_BLOOM;
  129. #else
  130. #define TATE 0.00 // TATE Mode Toggle, Off/On
  131. #define GAMMA_CRT 2.40 // Simulated CRT, Gamma (2.25 - 2.40) is recommened
  132. #define h_sharp 5.25 // pixel sharpness
  133. #define s_sharp 0.05 // substractive sharpness
  134. #define h_smart 0.00 // smart horizontal smoothing
  135. #define SCAN_STYLE 1.00 // Alternative Scanline Styles, (0 is Mild, 1 is a Middle Ground, 2 is Trinitron-ish)
  136. #define SCAN_SHAPE 7.00 // Scanline, Center Sharpness
  137. #define SCAN_EDGE_SHAPE 9.00 // Scanline, Edge Sharpness
  138. #define SCAN_BEAM_MIN 1.30 // Scanline, Dark Area Beam Min - Narrow
  139. #define SCAN_BEAM_MAX 1.10 // Scanline, Light Area Beam Max - Wide
  140. #define SCAN_BEAM_SIZE 0.65 // increased max. beam size
  141. #define MASK_SCALE 1.00 // Mask, Scale (HD/4k)
  142. #define MASK_STYLE 5.00 // Alternative Mask Styles, (-1 is Mask-Off, 1-4 are Shadow-Masks, 5-6 are Trinitron-ish Masks, 7 is for Slot-Mask)
  143. #define MASK_DARK 0.50 // Mask, Dark Phosphor Strength
  144. #define MASK_LIGHT 1.50 // Mask, Light Phosphor Strength
  145. #define MASK_CUT 0.20 // Mask, Cutoff for Styles 5-7
  146. #define SLOT_MASK 0.00 // Slot-Mask, Strength
  147. #define SLOT_WIDTH 2.00 // Slot-Mask, Width
  148. #define DOUBLE_SLOT 1.00 // Slot-Mask, Height (HD/4k)
  149. #define BLOOM_WIDTH 0.65 // Bloom, Width
  150. #define BLOOM_HEIGHT 0.65 // Bloom, Height
  151. #define BLOOM_HALATION 0.10 // Bloom, Halation Strength
  152. #define BLOOM_DIFFUSION 0.10 // Bloom, Diffusion Strength
  153. #define DPS_BRIGHTNESS 1.50 // Simulated CRT, Brightness
  154. #define GAMMA_DISPLAY 2.20 // Display, Gamma Correction
  155. #define CURVE_CORNER 0.00 // Curvature, Corner Size
  156. #define CURVE_X 0.03 // Curvature, X-Axis (0.03) is recommened
  157. #define CURVE_Y 0.04 // Curvature, Y-Axis (0.04) is recommened
  158. #define XFX_STATIC 0.00 // Effect, Static Strength
  159. #define XFX_HUMBAR 0.00 // Effect, Hum-Bar Strength
  160. #define XFX_VIGNETTE 0.00 // Effect, Vignette Strength
  161. #define XFX_PVM_COLOR 0.00 // PVM-ish Color Shift
  162. #define OS 2.00 // Do overscan
  163. #define R_BLOOM 0.00 // Bloom overscan percentage
  164. #endif
  165.  
  166. #define FIX(c) max(abs(c), 1e-5)
  167. #define PI 3.141592653589
  168. #define saturate(c) clamp(c, 0.0, 1.0)
  169. #define TEX2D(c) pow(tex2D(tex, c).rgb, vec3(GAMMA_CRT))
  170. #define TEX2DD(c) pow(tex2D(PassPrev3Texture, c).rgb, vec3(GAMMA_CRT))
  171. #define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
  172. #define OutputSize vec4(OutputSize, 1.0 / OutputSize)
  173.  
  174. float TimeMilliseconds = float(mod(FrameCount, 1000)) * 3.; // multiplier used to get humbar up to speed
  175. float HumBarDesync = 60.0 / 59.94 - 1.0; // difference between the 59.94 Hz field rate and 60 Hz line frequency (NTSC)
  176.  
  177. mat3 get_color_matrix(sampler2D tex, vec2 co, vec2 dx)
  178. {
  179. return mat3(TEX2D(co - dx), TEX2D(co), TEX2D(co + dx));
  180. }
  181.  
  182. vec3 blur(mat3 m, float dist, float rad)
  183. {
  184. vec3 x = vec3(dist - 1.0, dist, dist + 1.0) / rad;
  185. vec3 w = exp2(x * x * -1.0);
  186.  
  187. return (m[0] * w.x + m[1] * w.y + m[2] * w.z) / (w.x + w.y + w.z);
  188. }
  189.  
  190. vec3 filter_gaussian(sampler2D tex, vec2 co, vec2 tex_size)
  191. {
  192.  
  193. vec2 dx = vec2(1.0 / tex_size.x, 0.0);
  194. vec2 dy = vec2(0.0, 1.0 / tex_size.y);
  195.  
  196. if (TATE > 0.5)
  197. {
  198. dy = vec2(1.0 / tex_size.x, 0.0);
  199. dx = vec2(0.0, 1.0 / tex_size.y);
  200. }
  201.  
  202. vec2 pix_co = co * tex_size;
  203. vec2 tex_co = (floor(pix_co) + 0.5) / tex_size;
  204. vec2 dist = (fract(pix_co) - 0.5) * -1.0;
  205.  
  206. if (TATE > 0.5)
  207. {
  208. dist = dist.yx;
  209. }
  210.  
  211. mat3 line0 = get_color_matrix(tex, tex_co - dy, dx);
  212. mat3 line1 = get_color_matrix(tex, tex_co, dx);
  213. mat3 line2 = get_color_matrix(tex, tex_co + dy, dx);
  214. mat3 column = mat3(blur(line0, dist.x, BLOOM_WIDTH),
  215. blur(line1, dist.x, BLOOM_WIDTH),
  216. blur(line2, dist.x, BLOOM_WIDTH));
  217.  
  218. return blur(column, dist.y, BLOOM_HEIGHT);
  219. }
  220.  
  221. float st(float x, float scanline)
  222. {
  223. return exp2(-scanline*x*x);
  224. }
  225.  
  226. vec3 sw0(vec3 x, vec3 color, float scanline)
  227. {
  228. vec3 tmp = mix(vec3(SCAN_BEAM_MIN),vec3(SCAN_BEAM_MAX), color);
  229. vec3 ex = x*tmp;
  230. return exp2(-scanline*ex*ex);
  231. }
  232.  
  233. vec3 sw1(vec3 x, vec3 color, float scanline)
  234. {
  235. float mx = max(max(color.r, color.g),color.b);
  236. x = mix (x, SCAN_BEAM_MIN*x, max(x-0.4*mx,0.0));
  237. vec3 tmp = mix(vec3(1.2*SCAN_BEAM_MIN),vec3(SCAN_BEAM_MAX), color);
  238. vec3 ex = x*tmp;
  239. float br = clamp(0.8*SCAN_BEAM_MIN - 1.0, 0.2, 0.45);
  240. return exp2(-scanline*ex*ex)/(1.0-br+br*color);
  241. }
  242.  
  243. vec3 sw2(vec3 x, vec3 color, float scanline)
  244. {
  245. vec3 tmp = mix(vec3(2.75*SCAN_BEAM_MIN),vec3(SCAN_BEAM_MAX), color);
  246. tmp = mix(vec3(SCAN_BEAM_MAX), tmp, pow(x, vec3(max(max(color.r, color.g),color.b)+0.3)));
  247. vec3 ex = x*tmp;
  248. return exp2(-scanline*ex*ex)/(0.6 + 0.4*color);
  249. }
  250.  
  251. // Shadow mask (1-4 from PD CRT Lottes shader).
  252. vec3 Mask(vec2 pos, vec3 c)
  253. {
  254. pos = floor(pos/MASK_SCALE);
  255. vec3 mask = vec3(MASK_DARK, MASK_DARK, MASK_DARK);
  256. float mx = max(max(c.r,c.g),c.b);
  257.  
  258. // No mask
  259. if (MASK_STYLE == -1.0)
  260. {
  261. mask = vec3(1.0);
  262. }
  263.  
  264. // Phosphor.
  265. else if (MASK_STYLE == 0.0)
  266. {
  267. pos.x = fract(pos.x*0.5);
  268. if (pos.x < 0.5) { mask.r = 1.1; mask.g = 0.7; mask.b = 1.1; }
  269. else { mask.r = 0.7; mask.g = 1.1; mask.b = 0.7; }
  270. }
  271.  
  272. // Very compressed TV style shadow mask.
  273. else if (MASK_STYLE == 1.0)
  274. {
  275. float line = MASK_LIGHT;
  276. float odd = 0.0;
  277.  
  278. if (fract(pos.x/6.0) < 0.5)
  279. odd = 1.0;
  280. if (fract((pos.y + odd)/2.0) < 0.5)
  281. line = MASK_DARK;
  282.  
  283. pos.x = fract(pos.x/3.0);
  284.  
  285. if (pos.x < 0.333) mask.r = MASK_LIGHT;
  286. else if (pos.x < 0.666) mask.g = MASK_LIGHT;
  287. else mask.b = MASK_LIGHT;
  288.  
  289. mask*=line;
  290. }
  291.  
  292. // Aperture-grille.
  293. else if (MASK_STYLE == 2.0)
  294. {
  295. pos.x = fract(pos.x/3.0);
  296.  
  297. if (pos.x < 0.333) mask.r = MASK_LIGHT;
  298. else if (pos.x < 0.666) mask.g = MASK_LIGHT;
  299. else mask.b = MASK_LIGHT;
  300. }
  301.  
  302. // Stretched VGA style shadow mask (same as prior shaders).
  303. else if (MASK_STYLE == 3.0)
  304. {
  305. pos.x += pos.y*3.0;
  306. pos.x = fract(pos.x/6.0);
  307.  
  308. if (pos.x < 0.333) mask.r = MASK_LIGHT;
  309. else if (pos.x < 0.666) mask.g = MASK_LIGHT;
  310. else mask.b = MASK_LIGHT;
  311. }
  312.  
  313. // VGA style shadow mask.
  314. else if (MASK_STYLE == 4.0)
  315. {
  316. pos.xy = floor(pos.xy*vec2(1.0, 0.5));
  317. pos.x += pos.y*3.0;
  318. pos.x = fract(pos.x/6.0);
  319.  
  320. if (pos.x < 0.333) mask.r = MASK_LIGHT;
  321. else if (pos.x < 0.666) mask.g = MASK_LIGHT;
  322. else mask.b = MASK_LIGHT;
  323. }
  324.  
  325. // Alternate mask 5
  326. else if (MASK_STYLE == 5.0)
  327. {
  328. vec3 maskTmp = vec3( min( 1.25*max(mx-MASK_CUT,0.0)/(1.0-MASK_CUT) ,MASK_DARK + 0.2*(1.0-MASK_DARK)*mx));
  329. float adj = 0.80*MASK_LIGHT - 0.5*(0.80*MASK_LIGHT - 1.0)*mx + 0.75*(1.0-mx);
  330. mask = maskTmp;
  331. pos.x = fract(pos.x/2.0);
  332. if (pos.x < 0.5)
  333. { mask.r = adj;
  334. mask.b = adj;
  335. }
  336. else mask.g = adj;
  337. }
  338.  
  339. // Alternate mask 6
  340. else if (MASK_STYLE == 6.0)
  341. {
  342. vec3 maskTmp = vec3( min( 1.33*max(mx-MASK_CUT,0.0)/(1.0-MASK_CUT) ,MASK_DARK + 0.225*(1.0-MASK_DARK)*mx));
  343. float adj = 0.80*MASK_LIGHT - 0.5*(0.80*MASK_LIGHT - 1.0)*mx + 0.75*(1.0-mx);
  344. mask = maskTmp;
  345. pos.x = fract(pos.x/3.0);
  346. if (pos.x < 0.333) mask.r = adj;
  347. else if (pos.x < 0.666) mask.g = adj;
  348. else mask.b = adj;
  349. }
  350.  
  351. // Alternate mask 7
  352. else if (MASK_STYLE == 7.0)
  353. {
  354. float maskTmp = min(1.6*max(mx-MASK_CUT,0.0)/(1.0-MASK_CUT) ,1.0 + 0.6*(1.0-mx));
  355. mask = vec3(maskTmp);
  356. pos.x = fract(pos.x/2.0);
  357. if (pos.x < 0.5) mask = vec3(1.0 + 0.6*(1.0-mx));
  358. }
  359.  
  360. return mask;
  361. }
  362.  
  363. float SlotMask(vec2 pos, vec3 c)
  364. {
  365. if (SLOT_MASK == 0.0) return 1.0;
  366.  
  367. float mx = pow(max(max(c.r,c.g),c.b),1.33);
  368. float mlen = SLOT_WIDTH*2.0;
  369. float px = fract(pos.x/mlen);
  370. float py = floor(fract(pos.y/(2.0*DOUBLE_SLOT))*2.0*DOUBLE_SLOT);
  371. float slot_dark = mix(1.0-SLOT_MASK, 1.0-0.80*SLOT_MASK, mx);
  372. float slot = 1.0 + 0.7*SLOT_MASK*(1.0-mx);
  373. if (py == 0.0 && px < 0.5) slot = slot_dark; else
  374. if (py == DOUBLE_SLOT && px >= 0.5) slot = slot_dark;
  375.  
  376. return slot;
  377. }
  378.  
  379. // Distortion of scanlines, and end of screen alpha (torridgristle's curvature)
  380. vec2 Warp(vec2 pos)
  381. {
  382. vec2 Distortion = vec2(CURVE_X, CURVE_Y) * 15.;
  383. vec2 curvedCoords = pos * 2.0 - 1.0;
  384. float curvedCoordsDistance = sqrt(curvedCoords.x*curvedCoords.x+curvedCoords.y*curvedCoords.y);
  385.  
  386. curvedCoords = curvedCoords / curvedCoordsDistance;
  387.  
  388. curvedCoords = curvedCoords * (1.0-pow(vec2(1.0-(curvedCoordsDistance/1.4142135623730950488016887242097)),(1.0/(1.0+Distortion*0.2))));
  389.  
  390. curvedCoords = curvedCoords / (1.0-pow(vec2(0.29289321881345247559915563789515),(1.0/(vec2(1.0)+Distortion*0.2))));
  391.  
  392. curvedCoords = curvedCoords * 0.5 + 0.5;
  393. return curvedCoords;
  394. }
  395.  
  396. vec2 Overscan(vec2 pos, float dx, float dy){
  397. pos=pos*2.0-1.0;
  398. pos*=vec2(dx,dy);
  399. return pos*0.5+0.5;
  400. }
  401.  
  402. // Borrowed from cgwg's crt-geom, under GPL
  403. float corner(vec2 coord)
  404. {
  405. coord *= SourceSize.xy / InputSize.xy;
  406. coord = (coord - vec2(0.5)) * 1.0 + vec2(0.5);
  407. coord = min(coord, vec2(1.0)-coord) * vec2(1.0, OutputSize.y/OutputSize.x);
  408. vec2 cdist = vec2(max(CURVE_CORNER,0.002));
  409. coord = (cdist - min(coord,cdist));
  410. float dist = sqrt(dot(coord,coord));
  411. return clamp((cdist.x-dist)*700.0,0.0, 1.0);
  412. }
  413.  
  414. float GetVignetteFactor(vec2 cooord, float amount)
  415. {
  416. vec2 VignetteCoord = cooord;
  417.  
  418. float VignetteLength = length(VignetteCoord);
  419. float VignetteBlur = (amount * 0.75) + 0.75;
  420.  
  421. // 0.5 full screen fitting circle
  422. float VignetteRadius = 1.75 - (amount * 0.25);
  423. float Vignette = smoothstep(VignetteRadius, VignetteRadius - VignetteBlur, VignetteLength);
  424.  
  425. return saturate(Vignette);
  426. }
  427.  
  428. //https://www.shadertoy.com/view/4sXSWs strength= 16.0
  429. vec3 filmGrain(vec2 uv, float strength )
  430. {
  431. float x = (uv.x + 4.0 ) * (uv.y + 4.0 ) * ((mod(vec2(FrameCount, FrameCount).x, 800.0) + 10.0) * 10.0);
  432. return vec3(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01)-0.005) * strength;
  433. }
  434.  
  435. void main()
  436. {
  437. vec3 lum = tex2D(PassPrev4Texture, vec2(0.33,0.33)).xyz;
  438. float factor = 1.00 + (1.0-0.5*OS)*R_BLOOM/100.0 - lum.x*R_BLOOM/100.0;
  439. vec2 R_Coord = Overscan(Coord*(SourceSize.xy/InputSize.xy), factor, factor)*(InputSize.xy/SourceSize.xy);
  440. vec2 pos = Warp(R_Coord.xy*(TextureSize.xy/InputSize.xy))*(InputSize.xy/TextureSize.xy);
  441. vec2 pos0 = Warp(Coord.xy*(TextureSize.xy/InputSize.xy))*(InputSize.xy/TextureSize.xy);
  442. vec3 film_grain = filmGrain(Coord, XFX_STATIC);
  443. vec3 col_glow = filter_gaussian(Texture, pos, TextureSize);
  444.  
  445. vec2 ps = SourceSize.zw;
  446. vec2 OGL2Pos = pos * SourceSize.xy - ((TATE < 0.5) ?
  447. vec2(0.0,0.5) : vec2(0.5, 0.0));
  448. vec2 fp = fract(OGL2Pos);
  449. vec2 dx0 = vec2(ps.x,0.0);
  450. vec2 dy0 = vec2(0.0, ps.y);
  451.  
  452. vec2 pC5 = floor(OGL2Pos) * ps + 0.5*ps;
  453.  
  454. // Reading the texels
  455. vec2 x20 = 2.0*dx0;
  456. vec2 y20 = 2.0*dy0;
  457.  
  458. vec2 offx = dx0;
  459. vec2 off2 = x20;
  460. vec2 offy = dy0;
  461. float fpx = fp.x;
  462. if(TATE > 0.5)
  463. {
  464. offx = dy0;
  465. off2 = y20;
  466. offy = dx0;
  467. fpx = fp.y;
  468. }
  469.  
  470. bool sharp = (s_sharp > 0.0);
  471.  
  472.  
  473. float hsharp_tl, hsharp_tr, hsharp_bl, hsharp_br, hsharp_tc, hsharp_bc;
  474.  
  475. if (h_smart == 0.0)
  476. {
  477. hsharp_tl = h_sharp; hsharp_tr = h_sharp; hsharp_bl = h_sharp; hsharp_br = h_sharp; hsharp_tc = h_sharp; hsharp_bc = h_sharp;
  478. }
  479. else
  480. {
  481. // reading differences for smoothing
  482. vec3 diffs_top = tex2D(PassPrev4Texture, pC5 ).xyz;
  483. vec3 diffs_bot = tex2D(PassPrev4Texture, pC5 + offy).xyz;
  484.  
  485. if(TATE > 0.5)
  486. {
  487. diffs_top.x = floor(10.0*diffs_top.z)*0.11111; diffs_top.y = fract(10.0*diffs_top.z)*1.11111;
  488. diffs_bot.x = floor(10.0*diffs_bot.z)*0.11111; diffs_bot.y = fract(10.0*diffs_bot.z)*1.11111;
  489. }
  490.  
  491. float ls = mix (4.5, 2.25, h_smart);
  492. hsharp_tl = mix(h_sharp, ls, diffs_top.x);
  493. hsharp_tr = mix(h_sharp, ls, diffs_top.y);
  494. hsharp_bl = mix(h_sharp, ls, diffs_bot.x);
  495. hsharp_br = mix(h_sharp, ls, diffs_bot.y);
  496. hsharp_tc = hsharp_tl;
  497. hsharp_bc = hsharp_bl;
  498. if (fpx == 0.5) { hsharp_tc = 0.5*(hsharp_tl + hsharp_tr); hsharp_bc = 0.5*(hsharp_bl + hsharp_br); }
  499. if (fpx > 0.5) { hsharp_tc = hsharp_tr; hsharp_bc = hsharp_bl; }
  500. }
  501.  
  502. float wl20 = 1.5 + fpx; wl20*=wl20; float twl2 = exp2(-hsharp_tl*wl20); twl2 = max(twl2 - s_sharp, -twl2); float bwl2 = exp2(-hsharp_bl*wl20); bwl2 = max(bwl2 - s_sharp, -bwl2);
  503. float wl10 = 0.5 + fpx; wl10*=wl10; float twl1 = exp2(-hsharp_tl*wl10); twl1 = max(twl1 - s_sharp, -0.4*s_sharp); float bwl1 = exp2(-hsharp_bl*wl10); bwl1 = max(bwl1 - s_sharp, -0.4*s_sharp);
  504. float wct = 0.5 - fpx; wct*=wct; float twct = exp2(-hsharp_tc*wct); twct = max(twct - s_sharp, s_sharp); float bwct = exp2(-hsharp_bc*wct); bwct = max(bwct - s_sharp, s_sharp);
  505. float wr10 = 1.5 - fpx; wr10*=wr10; float twr1 = exp2(-hsharp_tr*wr10); twr1 = max(twr1 - s_sharp, -0.4*s_sharp); float bwr1 = exp2(-hsharp_br*wr10); bwr1 = max(bwr1 - s_sharp, -0.4*s_sharp);
  506. float wr20 = 2.5 - fpx; wr20*=wr20; float twr2 = exp2(-hsharp_tr*wr20); twr2 = max(twr2 - s_sharp, -twr2); float bwr2 = exp2(-hsharp_br*wr20); bwr2 = max(bwr2 - s_sharp, -bwr2);
  507.  
  508. float wtt = 1.0/(twl2+twl1+twct+twr1+twr2);
  509. float wtb = 1.0/(bwl2+bwl1+bwct+bwr1+bwr2);
  510.  
  511. vec3 l20 = TEX2DD( pC5 -off2).xyz;
  512. vec3 l10 = TEX2DD( pC5 -offx).xyz;
  513. vec3 ct = TEX2DD( pC5 ).xyz;
  514. vec3 r10 = TEX2DD( pC5 +offx).xyz;
  515. vec3 r20 = TEX2DD( pC5 +off2).xyz;
  516.  
  517. vec3 color1 = (l20*twl2 + l10*twl1 + ct*twct + r10*twr1 + r20*twr2)*wtt;
  518. if (sharp) color1 = clamp(color1, min(min(l10,r10),ct), max(max(l10,r10),ct));
  519.  
  520. l20 = TEX2DD( pC5 -off2 +offy).xyz;
  521. l10 = TEX2DD( pC5 -offx +offy).xyz;
  522. ct = TEX2DD( pC5 +offy).xyz;
  523. r10 = TEX2DD( pC5 +offx +offy).xyz;
  524. r20 = TEX2DD( pC5 +off2 +offy).xyz;
  525.  
  526. vec3 color2 = (l20*bwl2 + l10*bwl1 + ct*bwct + r10*bwr1 + r20*bwr2)*wtb;
  527. if (sharp) color2 = clamp(color2, min(min(l10,r10),ct), max(max(l10,r10),ct));
  528.  
  529. // calculating scanlines
  530.  
  531. float f = (TATE < 0.5) ? fp.y : fp.x;
  532.  
  533. float shape1 = mix(SCAN_SHAPE, SCAN_EDGE_SHAPE, f);
  534. float shape2 = mix(SCAN_SHAPE, SCAN_EDGE_SHAPE, 1.0-f);
  535.  
  536. float wt1 = st(f, shape1);
  537. float wt2 = st(1.0-f, shape2);
  538. vec3 color0 = color1*wt1 + color2*wt2;
  539. vec3 ctmp = color0/(wt1+wt2);
  540. vec3 tmp = pow(ctmp, vec3(1.0/GAMMA_DISPLAY));
  541.  
  542. vec3 w1,w2 = vec3(0.0);
  543.  
  544. vec3 cref1 = mix(ctmp, color1, SCAN_BEAM_SIZE);
  545. vec3 cref2 = mix(ctmp, color2, SCAN_BEAM_SIZE);
  546.  
  547. vec3 shift = vec3(-XFX_PVM_COLOR, XFX_PVM_COLOR, -XFX_PVM_COLOR);
  548.  
  549. vec3 f1 = clamp(vec3(f) + shift*0.5*(1.0+f), 0.0, 1.0);
  550. vec3 f2 = clamp(vec3(1.0-f) - shift*0.5*(2.0-f), 0.0, 1.0);
  551.  
  552. if (SCAN_STYLE == 0.0) { w1 = sw0(f1,cref1,shape1); w2 = sw0(f2,cref2,shape2);} else
  553. if (SCAN_STYLE == 1.0) { w1 = sw1(f1,cref1,shape1); w2 = sw1(f2,cref2,shape2);} else
  554. if (SCAN_STYLE == 2.0) { w1 = sw2(f1,cref1,shape1); w2 = sw2(f2,cref2,shape2);}
  555.  
  556. vec3 col = color1*w1 + color2*w2;
  557.  
  558. // Apply Bloom Halation
  559.  
  560. col_glow = saturate(col_glow - col);
  561. col += col_glow * col_glow * BLOOM_HALATION;
  562.  
  563. // Apply Mask
  564.  
  565. col *= (TATE < 0.5) ? Mask(gl_FragCoord.xy * 1.000001,col) :
  566. Mask(gl_FragCoord.yx * 1.000001,col);
  567.  
  568. col = min(col,1.0);
  569.  
  570. col *= (TATE < 0.5) ? SlotMask(gl_FragCoord.xy * 1.000001,col) :
  571. SlotMask(gl_FragCoord.yx * 1.000001,col);
  572. col = pow(col * DPS_BRIGHTNESS, vec3(1.0 / GAMMA_DISPLAY));
  573.  
  574. // Apply Bloom
  575.  
  576. #define bloompix 1.0 // glow shape, more is harder
  577.  
  578. OGL2Pos = pos * TextureSize.xy - vec2(0.5);
  579. fp = fract(OGL2Pos);
  580.  
  581. vec2 pC4 = floor(OGL2Pos) / TextureSize.xy + 0.5/TextureSize.xy;
  582.  
  583. vec2 dx = vec2(1.0/TextureSize.x, 0.0);
  584. vec2 dy = vec2(0.0, 1.0/TextureSize.y);
  585. vec2 x2 = 2.0*dx; vec2 x3 = 3.0*dx;
  586. vec2 y2 = 2.0*dy; vec2 y3 = 3.0*dy;
  587.  
  588. float wl3 = 2.0 + fp.x; wl3*=wl3; wl3 = exp2(-bloompix*wl3);
  589. float wl2 = 1.0 + fp.x; wl2*=wl2; wl2 = exp2(-bloompix*wl2);
  590. float wl1 = fp.x; wl1*=wl1; wl1 = exp2(-bloompix*wl1);
  591. float wr1 = 1.0 - fp.x; wr1*=wr1; wr1 = exp2(-bloompix*wr1);
  592. float wr2 = 2.0 - fp.x; wr2*=wr2; wr2 = exp2(-bloompix*wr2);
  593. float wr3 = 3.0 - fp.x; wr3*=wr3; wr3 = exp2(-bloompix*wr3);
  594.  
  595. float wt = 1.0/(wl3+wl2+wl1+wr1+wr2+wr3);
  596.  
  597. vec3 l3 = tex2D(Texture, pC4 -x2 ).xyz; l3*=l3;
  598. vec3 l2 = tex2D(Texture, pC4 -dx ).xyz; l2*=l2;
  599. vec3 l1 = tex2D(Texture, pC4 ).xyz; l1*=l1;
  600. vec3 r1 = tex2D(Texture, pC4 +dx ).xyz; r1*=r1;
  601. vec3 r2 = tex2D(Texture, pC4 +x2 ).xyz; r2*=r2;
  602. vec3 r3 = tex2D(Texture, pC4 +x3 ).xyz; r3*=r3;
  603.  
  604. vec3 t1 = (l3*wl3 + l2*wl2 + l1*wl1 + r1*wr1 + r2*wr2 + r3*wr3)*wt;
  605.  
  606. l3 = tex2D(Texture, pC4 -x2 -dy).xyz; l3*=l3;
  607. l2 = tex2D(Texture, pC4 -dx -dy).xyz; l2*=l2;
  608. l1 = tex2D(Texture, pC4 -dy).xyz; l1*=l1;
  609. r1 = tex2D(Texture, pC4 +dx -dy).xyz; r1*=r1;
  610. r2 = tex2D(Texture, pC4 +x2 -dy).xyz; r2*=r2;
  611. r3 = tex2D(Texture, pC4 +x3 -dy).xyz; r3*=r3;
  612.  
  613. vec3 t2 = (l3*wl3 + l2*wl2 + l1*wl1 + r1*wr1 + r2*wr2 + r3*wr3)*wt;
  614.  
  615. l3 = tex2D(Texture, pC4 -x2 -y2).xyz; l3*=l3;
  616. l2 = tex2D(Texture, pC4 -dx -y2).xyz; l2*=l2;
  617. l1 = tex2D(Texture, pC4 -y2).xyz; l1*=l1;
  618. r1 = tex2D(Texture, pC4 +dx -y2).xyz; r1*=r1;
  619. r2 = tex2D(Texture, pC4 +x2 -y2).xyz; r2*=r2;
  620. r3 = tex2D(Texture, pC4 +x3 -y2).xyz; r3*=r3;
  621.  
  622. vec3 t3 = (l3*wl3 + l2*wl2 + l1*wl1 + r1*wr1 + r2*wr2 + r3*wr3)*wt;
  623.  
  624. l3 = tex2D(Texture, pC4 -x2 +dy).xyz; l3*=l3;
  625. l2 = tex2D(Texture, pC4 -dx +dy).xyz; l2*=l2;
  626. l1 = tex2D(Texture, pC4 +dy).xyz; l1*=l1;
  627. r1 = tex2D(Texture, pC4 +dx +dy).xyz; r1*=r1;
  628. r2 = tex2D(Texture, pC4 +x2 +dy).xyz; r2*=r2;
  629. r3 = tex2D(Texture, pC4 +x3 +dy).xyz; r3*=r3;
  630. vec3 b1 = (l3*wl3 + l2*wl2 + l1*wl1 + r1*wr1 + r2*wr2 + r3*wr3)*wt;
  631.  
  632. l3 = tex2D(Texture, pC4 -x2 +y2).xyz; l3*=l3;
  633. l2 = tex2D(Texture, pC4 -dx +y2).xyz; l2*=l2;
  634. l1 = tex2D(Texture, pC4 +y2).xyz; l1*=l1;
  635. r1 = tex2D(Texture, pC4 +dx +y2).xyz; r1*=r1;
  636. r2 = tex2D(Texture, pC4 +x2 +y2).xyz; r2*=r2;
  637. r3 = tex2D(Texture, pC4 +x3 +y2).xyz; r3*=r3;
  638.  
  639. vec3 b2 = (l3*wl3 + l2*wl2 + l1*wl1 + r1*wr1 + r2*wr2 + r3*wr3)*wt;
  640.  
  641. l3 = tex2D(Texture, pC4 -x2 +y3).xyz; l3*=l3;
  642. l2 = tex2D(Texture, pC4 -dx +y3).xyz; l2*=l2;
  643. l1 = tex2D(Texture, pC4 +y3).xyz; l1*=l1;
  644. r1 = tex2D(Texture, pC4 +dx +y3).xyz; r1*=r1;
  645. r2 = tex2D(Texture, pC4 +x2 +y3).xyz; r2*=r2;
  646. r3 = tex2D(Texture, pC4 +x3 +y3).xyz; r3*=r3;
  647.  
  648. vec3 b3 = (l3*wl3 + l2*wl2 + l1*wl1 + r1*wr1 + r2*wr2 + r3*wr3)*wt;
  649.  
  650. wl3 = 2.0 + fp.y; wl3*=wl3; wl3 = exp2(-bloompix*wl3);
  651. wl2 = 1.0 + fp.y; wl2*=wl2; wl2 = exp2(-bloompix*wl2);
  652. wl1 = fp.y; wl1*=wl1; wl1 = exp2(-bloompix*wl1);
  653. wr1 = 1.0 - fp.y; wr1*=wr1; wr1 = exp2(-bloompix*wr1);
  654. wr2 = 2.0 - fp.y; wr2*=wr2; wr2 = exp2(-bloompix*wr2);
  655. wr3 = 3.0 - fp.y; wr3*=wr3; wr3 = exp2(-bloompix*wr3);
  656.  
  657. wt = 1.0/(wl3+wl2+wl1+wr1+wr2+wr3);
  658.  
  659. vec3 Bloom = (t3*wl3 + t2*wl2 + t1*wl1 + b1*wr1 + b2*wr2 + b3*wr3)*wt;
  660.  
  661. //Apply Bloom Diffusion
  662.  
  663. col = col*col;
  664. col += Bloom*BLOOM_DIFFUSION;
  665. col = sqrt(col);
  666.  
  667. // Hum-Bar Simulation
  668. if (XFX_HUMBAR > 0.0)
  669. {
  670. float HumBarStep = fract(TimeMilliseconds * HumBarDesync);
  671. float HumBarBrightness = (TATE < 0.5) ? 1.0 - fract((pos.y * TextureSize.y / InputSize.y) + HumBarStep) * XFX_HUMBAR :
  672. 1.0 - fract((pos.x * TextureSize.x / InputSize.x) + HumBarStep) * XFX_HUMBAR;
  673.  
  674. // Apply Hum-Bar
  675.  
  676. col.rgb *= HumBarBrightness;
  677. }
  678.  
  679. // Vignetting Simulation
  680. if (XFX_VIGNETTE > 0.0)
  681. {
  682. vec2 pos1 = pos*(TextureSize.xy/InputSize.xy);
  683. pos1 = pos1*2.0-1.0;
  684. vec2 VignetteCoord = pos1;
  685.  
  686. float VignetteFactor = GetVignetteFactor(VignetteCoord, XFX_VIGNETTE);
  687.  
  688. // Apply Curvature, Vignette, and Static
  689.  
  690. FragColor = vec4(col*corner(pos)*VignetteFactor + film_grain, 1.0);
  691. }
  692. else FragColor = vec4(col*corner(pos0) + film_grain, 1.0);
  693. }
  694. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement