From faec80b8f9183d8210dcfd52bd6998dda6db3206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 6 Jan 2016 21:07:59 -0800 Subject: [PATCH] shaderlib: Added ACES filmic tone mapping curve. --- examples/common/shaderlib.sh | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/examples/common/shaderlib.sh b/examples/common/shaderlib.sh index da7bad78..a6a51199 100644 --- a/examples/common/shaderlib.sh +++ b/examples/common/shaderlib.sh @@ -60,11 +60,11 @@ vec3 decodeNormalSphereMap(vec2 _encodedNormal) return vec3(normalize(_encodedNormal.xy) * sqrt(1.0 - zz*zz), zz); } -// Reference: -// Octahedron normal vector encoding -// http://kriscg.blogspot.com/2014/04/octahedron-normal-vector-encoding.html vec2 octahedronWrap(vec2 _val) { + // Reference: + // Octahedron normal vector encoding + // http://kriscg.blogspot.com/2014/04/octahedron-normal-vector-encoding.html return (1.0 - abs(_val.yx) ) * mix(vec2_splat(-1.0), vec2_splat(1.0), vec2(greaterThanEqual(_val.xy, vec2_splat(0.0) ) ) ); } @@ -87,11 +87,11 @@ vec3 decodeNormalOctahedron(vec2 _encodedNormal) return normalize(normal); } -// Reference: -// RGB/XYZ Matrices -// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html vec3 convertRGB2XYZ(vec3 _rgb) { + // Reference: + // RGB/XYZ Matrices + // http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html vec3 xyz; xyz.x = dot(vec3(0.4124564, 0.3575761, 0.1804375), _rgb); xyz.y = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb); @@ -246,6 +246,24 @@ vec4 toFilmic(vec4 _rgba) return vec4(toFilmic(_rgba.xyz), _rgba.w); } +vec3 toAcesFilmic(vec3 _rgb) +{ + // Reference: + // ACES Filmic Tone Mapping Curve + // https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ + float aa = 2.51f; + float bb = 0.03f; + float cc = 2.43f; + float dd = 0.59f; + float ee = 0.14f; + return saturate( (_rgb*(aa*_rgb + bb) )/(_rgb*(cc*_rgb + dd) + ee) ); +} + +vec4 toAcesFilmic(vec4 _rgba) +{ + return vec4(toAcesFilmic(_rgba.xyz), _rgba.w); +} + vec3 luma(vec3 _rgb) { float yy = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb);