Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. /***************************************************************************************/
  2. /*! DopeShader settings available in \file APB-DopeShader-Settings.usf
  3. ****************************************************************************************/
  4.  
  5. #include "Common.usf"
  6. #include "PostProcessCommon.usf"
  7. #include "APB-DopeShader-Settings.usf"
  8.  
  9. // Tone-mapping parameters.
  10. sampler2D AdaptedLuminance;
  11. float MiddleGrey;
  12. float Lwhite;
  13.  
  14. #if SET_BLOOM
  15. sampler2D BlurredImage;
  16. float BloomAlpha;
  17. float BloomPostScale;
  18. #endif
  19.  
  20. // Colour adjustment parameters.
  21. #if SET_ADJUSTMENT
  22. float Brightness;
  23. float Contrast;
  24. float Saturation;
  25. float3 DesaturatedColour;
  26. #endif
  27.  
  28. // The per-color weighting to be used for luminance calculations in RGB order.
  29. static const float3 LuminanceVector = float3(0.3, 0.59, 0.11);
  30.  
  31. // SJT: Perform tone mapping on a pixel.
  32. float3 ToneMap(float3 WorldColour)
  33. {
  34. float fAdaptedLuminance = tex2D(AdaptedLuminance, float2(0.5f, 0.5f)).r;
  35.  
  36. float Lworld = dot(WorldColour, LuminanceVector);
  37. float Exposure = MiddleGrey / (fAdaptedLuminance + 0.2f);
  38.  
  39. float Ladapted = Lworld * Exposure;
  40. float Ldisplay = (Ladapted * (1.4 + Ladapted / (Lwhite * Lwhite))) / (1.0f + Ladapted);
  41.  
  42. return WorldColour * Ldisplay / (Lworld + 0.0016);
  43. }
  44.  
  45. // SJT: Basic colour adjustment.
  46. #if SET_ADJUSTMENT
  47. float3 ColourAdjust(float3 InColour)
  48. {
  49. float3 Result = InColour;
  50.  
  51. // Saturate before we do anything to prevent whackiness from values outside [0,1]
  52. Result = saturate(Result);
  53.  
  54. // (De)saturate.
  55. Result = lerp(dot(Result, LuminanceVector) * DesaturatedColour, Result, Saturation);
  56.  
  57. // Contrast adjustment (cubic).
  58. Result = Result - Contrast * (Result - 1) * Result * (Result - 0.5);
  59.  
  60. // Brightness adjustment (addition).
  61. Result = Result + Brightness;
  62.  
  63. return Result;
  64. }
  65. #endif
  66.  
  67. void Main(
  68. in float2 UV : TEXCOORD0,
  69. in float2 SceneUV : TEXCOORD1,
  70. out float4 OutColor : COLOR0
  71. )
  72. {
  73. float4 sceneColor=tex2D(SceneColorTexture,SceneUV);
  74.  
  75. #if SET_BLOOM
  76. float4 rawColor = tex2D(BlurredImage,UV);
  77. float3 filteredColor = MAX_SCENE_COLOR * rawColor.rgb * BloomPostScale;
  78. float3 RTWBloom = 1-(saturate(1-(filteredColor.rgb*BloomAlpha*0.2))*saturate(1-lerp(sceneColor.rgb, 0, BloomAlpha*saturate(rawColor.a*4)*0.2)));
  79. float3 ToneMappedColour = ToneMap(RTWBloom);
  80. #else
  81. float3 ToneMappedColour = ToneMap(sceneColor);
  82. #endif
  83.  
  84. #if SET_ADJUSTMENT
  85. float3 AdjustedColour = ColourAdjust(ToneMappedColour);
  86. OutColor = float4(AdjustedColour.rgb, sceneColor.a);
  87. #else
  88. OutColor = float4(ToneMappedColour.rgb, sceneColor.a);
  89. #endif
  90.  
  91. #if SET_DESATURATE
  92. float luminance = dot(OutColor, LuminanceVector);
  93. float4 eColor = lerp(luminance, OutColor, 0.9) ; // 1.0 no desaturation, while 0.0 is full desaturation
  94. OutColor = float4(eColor.rgb, OutColor.a);
  95. #endif
  96.  
  97. OutColor *= 2.15;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement