glsl-tone-map
Version:
A collection of tone mapping functions available both as ES modules strings and as GLSL files for use with glslify.
40 lines (35 loc) • 960 B
JavaScript
export default /* glsl */ `vec3 uncharted2Tonemap(vec3 x) {
float A = 0.15;
float B = 0.50;
float C = 0.10;
float D = 0.20;
float E = 0.02;
float F = 0.30;
float W = 11.2;
return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;
}
vec3 uncharted2(vec3 color) {
const float W = 11.2;
float exposureBias = 2.0;
vec3 curr = uncharted2Tonemap(exposureBias * color);
vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W));
return curr * whiteScale;
}
float uncharted2Tonemap(float x) {
float A = 0.15;
float B = 0.50;
float C = 0.10;
float D = 0.20;
float E = 0.02;
float F = 0.30;
float W = 11.2;
return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;
}
float uncharted2(float color) {
const float W = 11.2;
const float exposureBias = 2.0;
float curr = uncharted2Tonemap(exposureBias * color);
float whiteScale = 1.0 / uncharted2Tonemap(W);
return curr * whiteScale;
}
`;