Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.11 KB | None | 0 0
  1. /***************************************************************************************/
  2. /*! \file Crosshair.usf
  3. *
  4. * Adds a crosshair to APBr
  5. *
  6. *
  7. * Owned by dreamss, some code stolen from tobii and spec
  8. *
  9. * variable crosshair size added by Kimiko
  10. * and pretty much every change after that ... DYNAMIC_COLOR, internal color options, and making it work on rtw/1.9.1 shaders
  11. * fuckshadercoding
  12. *
  13. * Thanks to blizzy for the alternative crosshairs ENABLE_CROSSHAIR_DOT_2 ENABLE_CROSSHAIR_CIRCLE ENABLE_CROSSHAIR_CROSS
  14. *
  15. *
  16. *
  17. * Usage:
  18. *  Add '#include "Crosshair.usf"' to  APBUberPostProcessBlendPixelShader.usf before the bottom closing "}".
  19. *   view the included APBUberPostProcessBlendPixelShader.usf if you have questions
  20. *
  21. * DONT FORGET TO EDIT SCREEN_SIZE_X and SCREEN_SIZE_Y
  22. *
  23. * IF THE GAME CRASHES CROSSHAIR_SIZE IS WAY TO BIG!
  24. ****************************************************************************************/
  25.  
  26.  
  27. #define ENABLE_CROSSHAIR 1
  28. #define ENABLE_CROSSHAIR_DOT_1 0
  29. #define ENABLE_CROSSHAIR_DOT_2 0
  30. #define ENABLE_CROSSHAIR_CIRCLE 0
  31. #define ENABLE_CROSSHAIR_CROSS 0
  32. #define ENABLE_CROSSHAIR_CHEVRON 1
  33.  
  34. #define SCREEN_SIZE_X 1920
  35. #define SCREEN_SIZE_Y 1080
  36.  
  37. #define CROSSHAIR_DOT_1_SIZE .8
  38. #define IN_CROSSHAIR_DOT_1_COLOR float4( 0, 0, 0, 1)
  39. #define IN_CROSSHAIR_DOT_1_DYNAMIC_COLOR 1
  40. #define OUT_CROSSHAIR_DOT_1_COLOR float4( 255, 0, 0, 1)
  41. #define OUT_CROSSHAIR_DOT_1_DYNAMIC_COLOR 0
  42.  
  43.  
  44. #define CROSSHAIR_DOT_2_COLOR float4(0.0, 0.0, 0.0, 0.1)
  45.  
  46.  
  47. #define CROSSHAIR_CIRCLE_COLOR float4(255, 0, 0, 1.0)
  48. #define CROSSHAIR_CIRCLE_RADIOUS  .03
  49.  
  50.  
  51. #define CROSSHAIR_CROSS_COLOR float4(1.0, 1.0, 1.0, 1.0)
  52. #define CROSSHAIR_CROSS_SIZE .005
  53.  
  54. #define CROSSHAIR_CHEVRON_COLOR float4(1.0, 0, 0, 1.0)
  55. #define CROSSHAIR_CHEVRON_SIZE_A .01
  56. #define CROSSHAIR_CHEVRON_SIZE_B .001
  57.  
  58. //I officially give the fuck up. Set this to SCREEN_SIZE_Y / SCREEN_SIZE_X manually, it refuses to work when calculated.
  59. #define chevronaspectRatio .5625
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. // if someone figures out how to make this work let me know - it does not seem to make a difference
  67. #define IN_CROSSHAIR_ALPHA 1
  68. #define OUT_CROSSHAIR_ALPHA 1
  69.  
  70.  
  71.  
  72.  
  73. {
  74. #if ENABLE_CROSSHAIR
  75. #define aspectRatio SCREEN_SIZE_X/SCREEN_SIZE_Y
  76.  
  77.  
  78. #if ENABLE_CROSSHAIR_CIRCLE
  79.         float newX = SceneUV.x * aspectRatio;
  80.         float centerX = 0.5 * aspectRatio;
  81.         float newY = SceneUV.y;
  82.         float centerY = 0.5;
  83.         float cDis;
  84.  
  85.         cDis = sqrt(pow(newX - centerX, 2) + pow(newY - centerY, 2));
  86.  
  87.         if (cDis >= CROSSHAIR_CIRCLE_RADIOUS && cDis <= (CROSSHAIR_CIRCLE_RADIOUS+ 0.002f))
  88.         {
  89.             OutColor = CROSSHAIR_CIRCLE_COLOR;
  90.         }
  91. #endif
  92.  
  93. #if ENABLE_CROSSHAIR_CROSS
  94.             if (SceneUV.x >= 0.5 - CROSSHAIR_CROSS_SIZE && SceneUV.x <= 0.5 + CROSSHAIR_CROSS_SIZE && SceneUV.y >= 0.499 && SceneUV.y <= 0.501)
  95.             {
  96.                 OutColor =  CROSSHAIR_CROSS_COLOR;
  97.             }
  98.             else if (SceneUV.x >= 0.4995 && SceneUV.x <= 0.5005 && SceneUV.y >= 0.5 - (CROSSHAIR_CROSS_SIZE * aspectRatio) && SceneUV.y <= 0.5 + (CROSSHAIR_CROSS_SIZE * aspectRatio))
  99.             {
  100.                 OutColor =  CROSSHAIR_CROSS_COLOR;
  101.             }
  102. #endif
  103.  
  104. #if ENABLE_CROSSHAIR_CHEVRON // CROSSHAIR_CHEVRON_SIZE
  105.  
  106.             // seriously, shoot me
  107.  
  108.             //this works still...
  109.             //if (SceneUV.x >= 0.5 - CROSSHAIR_CHEVRON_SIZE_A && SceneUV.x <= 0.5 + CROSSHAIR_CHEVRON_SIZE_A && SceneUV.x >= SceneUV.y - CROSSHAIR_CHEVRON_SIZE_B && SceneUV.x <= SceneUV.y + CROSSHAIR_CHEVRON_SIZE_B && SceneUV.y >= 0.5)
  110.  
  111.             //Static aspect ratio 16:9
  112.             //if (SceneUV.x >= 0.5 - CROSSHAIR_CHEVRON_SIZE_A && SceneUV.x <= 0.5 + CROSSHAIR_CHEVRON_SIZE_A && SceneUV.x >= .5625 * SceneUV.y + ( 1 - .5625 ) / 2 - CROSSHAIR_CHEVRON_SIZE_B && SceneUV.x <= .5625 * SceneUV.y + ( 1 - .5625 ) / 2 + CROSSHAIR_CHEVRON_SIZE_B && SceneUV.y >= 0.5)
  113.             if (SceneUV.x >= 0.5 - CROSSHAIR_CHEVRON_SIZE_A && SceneUV.x <= 0.5 + CROSSHAIR_CHEVRON_SIZE_A && SceneUV.x >= chevronaspectRatio * SceneUV.y + ( 1 - chevronaspectRatio ) / 2 - CROSSHAIR_CHEVRON_SIZE_B && SceneUV.x <= chevronaspectRatio * SceneUV.y + ( 1 - chevronaspectRatio ) / 2 + CROSSHAIR_CHEVRON_SIZE_B && SceneUV.y >= 0.5)
  114.             {
  115.                 OutColor =  CROSSHAIR_CHEVRON_COLOR;
  116.             }
  117.             //static aspect ratio 16:9
  118.             //else if (SceneUV.x >= 0.5 - CROSSHAIR_CHEVRON_SIZE_A && SceneUV.x <= 0.5 + CROSSHAIR_CHEVRON_SIZE_A && SceneUV.x >= 1 - .5625 * SceneUV.y - ( 1 - .5625 ) / 2 - CROSSHAIR_CHEVRON_SIZE_B && SceneUV.x <= 1 - .5625 * SceneUV.y - ( 1 - .5625 ) / 2 + CROSSHAIR_CHEVRON_SIZE_B && SceneUV.y >= 0.5)
  119.             else if (SceneUV.x >= 0.5 - CROSSHAIR_CHEVRON_SIZE_A && SceneUV.x <= 0.5 + CROSSHAIR_CHEVRON_SIZE_A && SceneUV.x >= 1 - chevronaspectRatio * SceneUV.y - ( 1 - chevronaspectRatio ) / 2 - CROSSHAIR_CHEVRON_SIZE_B && SceneUV.x <= 1 - chevronaspectRatio * SceneUV.y - ( 1 - chevronaspectRatio ) / 2 + CROSSHAIR_CHEVRON_SIZE_B && SceneUV.y >= 0.5)
  120.             {
  121.                 OutColor =  CROSSHAIR_CHEVRON_COLOR;
  122.             }
  123. #endif
  124.  
  125. #if ENABLE_CROSSHAIR_DOT_2
  126.         if (SceneUV.x >= 0.498 && SceneUV.x <= 0.502 && SceneUV.y >= 0.498 && SceneUV.y <= 0.502)
  127.         {
  128.             OutColor = CROSSHAIR_DOT_2_COLOR;
  129.         }
  130. #endif
  131.  
  132.  
  133.  
  134.  #if ENABLE_CROSSHAIR_DOT_1
  135.         float2 ScreenSize = float2( CROSSHAIR_DOT_1_SIZE / SCREEN_SIZE_X , CROSSHAIR_DOT_1_SIZE / SCREEN_SIZE_Y );
  136.        
  137.        if(SceneUV.x >= 0.5 - ScreenSize.x && SceneUV.x <= 0.5 + ScreenSize.x && SceneUV.y >= 0.5 - ScreenSize.y && SceneUV.y <= 0.5 + ScreenSize.y)
  138.         {
  139.             #if IN_CROSSHAIR_DOT_1_DYNAMIC_COLOR
  140.                 OutColor = 1 - OutColor;
  141.               OutColor.a = IN_CROSSHAIR_ALPHA;
  142.             #else
  143.              OutColor = IN_CROSSHAIR_DOT_1_COLOR ;
  144.             #endif // IN_CROSSHAIR_DOT_1_DYNAMIC_COLOR
  145.         }
  146.         else if (SceneUV.x >= 0.5 - ScreenSize.x * 2 && SceneUV.x <= 0.5 + ScreenSize.x * 2 && SceneUV.y >= 0.5 - ScreenSize.y * 2 && SceneUV.y <= 0.5 + ScreenSize.y * 2 )
  147.         {
  148.             #if OUT_CROSSHAIR_DOT_1_DYNAMIC_COLOR
  149.                 OutColor = 1 - OutColor;
  150.               OutColor.a = OUT_CROSSHAIR_ALPHA;
  151.             #else
  152.             OutColor =  OUT_CROSSHAIR_DOT_1_COLOR;
  153.         #endif // OUT_CROSSHAIR_DOT_1_DYNAMIC_COLOR
  154.         }
  155.  #endif //ENABLE_CROSSHAIR_DOT_1
  156.  
  157. #endif // ENABLE_CROSSHAIR
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement