X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=shaderlib%2Fcolorcurve.glsl;h=23b5577dc4a05d72cfc46083aa714fd006484938;hp=fa3ba5107600f36f9a9e7b559b31e2b8fb5bf408;hb=ff85f90d33023d908c534b0bf5d9a65e9fc2cce2;hpb=e55f79ccb21e8c1be3d86f127e3ec1583e58ce92 diff --git a/shaderlib/colorcurve.glsl b/shaderlib/colorcurve.glsl index fa3ba510..23b5577d 100644 --- a/shaderlib/colorcurve.glsl +++ b/shaderlib/colorcurve.glsl @@ -3,27 +3,22 @@ import postprocess; uniform sampler1D curve; uniform ToneMapping { - float peak; - float brightness; + float exposure; + vec3 brightness_response; }; -////// fragment +#pragma MSP stage(fragment) void main() { - vec4 sample = texture(source, texcoord); - float maxc = max(sample.r, max(sample.g, sample.b)); - if(maxc>1.0-peak) + vec4 incoming = texture(source, texcoord); + float maxc = max(incoming.r, max(incoming.g, incoming.b)); + if(maxc>0.0) { - 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; } - frag_color = vec4(texture(curve, sample.r).r, texture(curve, sample.g).r, texture(curve, sample.b).r, sample.a); + frag_color = vec4(texture(curve, incoming.r).r, texture(curve, incoming.g).r, texture(curve, incoming.b).r, incoming.a); }