PPEyeAdaptationCommon.bslinc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. mixin PPEyeAdaptationParams
  2. {
  3. code
  4. {
  5. [internal]
  6. cbuffer EyeAdaptationParams
  7. {
  8. // [0]: x - histogram scale, y - histogram offset, z - histogram percent low, w - histogram percent high
  9. // [1]: x - min adaptation, y - max adaptation, z - adaptation speed up, w - adaptation speed down
  10. // [2]: x - exposure scale, y - frame time delta, z - min. allowed intensity, w - nothing
  11. float4 gEyeAdaptationParams[3];
  12. }
  13. /**
  14. * Smooths out eye adaptation changes over multiple frames so they aren't as jarring.
  15. *
  16. * @param old Eye adaptation value from the previous frame.
  17. * @param target Ideal eye adaptation value for this frame.
  18. * @param frameDelta Time difference between this and last frame, in seconds.
  19. * @return Smoothed eye adaptation.
  20. */
  21. float smoothEyeAdaptation(float old, float target, float frameDelta)
  22. {
  23. float diff = target - old;
  24. float speedUp = gEyeAdaptationParams[1].z;
  25. float speedDown = gEyeAdaptationParams[1].w;
  26. float adaptionSpeed = (diff > 0) ? speedUp : speedDown;
  27. float scale = 1.0f - exp2(-frameDelta * adaptionSpeed);
  28. return clamp(old + diff * scale, gEyeAdaptationParams[1].x, gEyeAdaptationParams[1].y);
  29. }
  30. };
  31. };