| 1 |
{ -*- buffer-read-only: t -*- } |
| 2 |
{ DON'T EDIT -- this file was automatically generated from "source/tone_mapping.fs" } |
| 3 |
'/*' + LineEnding + |
| 4 |
' Copyright 2020-2020 glTF-Sample-Viewer and Michalis Kamburelis.' + LineEnding + |
| 5 |
'' + LineEnding + |
| 6 |
' This file is part of "Castle Game Engine".' + LineEnding + |
| 7 |
' (And it is heavily based on glTF-Sample-Viewer,' + LineEnding + |
| 8 |
' on a compatible open-source license.)' + LineEnding + |
| 9 |
'' + LineEnding + |
| 10 |
' "Castle Game Engine" is free software; see the file COPYING.txt,' + LineEnding + |
| 11 |
' included in this distribution, for details about the copyright.' + LineEnding + |
| 12 |
'' + LineEnding + |
| 13 |
' "Castle Game Engine" is distributed in the hope that it will be useful,' + LineEnding + |
| 14 |
' but WITHOUT ANY WARRANTY; without even the implied warranty of' + LineEnding + |
| 15 |
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.' + LineEnding + |
| 16 |
'' + LineEnding + |
| 17 |
' ----------------------------------------------------------------------------' + LineEnding + |
| 18 |
'' + LineEnding + |
| 19 |
' Shader code used for gamma correction and tone mapping.' + LineEnding + |
| 20 |
'*/' + LineEnding + |
| 21 |
'' + LineEnding + |
| 22 |
'// Not used by CGE now:' + LineEnding + |
| 23 |
'// uniform float u_Exposure;' + LineEnding + |
| 24 |
'' + LineEnding + |
| 25 |
'const float GAMMA = 2.2;' + LineEnding + |
| 26 |
'const float INV_GAMMA = 1.0 / GAMMA;' + LineEnding + |
| 27 |
'' + LineEnding + |
| 28 |
'// sRGB to linear approximation' + LineEnding + |
| 29 |
'// see http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html' + LineEnding + |
| 30 |
'vec4 castle_texture_color_to_linear(const in vec4 srgbIn)' + LineEnding + |
| 31 |
'{' + LineEnding + |
| 32 |
'#ifdef CASTLE_GAMMA_CORRECTION' + LineEnding + |
| 33 |
' return vec4(pow(srgbIn.xyz, vec3(GAMMA)), srgbIn.w);' + LineEnding + |
| 34 |
'#else' + LineEnding + |
| 35 |
' return srgbIn;' + LineEnding + |
| 36 |
'#endif' + LineEnding + |
| 37 |
'}' + LineEnding + |
| 38 |
'' + LineEnding + |
| 39 |
'vec3 castle_texture_color_to_linear(const in vec3 srgbIn)' + LineEnding + |
| 40 |
'{' + LineEnding + |
| 41 |
'#ifdef CASTLE_GAMMA_CORRECTION' + LineEnding + |
| 42 |
' return pow(srgbIn, vec3(GAMMA));' + LineEnding + |
| 43 |
'#else' + LineEnding + |
| 44 |
' return srgbIn;' + LineEnding + |
| 45 |
'#endif' + LineEnding + |
| 46 |
'}' + LineEnding + |
| 47 |
'' + LineEnding + |
| 48 |
'// linear to sRGB approximation' + LineEnding + |
| 49 |
'// see http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html' + LineEnding + |
| 50 |
'vec3 LINEARtoSRGB(const in vec3 color)' + LineEnding + |
| 51 |
'{' + LineEnding + |
| 52 |
'#ifdef CASTLE_GAMMA_CORRECTION' + LineEnding + |
| 53 |
' return pow(color, vec3(INV_GAMMA));' + LineEnding + |
| 54 |
'#else' + LineEnding + |
| 55 |
' return color;' + LineEnding + |
| 56 |
'#endif' + LineEnding + |
| 57 |
'}' + LineEnding + |
| 58 |
'' + LineEnding + |
| 59 |
'// Uncharted 2 tone map' + LineEnding + |
| 60 |
'// see: http://filmicworlds.com/blog/filmic-tonemapping-operators/' + LineEnding + |
| 61 |
'vec3 toneMapUncharted2Impl(const in vec3 color)' + LineEnding + |
| 62 |
'{' + LineEnding + |
| 63 |
' const float A = 0.15;' + LineEnding + |
| 64 |
' const float B = 0.50;' + LineEnding + |
| 65 |
' const float C = 0.10;' + LineEnding + |
| 66 |
' const float D = 0.20;' + LineEnding + |
| 67 |
' const float E = 0.02;' + LineEnding + |
| 68 |
' const float F = 0.30;' + LineEnding + |
| 69 |
' return ((color*(A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-E/F;' + LineEnding + |
| 70 |
'}' + LineEnding + |
| 71 |
'' + LineEnding + |
| 72 |
'vec3 toneMapUncharted(in vec3 color)' + LineEnding + |
| 73 |
'{' + LineEnding + |
| 74 |
' const float W = 11.2;' + LineEnding + |
| 75 |
' color = toneMapUncharted2Impl(color * 2.0);' + LineEnding + |
| 76 |
' vec3 whiteScale = 1.0 / toneMapUncharted2Impl(vec3(W));' + LineEnding + |
| 77 |
' color = color * whiteScale;' + LineEnding + |
| 78 |
' #ifdef CASTLE_GAMMA_CORRECTION' + LineEnding + |
| 79 |
' color = LINEARtoSRGB(color);' + LineEnding + |
| 80 |
' #endif' + LineEnding + |
| 81 |
' return color;' + LineEnding + |
| 82 |
'}' + LineEnding + |
| 83 |
'' + LineEnding + |
| 84 |
'// Hejl Richard tone map' + LineEnding + |
| 85 |
'// see: http://filmicworlds.com/blog/filmic-tonemapping-operators/' + LineEnding + |
| 86 |
'vec3 toneMapHejlRichard(in vec3 color)' + LineEnding + |
| 87 |
'{' + LineEnding + |
| 88 |
' color = max(vec3(0.0), color - vec3(0.004));' + LineEnding + |
| 89 |
' color = (color*(6.2*color+.5))/(color*(6.2*color+1.7)+0.06);' + LineEnding + |
| 90 |
' #ifndef CASTLE_GAMMA_CORRECTION' + LineEnding + |
| 91 |
' // The above calculation did equivalent of "pow(color, vec3(1 / 2.2))" already.' + LineEnding + |
| 92 |
' // So invert it, if no gamma correction.' + LineEnding + |
| 93 |
' color = pow(color, vec3(GAMMA));' + LineEnding + |
| 94 |
' #endif' + LineEnding + |
| 95 |
' return color;' + LineEnding + |
| 96 |
'}' + LineEnding + |
| 97 |
'' + LineEnding + |
| 98 |
'// ACES tone map' + LineEnding + |
| 99 |
'// see: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/' + LineEnding + |
| 100 |
'vec3 toneMapACES(in vec3 color)' + LineEnding + |
| 101 |
'{' + LineEnding + |
| 102 |
' const float A = 2.51;' + LineEnding + |
| 103 |
' const float B = 0.03;' + LineEnding + |
| 104 |
' const float C = 2.43;' + LineEnding + |
| 105 |
' const float D = 0.59;' + LineEnding + |
| 106 |
' const float E = 0.14;' + LineEnding + |
| 107 |
' color = clamp((color * (A * color + B)) / (color * (C * color + D) + E), 0.0, 1.0);' + LineEnding + |
| 108 |
' #ifdef CASTLE_GAMMA_CORRECTION' + LineEnding + |
| 109 |
' color = LINEARtoSRGB(color);' + LineEnding + |
| 110 |
' #endif' + LineEnding + |
| 111 |
' return color;' + LineEnding + |
| 112 |
'}' + LineEnding + |
| 113 |
'' + LineEnding + |
| 114 |
'vec3 castle_linear_to_screen(const in vec3 color)' + LineEnding + |
| 115 |
'{' + LineEnding + |
| 116 |
' // color *= u_Exposure;' + LineEnding + |
| 117 |
'' + LineEnding + |
| 118 |
' #ifdef CASTLE_TONE_MAPPING' + LineEnding + |
| 119 |
' #ifdef CASTLE_TONE_MAPPING_UNCHARTED' + LineEnding + |
| 120 |
' return toneMapUncharted(color);' + LineEnding + |
| 121 |
' #endif' + LineEnding + |
| 122 |
'' + LineEnding + |
| 123 |
' #ifdef CASTLE_TONE_MAPPING_HEJLRICHARD' + LineEnding + |
| 124 |
' return toneMapHejlRichard(color);' + LineEnding + |
| 125 |
' #endif' + LineEnding + |
| 126 |
'' + LineEnding + |
| 127 |
' #ifdef CASTLE_TONE_MAPPING_ACES' + LineEnding + |
| 128 |
' return toneMapACES(color);' + LineEnding + |
| 129 |
' #endif' + LineEnding + |
| 130 |
' #endif' + LineEnding + |
| 131 |
'' + LineEnding + |
| 132 |
' return LINEARtoSRGB(color);' + LineEnding + |
| 133 |
'}' + LineEnding + |
| 134 |
'' |