- vec3 saturated = sample.rgb/maxc;
- if(maxc>1.0+peak)
- {
- sample.rgb = mix(vec3(1.0), saturated, 1.0/pow(brightness, maxc-1.0-peak));
- }
- else
- {
- float x = (1.0+peak-maxc)/(2.0*peak);
- sample.rgb = saturated.rgb*(1.0-peak+(1.0-x*x)*peak);
- }
+ vec3 saturated = incoming.rgb/maxc;
+ maxc = pow(maxc*exposure+brightness_response.y, brightness_response.x)-brightness_response.z;
+ float c = min(maxc, 1.0);
+ float minc = min(saturated.r, min(saturated.g, saturated.b));
+ incoming.rgb = mix(saturated, vec3(1.0), min((maxc-c)/(1.0-minc), 1.0))*c;