Created
May 12, 2021 11:53
-
-
Save shakesoda/1dcb3e159f586995ca076c8b21f05a67 to your computer and use it in GitHub Desktop.
variable HDR GT Tonemap, as described in http://cdn2.gran-turismo.com/data/www/pdi_publications/PracticalHDRandWCGinGTS_20181222.pdf + https://www.desmos.com/calculator/gslcdxvipg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// read the PDF about this if you precompute it! it's got helpful info! | |
// can be optimized into lut (compute can gen it) | |
float GTTonemap(float x) { | |
float m = 0.22; // linear section start | |
float a = 1.0; // contrast | |
float c = 1.33; // black brightness | |
float P = 1.0; // maximum brightness | |
float l = 0.4; // linear section length | |
float l0 = ((P-m)*l) / a; // 0.312 | |
float S0 = m + l0; // 0.532 | |
float S1 = m + a * l0; // 0.532 | |
float C2 = (a*P) / (P - S1); // 2.13675213675 | |
float L = m + a * (x - m); | |
float T = m * pow(x/m, c); | |
float S = P - (P - S1) * exp(-C2*(x - S0)/P); | |
float w0 = 1 - smoothstep(0.0, m, x); | |
float w2 = (x < m+l)?0:1; | |
float w1 = 1 - w0 - w2; | |
return float(T * w0 + L * w1 + S * w2); | |
} | |
// this costs about 0.2-0.3ms more than aces, as-is | |
vec3 GTTonemap(vec3 x) { | |
return vec3( | |
GTTonemap(x.r), | |
GTTonemap(x.g), | |
GTTonemap(x.b) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment