DPX.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. DPX/Cineon shader by Loadus ( http://www.loadusfx.net/virtualdub/DPX.fx )
  3. Version 1.0
  4. Ported to SweetFX by CeeJay.dk
  5. Version 1.1
  6. Improved performance
  7. */
  8. static float3x3 RGB =
  9. {
  10. 2.67147117265996,-1.26723605786241,-0.410995602172227,
  11. -1.02510702934664,1.98409116241089,0.0439502493584124,
  12. 0.0610009456429445,-0.223670750812863,1.15902104167061
  13. };
  14. static float3x3 XYZ =
  15. {
  16. 0.500303383543316,0.338097573222739,0.164589779545857,
  17. 0.257968894274758,0.676195259144706,0.0658358459823868,
  18. 0.0234517888692628,0.1126992737203,0.866839673124201
  19. };
  20. float4 DPXPass(float4 InputColor){
  21. float DPXContrast = 0.1;
  22. float DPXGamma = 1.0;
  23. float RedCurve = Red;
  24. float GreenCurve = Green;
  25. float BlueCurve = Blue;
  26. float3 RGB_Curve = float3(Red,Green,Blue);
  27. float3 RGB_C = float3(RedC,GreenC,BlueC);
  28. float3 B = InputColor.rgb;
  29. //float3 Bn = B; // I used InputColor.rgb instead.
  30. B = pow(B, 1.0/DPXGamma);
  31. B = B * (1.0 - DPXContrast) + (0.5 * DPXContrast);
  32. //B = (1.0 /(1.0 + exp(- RGB_Curve * (B - RGB_C))) - (1.0 / (1.0 + exp(RGB_Curve / 2.0))))/(1.0 - 2.0 * (1.0 / (1.0 + exp(RGB_Curve / 2.0))));
  33. float3 Btemp = (1.0 / (1.0 + exp(RGB_Curve / 2.0)));
  34. B = ((1.0 / (1.0 + exp(-RGB_Curve * (B - RGB_C)))) / (-2.0 * Btemp + 1.0)) + (-Btemp / (-2.0 * Btemp + 1.0));
  35. //TODO use faster code for conversion between RGB/HSV - see http://www.chilliant.com/rgb2hsv.html
  36. float value = max(max(B.r, B.g), B.b);
  37. float3 color = B / value;
  38. color = pow(color, 1.0/ColorGamma);
  39. float3 c0 = color * value;
  40. c0 = mul(XYZ, c0);
  41. float luma = dot(c0, float3(0.30, 0.59, 0.11)); //Use BT 709 instead?
  42. //float3 chroma = c0 - luma;
  43. //c0 = chroma * DPXSaturation + luma;
  44. c0 = (1.0 - DPXSaturation) * luma + DPXSaturation * c0;
  45. c0 = mul(RGB, c0);
  46. InputColor.rgb = lerp(InputColor.rgb, c0, Blend);
  47. return InputColor;
  48. }