Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ACES tonemapping support #203

Merged
merged 3 commits into from
Apr 17, 2019
Merged

Add ACES tonemapping support #203

merged 3 commits into from
Apr 17, 2019

Conversation

TimvanScherpenzeel
Copy link
Contributor

This PR adds support for ACES tonemapping to the viewer.

Kind regards,

Tim

@UX3D-nopper UX3D-nopper requested review from a user and UX3D-wahlster April 16, 2019 09:22
@emackey
Copy link
Member

emackey commented Apr 16, 2019

/cc @abwood

@UX3D-nopper
Copy link
Contributor

@emackey You want this to be cross-checked by @abwood?

@emackey
Copy link
Member

emackey commented Apr 17, 2019

@UX3D-nopper Ah sorry, no, just wanted to give him a heads-up. He and I looked at a number of tone-mapping curves last year and decided that ACES Fitted was our favorite of the bunch.

@UX3D-nopper UX3D-nopper merged commit 46c8a10 into KhronosGroup:master Apr 17, 2019
@TimvanScherpenzeel
Copy link
Contributor Author

@emackey

If you are interested I could open a new PR with the following ACES Fitted snippet (ported from this HLSL ACES fitted implementation into GLSL).

This merged PR is a cheaper and simplified version of ACES (which, as mentioned by Krzysztof Narkowicz, over-saturates brights) but in my opinion looks quite good.

//=================================================================================================
//
//  Baking Lab
//  by MJP and David Neubelt
//  http://mynameismjp.wordpress.com/
//
//  All code licensed under the MIT license
//
//=================================================================================================

// ACES sRGB Monitor – a fitted polynomial version of the ACES[17] reference rendering transform (RRT) 
// combined with the sRGB monitor output display transform (ODT), generously provided by Stephen Hill.

// The code in this file was originally written by Stephen Hill (@self_shadow), who deserves all
// credit for coming up with this fit and implementing it. Buy him a beer next time you see him. :)

// HLSL matrices are row major, GLSL are column major so values have been swapped

// 1 2 3
// 4 5 6
// 7 8 9

// Row major (HLSL)
// 1 2 3 4 5 6 7 8 9

// Column major (GLSL)
// 1 4 7 2 5 8 3 6 9

// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
const mat3 ACESInputMat = mat3(
    0.59719, 0.07600, 0.02840,
    0.35458, 0.90834, 0.13383,
    0.04823, 0.01566, 0.83777
);

// ODT_SAT => XYZ => D60_2_D65 => sRGB
const mat3 ACESOutputMat = mat3(
    1.60475, -0.10208, -0.00327,
    -0.53108, 1.10813, -0.07276,
    -0.07367, -0.00605, 1.07602
);

vec3 RRTAndODTFit(vec3 v) {
    vec3 a = v * (v + 0.0245786) - 0.000090537;
    vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081;

    return a / b;
}

vec3 ACESFitted(vec3 color) {
    color = ACESInputMat * color;

    // Apply RTT (reference rendering transform) and ODT (sRGB monitor output display transform)
    color = RRTAndODTFit(color);
    
    color = ACESOutputMat * color;

    // Clamp to [0, 1]
    color = clamp(color, 0.0, 1.0);

    return color;
}

@TimvanScherpenzeel TimvanScherpenzeel deleted the add-aces-tonemapping branch April 17, 2019 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants