#define SHUTTER_SPEED 60.0 //[500.0 250.0 125.0 60.0 30.0 15.0 8.0]
#define SENSITIVITY_TO_LIGHT 100.0 //[50.0 100.0 200.0 400.0 600.0 800.0 1200.0 1600.0 2400.0 3200.0]
#define F_STOPS 8.0 //[1.4 2.0 2.8 4.0 5.6 8.0 11.0 16.0 22.0 32.0]

#define CAMERA_SCALE 1 //[1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 10 15 20 25 30 35 40 45 50 55 60] Increases the size of the camera relative to the scene, allowing for some macro photography.

//#define MANUAL_CAMERA
//#define MANUAL_FOCUS

#define FOCUS_DISTANCE 10 //[1 2 3 4 5 6 7 8.0 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30]
#define FOV 60 //[6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130]

//#define ANAMORPHIC_LENS

#ifdef MANUAL_FOCUS
#endif

uniform float aspectRatio;

struct camera {
    float scale;
    float sensorWidth;
    float sensorHeight;
    float r;
    float fstops;
    float shutterTime;
    float ISO;

    vec2 sensorSize;
    vec2 focalLength;
    vec2 apertureRadius;
}cm;

vec2 bokehShape() {
    const int blades = 5;

    vec2 uv = randNext2F();

    vec2 axis;
    if(blades > 0) {
        const float angle = tau/blades;
        
        uv.x *= blades;
        float blade = floor(uv.x);
        uv.x = fract(uv.x);

        mat2 rot = rotate((blade+0.0) * angle);

        axis  = rot * vec2(cos(angle / 2.0), sin(angle / 2.0) * (uv.x * 2.0 - 1.0));
        axis *= sqrt(uv.y);
    } else {
        axis  = vec2(0.0);
        axis  = vec2(cos(tau * uv.x), sin(tau * uv.x));
        axis *= sqrt(uv.y);
    }
    vec2 anamorphic = vec2(1.0);
    #ifdef ANAMORPHIC_LENS
        anamorphic = vec2(1.0, 2.0);
    #endif

    return pow(length(uv), -0.15) * axis * anamorphic;
}

void defineCamera() {
    cm.sensorWidth = CAMERA_SCALE * 1e-3 * 36;
    cm.sensorHeight = CAMERA_SCALE * 1e-3 * 24;
    cm.r = length(bokehShape());
    cm.fstops = F_STOPS;
    cm.shutterTime = 1.0/SHUTTER_SPEED;
    cm.ISO = SENSITIVITY_TO_LIGHT;

    cm.sensorSize = vec2(cm.sensorWidth, cm.sensorHeight);
    cm.focalLength  = 0.5 * cm.sensorSize * vec2(gbufferProjection[0].x, gbufferProjection[1].y);
    #ifdef MANUAL_CAMERA
        cm.focalLength  = 0.5 * cm.sensorSize / (2.0 * vec2(aspectRatio, 1.0) * tan(radians(FOV) / 2.0));
    #endif
    cm.focalLength *= 1.0 + cm.r * 0.0;
    cm.apertureRadius = (cm.focalLength / cm.fstops) / 2.0;
}