Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef UNITY_PHYSICAL_CAMERA_INCLUDED
  2. #define UNITY_PHYSICAL_CAMERA_INCLUDED
  3. // Has to be kept in sync with ColorUtils.cs
  4. // References:
  5. // "Moving Frostbite to PBR" (Sebastien Lagarde & Charles de Rousiers)
  6. // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  7. // "Implementing a Physically Based Camera" (Padraic Hennessy)
  8. // https://placeholderart.wordpress.com/2014/11/16/implementing-a-physically-based-camera-understanding-exposure/
  9. float ComputeEV100(float aperture, float shutterSpeed, float ISO)
  10. {
  11. // EV number is defined as:
  12. // 2^ EV_s = N^2 / t and EV_s = EV_100 + log2 (S /100)
  13. // This gives
  14. // EV_s = log2 (N^2 / t)
  15. // EV_100 + log2 (S /100) = log2 (N^2 / t)
  16. // EV_100 = log2 (N^2 / t) - log2 (S /100)
  17. // EV_100 = log2 (N^2 / t . 100 / S)
  18. return log2((aperture * aperture) / shutterSpeed * 100.0 / ISO);
  19. }
  20. float ComputeEV100FromAvgLuminance(float avgLuminance, float calibrationConstant)
  21. {
  22. const float K = calibrationConstant;
  23. return log2(avgLuminance * 100.0 / K);
  24. }
  25. float ComputeEV100FromAvgLuminance(float avgLuminance)
  26. {
  27. // We later use the middle gray at 12.7% in order to have
  28. // a middle gray at 18% with a sqrt(2) room for specular highlights
  29. // But here we deal with the spot meter measuring the middle gray
  30. // which is fixed at 12.5 for matching standard camera
  31. // constructor settings (i.e. calibration constant K = 12.5)
  32. // Reference: http://en.wikipedia.org/wiki/Film_speed
  33. const float K = 12.5; // Reflected-light meter calibration constant
  34. return ComputeEV100FromAvgLuminance(avgLuminance, K);
  35. }
  36. float ConvertEV100ToExposure(float EV100, float exposureScale)
  37. {
  38. // Compute the maximum luminance possible with H_sbs sensitivity
  39. // maxLum = 78 / ( S * q ) * N^2 / t
  40. // = 78 / ( S * q ) * 2^ EV_100
  41. // = 78 / (100 * s_LensAttenuation) * 2^ EV_100
  42. // = exposureScale * 2^ EV
  43. // Reference: http://en.wikipedia.org/wiki/Film_speed
  44. float maxLuminance = exposureScale * pow(2.0, EV100);
  45. return 1.0 / maxLuminance;
  46. }
  47. float ConvertEV100ToExposure(float EV100)
  48. {
  49. const float exposureScale = 1.2;
  50. return ConvertEV100ToExposure(EV100, exposureScale);
  51. }
  52. float ComputeISO(float aperture, float shutterSpeed, float targetEV100)
  53. {
  54. // Compute the required ISO to reach the target EV100
  55. return ((aperture * aperture) * 100.0) / (shutterSpeed * pow(2.0, targetEV100));
  56. }
  57. float ComputeLuminanceAdaptation(float previousLuminance, float currentLuminance, float speedDarkToLight, float speedLightToDark, float deltaTime)
  58. {
  59. float delta = currentLuminance - previousLuminance;
  60. float speed = delta > 0.0 ? speedDarkToLight : speedLightToDark;
  61. // Exponential decay
  62. return previousLuminance + delta * (1.0 - exp2(-deltaTime * speed));
  63. }
  64. #endif // UNITY_PHYSICAL_CAMERA_INCLUDED