nightvision2.glsl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. void main()
  2. {
  3. //variables
  4. float internalresolution = 1278.0;
  5. float4 c0 = Sample();
  6. //blur
  7. float4 blurtotal = float4(0.0, 0.0, 0.0, 0.0);
  8. float blursize = 1.5;
  9. blurtotal += SampleLocation(GetCoordinates() + float2(-blursize, -blursize) * GetInvResolution());
  10. blurtotal += SampleLocation(GetCoordinates() + float2(-blursize, blursize) * GetInvResolution());
  11. blurtotal += SampleLocation(GetCoordinates() + float2( blursize, -blursize) * GetInvResolution());
  12. blurtotal += SampleLocation(GetCoordinates() + float2( blursize, blursize) * GetInvResolution());
  13. blurtotal += SampleLocation(GetCoordinates() + float2(-blursize, 0.0) * GetInvResolution());
  14. blurtotal += SampleLocation(GetCoordinates() + float2( blursize, 0.0) * GetInvResolution());
  15. blurtotal += SampleLocation(GetCoordinates() + float2( 0.0, -blursize) * GetInvResolution());
  16. blurtotal += SampleLocation(GetCoordinates() + float2( 0.0, blursize) * GetInvResolution());
  17. blurtotal *= 0.125;
  18. c0 = blurtotal;
  19. //greyscale
  20. float grey = ((0.3 * c0.r) + (0.4 * c0.g) + (0.3 * c0.b));
  21. // brighten
  22. grey = grey * 0.5 + 0.7;
  23. // darken edges
  24. float x = GetCoordinates().x * GetResolution().x;
  25. float y = GetCoordinates().y * GetResolution().y;
  26. if (x > internalresolution/2.0)
  27. x = internalresolution-x;
  28. if (y > internalresolution/2.0)
  29. y = internalresolution-y;
  30. if (x > internalresolution/2.0*0.95)
  31. x = internalresolution/2.0*0.95;
  32. if (y > internalresolution/2.0*0.95)
  33. y = internalresolution/2.0*0.95;
  34. x = -x+641.0;
  35. y = -y+641.0;
  36. /*****inline square root routines*****/
  37. // bit of a performance bottleneck.
  38. // neccessary to make the darkened area rounded
  39. // instead of rhombus-shaped.
  40. float sqrt = x / 10.0;
  41. while ((sqrt*sqrt) < x)
  42. sqrt+=0.1;
  43. x = sqrt;
  44. sqrt = y / 10.0;
  45. while ((sqrt*sqrt) < y)
  46. sqrt+=0.1;
  47. y = sqrt;
  48. x *= 2.0;
  49. y *= 2.0;
  50. grey -= x / 200.0;
  51. grey -= y / 200.0;
  52. // output
  53. SetOutput(float4(0.0, grey, 0.0, 1.0));
  54. }