Last active
December 1, 2024 04:18
-
-
Save da-molchanov/85b95ab3f20fa4eb5624f9b3b959a0ee to your computer and use it in GitHub Desktop.
Simple custom ACES tonemapper that approximates the default UE4 filmic tonemapper in 11 instructions.
This file contains 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
// Copyright 2021 Dmitry Molchanov and Julia Molchanova | |
// This code is licensed under the MIT license | |
// Output type: CMOT float 3 | |
// Input name: LinearColor | |
// This multiplier corresponds to "ExposureCompensation=1" and disabled auto exposure | |
const float ExposureMultiplier = 1.4; | |
const float3x3 PRE_TONEMAPPING_TRANSFORM = | |
{ | |
0.575961650, 0.344143820, 0.079952030, | |
0.070806820, 0.827392350, 0.101774690, | |
0.028035252, 0.131523770, 0.840242300 | |
}; | |
const float3x3 EXPOSED_PRE_TONEMAPPING_TRANSFORM = ExposureMultiplier * PRE_TONEMAPPING_TRANSFORM; | |
const float3x3 POST_TONEMAPPING_TRANSFORM = | |
{ | |
1.666954300, -0.601741150, -0.065202855, | |
-0.106835220, 1.237778600, -0.130948950, | |
-0.004142626, -0.087411870, 1.091555000 | |
}; | |
// Transform color spaces, perform blue correction and pre desaturation | |
float3 WorkingColor = mul(EXPOSED_PRE_TONEMAPPING_TRANSFORM, LinearColor); | |
// Apply tonemapping curve | |
// Narkowicz 2016, "ACES Filmic Tone Mapping Curve" | |
// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ | |
const float a = 2.51; | |
const float b = 0.03; | |
const float c = 2.43; | |
const float d = 0.59; | |
const float e = 0.14; | |
WorkingColor = saturate((WorkingColor * (a * WorkingColor + b)) / (WorkingColor * (c * WorkingColor + d) + e)); | |
// Transform color spaces, apply blue correction and post desaturation | |
return mul( POST_TONEMAPPING_TRANSFORM, WorkingColor ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put the code into a Custom node with a LinearColor input variable and CMOT float 3 output type. Docs on custom nodes.
Looks like this (top right). The spheres have pure R G or B color with different emission values.