Add Tonemap shader

This commit is contained in:
C.S. Melis 2022-05-28 15:38:35 +02:00
parent 3e4fe58c37
commit a84ba8861d
2 changed files with 80 additions and 1 deletions

View File

@ -1,6 +1,6 @@
PreprocessorDefinitions=
Techniques=
TechniqueSorting=MagicBloom@MagicBloom.fx,HDR@FakeHDR.fx,Colourfulness@Colourfulness.fx
TechniqueSorting=MagicBloom@MagicBloom.fx,HDR@FakeHDR.fx,Colourfulness@Colourfulness.fx,Tonemap@Tonemap.fx
[Colourfulness.fx]
backbuffer_bits=8.000000
@ -25,3 +25,10 @@ fExposure=0.500000
iAdapt_Precision=0
iDebug=0
[Tonemap.fx]
Bleach=0.000000
Defog=0.000000
Exposure=0.000000
FogColor=0.000000,0.000000,1.000000
Gamma=0.775000
Saturation=0.000000

View File

@ -0,0 +1,72 @@
/**
* Tonemap version 1.1
* by Christian Cann Schuldt Jensen ~ CeeJay.dk
*/
#include "ReShadeUI.fxh"
uniform float Gamma < __UNIFORM_SLIDER_FLOAT1
ui_min = 0.0; ui_max = 2.0;
ui_tooltip = "Adjust midtones. 1.0 is neutral. This setting does exactly the same as the one in Lift Gamma Gain, only with less control.";
> = 1.0;
uniform float Exposure < __UNIFORM_SLIDER_FLOAT1
ui_min = -1.0; ui_max = 1.0;
ui_tooltip = "Adjust exposure";
> = 0.0;
uniform float Saturation < __UNIFORM_SLIDER_FLOAT1
ui_min = -1.0; ui_max = 1.0;
ui_tooltip = "Adjust saturation";
> = 0.0;
uniform float Bleach < __UNIFORM_SLIDER_FLOAT1
ui_min = 0.0; ui_max = 1.0;
ui_tooltip = "Brightens the shadows and fades the colors";
> = 0.0;
uniform float Defog < __UNIFORM_SLIDER_FLOAT1
ui_min = 0.0; ui_max = 1.0;
ui_tooltip = "How much of the color tint to remove";
> = 0.0;
uniform float3 FogColor < __UNIFORM_COLOR_FLOAT3
ui_label = "Defog Color";
ui_tooltip = "Which color tint to remove";
> = float3(0.0, 0.0, 1.0);
#include "ReShade.fxh"
float3 TonemapPass(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float3 color = tex2D(ReShade::BackBuffer, texcoord).rgb;
color = saturate(color - Defog * FogColor * 2.55); // Defog
color *= pow(2.0f, Exposure); // Exposure
color = pow(color, Gamma); // Gamma
const float3 coefLuma = float3(0.2126, 0.7152, 0.0722);
float lum = dot(coefLuma, color);
float L = saturate(10.0 * (lum - 0.45));
float3 A2 = Bleach * color;
float3 result1 = 2.0f * color * lum;
float3 result2 = 1.0f - 2.0f * (1.0f - lum) * (1.0f - color);
float3 newColor = lerp(result1, result2, L);
float3 mixRGB = A2 * newColor;
color += ((1.0f - A2) * mixRGB);
float3 middlegray = dot(color, (1.0 / 3.0));
float3 diffcolor = color - middlegray;
color = (color + diffcolor * Saturation) / (1 + (diffcolor * Saturation)); // Saturation
return color;
}
technique Tonemap
{
pass
{
VertexShader = PostProcessVS;
PixelShader = TonemapPass;
}
}