nightvision2scanlines.glsl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 and apply horizontal scanlines
  22. // This would have been much simpler if I could get the stupid modulo (%) to work
  23. // If anyone who is more well versed in Cg knows how to do this it'd be slightly more efficient
  24. // float lineIntensity = ((GetCoordinates()[1] % 9) - 4) / 40;
  25. float vPos = GetCoordinates().y*GetResolution().y / 9.0;
  26. float lineIntensity = (((vPos - floor(vPos)) * 9.0) - 4.0) / 40.0;
  27. grey = grey * 0.5 + 0.7 + lineIntensity;
  28. // darken edges
  29. float x = GetCoordinates().x * GetResolution().x;
  30. float y = GetCoordinates().y * GetResolution().y;
  31. if (x > internalresolution/2.0)
  32. x = internalresolution-x;
  33. if (y > internalresolution/2.0)
  34. y = internalresolution-y;
  35. if (x > internalresolution/2.0*0.95)
  36. x = internalresolution/2.0*0.95;
  37. if (y > internalresolution/2.0*0.95)
  38. y = internalresolution/2.0*0.95;
  39. x = -x + 641.0;
  40. y = -y + 641.0;
  41. //****inline square root routines*****/
  42. // bit of a performance bottleneck.
  43. // neccessary to make the darkened area rounded
  44. // instead of rhombus-shaped.
  45. float sqrt = x / 10.0;
  46. while ((sqrt*sqrt) < x)
  47. sqrt+=0.1;
  48. x = sqrt;
  49. sqrt = y / 10.0;
  50. while ((sqrt*sqrt) < y)
  51. sqrt+=0.1;
  52. y = sqrt;
  53. x *= 2.0;
  54. y *= 2.0;
  55. grey -= x / 200.0;
  56. grey -= y / 200.0;
  57. // output
  58. SetOutput(float4(0.0, grey, 0.0, 1.0));
  59. }