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