X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=shaderlib%2Fcolorcurve.glsl;fp=shaderlib%2Fcolorcurve.glsl;h=fa3ba5107600f36f9a9e7b559b31e2b8fb5bf408;hb=e55f79ccb21e8c1be3d86f127e3ec1583e58ce92;hp=0000000000000000000000000000000000000000;hpb=b2764a3a349b48d7445202faa903383386c09a4c;p=libs%2Fgl.git diff --git a/shaderlib/colorcurve.glsl b/shaderlib/colorcurve.glsl new file mode 100644 index 00000000..fa3ba510 --- /dev/null +++ b/shaderlib/colorcurve.glsl @@ -0,0 +1,29 @@ +import postprocess; + +uniform sampler1D curve; +uniform ToneMapping +{ + float peak; + float brightness; +}; + +////// fragment +void main() +{ + vec4 sample = texture(source, texcoord); + float maxc = max(sample.r, max(sample.g, sample.b)); + if(maxc>1.0-peak) + { + 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); + } + } + frag_color = vec4(texture(curve, sample.r).r, texture(curve, sample.g).r, texture(curve, sample.b).r, sample.a); +}