twiliteblue

AV for Handschuh

May 25th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. #include <renderer/RenderSetup.hlsl>
  2.  
  3. struct VS_INPUT
  4. {
  5. float3 ssPosition : POSITION;
  6. float2 texCoord : TEXCOORD0;
  7. float4 color : COLOR0;
  8. };
  9.  
  10. struct VS_OUTPUT
  11. {
  12. float2 texCoord : TEXCOORD0;
  13. float4 color : COLOR0;
  14. float4 ssPosition : SV_POSITION;
  15. };
  16.  
  17. struct PS_INPUT
  18. {
  19. float2 texCoord : TEXCOORD0;
  20. float4 color : COLOR0;
  21. };
  22.  
  23. sampler2D baseTexture;
  24. sampler2D depthTexture;
  25. sampler2D normalTexture;
  26.  
  27. cbuffer LayerConstants
  28. {
  29. float startTime;
  30. float amount;
  31. };
  32.  
  33. /**
  34. * Vertex shader.
  35. */
  36. VS_OUTPUT SFXBasicVS(VS_INPUT input)
  37. {
  38.  
  39. VS_OUTPUT output;
  40.  
  41. output.ssPosition = float4(input.ssPosition, 1);
  42. output.texCoord = input.texCoord + texelCenter;
  43. output.color = input.color;
  44.  
  45. return output;
  46.  
  47. }
  48.  
  49. float2 clamp_tex2D( sampler2D tex, float2 coord )
  50. {
  51. // TODO: remove this and fix sampler using wrapped instead of clamped addressing for depthTexture
  52. return tex2D( tex, clamp( coord, float2( 0.001, 0.001 ), float2( 0.999, 0.999 ) ) );
  53. }
  54.  
  55. const float4 edgeColorOrange = float4(1.0, 0.05, 0.0, 0);
  56. const float4 edgeColorDarkOrange = float4(0.3, 0.08, 0.0, 0);
  57. const float4 edgeColorGreen = float4(0.0, 0.8, 0.0, 0);
  58. const float4 edgeColorDarkGreen = float4(0.02, 0.15, 0.01, 0);
  59. const float4 edgeColorDarkGreen2 = float4(0.02, 0.25, 0.01, 0);
  60.  
  61. const float4 edgeColor2 = float4(1.0, 1.0, 1.0, 0) * 0.15;
  62.  
  63. float4 SFXDarkVisionPS(PS_INPUT input) : COLOR0
  64. {
  65. float2 texCoord = input.texCoord;
  66. float4 inputPixel = tex2D(baseTexture, texCoord);
  67.  
  68. if (amount == 0) // AV off - nothing else to see here
  69. {
  70. return inputPixel;
  71. }
  72.  
  73. float2 depth1 = tex2D(depthTexture, input.texCoord).rg;
  74.  
  75. // Flashlight on
  76. float offset = 0.0006; // width of the silhoutte around units
  77.  
  78. //sample the difference in distance of nearby pixel to create a depth map
  79. float depth2 = clamp_tex2D(depthTexture, texCoord + float2(-offset, -offset)).r;
  80. float depth3 = clamp_tex2D(depthTexture, texCoord + float2(-offset, offset)).r;
  81. float depth4 = clamp_tex2D(depthTexture, texCoord + float2( offset, -offset)).r;
  82. float depth5 = clamp_tex2D(depthTexture, texCoord + float2( offset, offset)).r;
  83.  
  84. float edge =
  85. abs(depth2 - depth1.r) +
  86. abs(depth3 - depth1.r) +
  87. abs(depth4 - depth1.r) +
  88. abs(depth5 - depth1.r);
  89.  
  90. edge = clamp(pow(edge, 2), 0, 1);
  91.  
  92. // diminish with distance
  93. float fadeout = pow(2, -depth1.r * 0.2 + 0.2);
  94.  
  95. if (depth1.g > 0.5) // entities
  96. {
  97.  
  98. //if (depth1.r < 0.4) // view model
  99. //{
  100. // return inputPixel;
  101. //}
  102.  
  103. float4 edgeColor;
  104. if ( depth1.g > 0.9 ) // gorges
  105. {
  106. return inputPixel * 0.5 + edgeColorDarkGreen2 * edge;
  107. }
  108. else if ( depth1.g > 0.8 ) // aliens
  109. {
  110. return inputPixel * 0.5 + edgeColorDarkGreen * edge;
  111. }
  112. else // targets and world ents
  113. {
  114. return inputPixel * 0.5 + edgeColorGreen * (edge + 0.007);
  115. }
  116. }
  117. else // world geometry
  118. {
  119. if (depth1.g > 0) // view model
  120. {
  121. return inputPixel * 0.3;
  122. }
  123. edge = edge * step( depth1.r, 100 ); // no edges for skyboxes
  124. return inputPixel * 0.05 + (edgeColor2 * edge * fadeout);
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment