diff --git a/Minecraft.Client/Common/App_enums.h b/Minecraft.Client/Common/App_enums.h index 7e9eb208..6c065cea 100644 --- a/Minecraft.Client/Common/App_enums.h +++ b/Minecraft.Client/Common/App_enums.h @@ -197,6 +197,12 @@ enum eGameSetting // custom eGameSetting_PassiveChunkLoading, + + eGameSetting_Bloom_Toggle, + eGameSetting_FXAA_Toggle, + eGameSetting_FXAA_Strength, + eGameSetting_MipMap_Toggle, + eGameSetting_MipMap_Strength, }; diff --git a/Minecraft.Client/Common/App_structs.h b/Minecraft.Client/Common/App_structs.h index 7500e305..88b71384 100644 --- a/Minecraft.Client/Common/App_structs.h +++ b/Minecraft.Client/Common/App_structs.h @@ -105,6 +105,13 @@ typedef struct // 29/Oct/2014 - Language selector. unsigned char ucLocale; + DWORD dwPostProcessingSettingsSignature; + unsigned char ucBloomToggle; + unsigned char ucFXAAToggle; + unsigned char ucFXAAStrength; + unsigned char ucMipMapToggle; + unsigned char ucMipMapStrength; + // 4J Stu - See comment for GAME_SETTINGS_PROFILE_DATA_BYTES below // was 192 //unsigned char ucUnused[192-TUTORIAL_PROFILE_STORAGE_BYTES-sizeof(DWORD)-sizeof(char)-sizeof(char)-sizeof(char)-sizeof(char)-sizeof(LONG)-sizeof(LONG)-sizeof(DWORD)]; diff --git a/Minecraft.Client/Common/Consoles_App.cpp b/Minecraft.Client/Common/Consoles_App.cpp index d97f7291..8562f012 100644 --- a/Minecraft.Client/Common/Consoles_App.cpp +++ b/Minecraft.Client/Common/Consoles_App.cpp @@ -77,6 +77,8 @@ //CMinecraftApp app; unsigned int CMinecraftApp::m_uiLastSignInData = 0; +static_assert(sizeof(GAME_SETTINGS) == CMinecraftApp::GAME_SETTINGS_PROFILE_DATA_BYTES, + "GAME_SETTINGS must retain its profile data size"); const float CMinecraftApp::fSafeZoneX = 64.0f; // 5% of 1280 const float CMinecraftApp::fSafeZoneY = 36.0f; // 5% of 720 @@ -956,18 +958,20 @@ bool CMinecraftApp::LoadWritingBookMenu(int iPad, shared_ptr insta ////////////////////////////////////////////// #ifdef _WINDOWS64 -static void Win64_GetSettingsPath(char *outPath, DWORD size) +static void Win64_GetSettingsPath(char *outPath, DWORD size, int iPad) { GetModuleFileNameA(nullptr, outPath, size); char *lastSlash = strrchr(outPath, '\\'); if (lastSlash) *(lastSlash + 1) = '\0'; - strncat_s(outPath, size, "settings.dat", _TRUNCATE); + char fileName[32] = {}; + sprintf_s(fileName, "settings%d.dat", iPad); + strncat_s(outPath, size, fileName, _TRUNCATE); } -static void Win64_SaveSettings(GAME_SETTINGS *gs) +static void Win64_SaveSettings(GAME_SETTINGS *gs, int iPad) { if (!gs) return; char filePath[MAX_PATH] = {}; - Win64_GetSettingsPath(filePath, MAX_PATH); + Win64_GetSettingsPath(filePath, MAX_PATH, iPad); FILE *f = nullptr; if (fopen_s(&f, filePath, "wb") == 0 && f) { @@ -975,13 +979,22 @@ static void Win64_SaveSettings(GAME_SETTINGS *gs) fclose(f); } } -static void Win64_LoadSettings(GAME_SETTINGS *gs) +static void Win64_LoadSettings(GAME_SETTINGS *gs, int iPad) { if (!gs) return; char filePath[MAX_PATH] = {}; - Win64_GetSettingsPath(filePath, MAX_PATH); + Win64_GetSettingsPath(filePath, MAX_PATH, iPad); FILE *f = nullptr; - if (fopen_s(&f, filePath, "rb") == 0 && f) + if (fopen_s(&f, filePath, "rb") != 0) + { + GetModuleFileNameA(nullptr, filePath, MAX_PATH); + char *lastSlash = strrchr(filePath, '\\'); + if (lastSlash) *(lastSlash + 1) = '\0'; + strncat_s(filePath, MAX_PATH, "settings.dat", _TRUNCATE); + fopen_s(&f, filePath, "rb"); + } + + if (f) { GAME_SETTINGS temp = {}; if (fread(&temp, sizeof(GAME_SETTINGS), 1, f) == 1) @@ -1011,7 +1024,7 @@ void CMinecraftApp::InitGameSettings() // clear this for now - it will come from reading the system values memset(pProfileSettings,0,sizeof(C_4JProfile::PROFILESETTINGS)); SetDefaultOptions(pProfileSettings,i); - Win64_LoadSettings(GameSettingsA[i]); + Win64_LoadSettings(GameSettingsA[i], i); #ifndef MINECRAFT_SERVER_BUILD ApplyGameSettingsChanged(i); #endif @@ -1022,6 +1035,34 @@ void CMinecraftApp::InitGameSettings() #endif + if (GameSettingsA[i]->dwPostProcessingSettingsSignature == 0x50505331) + { + unsigned char mipMapDistance = GameSettingsA[i]->ucMipMapStrength; + GameSettingsA[i]->ucMipMapStrength = mipMapDistance == 0 + ? 5 + : static_cast(mipMapDistance <= 5 ? mipMapDistance : 5); + GameSettingsA[i]->dwPostProcessingSettingsSignature = 0x50505333; + GameSettingsA[i]->bSettingsChanged = true; + } + else if (GameSettingsA[i]->dwPostProcessingSettingsSignature == 0x50505332) + { + const unsigned char oldMipMapPercent = GameSettingsA[i]->ucMipMapStrength; + GameSettingsA[i]->ucMipMapStrength = static_cast( + 1 + (min(oldMipMapPercent, static_cast(100)) * 4 + 50) / 100); + GameSettingsA[i]->dwPostProcessingSettingsSignature = 0x50505333; + GameSettingsA[i]->bSettingsChanged = true; + } + else if (GameSettingsA[i]->dwPostProcessingSettingsSignature != 0x50505333) + { + GameSettingsA[i]->dwPostProcessingSettingsSignature = 0x50505333; + GameSettingsA[i]->ucBloomToggle = 1; + GameSettingsA[i]->ucFXAAToggle = 1; + GameSettingsA[i]->ucFXAAStrength = 75; + GameSettingsA[i]->ucMipMapToggle = 1; + GameSettingsA[i]->ucMipMapStrength = 5; + GameSettingsA[i]->bSettingsChanged = true; + } + Minecraft* minecraft = Minecraft::GetInstance(); if (minecraft != nullptr && minecraft->stats[i] != nullptr) { @@ -1118,6 +1159,13 @@ int CMinecraftApp::SetDefaultOptions(C_4JProfile::PROFILESETTINGS *pSettings,con // custom SetGameSettings(iPad, eGameSetting_PassiveChunkLoading, 0); + SetGameSettings(iPad, eGameSetting_Bloom_Toggle, 1); + SetGameSettings(iPad, eGameSetting_FXAA_Toggle, 1); + SetGameSettings(iPad, eGameSetting_FXAA_Strength, 75); + SetGameSettings(iPad, eGameSetting_MipMap_Toggle, 1); + SetGameSettings(iPad, eGameSetting_MipMap_Strength, 5); + + // 4J-PB - leave these in, or remove from everywhere they are referenced! // Although probably best to leave in unless we split the profile settings into platform specific classes - having different meaning per platform for the same bitmask could get confusing //#ifdef __PS3__ @@ -1586,6 +1634,12 @@ void CMinecraftApp::ApplyGameSettingsChanged(int iPad) // custom ActionGameSettings(iPad, eGameSetting_PassiveChunkLoading); + + ActionGameSettings(iPad, eGameSetting_Bloom_Toggle); + ActionGameSettings(iPad, eGameSetting_FXAA_Toggle); + ActionGameSettings(iPad, eGameSetting_FXAA_Strength); + ActionGameSettings(iPad, eGameSetting_MipMap_Toggle); + ActionGameSettings(iPad, eGameSetting_MipMap_Strength); } void CMinecraftApp::ActionGameSettings(int iPad,eGameSetting eVal) @@ -1808,6 +1862,21 @@ void CMinecraftApp::ActionGameSettings(int iPad,eGameSetting eVal) case eGameSetting_PassiveChunkLoading: //nothing to do here break; + case eGameSetting_Bloom_Toggle: + //nothing to do here + break; + case eGameSetting_FXAA_Toggle: + //nothing to do here + break; + case eGameSetting_FXAA_Strength: + //nothing to do here + break; + case eGameSetting_MipMap_Toggle: + //nothing to do here + break; + case eGameSetting_MipMap_Strength: + //nothing to do here + break; case eGameSetting_UISize: //nothing to do here break; @@ -2537,6 +2606,48 @@ void CMinecraftApp::SetGameSettings(int iPad,eGameSetting eVal,unsigned char ucV GameSettingsA[iPad]->bSettingsChanged=true; } break; + case eGameSetting_Bloom_Toggle: + if (GameSettingsA[iPad]->ucBloomToggle != (ucVal != 0)) + { + GameSettingsA[iPad]->ucBloomToggle = (ucVal != 0); + ActionGameSettings(iPad, eVal); + GameSettingsA[iPad]->bSettingsChanged = true; + } + break; + case eGameSetting_FXAA_Toggle: + if (GameSettingsA[iPad]->ucFXAAToggle != (ucVal != 0)) + { + GameSettingsA[iPad]->ucFXAAToggle = (ucVal != 0); + ActionGameSettings(iPad, eVal); + GameSettingsA[iPad]->bSettingsChanged = true; + } + break; + case eGameSetting_FXAA_Strength: + ucVal = min(ucVal, static_cast(100)); + if (GameSettingsA[iPad]->ucFXAAStrength != ucVal) + { + GameSettingsA[iPad]->ucFXAAStrength = ucVal; + ActionGameSettings(iPad, eVal); + GameSettingsA[iPad]->bSettingsChanged = true; + } + break; + case eGameSetting_MipMap_Toggle: + if (GameSettingsA[iPad]->ucMipMapToggle != (ucVal != 0)) + { + GameSettingsA[iPad]->ucMipMapToggle = (ucVal != 0); + ActionGameSettings(iPad, eVal); + GameSettingsA[iPad]->bSettingsChanged = true; + } + break; + case eGameSetting_MipMap_Strength: + ucVal = max(static_cast(1), min(ucVal, static_cast(5))); + if (GameSettingsA[iPad]->ucMipMapStrength != ucVal) + { + GameSettingsA[iPad]->ucMipMapStrength = ucVal; + ActionGameSettings(iPad, eVal); + GameSettingsA[iPad]->bSettingsChanged = true; + } + break; case eGameSetting_UISize: if((GameSettingsA[iPad]->uiBitmaskValues&GAMESETTING_UISIZE)!=((ucVal&0x03)<<11)) { @@ -2850,6 +2961,16 @@ unsigned char CMinecraftApp::GetGameSettings(int iPad,eGameSetting eVal) case eGameSetting_PassiveChunkLoading: return (GameSettingsA[iPad]->uiBitmaskValues&GAMESETTING_PASSIVECHUNKLOADING)>>18; break; + case eGameSetting_Bloom_Toggle: + return GameSettingsA[iPad]->ucBloomToggle; + case eGameSetting_FXAA_Toggle: + return GameSettingsA[iPad]->ucFXAAToggle; + case eGameSetting_FXAA_Strength: + return GameSettingsA[iPad]->ucFXAAStrength; + case eGameSetting_MipMap_Toggle: + return GameSettingsA[iPad]->ucMipMapToggle; + case eGameSetting_MipMap_Strength: + return GameSettingsA[iPad]->ucMipMapStrength; case eGameSetting_UISize: { unsigned char ucVal=(GameSettingsA[iPad]->uiBitmaskValues&GAMESETTING_UISIZE)>>11; @@ -2916,7 +3037,7 @@ void CMinecraftApp::CheckGameSettingsChanged(bool bOverride5MinuteTimer, int iPa #else ProfileManager.WriteToProfile(i,true, bOverride5MinuteTimer); #ifdef _WINDOWS64 - Win64_SaveSettings(GameSettingsA[i]); + Win64_SaveSettings(GameSettingsA[i], i); #endif #endif GameSettingsA[i]->bSettingsChanged=false; @@ -2932,7 +3053,7 @@ void CMinecraftApp::CheckGameSettingsChanged(bool bOverride5MinuteTimer, int iPa #else ProfileManager.WriteToProfile(iPad,true, bOverride5MinuteTimer); #ifdef _WINDOWS64 - Win64_SaveSettings(GameSettingsA[iPad]); + Win64_SaveSettings(GameSettingsA[iPad], iPad); #endif #endif GameSettingsA[iPad]->bSettingsChanged=false; diff --git a/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenu1080.swf b/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenu1080.swf index 626b1d0c..9ff74c42 100644 Binary files a/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenu1080.swf and b/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenu1080.swf differ diff --git a/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenu720.swf b/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenu720.swf index 626b1d0c..fe7cf48d 100644 Binary files a/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenu720.swf and b/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenu720.swf differ diff --git a/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenuSplit1080.swf b/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenuSplit1080.swf index 35998343..4d4d410a 100644 Binary files a/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenuSplit1080.swf and b/Minecraft.Client/Common/Media/MediaWindows64/SettingsMenuSplit1080.swf differ diff --git a/Minecraft.Client/Common/PostProcesser.h b/Minecraft.Client/Common/PostProcesser.h index 966d58bc..060df7d6 100644 --- a/Minecraft.Client/Common/PostProcesser.h +++ b/Minecraft.Client/Common/PostProcesser.h @@ -1,6 +1,21 @@ #pragma once #include +#include + +enum class PostProcessType +{ + FXAA, + Bloom, + Gamma +}; + +enum class PostProcessStage +{ + BeforeNativeHud, + AfterNativeHud, + AfterIggy +}; class PostProcesser { @@ -15,11 +30,15 @@ public: void Apply() const; void SetViewport(const D3D11_VIEWPORT& viewport); void ResetViewport(); - void CopyBackbuffer(); // Copy backbuffer once before multi-pass gamma - void ApplyFromCopied() const; // Apply gamma using already-copied offscreen texture + void CopyBackbuffer(); + void ApplyFromCopied() const; void Cleanup(); void SetGamma(float gamma); float GetGamma() const { return m_gamma; } + void SetFXAAStrength(float strength); + void RegisterPass(PostProcessType type, PostProcessStage stage, bool enabled = true); + void SetPassEnabled(PostProcessType type, bool enabled); + void RunStage(PostProcessStage stage); PostProcesser(const PostProcesser&) = delete; PostProcesser& operator=(const PostProcesser&) = delete; @@ -28,35 +47,92 @@ private: ~PostProcesser(); static bool IsRunningUnderWine(); + void ApplyFXAA(const D3D11_VIEWPORT& viewport); + void ApplyBloom(const D3D11_VIEWPORT& viewport); + void ApplyGamma(const D3D11_VIEWPORT& viewport); + bool DrawFullscreen(ID3D11PixelShader* pixelShader, + ID3D11ShaderResourceView* source, + ID3D11ShaderResourceView* bloom, + ID3D11RenderTargetView* target, + const D3D11_VIEWPORT& outputViewport, + const D3D11_VIEWPORT& sourceViewport, + float sourceWidth, + float sourceHeight, + const D3D11_VIEWPORT* bloomViewport, + float bloomWidth, + float bloomHeight, + float directionX, + float directionY, + float gamma, + float threshold, + float bloomIntensity, + float bloomKnee) const; + + struct RegisteredPass + { + PostProcessType type; + PostProcessStage stage; + bool enabled; + }; + + struct PostProcessCBData + { + float gamma; + float inverseWidth; + float inverseHeight; + float threshold; + float uvOffsetX; + float uvOffsetY; + float uvScaleX; + float uvScaleY; + float bloomUvOffsetX; + float bloomUvOffsetY; + float bloomUvScaleX; + float bloomUvScaleY; + float directionX; + float directionY; + float bloomIntensity; + float bloomKnee; + }; ID3D11Texture2D* m_pGammaOffscreenTex = nullptr; ID3D11ShaderResourceView* m_pGammaOffscreenSRV = nullptr; ID3D11RenderTargetView* m_pGammaOffscreenRTV = nullptr; + ID3D11Texture2D* m_pBloomTexA = nullptr; + ID3D11ShaderResourceView* m_pBloomSRVA = nullptr; + ID3D11RenderTargetView* m_pBloomRTVA = nullptr; + ID3D11Texture2D* m_pBloomTexB = nullptr; + ID3D11ShaderResourceView* m_pBloomSRVB = nullptr; + ID3D11RenderTargetView* m_pBloomRTVB = nullptr; ID3D11VertexShader* m_pGammaVS = nullptr; ID3D11PixelShader* m_pGammaPS = nullptr; + ID3D11PixelShader* m_pFXAAPS = nullptr; + ID3D11PixelShader* m_pBloomExtractPS = nullptr; + ID3D11PixelShader* m_pBloomBlurPS = nullptr; + ID3D11PixelShader* m_pBloomCompositePS = nullptr; ID3D11Buffer* m_pGammaCB = nullptr; ID3D11SamplerState* m_pGammaSampler = nullptr; + ID3D11SamplerState* m_pPostProcessSampler = nullptr; ID3D11RasterizerState* m_pGammaRastState = nullptr; ID3D11DepthStencilState* m_pGammaDepthState = nullptr; ID3D11BlendState* m_pGammaBlendState = nullptr; bool m_initialized = false; float m_gamma = 1.0f; + float m_fxaaStrength = 0.75f; bool m_wineMode = false; D3D11_VIEWPORT m_customViewport; bool m_useCustomViewport = false; UINT m_gammaTexWidth = 0; UINT m_gammaTexHeight = 0; - - struct GammaCBData - { - float gamma; - float pad; - float uvOffsetX, uvOffsetY; - float uvScaleX, uvScaleY; - float pad2[2]; - }; + UINT m_bloomTexWidth = 0; + UINT m_bloomTexHeight = 0; + std::vector m_registeredPasses; static const char* g_gammaVSCode; static const char* g_gammaPSCode; -}; \ No newline at end of file + static const char* g_fxaaPSCode; + static const char* g_bloomExtractPSCode; + static const char* g_bloomBlurPSCode; + static const char* g_bloomCompositePSCode; +}; diff --git a/Minecraft.Client/Common/UI/UI.h b/Minecraft.Client/Common/UI/UI.h index fdd8d0b5..ff54bc46 100644 --- a/Minecraft.Client/Common/UI/UI.h +++ b/Minecraft.Client/Common/UI/UI.h @@ -84,6 +84,7 @@ #include "UIScene_SettingsOptionsMenu.h" #include "UIScene_SettingsAudioMenu.h" #include "UIScene_SettingsGraphicsMenu.h" +#include "UIScene_SettingsPostProcessingMenu.h" #include "UIScene_SettingsUIMenu.h" #include "UIScene_SkinSelectMenu.h" #include "UIScene_HowToPlayMenu.h" diff --git a/Minecraft.Client/Common/UI/UIController.cpp b/Minecraft.Client/Common/UI/UIController.cpp index 119e3490..569d7d9b 100644 --- a/Minecraft.Client/Common/UI/UIController.cpp +++ b/Minecraft.Client/Common/UI/UIController.cpp @@ -13,6 +13,9 @@ #include "../../DLCTexturePack.h" #include "../../TexturePackRepository.h" #include "../../Minecraft.h" +#ifdef _WINDOWS64 +#include "../PostProcesser.h" +#endif #include "../../../Minecraft.World/net.minecraft.world.entity.boss.enderdragon.h" #include "../../EnderDragonRenderer.h" #include "../../MultiPlayerLocalPlayer.h" @@ -1909,6 +1912,10 @@ void UIController::renderScenes() PM_ORIGIN_X, PM_ORIGIN_Y, getScreenWidth(), getScreenHeight()); // perfmon draw area in window coords } #endif + +#ifdef _WINDOWS64 + PostProcesser::GetInstance().RunStage(PostProcessStage::AfterIggy); +#endif } void UIController::getRenderDimensions(C4JRender::eViewportType viewport, S32 &width, S32 &height) diff --git a/Minecraft.Client/Common/UI/UIEnums.h b/Minecraft.Client/Common/UI/UIEnums.h index ec7ac541..f2b1ccf2 100644 --- a/Minecraft.Client/Common/UI/UIEnums.h +++ b/Minecraft.Client/Common/UI/UIEnums.h @@ -60,6 +60,7 @@ enum EUIScene eUIScene_SettingsOptionsMenu, eUIScene_SettingsAudioMenu, eUIScene_SettingsGraphicsMenu, + eUIScene_SettingsPostProcessingMenu, eUIScene_SettingsUIMenu, eUIScene_SettingsMenu, eUIScene_LeaderboardsMenu, diff --git a/Minecraft.Client/Common/UI/UILayer.cpp b/Minecraft.Client/Common/UI/UILayer.cpp index e5aa17c6..27f91018 100644 --- a/Minecraft.Client/Common/UI/UILayer.cpp +++ b/Minecraft.Client/Common/UI/UILayer.cpp @@ -296,6 +296,9 @@ bool UILayer::NavigateToScene(int iPad, EUIScene scene, void *initData) case eUIScene_SettingsGraphicsMenu: newScene = new UIScene_SettingsGraphicsMenu(iPad, initData, this); break; + case eUIScene_SettingsPostProcessingMenu: + newScene = new UIScene_SettingsPostProcessingMenu(iPad, initData, this); + break; case eUIScene_SettingsUIMenu: newScene = new UIScene_SettingsUIMenu(iPad, initData, this); break; diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsMenu.cpp b/Minecraft.Client/Common/UI/UIScene_SettingsMenu.cpp index 98e47a02..3cfffaed 100644 --- a/Minecraft.Client/Common/UI/UIScene_SettingsMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_SettingsMenu.cpp @@ -13,6 +13,7 @@ UIScene_SettingsMenu::UIScene_SettingsMenu(int iPad, void *initData, UILayer *pa m_buttons[BUTTON_ALL_OPTIONS].init(IDS_OPTIONS,BUTTON_ALL_OPTIONS); m_buttons[BUTTON_ALL_AUDIO].init(IDS_AUDIO,BUTTON_ALL_AUDIO); m_buttons[BUTTON_ALL_GRAPHICS].init(IDS_GRAPHICS,BUTTON_ALL_GRAPHICS); + m_buttons[BUTTON_ALL_POSTPROCESSING].init(IDS_POSTPROCESSING,BUTTON_ALL_POSTPROCESSING); m_buttons[BUTTON_ALL_UI].init(IDS_USER_INTERFACE,BUTTON_ALL_UI); m_buttons[BUTTON_ALL_RESETTODEFAULTS].init(IDS_RESET_TO_DEFAULTS,BUTTON_ALL_RESETTODEFAULTS); @@ -20,6 +21,7 @@ UIScene_SettingsMenu::UIScene_SettingsMenu(int iPad, void *initData, UILayer *pa { removeControl( &m_buttons[BUTTON_ALL_AUDIO], bNotInGame); removeControl( &m_buttons[BUTTON_ALL_GRAPHICS], bNotInGame); + removeControl( &m_buttons[BUTTON_ALL_POSTPROCESSING], bNotInGame); } doHorizontalResizeCheck(); @@ -55,6 +57,7 @@ void UIScene_SettingsMenu::handleReload() { removeControl( &m_buttons[BUTTON_ALL_AUDIO], bNotInGame); removeControl( &m_buttons[BUTTON_ALL_GRAPHICS], bNotInGame); + removeControl( &m_buttons[BUTTON_ALL_POSTPROCESSING], bNotInGame); } doHorizontalResizeCheck(); @@ -129,6 +132,9 @@ void UIScene_SettingsMenu::handlePress(F64 controlId, F64 childId) case BUTTON_ALL_GRAPHICS: ui.NavigateToScene(m_iPad, eUIScene_SettingsGraphicsMenu); break; + case BUTTON_ALL_POSTPROCESSING: + ui.NavigateToScene(m_iPad, eUIScene_SettingsPostProcessingMenu); + break; case BUTTON_ALL_UI: ui.NavigateToScene(m_iPad, eUIScene_SettingsUIMenu); break; diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsMenu.h b/Minecraft.Client/Common/UI/UIScene_SettingsMenu.h index 612a15d3..2769116a 100644 --- a/Minecraft.Client/Common/UI/UIScene_SettingsMenu.h +++ b/Minecraft.Client/Common/UI/UIScene_SettingsMenu.h @@ -5,8 +5,9 @@ #define BUTTON_ALL_OPTIONS 0 #define BUTTON_ALL_AUDIO 1 #define BUTTON_ALL_GRAPHICS 3 -#define BUTTON_ALL_UI 4 -#define BUTTON_ALL_RESETTODEFAULTS 5 +#define BUTTON_ALL_POSTPROCESSING 4 +#define BUTTON_ALL_UI 5 +#define BUTTON_ALL_RESETTODEFAULTS 6 #define BUTTONS_ALL_MAX BUTTON_ALL_RESETTODEFAULTS + 1 class UIScene_SettingsMenu : public UIScene @@ -17,8 +18,9 @@ private: UI_MAP_ELEMENT( m_buttons[BUTTON_ALL_OPTIONS], "Button1") UI_MAP_ELEMENT( m_buttons[BUTTON_ALL_AUDIO], "Button2") UI_MAP_ELEMENT( m_buttons[BUTTON_ALL_GRAPHICS], "Button3") - UI_MAP_ELEMENT( m_buttons[BUTTON_ALL_UI], "Button4") - UI_MAP_ELEMENT( m_buttons[BUTTON_ALL_RESETTODEFAULTS], "Button5") + UI_MAP_ELEMENT( m_buttons[BUTTON_ALL_POSTPROCESSING], "Button4") + UI_MAP_ELEMENT( m_buttons[BUTTON_ALL_UI], "Button5") + UI_MAP_ELEMENT( m_buttons[BUTTON_ALL_RESETTODEFAULTS], "Button6") UI_END_MAP_ELEMENTS_AND_NAMES() public: UIScene_SettingsMenu(int iPad, void *initData, UILayer *parentLayer); diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsPostProcessingMenu.cpp b/Minecraft.Client/Common/UI/UIScene_SettingsPostProcessingMenu.cpp new file mode 100644 index 00000000..2a09e7da --- /dev/null +++ b/Minecraft.Client/Common/UI/UIScene_SettingsPostProcessingMenu.cpp @@ -0,0 +1,207 @@ +#include "stdafx.h" +#include "UI.h" +#include "UIScene_SettingsPostProcessingMenu.h" + +UIScene_SettingsPostProcessingMenu::UIScene_SettingsPostProcessingMenu(int iPad, void* initData, UILayer* parentLayer) : UIScene(iPad, parentLayer) +{ + // Setup all the Iggy references we need for this scene + initialiseMovie(); + + m_bNotInGame = (Minecraft::GetInstance()->level == nullptr); + m_bNeedsMultiListPopulate = true; + m_bInitialPopulateDone = false; + m_bPendingSliderUpdate = false; + m_iPendingSliderId = 0; + m_iPendingSliderValue = 0; + + doHorizontalResizeCheck(); + + if (app.GetLocalPlayerCount() > 1) + { +#if TO_BE_IMPLEMENTED + app.AdjustSplitscreenScene(m_hObj, &m_OriginalPosition, m_iPad); +#endif + } +} + +UIScene_SettingsPostProcessingMenu::~UIScene_SettingsPostProcessingMenu() +{ +} + +wstring UIScene_SettingsPostProcessingMenu::getMoviePath() +{ + if (app.GetLocalPlayerCount() > 1) + { + return L"MultilistMenuSplit"; + } + else + { + return L"MultilistMenu"; + } +} + +void UIScene_SettingsPostProcessingMenu::tick() +{ + if (m_bNeedsMultiListPopulate) + { + m_bNeedsMultiListPopulate = false; + m_multiList.setupControl(this, m_rootPath, "MultiList"); + m_controls.push_back(&m_multiList); + m_multiList.clearList(); + m_multiList.init(eControl_MultiList); + + m_multiList.AddNewCheckbox(app.GetString(IDS_CHECKBOX_CUSTOM_BLOOM), eControl_Bloom_Toggle, (app.GetGameSettings(m_iPad, eGameSetting_Bloom_Toggle) != 0)); + m_multiList.AddNewCheckbox(app.GetString(IDS_CHECKBOX_CUSTOM_FXAA_TOGGLE), eControl_FXAA_Toggle, (app.GetGameSettings(m_iPad, eGameSetting_FXAA_Toggle) != 0)); + m_multiList.AddNewCheckbox(app.GetString(IDS_CHECKBOX_CUSTOM_MIPMAP_TOGGLE), eControl_MipMap_Toggle, (app.GetGameSettings(m_iPad, eGameSetting_MipMap_Toggle) != 0)); + + WCHAR TempString[256]; + + { + int fxaaVal = app.GetGameSettings(m_iPad, eGameSetting_FXAA_Strength); + swprintf(TempString, 256, L"%ls: %d%%", app.GetString(IDS_SLIDER_CUSTOM_FXAA_STRENGTH), fxaaVal); + m_multiList.AddNewSlider(TempString, eControl_FXAA_Strength, 0, 100, 1, fxaaVal); + } + + { + int strength = app.GetGameSettings(m_iPad, eGameSetting_MipMap_Strength); + swprintf(TempString, 256, L"%ls: %d", app.GetString(IDS_SLIDER_CUSTOM_MIPMAP_STRENGTH), strength); + m_multiList.AddNewSlider(TempString, eControl_MipMap_Strength, 1, 5, 1, strength); + } + + IggyName funcDoVert = registerFastName(L"DoVerticalResizeCheck"); + IggyName funcHideDesc = registerFastName(L"HideDescription"); + IggyDataValue result; + IggyPlayerCallMethodRS(getMovie(), &result, m_rootPath, funcDoVert, 0, nullptr); + doHorizontalResizeCheck(); + IggyPlayerCallMethodRS(getMovie(), &result, m_rootPath, funcHideDesc, 0, nullptr); + m_multiList.HighlightItem(eControl_MultiList + 1); + } + + if (m_bPendingSliderUpdate) + { + m_bPendingSliderUpdate = false; + m_multiList.SetSliderValue(m_iPendingSliderId, m_iPendingSliderValue); + + WCHAR TempString[256]; + switch (m_iPendingSliderId) + { + case eControl_FXAA_Strength: + { + app.SetGameSettings(m_iPad, eGameSetting_FXAA_Strength, m_iPendingSliderValue); + swprintf(TempString, 256, L"%ls: %d", app.GetString(IDS_SLIDER_CUSTOM_FXAA_STRENGTH), m_iPendingSliderValue); + m_multiList.SetSliderLabel(eControl_FXAA_Strength, TempString); + break; + } + case eControl_MipMap_Strength: + { + app.SetGameSettings(m_iPad, eGameSetting_MipMap_Strength, m_iPendingSliderValue); + swprintf(TempString, 256, L"%ls: %d", app.GetString(IDS_SLIDER_CUSTOM_MIPMAP_STRENGTH), m_iPendingSliderValue); + m_multiList.SetSliderLabel(eControl_MipMap_Strength, TempString); + break; + } + } + } + + UIScene::tick(); + m_bInitialPopulateDone = true; +} + + +void UIScene_SettingsPostProcessingMenu::updateTooltips() +{ + ui.SetTooltips(m_iPad, IDS_TOOLTIPS_SELECT, IDS_TOOLTIPS_BACK); +} + +void UIScene_SettingsPostProcessingMenu::updateComponents() +{ + bool bNotInGame=(Minecraft::GetInstance()->level==nullptr); + if(bNotInGame) + { + m_parentLayer->showComponent(m_iPad,eUIComponent_Panorama,true); + m_parentLayer->showComponent(m_iPad,eUIComponent_Logo,true); + } + else + { + m_parentLayer->showComponent(m_iPad,eUIComponent_Panorama,false); + + if( app.GetLocalPlayerCount() == 1 ) m_parentLayer->showComponent(m_iPad,eUIComponent_Logo,true); + else m_parentLayer->showComponent(m_iPad,eUIComponent_Logo,false); + + } +} + + +void UIScene_SettingsPostProcessingMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) +{ + ui.AnimateKeyPress(iPad, key, repeat, pressed, released); + switch(key) + { + case ACTION_MENU_CANCEL: + if(pressed) { + applyChangedSettings(); + navigateBack(); + } + break; + case ACTION_MENU_OK: +#ifdef __ORBIS__ + case ACTION_MENU_TOUCHPAD_PRESS: +#endif + sendInputToMovie(key, repeat, pressed, released); + break; + case ACTION_MENU_UP: + case ACTION_MENU_DOWN: + case ACTION_MENU_LEFT: + case ACTION_MENU_RIGHT: + sendInputToMovie(key, repeat, pressed, released); + break; + } +} + +void UIScene_SettingsPostProcessingMenu::handleSliderMove(F64 sliderId, F64 currentValue) +{ + int sliderIdInt = static_cast(sliderId); + int value = static_cast(currentValue); + + m_multiList.handleSliderMove(sliderIdInt, value); + + switch (sliderIdInt) + { + case eControl_FXAA_Strength: + case eControl_MipMap_Strength: + m_bPendingSliderUpdate = true; + m_iPendingSliderId = sliderIdInt; + m_iPendingSliderValue = value; + break; + } +} + +void UIScene_SettingsPostProcessingMenu::handleCheckboxToggled(F64 controlId, bool selected) +{ + if (m_bInitialPopulateDone) + ui.PlayUISFX(eSFX_Press); +} + +void UIScene_SettingsPostProcessingMenu::handlePress(F64 controlId, F64 childId) +{ + ui.PlayUISFX(eSFX_Press); +} + +void UIScene_SettingsPostProcessingMenu::applyChangedSettings() +{ + app.SetGameSettings(m_iPad, eGameSetting_Bloom_Toggle, m_multiList.GetCheckboxValue(eControl_Bloom_Toggle) ? 1 : 0); + + app.SetGameSettings(m_iPad, eGameSetting_FXAA_Toggle, m_multiList.GetCheckboxValue(eControl_FXAA_Toggle) ? 1 : 0); + app.SetGameSettings(m_iPad, eGameSetting_FXAA_Strength, m_multiList.GetSliderValue(eControl_FXAA_Strength)); + + app.SetGameSettings(m_iPad, eGameSetting_MipMap_Toggle, m_multiList.GetCheckboxValue(eControl_MipMap_Toggle) ? 1 : 0); + app.SetGameSettings(m_iPad, eGameSetting_MipMap_Strength, m_multiList.GetSliderValue(eControl_MipMap_Strength)); +} + +void UIScene_SettingsPostProcessingMenu::handleGainFocus(bool navBack) +{ + if (navBack) + { + m_bNeedsMultiListPopulate = true; + m_bInitialPopulateDone = false; + } +} \ No newline at end of file diff --git a/Minecraft.Client/Common/UI/UIScene_SettingsPostProcessingMenu.h b/Minecraft.Client/Common/UI/UIScene_SettingsPostProcessingMenu.h new file mode 100644 index 00000000..65e8f63a --- /dev/null +++ b/Minecraft.Client/Common/UI/UIScene_SettingsPostProcessingMenu.h @@ -0,0 +1,57 @@ +#pragma once + +#include "UIScene.h" +#include "UIControl_MultiList.h" + +class UIScene_SettingsPostProcessingMenu : public UIScene +{ +private: + enum EControls + { + eControl_MultiList = 0, + eControl_Bloom_Toggle = 1, + + eControl_FXAA_Toggle = 2, + eControl_FXAA_Strength = 3, + + eControl_MipMap_Toggle = 4, + eControl_MipMap_Strength = 5, + }; + + UIControl_MultiList m_multiList; + bool m_bNeedsMultiListPopulate; + bool m_bInitialPopulateDone; + bool m_bPendingSliderUpdate; + int m_iPendingSliderId; + int m_iPendingSliderValue; + + bool m_bNotInGame; + + UI_BEGIN_MAP_ELEMENTS_AND_NAMES(UIScene) + UI_END_MAP_ELEMENTS_AND_NAMES() + +public: + UIScene_SettingsPostProcessingMenu(int iPad, void* initData, UILayer* parentLayer); + virtual ~UIScene_SettingsPostProcessingMenu(); + + virtual EUIScene getSceneType() { return eUIScene_SettingsPostProcessingMenu; } + + virtual void tick(); + virtual void updateTooltips(); + virtual void updateComponents(); + +protected: + // TODO: This should be pure virtual in this class + virtual wstring getMoviePath(); + +public: + // INPUT + virtual void handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool& handled); + + virtual void handleSliderMove(F64 sliderId, F64 currentValue); + virtual void handleCheckboxToggled(F64 controlId, bool selected); + virtual void handlePress(F64 controlId, F64 childId); + virtual void handleGainFocus(bool navBack); + + void applyChangedSettings(); +}; diff --git a/Minecraft.Client/Extrax64Stubs.cpp b/Minecraft.Client/Extrax64Stubs.cpp index e414d5f4..d5d38d9d 100644 --- a/Minecraft.Client/Extrax64Stubs.cpp +++ b/Minecraft.Client/Extrax64Stubs.cpp @@ -665,6 +665,12 @@ static void Win64_ApplyDefaultProfileGameSettings(void* profileBytes) pGameSettings->uiBitmaskValues |= GAMESETTING_CUSTOMSKINANIM; //eGameSetting_CustomSkinAnim - on pGameSettings->uiBitmaskValues |= GAMESETTING_DEATHMESSAGES; //eGameSetting_DeathMessages - on pGameSettings->uiBitmaskValues &= ~GAMESETTING_PASSIVECHUNKLOADING; //eGameSetting_PassiveChunkLoading - off + pGameSettings->dwPostProcessingSettingsSignature = 0x50505333; + pGameSettings->ucBloomToggle = 1; + pGameSettings->ucFXAAToggle = 1; + pGameSettings->ucFXAAStrength = 75; + pGameSettings->ucMipMapToggle = 1; + pGameSettings->ucMipMapStrength = 5; pGameSettings->uiBitmaskValues |= (GAMESETTING_UISIZE & 0x00000800); // uisize 2 pGameSettings->uiBitmaskValues |= (GAMESETTING_UISIZE_SPLITSCREEN & 0x00004000); // splitscreen ui size 3 pGameSettings->uiBitmaskValues |= GAMESETTING_ANIMATEDCHARACTER; //eGameSetting_AnimatedCharacter - on diff --git a/Minecraft.Client/GameRenderer.cpp b/Minecraft.Client/GameRenderer.cpp index 9a891c30..784d7440 100644 --- a/Minecraft.Client/GameRenderer.cpp +++ b/Minecraft.Client/GameRenderer.cpp @@ -1064,13 +1064,28 @@ float GameRenderer::ComputeGammaFromSlider(float slider0to100) void GameRenderer::CachePlayerGammas() { - const float slider = app.GetGameSettings(ProfileManager.GetPrimaryPad(), eGameSetting_Gamma); - const float gamma = ComputeGammaFromSlider(slider); - for (int j = 0; j < XUSER_MAX_COUNT && j < NUM_LIGHT_TEXTURES; ++j) - m_cachedGammaPerPlayer[j] = gamma; + { + std::shared_ptr player = Minecraft::GetInstance()->localplayers[j]; + const int iPad = player ? player->GetXboxPad() : j; + m_cachedGammaPerPlayer[j] = ComputeGammaFromSlider(app.GetGameSettings(iPad, eGameSetting_Gamma)); + } } +#ifdef _WINDOWS64 +void GameRenderer::RunWorldPostProcess() const +{ + const int iPad = mc->player->GetXboxPad(); + PostProcesser& postProcesser = PostProcesser::GetInstance(); + postProcesser.SetPassEnabled(PostProcessType::Bloom, app.GetGameSettings(iPad, eGameSetting_Bloom_Toggle) != 0); + postProcesser.SetPassEnabled(PostProcessType::FXAA, app.GetGameSettings(iPad, eGameSetting_FXAA_Toggle) != 0); + postProcesser.SetFXAAStrength(app.GetGameSettings(iPad, eGameSetting_FXAA_Strength) / 100.0f); + postProcesser.SetGamma(ComputeGammaFromSlider(app.GetGameSettings(iPad, eGameSetting_Gamma))); + postProcesser.RunStage(PostProcessStage::BeforeNativeHud); + RenderManager.TextureSetMipMapOptions(5, true); +} +#endif + bool GameRenderer::ComputeViewportForPlayer(int j, D3D11_VIEWPORT &outViewport) const { extern int g_rScreenWidth; @@ -1476,6 +1491,12 @@ void GameRenderer::DisableUpdateThread() void GameRenderer::renderLevel(float a, int64_t until) { // if (updateLightTexture) updateLightTexture(); // 4J - TODO - Java 1.0.1 has this line enabled, should check why - don't want to put it in now in case it breaks split-screen +#ifdef _WINDOWS64 + const int iPad = mc->player->GetXboxPad(); + RenderManager.TextureSetMipMapOptions( + app.GetGameSettings(iPad, eGameSetting_MipMap_Strength), + app.GetGameSettings(iPad, eGameSetting_MipMap_Toggle) != 0); +#endif glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); @@ -1755,10 +1776,16 @@ void GameRenderer::renderLevel(float a, int64_t until) if (!mc->options->anaglyph3d) { +#ifdef _WINDOWS64 + RunWorldPostProcess(); +#endif return; } } glColorMask(true, true, true, false); +#ifdef _WINDOWS64 + RunWorldPostProcess(); +#endif } void GameRenderer::prepareAndRenderClouds(LevelRenderer *levelRenderer, float a) diff --git a/Minecraft.Client/GameRenderer.h b/Minecraft.Client/GameRenderer.h index a2ef0023..b1183589 100644 --- a/Minecraft.Client/GameRenderer.h +++ b/Minecraft.Client/GameRenderer.h @@ -88,6 +88,9 @@ private: float m_cachedGammaPerPlayer[NUM_LIGHT_TEXTURES]; static float ComputeGammaFromSlider(float slider0to100); void CachePlayerGammas(); +#ifdef _WINDOWS64 + void RunWorldPostProcess() const; +#endif public: void ApplyGammaPostProcess() const; private: diff --git a/Minecraft.Client/Gui.cpp b/Minecraft.Client/Gui.cpp index 94a3c8d1..899e860b 100644 --- a/Minecraft.Client/Gui.cpp +++ b/Minecraft.Client/Gui.cpp @@ -2,6 +2,9 @@ #include "Gui.h" #include "ItemRenderer.h" #include "GameRenderer.h" +#ifdef _WINDOWS64 +#include "Common/PostProcesser.h" +#endif #include "Options.h" #include "MultiPlayerLocalPlayer.h" #include "Textures.h" @@ -1401,6 +1404,9 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) glColor4f(1, 1, 1, 1); glDisable(GL_BLEND); glEnable(GL_ALPHA_TEST); +#ifdef _WINDOWS64 + PostProcesser::GetInstance().RunStage(PostProcessStage::AfterNativeHud); +#endif } // Moved to the xui base scene diff --git a/Minecraft.Client/Windows64/4JLibs b/Minecraft.Client/Windows64/4JLibs index 96a77b2c..a549f6a5 160000 --- a/Minecraft.Client/Windows64/4JLibs +++ b/Minecraft.Client/Windows64/4JLibs @@ -1 +1 @@ -Subproject commit 96a77b2ce6f5daf9300277b07e59e837d282340c +Subproject commit a549f6a5b3f8fee379280154ccd4f446f74adbd6 diff --git a/Minecraft.Client/Windows64/PostProcesser.cpp b/Minecraft.Client/Windows64/PostProcesser.cpp index 9ab7bde1..623c9178 100644 --- a/Minecraft.Client/Windows64/PostProcesser.cpp +++ b/Minecraft.Client/Windows64/PostProcesser.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "../Common/PostProcesser.h" #include -#include #pragma comment(lib, "d3dcompiler.lib") @@ -18,29 +17,111 @@ const char* PostProcesser::g_gammaVSCode = "}\n"; const char* PostProcesser::g_gammaPSCode = - "cbuffer GammaCB : register(b0)\n" - "{\n" - " float gamma;\n" - " float _pad;\n" - " float2 uvOffset;\n" - " float2 uvScale;\n" - " float2 _pad2;\n" - "};\n" - "Texture2D sceneTex : register(t0);\n" - "SamplerState sceneSampler : register(s0);\n" - "float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target\n" - "{\n" - " float2 texUV = uvOffset + uv * uvScale;\n" - " float4 color = sceneTex.Sample(sceneSampler, texUV);\n" - "\n" - " color.rgb = max(color.rgb, 0.0);\n" - "\n" - " color.rgb = pow(color.rgb, 1.0 / gamma);\n" - "\n" + "cbuffer PostProcessCB : register(b0) { float gamma; float inverseWidth; float inverseHeight; float threshold; float2 uvOffset; float2 uvScale; float2 bloomUvOffset; float2 bloomUvScale; float2 direction; float bloomIntensity; float bloomKnee; };\n" + "Texture2D sceneTex : register(t0); SamplerState sceneSampler : register(s0);\n" + "float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target {\n" + " float4 color = sceneTex.Sample(sceneSampler, uvOffset + uv * uvScale);\n" + " color.rgb = pow(max(color.rgb, 0.0), 1.0 / max(gamma, 0.001));\n" " return color;\n" "}\n"; -PostProcesser::PostProcesser() = default; +const char* PostProcesser::g_fxaaPSCode = + "cbuffer PostProcessCB : register(b0) { float gamma; float inverseWidth; float inverseHeight; float threshold; float2 uvOffset; float2 uvScale; float2 bloomUvOffset; float2 bloomUvScale; float2 direction; float bloomIntensity; float bloomKnee; };\n" + "Texture2D sceneTex : register(t0); SamplerState sceneSampler : register(s0);\n" + "float Luma(float3 color) { return dot(color, float3(0.299, 0.587, 0.114)); }\n" + "float2 ClampUV(float2 uv) { float2 halfPixel = float2(inverseWidth, inverseHeight) * 0.5; return clamp(uv, uvOffset + halfPixel, uvOffset + uvScale - halfPixel); }\n" + "float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target {\n" + " float2 pixel = float2(inverseWidth, inverseHeight);\n" + " float2 uvCenter = uvOffset + uv * uvScale;\n" + " float lumaNW = Luma(sceneTex.Sample(sceneSampler, ClampUV(uvCenter + pixel * float2(-1.0, -1.0))).rgb);\n" + " float lumaNE = Luma(sceneTex.Sample(sceneSampler, ClampUV(uvCenter + pixel * float2(1.0, -1.0))).rgb);\n" + " float lumaSW = Luma(sceneTex.Sample(sceneSampler, ClampUV(uvCenter + pixel * float2(-1.0, 1.0))).rgb);\n" + " float lumaSE = Luma(sceneTex.Sample(sceneSampler, ClampUV(uvCenter + pixel * float2(1.0, 1.0))).rgb);\n" + " float4 center = sceneTex.Sample(sceneSampler, uvCenter);\n" + " float lumaM = Luma(center.rgb);\n" + " float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n" + " float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n" + " if (lumaMax - lumaMin < max(0.0312, lumaMax * threshold)) return center;\n" + " float2 edge = float2(-((lumaNW + lumaNE) - (lumaSW + lumaSE)), (lumaNW + lumaSW) - (lumaNE + lumaSE));\n" + " float reduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * 0.03125, 0.0078125);\n" + " float reciprocal = 1.0 / (min(abs(edge.x), abs(edge.y)) + reduce);\n" + " edge = clamp(edge * reciprocal, -8.0, 8.0) * pixel;\n" + " float3 rgbA = 0.5 * (sceneTex.Sample(sceneSampler, ClampUV(uvCenter + edge * (1.0 / 3.0 - 0.5))).rgb + sceneTex.Sample(sceneSampler, ClampUV(uvCenter + edge * (2.0 / 3.0 - 0.5))).rgb);\n" + " float3 rgbB = rgbA * 0.5 + 0.25 * (sceneTex.Sample(sceneSampler, ClampUV(uvCenter + edge * -0.5)).rgb + sceneTex.Sample(sceneSampler, ClampUV(uvCenter + edge * 0.5)).rgb);\n" + " float lumaB = Luma(rgbB);\n" + " float3 filtered = (lumaB < lumaMin || lumaB > lumaMax) ? rgbA : rgbB;\n" + " return float4(lerp(center.rgb, filtered, saturate(bloomIntensity)), center.a);\n" + "}\n"; + +const char* PostProcesser::g_bloomExtractPSCode = + "cbuffer PostProcessCB : register(b0) { float gamma; float inverseWidth; float inverseHeight; float threshold; float2 uvOffset; float2 uvScale; float2 bloomUvOffset; float2 bloomUvScale; float2 direction; float bloomIntensity; float bloomKnee; };\n" + "Texture2D sceneTex : register(t0); SamplerState sceneSampler : register(s0);\n" + "float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target {\n" + " float4 color = sceneTex.Sample(sceneSampler, uvOffset + uv * uvScale);\n" + " float brightness = max(color.r, max(color.g, color.b));\n" + " float soft = saturate((brightness - threshold + bloomKnee) / max(2.0 * bloomKnee, 0.0001));\n" + " soft = soft * soft * bloomKnee;\n" + " float contribution = max(brightness - threshold, soft) / max(brightness, 0.0001);\n" + " return float4(color.rgb * contribution, color.a);\n" + "}\n"; + +const char* PostProcesser::g_bloomBlurPSCode = + "cbuffer PostProcessCB : register(b0) { float gamma; float inverseWidth; float inverseHeight; float threshold; float2 uvOffset; float2 uvScale; float2 bloomUvOffset; float2 bloomUvScale; float2 direction; float bloomIntensity; float bloomKnee; };\n" + "Texture2D sceneTex : register(t0); SamplerState sceneSampler : register(s0);\n" + "float2 ClampUV(float2 uv) { float2 halfPixel = float2(inverseWidth, inverseHeight) * 0.5; return clamp(uv, uvOffset + halfPixel, uvOffset + uvScale - halfPixel); }\n" + "float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target {\n" + " float2 center = uvOffset + uv * uvScale;\n" + " float2 stepUV = direction * float2(inverseWidth, inverseHeight);\n" + " float4 color = sceneTex.Sample(sceneSampler, center) * 0.227027;\n" + " color += sceneTex.Sample(sceneSampler, ClampUV(center + stepUV * 1.0)) * 0.1945946;\n" + " color += sceneTex.Sample(sceneSampler, ClampUV(center - stepUV * 1.0)) * 0.1945946;\n" + " color += sceneTex.Sample(sceneSampler, ClampUV(center + stepUV * 2.0)) * 0.1216216;\n" + " color += sceneTex.Sample(sceneSampler, ClampUV(center - stepUV * 2.0)) * 0.1216216;\n" + " color += sceneTex.Sample(sceneSampler, ClampUV(center + stepUV * 3.0)) * 0.054054;\n" + " color += sceneTex.Sample(sceneSampler, ClampUV(center - stepUV * 3.0)) * 0.054054;\n" + " color += sceneTex.Sample(sceneSampler, ClampUV(center + stepUV * 4.0)) * 0.016216;\n" + " color += sceneTex.Sample(sceneSampler, ClampUV(center - stepUV * 4.0)) * 0.016216;\n" + " return color;\n" + "}\n"; + +const char* PostProcesser::g_bloomCompositePSCode = + "cbuffer PostProcessCB : register(b0) { float gamma; float inverseWidth; float inverseHeight; float threshold; float2 uvOffset; float2 uvScale; float2 bloomUvOffset; float2 bloomUvScale; float2 direction; float bloomIntensity; float bloomKnee; };\n" + "Texture2D sceneTex : register(t0); Texture2D bloomTex : register(t1); SamplerState sceneSampler : register(s0);\n" + "float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target {\n" + " float2 texUV = uvOffset + uv * uvScale;\n" + " float4 color = sceneTex.Sample(sceneSampler, texUV);\n" + " float2 bloomUV = bloomUvOffset + uv * bloomUvScale;\n" + " color.rgb = saturate(color.rgb + bloomTex.Sample(sceneSampler, bloomUV).rgb * bloomIntensity);\n" + " return color;\n" + "}\n"; + +bool CompilePixelShader(ID3D11Device* device, const char* source, const char* name, UINT compileFlags, ID3D11PixelShader** shader) { + ID3DBlob* shaderBlob = nullptr; + ID3DBlob* errorBlob = nullptr; + const HRESULT compileResult = D3DCompile(source, strlen(source), name, nullptr, nullptr, "main", "ps_4_0", compileFlags, 0, &shaderBlob, &errorBlob); + if (FAILED(compileResult)) { + if (errorBlob) { + app.DebugPrintf(static_cast(errorBlob->GetBufferPointer())); + errorBlob->Release(); + } + return false; + } + + const HRESULT createResult = device->CreatePixelShader(shaderBlob->GetBufferPointer(), shaderBlob->GetBufferSize(), nullptr, shader); + + shaderBlob->Release(); + if (errorBlob) errorBlob->Release(); + if (FAILED(createResult)) app.DebugPrintf("PostProcesser: failed to create a pixel shader.\n"); + + return SUCCEEDED(createResult); +} + +PostProcesser::PostProcesser() +{ + RegisterPass(PostProcessType::Bloom, PostProcessStage::BeforeNativeHud); + RegisterPass(PostProcessType::FXAA, PostProcessStage::BeforeNativeHud); + RegisterPass(PostProcessType::Gamma, PostProcessStage::BeforeNativeHud); +} PostProcesser::~PostProcesser() { @@ -63,6 +144,11 @@ void PostProcesser::SetGamma(float gamma) m_gamma = gamma; } +void PostProcesser::SetFXAAStrength(float strength) +{ + m_fxaaStrength = max(0.0f, min(strength, 1.0f)); +} + void PostProcesser::Init() { if (!g_pd3dDevice || !g_pSwapChain) @@ -155,14 +241,45 @@ void PostProcesser::Init() if (FAILED(hr)) return; + if (!CompilePixelShader(g_pd3dDevice, g_fxaaPSCode, "FXAAPS", compileFlags, &m_pFXAAPS) || + !CompilePixelShader(g_pd3dDevice, g_bloomExtractPSCode, "BloomExtractPS", compileFlags, &m_pBloomExtractPS) || + !CompilePixelShader(g_pd3dDevice, g_bloomBlurPSCode, "BloomBlurPS", compileFlags, &m_pBloomBlurPS) || + !CompilePixelShader(g_pd3dDevice, g_bloomCompositePSCode, "BloomCompositePS", compileFlags, &m_pBloomCompositePS)) + { + Cleanup(); + return; + } + + D3D11_TEXTURE2D_DESC bloomDesc = texDesc; + bloomDesc.Width = max(1U, bbDesc.Width / 2); + bloomDesc.Height = max(1U, bbDesc.Height / 2); + m_bloomTexWidth = bloomDesc.Width; + m_bloomTexHeight = bloomDesc.Height; + + if (FAILED(g_pd3dDevice->CreateTexture2D(&bloomDesc, nullptr, &m_pBloomTexA)) || + FAILED(g_pd3dDevice->CreateShaderResourceView(m_pBloomTexA, nullptr, &m_pBloomSRVA)) || + FAILED(g_pd3dDevice->CreateRenderTargetView(m_pBloomTexA, nullptr, &m_pBloomRTVA)) || + FAILED(g_pd3dDevice->CreateTexture2D(&bloomDesc, nullptr, &m_pBloomTexB)) || + FAILED(g_pd3dDevice->CreateShaderResourceView(m_pBloomTexB, nullptr, &m_pBloomSRVB)) || + FAILED(g_pd3dDevice->CreateRenderTargetView(m_pBloomTexB, nullptr, &m_pBloomRTVB))) + { + OutputDebugStringA("PostProcesser: failed to create bloom render targets.\n"); + Cleanup(); + return; + } + D3D11_BUFFER_DESC cbDesc; ZeroMemory(&cbDesc, sizeof(cbDesc)); - cbDesc.ByteWidth = sizeof(GammaCBData); + cbDesc.ByteWidth = sizeof(PostProcessCBData); cbDesc.Usage = D3D11_USAGE_DYNAMIC; cbDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - GammaCBData initData = {1.0f, 0, 0.0f, 0.0f, 1.0f, 1.0f, {0, 0}}; + PostProcessCBData initData = {1.0f, 1.0f / static_cast(m_gammaTexWidth), + 1.0f / static_cast(m_gammaTexHeight), + 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, + 0.0f, 0.0f, 1.0f, 1.0f, + 0.0f, 0.0f, 0.0f, 0.0f}; D3D11_SUBRESOURCE_DATA srData; srData.pSysMem = &initData; srData.SysMemPitch = 0; @@ -170,7 +287,10 @@ void PostProcesser::Init() hr = g_pd3dDevice->CreateBuffer(&cbDesc, &srData, &m_pGammaCB); if (FAILED(hr)) + { + Cleanup(); return; + } D3D11_SAMPLER_DESC sampDesc; ZeroMemory(&sampDesc, sizeof(sampDesc)); @@ -181,7 +301,18 @@ void PostProcesser::Init() hr = g_pd3dDevice->CreateSamplerState(&sampDesc, &m_pGammaSampler); if (FAILED(hr)) + { + Cleanup(); return; + } + + sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; + hr = g_pd3dDevice->CreateSamplerState(&sampDesc, &m_pPostProcessSampler); + if (FAILED(hr)) + { + Cleanup(); + return; + } D3D11_RASTERIZER_DESC rasDesc; ZeroMemory(&rasDesc, sizeof(rasDesc)); @@ -192,7 +323,10 @@ void PostProcesser::Init() hr = g_pd3dDevice->CreateRasterizerState(&rasDesc, &m_pGammaRastState); if (FAILED(hr)) + { + Cleanup(); return; + } D3D11_DEPTH_STENCIL_DESC dsDesc; ZeroMemory(&dsDesc, sizeof(dsDesc)); @@ -201,7 +335,10 @@ void PostProcesser::Init() hr = g_pd3dDevice->CreateDepthStencilState(&dsDesc, &m_pGammaDepthState); if (FAILED(hr)) + { + Cleanup(); return; + } D3D11_BLEND_DESC blendDesc; ZeroMemory(&blendDesc, sizeof(blendDesc)); @@ -210,7 +347,10 @@ void PostProcesser::Init() hr = g_pd3dDevice->CreateBlendState(&blendDesc, &m_pGammaBlendState); if (FAILED(hr)) + { + Cleanup(); return; + } m_initialized = true; } @@ -239,8 +379,10 @@ void PostProcesser::Apply() const hr = ctx->Map(m_pGammaCB, 0, mapType, 0, &mapped); if (SUCCEEDED(hr)) { - GammaCBData *cb = static_cast(mapped.pData); + PostProcessCBData *cb = static_cast(mapped.pData); cb->gamma = m_gamma; + cb->inverseWidth = 1.0f / static_cast(m_gammaTexWidth); + cb->inverseHeight = 1.0f / static_cast(m_gammaTexHeight); cb->uvOffsetX = 0.0f; cb->uvOffsetY = 0.0f; cb->uvScaleX = 1.0f; @@ -324,7 +466,10 @@ void PostProcesser::CopyBackbuffer() ID3D11Texture2D* pBackBuffer = nullptr; HRESULT hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast(&pBackBuffer)); if (FAILED(hr)) + { + OutputDebugStringA("PostProcesser: failed to acquire the backbuffer for copying.\n"); return; + } D3D11_BOX srcBox = { 0, 0, 0, m_gammaTexWidth, m_gammaTexHeight, 1 }; ctx->CopySubresourceRegion(m_pGammaOffscreenTex, 0, 0, 0, 0, pBackBuffer, 0, &srcBox); @@ -361,10 +506,12 @@ void PostProcesser::ApplyFromCopied() const const HRESULT hr = ctx->Map(m_pGammaCB, 0, mapType, 0, &mapped); if (SUCCEEDED(hr)) { - const auto cb = static_cast(mapped.pData); + const auto cb = static_cast(mapped.pData); cb->gamma = m_gamma; const float texW = static_cast(m_gammaTexWidth); const float texH = static_cast(m_gammaTexHeight); + cb->inverseWidth = 1.0f / texW; + cb->inverseHeight = 1.0f / texH; cb->uvOffsetX = vp.TopLeftX / texW; cb->uvOffsetY = vp.TopLeftY / texH; cb->uvScaleX = vp.Width / texW; @@ -412,8 +559,337 @@ void PostProcesser::ApplyFromCopied() const oldDSV->Release(); } +void PostProcesser::RegisterPass(PostProcessType type, PostProcessStage stage, bool enabled) +{ + for (RegisteredPass& pass : m_registeredPasses) + { + if (pass.type == type) + { + pass.stage = stage; + pass.enabled = enabled; + return; + } + } + + m_registeredPasses.push_back({type, stage, enabled}); +} + +void PostProcesser::SetPassEnabled(PostProcessType type, bool enabled) +{ + for (RegisteredPass& pass : m_registeredPasses) + { + if (pass.type == type) + { + pass.enabled = enabled; + return; + } + } +} + +void PostProcesser::RunStage(PostProcessStage stage) +{ + if (!m_initialized || !g_pImmediateContext) + return; + + D3D11_VIEWPORT viewport = {}; + UINT viewportCount = 1; + g_pImmediateContext->RSGetViewports(&viewportCount, &viewport); + if (viewportCount == 0 || viewport.Width <= 0.0f || viewport.Height <= 0.0f) + return; + + for (const RegisteredPass& pass : m_registeredPasses) + { + if (!pass.enabled || pass.stage != stage) + continue; + + switch (pass.type) + { + case PostProcessType::Bloom: + ApplyBloom(viewport); + break; + case PostProcessType::FXAA: + ApplyFXAA(viewport); + break; + case PostProcessType::Gamma: + ApplyGamma(viewport); + break; + } + } +} + +bool PostProcesser::DrawFullscreen(ID3D11PixelShader* pixelShader, + ID3D11ShaderResourceView* source, + ID3D11ShaderResourceView* bloom, + ID3D11RenderTargetView* target, + const D3D11_VIEWPORT& outputViewport, + const D3D11_VIEWPORT& sourceViewport, + float sourceWidth, + float sourceHeight, + const D3D11_VIEWPORT* bloomViewport, + float bloomWidth, + float bloomHeight, + float directionX, + float directionY, + float gamma, + float threshold, + float bloomIntensity, + float bloomKnee) const +{ + if (!pixelShader || !source || !target || !g_pImmediateContext) + return false; + + D3D11_MAPPED_SUBRESOURCE mapped = {}; + const D3D11_MAP mapType = m_wineMode ? D3D11_MAP_WRITE_NO_OVERWRITE : D3D11_MAP_WRITE_DISCARD; + if (FAILED(g_pImmediateContext->Map(m_pGammaCB, 0, mapType, 0, &mapped))) + { + OutputDebugStringA("PostProcesser: failed to map post-process constants.\n"); + return false; + } + + PostProcessCBData* cb = static_cast(mapped.pData); + const float textureWidth = sourceWidth; + const float textureHeight = sourceHeight; + const D3D11_VIEWPORT& bloomSourceViewport = bloomViewport ? *bloomViewport : sourceViewport; + if (!bloomViewport) + { + bloomWidth = sourceWidth; + bloomHeight = sourceHeight; + } + cb->gamma = gamma; + cb->inverseWidth = 1.0f / textureWidth; + cb->inverseHeight = 1.0f / textureHeight; + cb->threshold = threshold; + cb->uvOffsetX = sourceViewport.TopLeftX / textureWidth; + cb->uvOffsetY = sourceViewport.TopLeftY / textureHeight; + cb->uvScaleX = sourceViewport.Width / textureWidth; + cb->uvScaleY = sourceViewport.Height / textureHeight; + cb->bloomUvOffsetX = bloomSourceViewport.TopLeftX / bloomWidth; + cb->bloomUvOffsetY = bloomSourceViewport.TopLeftY / bloomHeight; + cb->bloomUvScaleX = bloomSourceViewport.Width / bloomWidth; + cb->bloomUvScaleY = bloomSourceViewport.Height / bloomHeight; + cb->directionX = directionX; + cb->directionY = directionY; + cb->bloomIntensity = bloomIntensity; + cb->bloomKnee = bloomKnee; + g_pImmediateContext->Unmap(m_pGammaCB, 0); + + ID3D11RenderTargetView* oldRTV = nullptr; + ID3D11DepthStencilView* oldDSV = nullptr; + g_pImmediateContext->OMGetRenderTargets(1, &oldRTV, &oldDSV); + D3D11_VIEWPORT oldViewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE] = {}; + UINT oldViewportCount = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; + g_pImmediateContext->RSGetViewports(&oldViewportCount, oldViewports); + + ID3D11InputLayout* oldInputLayout = nullptr; + g_pImmediateContext->IAGetInputLayout(&oldInputLayout); + D3D11_PRIMITIVE_TOPOLOGY oldTopology; + g_pImmediateContext->IAGetPrimitiveTopology(&oldTopology); + + constexpr UINT maxClassInstances = 256; + ID3D11ClassInstance* oldVSInstances[maxClassInstances] = {}; + ID3D11ClassInstance* oldPSInstances[maxClassInstances] = {}; + UINT oldVSInstanceCount = maxClassInstances; + UINT oldPSInstanceCount = maxClassInstances; + ID3D11VertexShader* oldVS = nullptr; + ID3D11PixelShader* oldPS = nullptr; + g_pImmediateContext->VSGetShader(&oldVS, oldVSInstances, &oldVSInstanceCount); + g_pImmediateContext->PSGetShader(&oldPS, oldPSInstances, &oldPSInstanceCount); + + ID3D11ShaderResourceView* oldResources[2] = {nullptr, nullptr}; + ID3D11SamplerState* oldSampler = nullptr; + ID3D11Buffer* oldConstantBuffer = nullptr; + g_pImmediateContext->PSGetShaderResources(0, 2, oldResources); + g_pImmediateContext->PSGetSamplers(0, 1, &oldSampler); + g_pImmediateContext->PSGetConstantBuffers(0, 1, &oldConstantBuffer); + + ID3D11RasterizerState* oldRasterizer = nullptr; + ID3D11DepthStencilState* oldDepthState = nullptr; + UINT oldStencilReference = 0; + ID3D11BlendState* oldBlendState = nullptr; + FLOAT oldBlendFactor[4] = {}; + UINT oldSampleMask = 0; + g_pImmediateContext->RSGetState(&oldRasterizer); + g_pImmediateContext->OMGetDepthStencilState(&oldDepthState, &oldStencilReference); + g_pImmediateContext->OMGetBlendState(&oldBlendState, oldBlendFactor, &oldSampleMask); + + ID3D11ShaderResourceView* nullResources[2] = {nullptr, nullptr}; + g_pImmediateContext->PSSetShaderResources(0, 2, nullResources); + g_pImmediateContext->OMSetRenderTargets(1, &target, nullptr); + g_pImmediateContext->RSSetViewports(1, &outputViewport); + g_pImmediateContext->IASetInputLayout(nullptr); + g_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + g_pImmediateContext->VSSetShader(m_pGammaVS, nullptr, 0); + g_pImmediateContext->PSSetShader(pixelShader, nullptr, 0); + ID3D11ShaderResourceView* resources[2] = {source, bloom}; + g_pImmediateContext->PSSetShaderResources(0, 2, resources); + g_pImmediateContext->PSSetSamplers(0, 1, &m_pPostProcessSampler); + g_pImmediateContext->PSSetConstantBuffers(0, 1, &m_pGammaCB); + g_pImmediateContext->RSSetState(m_pGammaRastState); + g_pImmediateContext->OMSetDepthStencilState(m_pGammaDepthState, 0); + + constexpr float blendFactor[4] = {0, 0, 0, 0}; + g_pImmediateContext->OMSetBlendState(m_pGammaBlendState, blendFactor, 0xFFFFFFFF); + g_pImmediateContext->Draw(3, 0); + g_pImmediateContext->PSSetShaderResources(0, 2, nullResources); + + g_pImmediateContext->OMSetRenderTargets(1, &oldRTV, oldDSV); + g_pImmediateContext->RSSetViewports(oldViewportCount, oldViewports); + g_pImmediateContext->IASetInputLayout(oldInputLayout); + g_pImmediateContext->IASetPrimitiveTopology(oldTopology); + g_pImmediateContext->VSSetShader(oldVS, oldVSInstances, oldVSInstanceCount); + g_pImmediateContext->PSSetShader(oldPS, oldPSInstances, oldPSInstanceCount); + g_pImmediateContext->PSSetShaderResources(0, 2, oldResources); + g_pImmediateContext->PSSetSamplers(0, 1, &oldSampler); + g_pImmediateContext->PSSetConstantBuffers(0, 1, &oldConstantBuffer); + g_pImmediateContext->RSSetState(oldRasterizer); + g_pImmediateContext->OMSetDepthStencilState(oldDepthState, oldStencilReference); + g_pImmediateContext->OMSetBlendState(oldBlendState, oldBlendFactor, oldSampleMask); + + if (oldRTV) + oldRTV->Release(); + if (oldDSV) + oldDSV->Release(); + if (oldInputLayout) + oldInputLayout->Release(); + if (oldVS) + oldVS->Release(); + if (oldPS) + oldPS->Release(); + for (UINT i = 0; i < oldVSInstanceCount; ++i) + { + if (oldVSInstances[i]) + oldVSInstances[i]->Release(); + } + for (UINT i = 0; i < oldPSInstanceCount; ++i) + { + if (oldPSInstances[i]) + oldPSInstances[i]->Release(); + } + for (ID3D11ShaderResourceView* resource : oldResources) + { + if (resource) + resource->Release(); + } + if (oldSampler) + oldSampler->Release(); + if (oldConstantBuffer) + oldConstantBuffer->Release(); + if (oldRasterizer) + oldRasterizer->Release(); + if (oldDepthState) + oldDepthState->Release(); + if (oldBlendState) + oldBlendState->Release(); + return true; +} + +void PostProcesser::ApplyFXAA(const D3D11_VIEWPORT& viewport) +{ + CopyBackbuffer(); + DrawFullscreen(m_pFXAAPS, m_pGammaOffscreenSRV, nullptr, g_pRenderTargetView, + viewport, viewport, static_cast(m_gammaTexWidth), + static_cast(m_gammaTexHeight), nullptr, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.125f, m_fxaaStrength, 0.0f); +} + +void PostProcesser::ApplyGamma(const D3D11_VIEWPORT& viewport) +{ + if (m_gamma > 0.99f && m_gamma < 1.01f) + return; + + CopyBackbuffer(); + DrawFullscreen(m_pGammaPS, m_pGammaOffscreenSRV, nullptr, g_pRenderTargetView, + viewport, viewport, static_cast(m_gammaTexWidth), + static_cast(m_gammaTexHeight), nullptr, 0.0f, 0.0f, + 0.0f, 0.0f, m_gamma, 0.0f, 0.0f, 0.0f); +} + +void PostProcesser::ApplyBloom(const D3D11_VIEWPORT& viewport) +{ + const float scaleX = static_cast(m_bloomTexWidth) / static_cast(m_gammaTexWidth); + const float scaleY = static_cast(m_bloomTexHeight) / static_cast(m_gammaTexHeight); + D3D11_VIEWPORT bloomViewport = viewport; + bloomViewport.TopLeftX *= scaleX; + bloomViewport.TopLeftY *= scaleY; + bloomViewport.Width *= scaleX; + bloomViewport.Height *= scaleY; + + CopyBackbuffer(); + if (!DrawFullscreen(m_pBloomExtractPS, m_pGammaOffscreenSRV, nullptr, m_pBloomRTVA, + bloomViewport, viewport, static_cast(m_gammaTexWidth), + static_cast(m_gammaTexHeight), nullptr, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.8f, 0.0f, 0.5f)) + return; + if (!DrawFullscreen(m_pBloomBlurPS, m_pBloomSRVA, nullptr, m_pBloomRTVB, + bloomViewport, bloomViewport, static_cast(m_bloomTexWidth), + static_cast(m_bloomTexHeight), nullptr, 0.0f, 0.0f, + 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f)) + return; + if (!DrawFullscreen(m_pBloomBlurPS, m_pBloomSRVB, nullptr, m_pBloomRTVA, + bloomViewport, bloomViewport, static_cast(m_bloomTexWidth), + static_cast(m_bloomTexHeight), nullptr, 0.0f, 0.0f, + 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f)) + return; + DrawFullscreen(m_pBloomCompositePS, m_pGammaOffscreenSRV, m_pBloomSRVA, + g_pRenderTargetView, viewport, viewport, + static_cast(m_gammaTexWidth), static_cast(m_gammaTexHeight), + &bloomViewport, static_cast(m_bloomTexWidth), + static_cast(m_bloomTexHeight), 0.0f, 0.0f, 1.0f, + 0.0f, 0.65f, 0.0f); +} + void PostProcesser::Cleanup() { + if (m_pBloomCompositePS) + { + m_pBloomCompositePS->Release(); + m_pBloomCompositePS = nullptr; + } + if (m_pBloomBlurPS) + { + m_pBloomBlurPS->Release(); + m_pBloomBlurPS = nullptr; + } + if (m_pBloomExtractPS) + { + m_pBloomExtractPS->Release(); + m_pBloomExtractPS = nullptr; + } + if (m_pFXAAPS) + { + m_pFXAAPS->Release(); + m_pFXAAPS = nullptr; + } + if (m_pBloomRTVA) + { + m_pBloomRTVA->Release(); + m_pBloomRTVA = nullptr; + } + if (m_pBloomSRVA) + { + m_pBloomSRVA->Release(); + m_pBloomSRVA = nullptr; + } + if (m_pBloomTexA) + { + m_pBloomTexA->Release(); + m_pBloomTexA = nullptr; + } + if (m_pBloomRTVB) + { + m_pBloomRTVB->Release(); + m_pBloomRTVB = nullptr; + } + if (m_pBloomSRVB) + { + m_pBloomSRVB->Release(); + m_pBloomSRVB = nullptr; + } + if (m_pBloomTexB) + { + m_pBloomTexB->Release(); + m_pBloomTexB = nullptr; + } if (m_pGammaBlendState) { m_pGammaBlendState->Release(); @@ -434,6 +910,11 @@ void PostProcesser::Cleanup() m_pGammaSampler->Release(); m_pGammaSampler = nullptr; } + if (m_pPostProcessSampler) + { + m_pPostProcessSampler->Release(); + m_pPostProcessSampler = nullptr; + } if (m_pGammaCB) { m_pGammaCB->Release(); @@ -466,4 +947,9 @@ void PostProcesser::Cleanup() } m_initialized = false; + m_useCustomViewport = false; + m_gammaTexWidth = 0; + m_gammaTexHeight = 0; + m_bloomTexWidth = 0; + m_bloomTexHeight = 0; } diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 543f1dfa..aaa3f7fc 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -2039,8 +2039,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, ui.tick(); ui.render(); - pMinecraft->gameRenderer->ApplyGammaPostProcess(); - #if 0 app.HandleButtonPresses(); diff --git a/Minecraft.Client/Windows64Media/loc/stringsGeneric.xml b/Minecraft.Client/Windows64Media/loc/stringsGeneric.xml index e90daed2..08bf0f89 100644 --- a/Minecraft.Client/Windows64Media/loc/stringsGeneric.xml +++ b/Minecraft.Client/Windows64Media/loc/stringsGeneric.xml @@ -6689,6 +6689,26 @@ Would you like to install the mash-up pack or texture pack now? Render Clouds + + Bloom + + + + Enable FXAA + + + + FXAA Strength + + + + Enable MipMap + + + + MipMap Strength + + Cave Sounds @@ -7625,6 +7645,10 @@ Would you like to install the mash-up pack or texture pack now? Graphics + + Post Processing + + User Interface diff --git a/Minecraft.Client/cmake/sources/Windows.cmake b/Minecraft.Client/cmake/sources/Windows.cmake index a01142d6..e2c7aa3d 100644 --- a/Minecraft.Client/cmake/sources/Windows.cmake +++ b/Minecraft.Client/cmake/sources/Windows.cmake @@ -204,6 +204,7 @@ set(_MINECRAFT_CLIENT_WINDOWS_COMMON_UI_SCENES_HELP__OPTIONS "${CMAKE_CURRENT_SOURCE_DIR}/Common/UI/UIScene_SettingsAudioMenu.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Common/UI/UIScene_SettingsAudioMenu.h" "${CMAKE_CURRENT_SOURCE_DIR}/Common/UI/UIScene_SettingsGraphicsMenu.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/Common/UI/UIScene_SettingsPostProcessingMenu.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Common/UI/UIScene_SettingsGraphicsMenu.h" "${CMAKE_CURRENT_SOURCE_DIR}/Common/UI/UIScene_SettingsMenu.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Common/UI/UIScene_SettingsMenu.h" diff --git a/Minecraft.Server/cmake/sources/Common.cmake b/Minecraft.Server/cmake/sources/Common.cmake index 686bedf5..43ff5460 100644 --- a/Minecraft.Server/cmake/sources/Common.cmake +++ b/Minecraft.Server/cmake/sources/Common.cmake @@ -240,6 +240,7 @@ set(_MINECRAFT_SERVER_COMMON_ROOT "${_MS_SRC}/../Minecraft.Client/Common/UI/UIScene_SaveMessage.cpp" "${_MS_SRC}/../Minecraft.Client/Common/UI/UIScene_SettingsAudioMenu.cpp" "${_MS_SRC}/../Minecraft.Client/Common/UI/UIScene_SettingsGraphicsMenu.cpp" + "${_MS_SRC}/../Minecraft.Client/Common/UI/UIScene_SettingsPostProcessingMenu.cpp" "${_MS_SRC}/../Minecraft.Client/Common/UI/UIScene_SettingsMenu.cpp" "${_MS_SRC}/../Minecraft.Client/Common/UI/UIScene_SettingsOptionsMenu.cpp" "${_MS_SRC}/../Minecraft.Client/Common/UI/UIScene_SettingsUIMenu.cpp"