Vignette.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*-----------------------------------------------------------.
  2. / Vignette /
  3. '-----------------------------------------------------------*/
  4. /*
  5. Version 1.3
  6. Darkens the edges of the image to make it look more like it was shot with a camera lens.
  7. May cause banding artifacts.
  8. */
  9. //Make sure the VignetteRatio exits to avoid breaking if the user uses a Settings for a previous version that didn't include this
  10. #ifndef VignetteRatio
  11. #define VignetteRatio 1.0
  12. #endif
  13. #ifndef VignetteType
  14. #define VignetteType 1
  15. #endif
  16. //Logical XOR - not used right now but it might be useful at a later time
  17. float XOR( float xor_A, float xor_B )
  18. {
  19. return saturate( dot(float4(-xor_A ,-xor_A ,xor_A , xor_B) , float4(xor_B, xor_B ,1.0 ,1.0 ) ) ); // -2 * A * B + A + B
  20. }
  21. float4 VignettePass( float4 colorInput, float2 tex )
  22. {
  23. #if VignetteType == 1
  24. //Set the center
  25. float2 tc = tex - VignetteCenter;
  26. //Adjust the ratio
  27. tc *= float2((pixel.y / pixel.x),VignetteRatio);
  28. //Calculate the distance
  29. tc /= VignetteRadius;
  30. float v = dot(tc,tc);
  31. //Apply the vignette
  32. colorInput.rgb *= (1.0 + pow(v, VignetteSlope * 0.5) * VignetteAmount); //pow - multiply
  33. #endif
  34. #if VignetteType == 2 // New round (-x*x+x) + (-y*y+y) method.
  35. tex = -tex * tex + tex;
  36. colorInput.rgb = saturate(( (pixel.y / pixel.x)*(pixel.y / pixel.x) * VignetteRatio * tex.x + tex.y) * 4.0) * colorInput.rgb;
  37. #endif
  38. #if VignetteType == 3 // New (-x*x+x) * (-y*y+y) TV style method.
  39. tex = -tex * tex + tex;
  40. colorInput.rgb = saturate(tex.x * tex.y * 100.0) * colorInput.rgb;
  41. #endif
  42. #if VignetteType == 4
  43. tex = abs(tex - 0.5);
  44. //tex = abs(0.5 - tex); //same result
  45. float tc = dot(float4(-tex.x ,-tex.x ,tex.x , tex.y) , float4(tex.y, tex.y ,1.0 ,1.0 ) ); //XOR
  46. tc = saturate(tc -0.495);
  47. colorInput.rgb *= (pow((1.0 - tc * 200),4)+0.25); //or maybe abs(tc*100-1) (-(tc*100)-1)
  48. #endif
  49. #if VignetteType == 5
  50. tex = abs(tex - 0.5);
  51. //tex = abs(0.5 - tex); //same result
  52. float tc = dot(float4(-tex.x ,-tex.x ,tex.x , tex.y) , float4(tex.y, tex.y ,1.0 ,1.0 ) ); //XOR
  53. tc = saturate(tc -0.495)-0.0002;
  54. colorInput.rgb *= (pow((1.0 - tc * 200),4)+0.0); //or maybe abs(tc*100-1) (-(tc*100)-1)
  55. #endif
  56. #if VignetteType == 6 //MAD version of 2
  57. tex = abs(tex - 0.5);
  58. //tex = abs(0.5 - tex); //same result
  59. float tc = tex.x * (-2.0 * tex.y + 1.0) + tex.y; //XOR
  60. tc = saturate(tc -0.495);
  61. colorInput.rgb *= (pow((-tc * 200 + 1.0),4)+0.25); //or maybe abs(tc*100-1) (-(tc*100)-1)
  62. //colorInput.rgb *= (pow(((tc*200.0)-1.0),4)); //or maybe abs(tc*100-1) (-(tc*100)-1)
  63. #endif
  64. #if VignetteType == 7 // New round (-x*x+x) * (-y*y+y) method.
  65. //tex.y /= float2((pixel.y / pixel.x),VignetteRatio);
  66. float tex_xy = dot( float4(tex,tex) , float4(-tex,1.0,1.0) ); //dot is actually slower
  67. colorInput.rgb = saturate(tex_xy * 4.0) * colorInput.rgb;
  68. #endif
  69. return colorInput;
  70. }