Use ACES tone mapping

This commit is contained in:
Simon Lübeß
2022-08-18 14:03:33 +02:00
parent 42e386a142
commit 0588a93ec4
2 changed files with 57 additions and 1 deletions
+52
View File
@@ -0,0 +1,52 @@
//=================================================================================================
//
// Baking Lab
// by MJP and David Neubelt
// http://mynameismjp.wordpress.com/
//
// All code licensed under the MIT license
//
//=================================================================================================
// 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. :)
// Source: https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl
// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
static const float3x3 ACESInputMat =
{
{0.59719, 0.35458, 0.04823},
{0.07600, 0.90834, 0.01566},
{0.02840, 0.13383, 0.83777}
};
// ODT_SAT => XYZ => D60_2_D65 => sRGB
static const float3x3 ACESOutputMat =
{
{ 1.60475, -0.53108, -0.07367},
{-0.10208, 1.10813, -0.00605},
{-0.00327, -0.07276, 1.07602}
};
float3 RRTAndODTFit(float3 v)
{
float3 a = v * (v + 0.0245786f) - 0.000090537f;
float3 b = v * (0.983729f * v + 0.4329510f) + 0.238081f;
return a / b;
}
float3 ACESFitted(float3 color)
{
color = mul(ACESInputMat, color);
// Apply RRT and ODT
color = RRTAndODTFit(color);
color = mul(ACESOutputMat, color);
// Clamp to [0, 1]
color = saturate(color);
return color;
}
@@ -1,3 +1,5 @@
#include "ACES.hlsl"
Texture2D CameraTarget : register(t0); Texture2D CameraTarget : register(t0);
SamplerState CameraTargetSampler : register(s0); SamplerState CameraTargetSampler : register(s0);
@@ -27,7 +29,9 @@ float4 PS(PS_IN input) : SV_TARGET
{ {
float4 rawColor = CameraTarget.Sample(CameraTargetSampler, input.TexCoord); float4 rawColor = CameraTarget.Sample(CameraTargetSampler, input.TexCoord);
float3 color = rawColor.rgb / (rawColor.rgb + 1.0f); // float3 color = rawColor.rgb / (rawColor.rgb + 1.0f);
float3 color = ACESFitted(rawColor.rgb);
return float4(color, 1); return float4(color, 1);
} }