nightvision2scanlines.glsl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. uniform sampler2D samp9;
  2. out vec4 ocol0;
  3. in vec2 uv0;
  4. uniform vec4 resolution;
  5. void main()
  6. {
  7. //variables
  8. int internalresolution = 1278;
  9. float4 c0 = texture(samp9, uv0).rgba;
  10. //blur
  11. float4 blurtotal = float4(0, 0, 0, 0);
  12. float blursize = 1.5;
  13. blurtotal += texture(samp9, uv0 + float2(-blursize, -blursize)*resolution.zw);
  14. blurtotal += texture(samp9, uv0 + float2(-blursize, blursize)*resolution.zw);
  15. blurtotal += texture(samp9, uv0 + float2( blursize, -blursize)*resolution.zw);
  16. blurtotal += texture(samp9, uv0 + float2( blursize, blursize)*resolution.zw);
  17. blurtotal += texture(samp9, uv0 + float2(-blursize, 0)*resolution.zw);
  18. blurtotal += texture(samp9, uv0 + float2( blursize, 0)*resolution.zw);
  19. blurtotal += texture(samp9, uv0 + float2( 0, -blursize)*resolution.zw);
  20. blurtotal += texture(samp9, uv0 + float2( 0, blursize)*resolution.zw);
  21. blurtotal *= 0.125;
  22. c0 = blurtotal;
  23. //greyscale
  24. float grey = ((0.3 * c0.r) + (0.4 * c0.g) + (0.3 * c0.b));
  25. // brighten and apply horizontal scanlines
  26. // This would have been much simpler if I could get the stupid modulo (%) to work
  27. // If anyone who is more well versed in Cg knows how to do this it'd be slightly more efficient
  28. // float lineIntensity = ((uv0[1] % 9) - 4) / 40;
  29. float vPos = uv0.y*resolution.y / 9;
  30. float lineIntensity = (((vPos - floor(vPos)) * 9) - 4) / 40;
  31. grey = grey * 0.5 + 0.7 + lineIntensity;
  32. // darken edges
  33. float x = uv0.x * resolution.x;
  34. float y = uv0.y * resolution.y;
  35. if (x > internalresolution/2) x = internalresolution-x;
  36. if (y > internalresolution/2) y = internalresolution-y;
  37. if (x > internalresolution/2*0.95) x = internalresolution/2*0.95;
  38. if (y > internalresolution/2*0.95) y = internalresolution/2*0.95;
  39. x = -x+641;
  40. y = -y+641;
  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;
  46. while((sqrt*sqrt) < x) sqrt+=0.1;
  47. x = sqrt;
  48. sqrt=y/10;
  49. while((sqrt*sqrt) < y) sqrt+=0.1;
  50. y = sqrt;
  51. /*****end of inline square root routines*****/
  52. x *= 2;
  53. y *= 2;
  54. grey -= x/200;
  55. grey -= y/200;
  56. // output
  57. ocol0 = float4(0, grey, 0, 1.0);
  58. }