Skip to content

Commit 570fafe

Browse files
committed
feat: additional tonemap options
1 parent 7c86214 commit 570fafe

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

editor/app.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,9 @@ pl__show_editor_window(plAppData* ptAppData)
806806
static const char* apcTonemapText[] = {
807807
"None",
808808
"Simple",
809-
"ACES",
809+
"ACES Filmic (Narkowicz)",
810+
"ACES Filmic (Hill)",
811+
"ACES Filmic (Hill Exposure Boost)",
810812
"Reinhard",
811813
};
812814
bool abTonemap[PL_ARRAYSIZE(apcTonemapText)] = {0};

editor/editor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,9 @@ pl__show_editor_window(plAppData* ptAppData)
10341034
static const char* apcTonemapText[] = {
10351035
"None",
10361036
"Simple",
1037-
"ACES",
1037+
"ACES Filmic (Narkowicz)",
1038+
"ACES Filmic (Hill)",
1039+
"ACES Filmic (Hill Exposure Boost)",
10381040
"Reinhard",
10391041
};
10401042
ImGui::Combo("Tonemapping", &ptRuntimeOptions->tTonemapMode, apcTonemapText, PL_ARRAYSIZE(apcTonemapText));

shaders/pl_shader_interop_renderer.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ PL_BEGIN_ENUM(plMeshFormatFlags)
7373
PL_END_ENUM
7474

7575
PL_BEGIN_ENUM(plTonemapMode)
76-
PL_ENUM_ITEM(PL_TONEMAP_MODE_NONE, 0)
77-
PL_ENUM_ITEM(PL_TONEMAP_MODE_SIMPLE, 1)
78-
PL_ENUM_ITEM(PL_TONEMAP_MODE_ACES, 2)
79-
PL_ENUM_ITEM(PL_TONEMAP_MODE_REINHARD, 3)
76+
PL_ENUM_ITEM(PL_TONEMAP_MODE_NONE, 0)
77+
PL_ENUM_ITEM(PL_TONEMAP_MODE_SIMPLE, 1)
78+
PL_ENUM_ITEM(PL_TONEMAP_MODE_ACES_NARKOWICZ, 2)
79+
PL_ENUM_ITEM(PL_TONEMAP_MODE_ACES_HILL, 3)
80+
PL_ENUM_ITEM(PL_TONEMAP_MODE_ACES_HILL_EXPOSURE_BOOST, 4)
81+
PL_ENUM_ITEM(PL_TONEMAP_MODE_REINHARD, 5)
8082
PL_END_ENUM
8183

8284
PL_BEGIN_ENUM(plLightType)

shaders/tonemap.comp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
//simple fit from: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
88
vec3 ACESFilmApproximate(vec3 x)
99
{
10-
float a = 2.51f;
11-
float b = 0.03f;
12-
float c = 2.43f;
13-
float d = 0.59f;
14-
float e = 0.14f;
10+
float a = 2.51;
11+
float b = 0.03;
12+
float c = 2.43;
13+
float d = 0.59;
14+
float e = 0.14;
1515
return clamp((x*(a*x+b))/(x*(c*x+d)+e), 0, 1);
1616
}
1717

@@ -39,15 +39,19 @@ vec3 RRTAndODTFit(vec3 v)
3939
return a / b;
4040
}
4141

42-
//matrices are transposed because they are from HLSL code
43-
vec3 ACESFitted(vec3 color)
42+
// tone mapping
43+
vec3 toneMapACES_Hill(vec3 color)
4444
{
4545
color = transpose(ACESInputMat) * color;
4646

4747
// Apply RRT and ODT
4848
color = RRTAndODTFit(color);
49+
4950
color = transpose(ACESOutputMat) * color;
50-
color = clamp(color, 0, 1);
51+
52+
// Clamp to [0, 1]
53+
color = clamp(color, 0.0, 1.0);
54+
5155
return color;
5256
}
5357

@@ -116,9 +120,18 @@ main()
116120
{
117121
tTonemappedColor = tLinearColor.rgb;
118122
}
119-
else if(tDynamicData.tData.iMode == PL_TONEMAP_MODE_ACES)
123+
else if(tDynamicData.tData.iMode == PL_TONEMAP_MODE_ACES_NARKOWICZ)
124+
{
125+
tTonemappedColor = ACESFilmApproximate(tLinearColor.rgb);
126+
}
127+
else if(tDynamicData.tData.iMode == PL_TONEMAP_MODE_ACES_HILL)
128+
{
129+
tTonemappedColor = toneMapACES_Hill(tLinearColor.rgb);
130+
}
131+
else if(tDynamicData.tData.iMode == PL_TONEMAP_MODE_ACES_HILL_EXPOSURE_BOOST)
120132
{
121-
tTonemappedColor = ACESFitted(tLinearColor.rgb);
133+
tLinearColor.rgb /= 0.6;
134+
tTonemappedColor = toneMapACES_Hill(tLinearColor.rgb);
122135
}
123136
else if(tDynamicData.tData.iMode == PL_TONEMAP_MODE_REINHARD)
124137
{

0 commit comments

Comments
 (0)