From e949b3419e13acc811a8feb92fb05c15a2a524c7 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 21 Jan 2018 12:05:25 -1000 Subject: [PATCH 1/2] Display Gamma integration --- Runtime/CGameOptions.cpp | 32 ++++++++++++++++--- Runtime/CGameOptions.hpp | 5 +++ Runtime/Graphics/CBooRenderer.cpp | 9 ++++-- .../Graphics/Shaders/CFluidPlaneShader.hpp | 1 + .../Graphics/Shaders/CTexturedQuadFilter.cpp | 21 +++++++++--- .../Graphics/Shaders/CTexturedQuadFilter.hpp | 1 + Runtime/MP1/MP1.cpp | 1 + hecl | 2 +- hecl-gui | 2 +- 9 files changed, 61 insertions(+), 13 deletions(-) diff --git a/Runtime/CGameOptions.cpp b/Runtime/CGameOptions.cpp index 262cbee6e..7a594b929 100644 --- a/Runtime/CGameOptions.cpp +++ b/Runtime/CGameOptions.cpp @@ -11,6 +11,7 @@ #include "Audio/CStreamAudioManager.hpp" #include "Graphics/CMoviePlayer.hpp" #include "CStateManager.hpp" +#include "hecl/CVarManager.hpp" namespace urde { @@ -26,7 +27,8 @@ static const SGameOption VisorOpts[] = static const SGameOption DisplayOpts[] = { - {EGameOption::ScreenBrightness, 25, 0.f, 8.f, 1.f, EOptionType::Float}, + //{EGameOption::ScreenBrightness, 25, 0.f, 8.f, 1.f, EOptionType::Float}, + {EGameOption::ScreenBrightness, 25, -100.f, 100.f, 1.f, EOptionType::Float}, {EGameOption::ScreenOffsetX, 26, -30.f, 30.f, 1.f, EOptionType::Float}, {EGameOption::ScreenOffsetY, 27, -30.f, 30.f, 1.f, EOptionType::Float}, {EGameOption::ScreenStretch, 28, -10.f, 10.f, 1.f, EOptionType::Float}, @@ -243,14 +245,32 @@ void CGameOptions::InitSoundMode() /* If system is mono, force x44 to mono, otherwise honor user preference */ } static float BrightnessCopyFilter = 0.f; -void CGameOptions::SetScreenBrightness(s32 val, bool b) +void CGameOptions::SetScreenBrightness(s32 val, bool apply) { x48_screenBrightness = zeus::clamp(0, val, 8); - if (b) + if (apply) BrightnessCopyFilter = TuneScreenBrightness(); } +void CGameOptions::ApplyGamma() +{ + float gammaT = -m_gamma / 100.f + 1.f; + if (gammaT < 1.f) + gammaT = gammaT * 0.5f + 0.5f; + if (zeus::close_enough(gammaT, 1.f, 0.05f)) + gammaT = 1.f; + CGraphics::g_BooFactory->setDisplayGamma(gammaT); +} + +void CGameOptions::SetGamma(s32 val, bool apply) +{ + m_gamma = zeus::clamp(-100, val, 100); + + if (apply) + ApplyGamma(); +} + void CGameOptions::SetScreenPositionX(s32 pos, bool apply) { x4c_screenXOffset = zeus::clamp(-30, pos, 30); @@ -414,6 +434,7 @@ void CGameOptions::ResetControllerAssets(int controls) void CGameOptions::EnsureSettings() { SetScreenBrightness(x48_screenBrightness, true); + SetGamma(m_gamma, true); SetScreenPositionX(x4c_screenXOffset, true); SetScreenPositionY(x50_screenYOffset, true); SetScreenStretch(x54_screenStretch, true); @@ -462,6 +483,7 @@ void CGameOptions::TryRestoreDefaults(const CFinalInput& input, int category, case 1: gameOptions.SetScreenBrightness(4, true); + gameOptions.SetGamma(0, true); gameOptions.SetScreenPositionX(0, true); gameOptions.SetScreenPositionY(0, true); gameOptions.SetScreenStretch(0, true); @@ -502,7 +524,7 @@ void CGameOptions::SetOption(EGameOption option, int value) options.SetIsHintSystemEnabled(value); break; case EGameOption::ScreenBrightness: - options.SetScreenBrightness(value, true); + options.SetGamma(value, true); break; case EGameOption::ScreenOffsetX: options.SetScreenPositionX(value, true); @@ -550,7 +572,7 @@ int CGameOptions::GetOption(EGameOption option) case EGameOption::HintSystem: return options.GetIsHintSystemEnabled(); case EGameOption::ScreenBrightness: - return options.GetScreenBrightness(); + return options.GetGamma(); case EGameOption::ScreenOffsetX: return options.GetScreenPositionX(); case EGameOption::ScreenOffsetY: diff --git a/Runtime/CGameOptions.hpp b/Runtime/CGameOptions.hpp index 420a58bb4..daf98dae6 100644 --- a/Runtime/CGameOptions.hpp +++ b/Runtime/CGameOptions.hpp @@ -129,6 +129,8 @@ class CGameOptions u32 x60_hudAlpha = 0xff; u32 x64_helmetAlpha = 0xff; + s32 m_gamma = 0; + union { struct @@ -155,6 +157,9 @@ public: float TuneScreenBrightness(); void SetScreenBrightness(s32, bool); s32 GetScreenBrightness() const { return x48_screenBrightness; } + void ApplyGamma(); + void SetGamma(s32, bool); + s32 GetGamma() const { return m_gamma; } void SetScreenPositionX(s32, bool); s32 GetScreenPositionX() const { return x4c_screenXOffset; } void SetScreenPositionY(s32, bool); diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index a5c7bc6ae..0f330b32d 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -793,13 +793,18 @@ void CBooRenderer::UpdateAreaUniforms(int areaIdx, bool shadowRender) SetupRendererStates(); CModelFlags flags; + int bufIdx; if (shadowRender) { flags.m_extendedShader = EExtendedShader::SolidColor; flags.x4_color = zeus::CColor::skBlack; + bufIdx = 1; } else + { flags.m_extendedShader = EExtendedShader::Lighting; + bufIdx = 0; + } for (CAreaListItem& item : x1c_areaListItems) { @@ -807,7 +812,7 @@ void CBooRenderer::UpdateAreaUniforms(int areaIdx, bool shadowRender) continue; item.m_shaderSet->m_geomLayout->Update(flags, nullptr, nullptr, &item.m_shaderSet->m_matSet, - item.m_shaderSet->m_geomLayout->m_sharedBuffer[shadowRender]); + item.m_shaderSet->m_geomLayout->m_sharedBuffer[bufIdx]); for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) { @@ -815,7 +820,7 @@ void CBooRenderer::UpdateAreaUniforms(int areaIdx, bool shadowRender) if (model->TryLockTextures()) { ActivateLightsForModel(&item, *model); - model->UpdateUniformData(flags, nullptr, nullptr, shadowRender); + model->UpdateUniformData(flags, nullptr, nullptr, bufIdx); } } } diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp index 450291e07..ddc797cd2 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp @@ -104,6 +104,7 @@ private: zeus::CMatrix4f m_proj; zeus::CMatrix4f m_texMtxs[9]; // Pad out to 768 bytes CModelShaders::LightingUniform m_lighting; + zeus::CVector3f m_pad; // Pad out to 768 bytes }; std::experimental::optional> m_patternTex1; diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp index a8e4f4d2c..5a5f13347 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp @@ -7,11 +7,13 @@ namespace urde CTexturedQuadFilter::CTexturedQuadFilter(const boo::ObjToken& tex) : m_booTex(tex) { + m_flipRect = CGraphics::g_BooFactory->platform() == boo::IGraphicsDataFactory::Platform::Vulkan; } CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, const boo::ObjToken& tex, bool gequal) : m_booTex(tex), m_gequal(gequal) { + m_flipRect = CGraphics::g_BooFactory->platform() == boo::IGraphicsDataFactory::Platform::Vulkan; tex->setClampMode(boo::TextureClampMode::ClampToEdge); CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { @@ -26,6 +28,7 @@ CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, TLockedToken tex) : CTexturedQuadFilter(type, (tex ? tex->GetBooTexture() : nullptr)) { + m_flipRect = CGraphics::g_BooFactory->platform() == boo::IGraphicsDataFactory::Platform::Vulkan; m_tex = tex; } @@ -40,10 +43,20 @@ void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale, const z }; m_vbo->load(verts, sizeof(verts)); - m_uniform.m_matrix[0][0] = rect.size.x * 2.f; - m_uniform.m_matrix[1][1] = rect.size.y * 2.f; - m_uniform.m_matrix[3][0] = rect.position.x * 2.f - 1.f; - m_uniform.m_matrix[3][1] = rect.position.y * 2.f - 1.f; + if (!m_flipRect) + { + m_uniform.m_matrix[0][0] = rect.size.x * 2.f; + m_uniform.m_matrix[1][1] = rect.size.y * 2.f; + m_uniform.m_matrix[3][0] = rect.position.x * 2.f - 1.f; + m_uniform.m_matrix[3][1] = rect.position.y * 2.f - 1.f; + } + else + { + m_uniform.m_matrix[0][0] = rect.size.x * 2.f; + m_uniform.m_matrix[1][1] = rect.size.y * -2.f; + m_uniform.m_matrix[3][0] = rect.position.x * 2.f - 1.f; + m_uniform.m_matrix[3][1] = rect.position.y * -2.f + 1.f; + } m_uniform.m_color = color; m_uniBuf->load(&m_uniform, sizeof(m_uniform)); diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp index 5d2be91a6..88e73d2f8 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp @@ -36,6 +36,7 @@ protected: boo::ObjToken m_dataBind; Uniform m_uniform; bool m_gequal; + bool m_flipRect = false; CTexturedQuadFilter(const boo::ObjToken& tex); diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 4563f50cc..aa258af9e 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -500,6 +500,7 @@ void CMain::UpdateDiscordPresence(CAssetId worldSTRG) DiscordRichPresence discordPresence = {}; discordPresence.state = DiscordState.c_str(); discordPresence.details = DiscordWorldName.c_str(); + discordPresence.largeImageKey = "default"; discordPresence.startTimestamp = DiscordStartTime; Discord_UpdatePresence(&discordPresence); } diff --git a/hecl b/hecl index 49cd88784..b1e2635c2 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 49cd887849d90aa17751d4388309c624aa6599a3 +Subproject commit b1e2635c260fc028fe7879b033ec6e6a9b601813 diff --git a/hecl-gui b/hecl-gui index 3b70f8267..0667b95de 160000 --- a/hecl-gui +++ b/hecl-gui @@ -1 +1 @@ -Subproject commit 3b70f8267645ba99f44e2f2a9f58a2fad7a27c36 +Subproject commit 0667b95de23b9b15ab7f4d2335ddc78876d40505 From d23afc86ce4373098adc3f409545890e189b9b59 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 21 Jan 2018 13:30:40 -1000 Subject: [PATCH 2/2] Update boo --- hecl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hecl b/hecl index b1e2635c2..72fe321e9 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit b1e2635c260fc028fe7879b033ec6e6a9b601813 +Subproject commit 72fe321e97655b13b86a9d2421bfc5bee535737d