Advertisement
Guest User

Nightvision + Noise Shader (HLSL)

a guest
Jul 17th, 2018
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include "common_ps_fxc.h"
  2.  
  3. const HALF Brightness : register (c0); //this is a variable to set how bright the NV will be.
  4.  
  5. sampler BaseTextureSampler : register( s0 ); //a sampler to get the texture this shader will be used on (in this case it will be a frame buffer)
  6.  
  7. sampler ColorMapSampler : register(s0);
  8.  
  9. // A timer to animate our shader
  10. float fTimer;
  11.  
  12. // the amount of distortion
  13. float fNoiseAmount;
  14.  
  15. // just a random starting number
  16. int iSeed;
  17.  
  18.  
  19. HALF4 main(float2 iTexCoord : TEXCOORD0) : COLOR //out main function
  20. {
  21. float4 vAdd = float4(0.1,0.1,0.1,0); // just a float4 for use later
  22.  
  23. float4 cColor = tex2D(BaseTextureSampler,iTexCoord); //this takes our sampler and turns the rgba into floats between 0 and 1
  24. cColor += tex2D(BaseTextureSampler, iTexCoord.xy + 0.001); // these 3 lines blur the image slightly
  25. cColor += tex2D(BaseTextureSampler, iTexCoord.xy + 0.002);
  26. cColor += tex2D(BaseTextureSampler, iTexCoord.xy + 0.003);
  27. if (((cColor.r + cColor.g + cColor.b)/3) < 0.9) // if the pixel is bright leave it bright
  28. {
  29. cColor = cColor / 4; //otherwise set it to an average color of the 4 images we just added together
  30. }
  31.  
  32. float4 cTempColor = cColor; //a new float4 cTempColor for use later
  33.  
  34. cFinal.g = (cTempColor.r + cTempColor.g + cTempColor.b)/3; // sets green the the average of rgb
  35. cFinal.r = 0; //removes red and blue colors
  36. cFinal.b = 0;
  37.  
  38. // Distortion factor
  39. float NoiseX = iSeed * fTimer * sin(iTexCoord.x * iTexCoord.y+fTimer);
  40. NoiseX=fmod(NoiseX,8) * fmod(NoiseX,4);
  41.  
  42. // Use our distortion factor to compute how much it will affect each
  43. // texture coordinate
  44. float DistortX = fmod(NoiseX,fNoiseAmount);
  45. float DistortY = fmod(NoiseX,fNoiseAmount+0.002);
  46.  
  47. // Create our new texture coordinate based on our distortion factor
  48. float2 DistortTex = float2(DistortX,DistortY);
  49.  
  50. // Use our new texture coordinate to look-up a pixel in BaseTextureSampler.
  51. float4 Color=tex2D(ColorMapSampler, Tex+DistortTex);
  52.  
  53. // Keep our alphachannel at 1.
  54. Color.a = 1.0f;
  55.  
  56. cFinal.g = (cTempColor.r + cTempColor.g + cTempColor.b)/3; // sets green the the average of rgb
  57. cFinal.r = 0; //removes red and blue colors
  58. cFinal.b = 0;
  59.  
  60. return (cFinal * Brightness) + Color;
  61. }
  62.  
  63. technique PostProcess
  64. {
  65. pass P0
  66. {
  67. // A post process shader only needs a pixel shader.
  68. PixelShader = compile ps_2_0 PixelShader();
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement