Created
February 11, 2023 10:08
-
-
Save deccer/2fc5edfe375b52a290a4bc4c31cd8ce0 to your computer and use it in GitHub Desktop.
Tonemapping
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
float3 HableToneMap(float3 color) | |
{ | |
float A = 0.22;//Shoulder Strength | |
float B = 0.30;//Linear Strength | |
float C = 0.10;//Linear Angle | |
float D = 0.20;//Toe Strength | |
float E = 0.01;//Toe Numerator | |
float F = 0.30;//Toe Denominator | |
color = max(0, color - 0.004f); | |
color = ((color * (A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-(E/F); | |
return color; | |
} | |
float4 ToneMapPass(float2 TexC : TEXCOORD) : SV_TARGET | |
{ | |
// Get average luminance | |
float3 Color = gImage.Sample(gPointSampler, TexC).xyz; | |
// This should be a per-vertex opeartion, since it's constant | |
float AvgLuminance = exp(gLuminanceMap.SampleLevel(gPointSampler, float2(0, 0), 9)); | |
AvgLuminance = max(AvgLuminance, 0.001f); | |
Color *= gMiddleGray / AvgLuminance; | |
float TonedWhite = HableToneMap(gWhiteLevel.xxx); | |
Color = HableToneMap(Color)/TonedWhite.xxx; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment