Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.88 KB | None | 0 0
  1. /**
  2. * reshade-xhair 1.2.4
  3. * ReShade Crosshair Shader Overlay
  4. *
  5. * Copyright 2019 LouisTakePILLz
  6. */
  7.  
  8. #include "Reshade.fxh"
  9.  
  10. #define CATEGORY_GENERAL "General"
  11. #define CATEGORY_XHAIR_COMPOSITE "Composite Xhair"
  12. #define CATEGORY_XHAIR_CROSS "[Cross] Xhair"
  13. #define CATEGORY_XHAIR_CIRCLE "[Circle] Xhair"
  14.  
  15. #define MAX_CROSS_OUTLINE_THICKNESS 10
  16. #define MAX_CIRCLE_OUTLINE_THICKNESS 10.0
  17.  
  18. /**
  19. * General Settings
  20. */
  21.  
  22. uniform int OffsetX <
  23. ui_category = CATEGORY_GENERAL;
  24. ui_type = "drag";
  25. ui_min = -(BUFFER_WIDTH / 2); ui_max = (BUFFER_WIDTH / 2);
  26. ui_label = "X Axis Shift";
  27. ui_tooltip = "Offsets the crosshair horizontally from the center of the screen.";
  28. > = 0;
  29.  
  30. uniform int OffsetY <
  31. ui_category = CATEGORY_GENERAL;
  32. ui_type = "drag";
  33. ui_min = -(BUFFER_HEIGHT / 2); ui_max = (BUFFER_HEIGHT / 2);
  34. ui_label = "Y Axis Shift";
  35. ui_tooltip = "Offsets the crosshair vertically from the center of the screen.";
  36. > = 0;
  37.  
  38. uniform int XhairType <
  39. ui_category = CATEGORY_GENERAL;
  40. ui_type = "combo";
  41. ui_items = "Cross\0Circle";
  42. ui_label = "Xhair Type";
  43. > = 0;
  44.  
  45. uniform float XhairOpacity <
  46. ui_category = CATEGORY_GENERAL;
  47. ui_type = "drag";
  48. ui_min = 0.0; ui_max = 1.0;
  49. ui_label = "Xhair Opacity";
  50. > = 1.0;
  51.  
  52. uniform int HideOnRMB <
  53. ui_category = CATEGORY_GENERAL;
  54. ui_type = "combo";
  55. ui_items = "Hold\0Toggle\0Disabled";
  56. ui_label = "Hide on RMB";
  57. ui_tooltip = "Controls whether the crosshair should be hidden when clicking the right mouse button.";
  58. > = 0;
  59.  
  60. /**
  61. * Composite Xhair Settings
  62. */
  63.  
  64. uniform int DotType <
  65. ui_category = CATEGORY_XHAIR_COMPOSITE;
  66. ui_type = "combo";
  67. ui_items = "Circle\0Square\0Disabled";
  68. ui_label = "Use Dot";
  69. ui_tooltip = "Controls whether a dot should be rendered **on top** of the selected crosshair.";
  70. > = 2;
  71.  
  72. uniform float3 DotColor <
  73. ui_category = CATEGORY_XHAIR_COMPOSITE;
  74. ui_type = "color";
  75. ui_label = "Dot Color";
  76. > = float3(0.0, 1.0, 0.0);
  77.  
  78. uniform int DotSize <
  79. ui_category = CATEGORY_XHAIR_COMPOSITE;
  80. ui_type = "drag";
  81. ui_min = 1; ui_max = 30;
  82. ui_label = "Dot Size";
  83. > = 1;
  84.  
  85. uniform float DotOpacity <
  86. ui_category = CATEGORY_XHAIR_COMPOSITE;
  87. ui_type = "drag";
  88. ui_min = 0.0; ui_max = 1.0;
  89. ui_label = "Dot Opacity";
  90. > = 1.0;
  91.  
  92. /**
  93. * Cross Xhair Settings
  94. */
  95.  
  96. uniform float3 CrossColor <
  97. ui_category = CATEGORY_XHAIR_CROSS;
  98. ui_type = "color";
  99. ui_label = "Color";
  100. > = float3(0.0, 1.0, 0.0);
  101.  
  102. uniform int CrossLength <
  103. ui_category = CATEGORY_XHAIR_CROSS;
  104. ui_type = "drag";
  105. ui_min = 1; ui_max = 100;
  106. ui_label = "Length";
  107. > = 6;
  108.  
  109. uniform int CrossThickness <
  110. ui_category = CATEGORY_XHAIR_CROSS;
  111. ui_type = "drag";
  112. ui_min = 0; ui_max = 10;
  113. ui_label = "Thickness";
  114. > = 1;
  115.  
  116. uniform int CrossGap <
  117. ui_category = CATEGORY_XHAIR_CROSS;
  118. ui_type = "drag";
  119. ui_min = 0; ui_max = 20;
  120. ui_label = "Gap";
  121. > = 3;
  122.  
  123. /**
  124. * Cross Xhair Outline Settings
  125. */
  126.  
  127. uniform bool CrossOutlineEnabled <
  128. ui_category = CATEGORY_XHAIR_CROSS;
  129. ui_label = "Enable Outline";
  130. > = 1;
  131.  
  132. uniform bool CrossOutlineGlowEnabled <
  133. ui_category = CATEGORY_XHAIR_CROSS;
  134. ui_label = "Enable Outline Glow";
  135. > = true;
  136.  
  137. uniform float3 CrossOutlineColor <
  138. ui_category = CATEGORY_XHAIR_CROSS;
  139. ui_type = "color";
  140. ui_label = "Outline Color";
  141. > = float3(0.0, 0.0, 0.0);
  142.  
  143. uniform float CrossOutlineOpacity <
  144. ui_category = CATEGORY_XHAIR_CROSS;
  145. ui_type = "drag";
  146. ui_min = 0.0; ui_max = 1.0;
  147. ui_label = "Outline Opacity";
  148. > = 1.0;
  149.  
  150. uniform int f_crossOutlineSharpness <
  151. ui_category = CATEGORY_XHAIR_CROSS;
  152. ui_type = "drag";
  153. ui_min = 0; ui_max = (MAX_CROSS_OUTLINE_THICKNESS);
  154. ui_step = 1;
  155. ui_label = "Outline Sharpness";
  156. ui_tooltip = "Controls how many pixels should be rendered at 100% opaque around the crosshair (recommended: 1 or 0).";
  157. > = 1;
  158. #define CrossOutlineSharpness (max(f_crossOutlineSharpness, 0))
  159.  
  160. uniform int f_crossOutlineGlow <
  161. ui_category = CATEGORY_XHAIR_CROSS;
  162. ui_type = "drag";
  163. ui_min = 0; ui_max = MAX_CROSS_OUTLINE_THICKNESS;
  164. ui_step = 1;
  165. ui_label = "Outline Glow";
  166. ui_tooltip = "Controls how many outline **gradient** pixels should be rendered around the sharp outline.";
  167. > = 2;
  168. #define CrossOutlineGlow (max(f_crossOutlineGlow, 0))
  169.  
  170. uniform float CrossOutlineGlowOpacity <
  171. ui_category = CATEGORY_XHAIR_CROSS;
  172. ui_type = "drag";
  173. ui_min = 0.0; ui_max = 1.0;
  174. ui_step = 0.005;
  175. ui_label = "Outline Glow Opacity";
  176. > = 0.15;
  177.  
  178. /**
  179. * Circle Xhair Settings
  180. */
  181.  
  182. uniform float3 CircleColor <
  183. ui_category = CATEGORY_XHAIR_CIRCLE;
  184. ui_type = "color";
  185. ui_label = "Color";
  186. > = float3(0.0, 1.0, 0.0);
  187.  
  188. uniform float CircleThickness <
  189. ui_category = CATEGORY_XHAIR_CIRCLE;
  190. ui_type = "drag";
  191. ui_min = 0.0; ui_max = 20.0;
  192. ui_label = "Thickness";
  193. > = 2.0;
  194.  
  195. uniform float CircleGapRadius <
  196. ui_category = CATEGORY_XHAIR_CIRCLE;
  197. ui_type = "drag";
  198. ui_min = 0.0; ui_max = 20.0;
  199. ui_label = "Gap Radius";
  200. > = 4.0;
  201.  
  202. /**
  203. * Circle Xhair Outline Settings
  204. */
  205.  
  206. uniform bool CircleOutlineEnabled <
  207. ui_category = CATEGORY_XHAIR_CIRCLE;
  208. ui_label = "Enable Outline";
  209. > = 1;
  210.  
  211. uniform bool CircleOutlineGlowEnabled <
  212. ui_category = CATEGORY_XHAIR_CIRCLE;
  213. ui_label = "Enable Outline Glow";
  214. > = true;
  215.  
  216. uniform float3 CircleOutlineColor <
  217. ui_category = CATEGORY_XHAIR_CIRCLE;
  218. ui_type = "color";
  219. ui_label = "Outline Color";
  220. > = float3(0.0, 0.0, 0.0);
  221.  
  222. uniform float CircleOutlineOpacity <
  223. ui_category = CATEGORY_XHAIR_CIRCLE;
  224. ui_type = "drag";
  225. ui_min = 0.0; ui_max = 1.0;
  226. ui_label = "Outline Opacity";
  227. > = 1.0;
  228.  
  229. uniform float f_circleOuterOutlineSharpness <
  230. ui_category = CATEGORY_XHAIR_CIRCLE;
  231. ui_type = "drag";
  232. ui_min = 0; ui_max = MAX_CIRCLE_OUTLINE_THICKNESS;
  233. ui_step = 0.01;
  234. ui_label = "Outer Outline Sharpness";
  235. ui_tooltip = "Controls how many outline pixels (outside of the circle)\nshould be rendered as 100% opaque.";
  236. > = 1.0;
  237. #define CircleOuterOutlineSharpness (min(max(f_circleOuterOutlineSharpness, 0), CircleOuterOutlineGlow))
  238.  
  239. uniform float f_circleOuterOutlineGlow <
  240. ui_category = CATEGORY_XHAIR_CIRCLE;
  241. ui_type = "drag";
  242. ui_min = 0.0; ui_max = MAX_CIRCLE_OUTLINE_THICKNESS;
  243. ui_step = 0.01;
  244. ui_label = "Outer Outline Glow";
  245. ui_tooltip = "Controls how many outline **gradient** pixels (outside of the circle)\nshould be rendered around the sharp outline.";
  246. > = 2.0;
  247. #define CircleOuterOutlineGlow (max(f_circleOuterOutlineGlow, 0))
  248.  
  249. uniform float CircleOuterOutlineGlowOpacity <
  250. ui_category = CATEGORY_XHAIR_CIRCLE;
  251. ui_type = "drag";
  252. ui_min = 0.0; ui_max = 1.0;
  253. ui_step = 0.005;
  254. ui_label = "Outer Outline Glow Opacity";
  255. > = 0.15;
  256.  
  257. uniform float f_circleInnerOutlineSharpness <
  258. ui_category = CATEGORY_XHAIR_CIRCLE;
  259. ui_type = "drag";
  260. ui_min = 0; ui_max = MAX_CIRCLE_OUTLINE_THICKNESS;
  261. ui_step = 0.01;
  262. ui_label = "Inner Outline Sharpness";
  263. ui_tooltip = "Controls how many outline pixels (inside of the circle)\nshould be rendered as 100% opaque.";
  264. > = 1.0;
  265. #define CircleInnerOutlineSharpness (min(max(f_circleInnerOutlineSharpness, 0), CircleInnerOutlineGlow))
  266.  
  267. uniform float f_circleInnerOutlineGlow <
  268. ui_category = CATEGORY_XHAIR_CIRCLE;
  269. ui_type = "drag";
  270. ui_min = 0.0; ui_max = MAX_CIRCLE_OUTLINE_THICKNESS;
  271. ui_step = 0.01;
  272. ui_label = "Inner Outline Glow";
  273. ui_tooltip = "Controls how many gradient outline pixels (inside of the circle)\nshould be rendered around the sharp outline.";
  274. > = 2.0;
  275. #define CircleInnerOutlineGlow (max(f_circleInnerOutlineGlow, 0))
  276.  
  277. uniform float CircleInnerOutlineGlowOpacity <
  278. ui_category = CATEGORY_XHAIR_CIRCLE;
  279. ui_type = "drag";
  280. ui_min = 0.0; ui_max = 1.0;
  281. ui_step = 0.005;
  282. ui_label = "Inner Outline Glow Opacity";
  283. > = 0.15;
  284.  
  285. /**
  286. * RMB States
  287. */
  288.  
  289. uniform bool rightMouseDown <
  290. source = "mousebutton";
  291. keycode = 1;
  292. toggle = false;
  293. >;
  294.  
  295. uniform bool rightMouseToggle <
  296. source = "mousebutton";
  297. keycode = 1;
  298. mode = "toggle";
  299. toggle = false;
  300. >;
  301.  
  302. /**
  303. * Helpers
  304. */
  305.  
  306. #define BareCrossLength (CrossLength + CrossGap)
  307.  
  308. #define EULER (0.57721566490153286061)
  309.  
  310. #define CROSS_OUTLINE_GLOW_RADIAL(intensity) (lerp(0.0, CrossOutlineGlowOpacity, intensity))
  311. // http://cubic-bezier.com/#.06,1.2,0,.9
  312. #define CROSS_OUTLINE_GLOW_BEZIER_CUBIC_PRESET_1(intensity) (cubicBezier(float2(.06, 1.2), float2(0, .9), intensity) * CrossOutlineGlowOpacity)
  313.  
  314. #define CROSS_OUTLINE_GLOW_CURVE CROSS_OUTLINE_GLOW_BEZIER_CUBIC_PRESET_1
  315. #define CROSS_OUTLINE_GLOW(intensity) (CrossOutlineGlowEnabled ? saturate(CROSS_OUTLINE_GLOW_CURVE(intensity)) : 0.0)
  316.  
  317. #define CIRCLE_OUTER_OUTLINE_GLOW(intensity) (CircleOutlineGlowEnabled ? lerp(CircleOuterOutlineGlowOpacity, 0.0, intensity) : 0.0)
  318. #define CIRCLE_INNER_OUTLINE_GLOW(intensity) (CircleOutlineGlowEnabled ? lerp(CircleInnerOutlineGlowOpacity, 0.0, intensity) : 0.0)
  319.  
  320. float2 cubicBezier(float2 p1, float2 p2, float i) {
  321. float x = pow(1 - i, 3) * 0 +
  322. 3 * i * pow(1 - i, 2) * p1.x +
  323. 3 * pow(i, 2) * (1 - i) * p2.x +
  324. pow(i, 3) * 1;
  325. float y = pow(1 - i, 3) * 0 +
  326. 3 * i * pow(1 - i, 2) * p1.y +
  327. 3 * pow(i, 2) * (1 - i) * p2.y +
  328. pow(i, 3) * 1;
  329. return float2(x, y);
  330. }
  331.  
  332. #define invertSaturate(x) (1.0 - saturate((x)))
  333. #define manhattanDistance(p1, p2) (abs(p1.x - p2.x) + abs(p1.y - p2.y))
  334.  
  335. #ifdef __DEBUG__
  336. uniform int random1 < source = "random"; min = 0; max = 255; >;
  337. uniform int random2 < source = "random"; min = 0; max = 255; >;
  338. uniform int random3 < source = "random"; min = 0; max = 255; >;
  339. #endif
  340.  
  341. /*
  342. * Xhair Shader
  343. */
  344.  
  345. void drawCircleXhair(float distCenter, out float4 draw, inout float drawOpacity) {
  346. draw = float4(CircleColor, 1.0);
  347. drawOpacity = XhairOpacity;
  348.  
  349. bool isXhairPixel = int(round(
  350. max(CircleThickness - abs(distCenter - (CircleGapRadius + CircleThickness / 2.0)), 0) / CircleThickness
  351. )) == 1;
  352.  
  353. if (!isXhairPixel) {
  354. drawOpacity = 0;
  355. }
  356.  
  357. if (CircleOutlineEnabled && !isXhairPixel) {
  358.  
  359. float bareCrosshairInnerRadius = CircleGapRadius;
  360. float bareCrosshairOuterRadius = CircleGapRadius + CircleThickness;
  361.  
  362. float outerOutlineFullRadius = bareCrosshairOuterRadius + CircleOuterOutlineGlow;
  363. float outerOutlineSharpRadius = bareCrosshairOuterRadius + CircleOuterOutlineSharpness;
  364.  
  365. float innerOutlineFullRadius = bareCrosshairInnerRadius - CircleInnerOutlineGlow;
  366. float innerOutlineSharpRadius = bareCrosshairInnerRadius - CircleInnerOutlineSharpness;
  367.  
  368. draw = float4(CircleOutlineColor, 1.0);
  369.  
  370. if (distCenter < outerOutlineFullRadius && distCenter > CircleGapRadius) {
  371. float glowIntensity = invertSaturate((outerOutlineFullRadius - distCenter) / (CircleOuterOutlineGlow - CircleOuterOutlineSharpness));
  372. drawOpacity = distCenter < outerOutlineSharpRadius
  373. ? CircleOutlineOpacity * XhairOpacity
  374. : CIRCLE_OUTER_OUTLINE_GLOW(glowIntensity) * XhairOpacity;
  375. } else if (distCenter > innerOutlineFullRadius && distCenter < bareCrosshairInnerRadius) {
  376. float glowIntensity = saturate((innerOutlineFullRadius - distCenter) / (CircleInnerOutlineGlow - CircleInnerOutlineSharpness));
  377. drawOpacity = distCenter > innerOutlineSharpRadius
  378. ? CircleOutlineOpacity * XhairOpacity
  379. : CIRCLE_INNER_OUTLINE_GLOW(glowIntensity) * XhairOpacity;
  380. }
  381. }
  382. }
  383.  
  384. void drawCrossXhair(int distX, int distY, out float4 draw, inout float drawOpacity) {
  385. draw = float4(CrossColor, 1.0);
  386. drawOpacity = XhairOpacity;
  387.  
  388. if (distX < distY) { // Vertical pixel
  389.  
  390. bool isXhairPixel = int(round(min(
  391. max((CrossThickness * 2.0) - distX, 0) / max(CrossThickness * 2.0, 1),
  392. max(BareCrossLength - distY, 0)
  393. ))) == 1;
  394.  
  395. // Check if we should (not) render a xhair pixel
  396. if (distY < CrossGap || !isXhairPixel) {
  397. drawOpacity = 0;
  398. }
  399. // Check if we should render an outline pixel
  400. if (CrossOutlineEnabled && !isXhairPixel && distY >= CrossGap) {
  401.  
  402. // Pixel distance from the bare crosshair (w/o the outline)
  403. int bareCrossDistX = distX - CrossThickness;
  404. int bareCrossDistY = distY - BareCrossLength;
  405.  
  406. // Pixel distance from the sharp outline
  407. int sharpOutlineDistX = bareCrossDistX - CrossOutlineSharpness;
  408. int sharpOutlineDistY = bareCrossDistY - CrossOutlineSharpness;
  409.  
  410. draw = float4(CrossOutlineColor, 1.0);
  411.  
  412. #ifdef __DEBUG__
  413. if (sharpOutlineDistX == 0 && sharpOutlineDistY == 0) {
  414. draw = float4(random1/255.0, random2/255.0, random3/255.0, 1);
  415. return draw;
  416. }
  417. #endif
  418.  
  419. float2 relativePos = float2(max(bareCrossDistX, 0), max(bareCrossDistY, 0));
  420. float dist = distance(relativePos, float2(0, 0));
  421. if (dist < CrossOutlineSharpness) {
  422. drawOpacity = XhairOpacity;
  423. } else if (dist < (CrossOutlineSharpness + CrossOutlineGlow)) {
  424. float glowIntensity = saturate(1.0 - ((dist - CrossOutlineSharpness) / float(CrossOutlineGlow)));
  425. drawOpacity = CROSS_OUTLINE_GLOW(glowIntensity) * XhairOpacity;
  426. }
  427.  
  428. drawOpacity *= CrossOutlineOpacity * XhairOpacity;
  429. }
  430.  
  431. } else { // Horizontal pixel
  432.  
  433. bool isXhairPixel = int(round(min(
  434. max((CrossThickness * 2.0) - distY, 0) / max(CrossThickness * 2.0, 1),
  435. max(BareCrossLength - distX, 0)
  436. ))) == 1;
  437.  
  438. // Check if we should (not) render a xhair pixel
  439. if (distX < CrossGap || !isXhairPixel) {
  440. drawOpacity = 0;
  441. }
  442.  
  443. // Check if we should render an outline pixel
  444. if (CrossOutlineEnabled && !isXhairPixel && distX >= CrossGap) {
  445.  
  446. // Pixel distance from the bare crosshair (w/o the outline)
  447. int bareCrossDistX = distX - BareCrossLength;
  448. int bareCrossDistY = distY - CrossThickness;
  449.  
  450. // Pixel distance from the sharp outline
  451. int sharpOutlineDistX = bareCrossDistX - CrossOutlineSharpness;
  452. int sharpOutlineDistY = bareCrossDistY - CrossOutlineSharpness;
  453.  
  454. draw = float4(CrossOutlineColor, 1.0);
  455.  
  456. #ifdef __DEBUG__
  457. if (sharpOutlineDistX == 0 && sharpOutlineDistY == 0) {
  458. draw = float4(random1/255.0, random2/255.0, random3/255.0, 1);
  459. return draw;
  460. }
  461. #endif
  462.  
  463. float2 relativePos = float2(max(bareCrossDistX, 0), max(bareCrossDistY, 0));
  464. float dist = distance(relativePos, float2(0, 0));
  465. if (dist < CrossOutlineSharpness) {
  466. drawOpacity = XhairOpacity;
  467. } else if (dist < (CrossOutlineSharpness + CrossOutlineGlow)) {
  468. float glowIntensity = saturate(1.0 - ((dist - CrossOutlineSharpness) / float(CrossOutlineGlow)));
  469. drawOpacity = CROSS_OUTLINE_GLOW(glowIntensity) * XhairOpacity;
  470. }
  471.  
  472. drawOpacity *= CrossOutlineOpacity * XhairOpacity;
  473. }
  474.  
  475. }
  476. }
  477.  
  478. float4 PS_Xhair(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target {
  479. float4 drawBackground = tex2D(ReShade::BackBuffer, texcoord);
  480.  
  481. // Skip rendering if disabled
  482. if (XhairType == 2) {
  483. return drawBackground;
  484. }
  485.  
  486. // Don't render if RMB hiding is activated
  487. //if (HideOnRMB == 1 && rightMouseDown || HideOnRMB == 0 && rightMouseToggle) {
  488. if (!rightMouseDown) {
  489. return drawBackground;
  490. }
  491.  
  492. float2 center = float2((BUFFER_WIDTH / 2) + OffsetX, (BUFFER_HEIGHT / 2) + OffsetY);
  493.  
  494. int distX = abs(center.x - pos.x);
  495. int distY = abs(center.y - pos.y);
  496. float distCenter = distance(center, pos);
  497.  
  498. float4 draw;
  499. float drawOpacity = 0;
  500.  
  501. switch (XhairType) {
  502. case 1: { // Circle
  503. drawCircleXhair(distCenter, draw, drawOpacity);
  504. break;
  505. }
  506. case 0: // Cross
  507. default: {
  508. drawCrossXhair(distX, distY, draw, drawOpacity);
  509. break;
  510. }
  511. }
  512.  
  513. if (
  514. // Dot: Circle
  515. (DotType == 0 && distCenter <= DotSize) ||
  516. // Dot: Square
  517. (DotType == 1 && distX <= (DotSize - 1) && distY <= (DotSize - 1))
  518. ) {
  519. draw = float4(DotColor, 1.0);
  520. drawOpacity = DotOpacity;
  521. }
  522.  
  523. return lerp(drawBackground, draw, drawOpacity);
  524. }
  525.  
  526. technique xhair {
  527. pass HudPass {
  528. VertexShader = PostProcessVS;
  529. PixelShader = PS_Xhair;
  530. }
  531. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement