Add Tonemap support for Unclamped lighting mode

This commit is contained in:
Ricardo Luís Vaz Silva 2022-12-07 12:12:57 -03:00 committed by Rachael Alexanderson
parent 8e7897233e
commit 1ebd4f0d41
5 changed files with 54 additions and 22 deletions

View file

@ -29,6 +29,8 @@
#include "stats.h"
#include "g_levellocals.h"
Postprocess hw_postprocess;
PPResource *PPResource::First = nullptr;
@ -570,7 +572,8 @@ void PPColormap::Render(PPRenderState *renderstate, int fixedcm, float flash)
void PPTonemap::UpdateTextures()
{
if (gl_tonemap == Palette && !PaletteTexture.Data)
// level.info->tonemap cannot be ETonemapMode::Palette, so it's fine to only check gl_tonemap here
if (ETonemapMode((int)gl_tonemap) == ETonemapMode::Palette && !PaletteTexture.Data)
{
std::shared_ptr<void> data(new uint32_t[512 * 512], [](void *p) { delete[](uint32_t*)p; });
@ -598,7 +601,9 @@ void PPTonemap::UpdateTextures()
void PPTonemap::Render(PPRenderState *renderstate)
{
if (gl_tonemap == 0)
ETonemapMode level_tonemap = (level.info && level.info->tonemap != ETonemapMode::None) ? level.info->tonemap : ETonemapMode((int)gl_tonemap);
if (level_tonemap == ETonemapMode::None)
{
return;
}
@ -606,14 +611,14 @@ void PPTonemap::Render(PPRenderState *renderstate)
UpdateTextures();
PPShader *shader = nullptr;
switch (gl_tonemap)
switch (level_tonemap)
{
default:
case Linear: shader = &LinearShader; break;
case Reinhard: shader = &ReinhardShader; break;
case HejlDawson: shader = &HejlDawsonShader; break;
case Uncharted2: shader = &Uncharted2Shader; break;
case Palette: shader = &PaletteShader; break;
case ETonemapMode::Linear: shader = &LinearShader; break;
case ETonemapMode::Reinhard: shader = &ReinhardShader; break;
case ETonemapMode::HejlDawson: shader = &HejlDawsonShader; break;
case ETonemapMode::Uncharted2: shader = &Uncharted2Shader; break;
case ETonemapMode::Palette: shader = &PaletteShader; break;
}
renderstate->PushGroup("tonemap");
@ -622,7 +627,7 @@ void PPTonemap::Render(PPRenderState *renderstate)
renderstate->Shader = shader;
renderstate->Viewport = screen->mScreenViewport;
renderstate->SetInputCurrent(0);
if (gl_tonemap == Palette)
if (level_tonemap == ETonemapMode::Palette)
renderstate->SetInputTexture(1, &PaletteTexture);
renderstate->SetOutputNext();
renderstate->SetNoBlend();

View file

@ -555,16 +555,6 @@ private:
PPShader Uncharted2Shader = { "shaders/pp/tonemap.fp", "#define UNCHARTED2\n", {} };
PPShader PaletteShader = { "shaders/pp/tonemap.fp", "#define PALETTE\n", {} };
enum TonemapMode
{
None,
Uncharted2,
HejlDawson,
Reinhard,
Linear,
Palette,
NumTonemapModes
};
};
/////////////////////////////////////////////////////////////////////////////

View file

@ -62,4 +62,15 @@ enum class ELightBlendMode : uint8_t
DEFAULT = CLAMP,
};
enum class ETonemapMode : uint8_t
{
None,
Uncharted2,
HejlDawson,
Reinhard,
Linear,
Palette,
NumTonemapModes
};
#endif

View file

@ -303,6 +303,7 @@ void level_info_t::Reset()
skyrotatevector = FVector3(0, 0, 1);
skyrotatevector2 = FVector3(0, 0, 1);
lightblendmode = ELightBlendMode::DEFAULT;
tonemap = ETonemapMode::None;
}
@ -1501,17 +1502,41 @@ DEFINE_MAP_OPTION(lightblendmode, false)
parse.ParseAssign();
parse.sc.MustGetString();
if(strcmp(parse.sc.String,"DEFAULT") == 0 || strcmp(parse.sc.String,"CLAMP") == 0)
if (parse.sc.Compare("Default") || parse.sc.Compare("Clamp"))
{
info->lightblendmode = ELightBlendMode::DEFAULT;
}
else if(strcmp(parse.sc.String,"COLOR_CORRECT_CLAMP") == 0)
else if (parse.sc.Compare("ColoredClamp"))
{
info->lightblendmode = ELightBlendMode::CLAMP_COLOR;
}
else if(strcmp(parse.sc.String,"UNCLAMPED") == 0)
else if (parse.sc.Compare("Unclamped"))
{
info->lightblendmode = ELightBlendMode::NOCLAMP;
if(parse.sc.CheckString(","))
{
parse.sc.MustGetString();
if (parse.sc.Compare("None"))
{
info->tonemap = ETonemapMode::None;
}
else if (parse.sc.Compare("Linear"))
{
info->tonemap = ETonemapMode::Linear;
}
else if (parse.sc.Compare("Uncharted2"))
{
info->tonemap = ETonemapMode::Uncharted2;
}
else if (parse.sc.Compare("HejlDawson"))
{
info->tonemap = ETonemapMode::HejlDawson;
}
else if (parse.sc.Compare("Reinhard"))
{
info->tonemap = ETonemapMode::Reinhard;
}
}
}
else
{

View file

@ -410,6 +410,7 @@ struct level_info_t
FString acsName;
bool fs_nocheckposition;
ELightBlendMode lightblendmode;
ETonemapMode tonemap;
CutsceneDef intro, outro;