From f5ff8eb013a260c80293e36937bd75602bf944e1 Mon Sep 17 00:00:00 2001 From: elasota Date: Fri, 22 May 2020 21:14:43 -0400 Subject: [PATCH] Add color fade --- GpApp/GliderProtos.h | 3 +- GpApp/Main.cpp | 18 +- GpApp/MainWindow.cpp | 48 +--- GpCommon/IGpDisplayDriver.h | 2 + .../DrawQuadPaletteP_D3D11.cpp | 221 +++++++++++------- .../GpDisplayDriverD3D11.cpp | 2 + GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h | 3 + PortabilityLayer/PLCore.cpp | 6 - PortabilityLayer/WindowManager.cpp | 40 ++++ PortabilityLayer/WindowManager.h | 2 + ShaderSrc/DrawQuadPaletteP.hlsl | 6 +- ShaderSrc/DrawQuadPixelConstants.h | 14 +- ShaderSrc/Functions.h | 59 +++++ 13 files changed, 272 insertions(+), 152 deletions(-) create mode 100644 ShaderSrc/Functions.h diff --git a/GpApp/GliderProtos.h b/GpApp/GliderProtos.h index 25ab98c..78d36ce 100644 --- a/GpApp/GliderProtos.h +++ b/GpApp/GliderProtos.h @@ -156,10 +156,9 @@ void RedrawSplashScreen (void); // --- MainWindow.c void UpdateMainWindow (void); void OpenMainWindow (void); void CloseMainWindow (void); -void ZoomBetweenWindows (void); void UpdateEditWindowTitle (void); void HandleMainClick (Point, Boolean); -//void WashColorIn (void); +void WashColorIn (void); void CenterMapOnRoom (SInt16, SInt16); // --- Map.c Boolean ThisRoomVisibleOnMap (void); diff --git a/GpApp/Main.cpp b/GpApp/Main.cpp index dbd6be7..c4c500c 100644 --- a/GpApp/Main.cpp +++ b/GpApp/Main.cpp @@ -12,6 +12,7 @@ #include "Environ.h" #include "IOStream.h" #include "House.h" +#include "WindowManager.h" #define kPrefsVersion 0x0035 @@ -352,6 +353,10 @@ int gpAppMain() InitSrcRects(); CreateOffscreens(); SpinCursor(2); OpenMainWindow(); + + if (isDoColorFade) + PortabilityLayer::WindowManager::GetInstance()->SetWindowDesaturation(mainWindow, 1.0); + InitSound(); SpinCursor(2); InitMusic(); SpinCursor(2); BuildHouseList(); @@ -366,17 +371,8 @@ int gpAppMain() // HideMenuBarOld(); #endif -// if ((isDoColorFade) && (thisMac.isDepth == 8)) -// { -// wasSeed = ExtractCTSeed((CGrafPtr)mainWindow); -// WashColorIn(); -// ForceCTSeed((CGrafPtr)mainWindow, wasSeed); -// } -// if ((!thisMac.hasSM3) && (numSMWarnings < 3)) -// { -// numSMWarnings++; -// BitchAboutSM3(); -// } + if (isDoColorFade) + WashColorIn(); UpdateMainWindow(); diff --git a/GpApp/MainWindow.cpp b/GpApp/MainWindow.cpp index bd0a326..e821574 100644 --- a/GpApp/MainWindow.cpp +++ b/GpApp/MainWindow.cpp @@ -579,54 +579,20 @@ void HardDrawMainWindow (void) //-------------------------------------------------------------- WashColorIn // Slowly walks the palette from its gray luminance state to the full colorÉ // palette. In this way, color appears to slowly wash in. -/* void WashColorIn (void) { #define kGray2ColorSteps 180 - GDHandle theDevice; long longDelta; short i, c; - - theDevice = GetGDevice(); - SetGDevice(thisGDevice); - + for (i = 0; i < kGray2ColorSteps; i++) { - for (c = 0; c < 256; c++) - { - if (c != 5) - { - longDelta = (((long)wasColors[c].rgb.red - - (long)newColors[c].rgb.red) / - (long)(kGray2ColorSteps - i)) + (long)newColors[c].rgb.red; - newColors[c].rgb.red = (unsigned short)longDelta; - - longDelta = (((long)wasColors[c].rgb.green - - (long)newColors[c].rgb.green) / - (long)(kGray2ColorSteps - i)) + - (long)newColors[c].rgb.green; - newColors[c].rgb.green = (unsigned short)longDelta; - - longDelta = (((long)wasColors[c].rgb.blue - - (long)newColors[c].rgb.blue) / - (long)(kGray2ColorSteps - i)) + - (long)newColors[c].rgb.blue; - newColors[c].rgb.blue = (unsigned short)longDelta; - } - } - SetEntries(0, 255, newColors); - if (Button()) + PortabilityLayer::WindowManager::GetInstance()->SetWindowDesaturation(mainWindow, static_cast(kGray2ColorSteps - i) / static_cast(kGray2ColorSteps)); + + Delay(1, nullptr); + if (PortabilityLayer::InputManager::GetInstance()->GetKeys()->m_mouse.Get(GpMouseButtons::kLeft)) break; } - - SetEntries(0, 255, wasColors); - SetGDevice(theDevice); - - RestoreColorsSlam(); - - if (wasColors != nil) - DisposePtr((Ptr)wasColors); - if (newColors != nil) - DisposePtr((Ptr)newColors); + + PortabilityLayer::WindowManager::GetInstance()->SetWindowDesaturation(mainWindow, 0.0f); } -*/ diff --git a/GpCommon/IGpDisplayDriver.h b/GpCommon/IGpDisplayDriver.h index e34a974..372405a 100644 --- a/GpCommon/IGpDisplayDriver.h +++ b/GpCommon/IGpDisplayDriver.h @@ -16,6 +16,7 @@ struct GpDisplayDriverSurfaceEffects int32_t m_flickerAxisY; int32_t m_flickerStartThreshold; int32_t m_flickerEndThreshold; + float m_desaturation; }; // Display drivers are responsible for timing and calling the game tick function. @@ -48,5 +49,6 @@ inline GpDisplayDriverSurfaceEffects::GpDisplayDriverSurfaceEffects() , m_flickerAxisY(0) , m_flickerStartThreshold(0) , m_flickerEndThreshold(0) + , m_desaturation(0) { } diff --git a/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp b/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp index ee126f2..579e58a 100644 --- a/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp +++ b/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp @@ -1,10 +1,10 @@ static unsigned char gs_shaderData[] = { - 68, 88, 66, 67, 16, 112, 155, 167, 152, 216, 111, 160, 194, 37, 151, - 206, 26, 38, 150, 132, 1, 0, 0, 0, 140, 5, 0, 0, 5, 0, - 0, 0, 52, 0, 0, 0, 48, 2, 0, 0, 136, 2, 0, 0, 188, - 2, 0, 0, 16, 5, 0, 0, 82, 68, 69, 70, 244, 1, 0, 0, + 68, 88, 66, 67, 123, 171, 231, 206, 83, 178, 250, 149, 189, 168, 129, + 29, 12, 186, 195, 194, 1, 0, 0, 0, 24, 9, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, 172, 2, 0, 0, 4, 3, 0, 0, 56, + 3, 0, 0, 156, 8, 0, 0, 82, 68, 69, 70, 112, 2, 0, 0, 1, 0, 0, 0, 180, 0, 0, 0, 3, 0, 0, 0, 28, 0, 0, - 0, 0, 4, 255, 255, 0, 137, 0, 0, 202, 1, 0, 0, 124, 0, + 0, 0, 4, 255, 255, 0, 137, 0, 0, 72, 2, 0, 0, 124, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 139, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, @@ -15,85 +15,146 @@ static unsigned char gs_shaderData[] = { 117, 114, 101, 0, 112, 97, 108, 101, 116, 116, 101, 84, 101, 120, 116, 117, 114, 101, 0, 83, 68, 114, 97, 119, 81, 117, 97, 100, 80, 105, 120, 101, 108, 67, 111, 110, 115, 116, 97, 110, 116, 115, 0, 171, 171, - 154, 0, 0, 0, 4, 0, 0, 0, 204, 0, 0, 0, 32, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 1, 0, 0, 0, 0, - 0, 0, 16, 0, 0, 0, 2, 0, 0, 0, 68, 1, 0, 0, 0, - 0, 0, 0, 84, 1, 0, 0, 16, 0, 0, 0, 8, 0, 0, 0, - 2, 0, 0, 0, 108, 1, 0, 0, 0, 0, 0, 0, 124, 1, 0, - 0, 24, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 156, 1, - 0, 0, 0, 0, 0, 0, 172, 1, 0, 0, 28, 0, 0, 0, 4, - 0, 0, 0, 2, 0, 0, 0, 156, 1, 0, 0, 0, 0, 0, 0, - 99, 111, 110, 115, 116, 97, 110, 116, 115, 95, 77, 111, 100, 117, 108, - 97, 116, 105, 111, 110, 0, 171, 171, 171, 1, 0, 3, 0, 1, 0, - 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 111, 110, 115, 116, - 97, 110, 116, 115, 95, 70, 108, 105, 99, 107, 101, 114, 65, 120, 105, - 115, 0, 171, 171, 1, 0, 2, 0, 1, 0, 2, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 99, 111, 110, 115, 116, 97, 110, 116, 115, 95, - 70, 108, 105, 99, 107, 101, 114, 83, 116, 97, 114, 116, 84, 104, 114, - 101, 115, 104, 111, 108, 100, 0, 0, 0, 2, 0, 1, 0, 1, 0, + 154, 0, 0, 0, 6, 0, 0, 0, 204, 0, 0, 0, 48, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 92, 1, 0, 0, 0, 0, + 0, 0, 16, 0, 0, 0, 2, 0, 0, 0, 116, 1, 0, 0, 0, + 0, 0, 0, 132, 1, 0, 0, 16, 0, 0, 0, 8, 0, 0, 0, + 2, 0, 0, 0, 156, 1, 0, 0, 0, 0, 0, 0, 172, 1, 0, + 0, 24, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 204, 1, + 0, 0, 0, 0, 0, 0, 220, 1, 0, 0, 28, 0, 0, 0, 4, + 0, 0, 0, 2, 0, 0, 0, 204, 1, 0, 0, 0, 0, 0, 0, + 250, 1, 0, 0, 32, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, + 0, 20, 2, 0, 0, 0, 0, 0, 0, 36, 2, 0, 0, 36, 0, + 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 56, 2, 0, 0, 0, + 0, 0, 0, 99, 111, 110, 115, 116, 97, 110, 116, 115, 95, 77, 111, + 100, 117, 108, 97, 116, 105, 111, 110, 0, 171, 171, 171, 1, 0, 3, + 0, 1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 111, + 110, 115, 116, 97, 110, 116, 115, 95, 70, 108, 105, 99, 107, 101, 114, + 65, 120, 105, 115, 0, 171, 171, 1, 0, 2, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 111, 110, 115, 116, 97, 110, - 116, 115, 95, 70, 108, 105, 99, 107, 101, 114, 69, 110, 100, 84, 104, - 114, 101, 115, 104, 111, 108, 100, 0, 77, 105, 99, 114, 111, 115, 111, - 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83, 104, 97, - 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 49, 48, - 46, 49, 0, 171, 171, 73, 83, 71, 78, 80, 0, 0, 0, 2, 0, - 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, - 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, - 0, 1, 0, 0, 0, 3, 3, 0, 0, 83, 86, 95, 80, 79, 83, - 73, 84, 73, 79, 78, 0, 84, 69, 88, 67, 79, 79, 82, 68, 0, - 171, 171, 171, 79, 83, 71, 78, 44, 0, 0, 0, 1, 0, 0, 0, - 8, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 83, 86, - 95, 84, 65, 82, 71, 69, 84, 0, 171, 171, 83, 72, 68, 82, 76, - 2, 0, 0, 64, 0, 0, 0, 147, 0, 0, 0, 89, 0, 0, 4, - 70, 142, 32, 0, 0, 0, 0, 0, 2, 0, 0, 0, 88, 24, 0, - 4, 0, 112, 16, 0, 0, 0, 0, 0, 68, 68, 0, 0, 88, 16, - 0, 4, 0, 112, 16, 0, 1, 0, 0, 0, 85, 85, 0, 0, 98, - 16, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0, 101, 0, 0, 3, - 242, 32, 16, 0, 0, 0, 0, 0, 104, 0, 0, 2, 2, 0, 0, - 0, 65, 0, 0, 5, 50, 0, 16, 0, 0, 0, 0, 0, 70, 16, - 16, 0, 1, 0, 0, 0, 27, 0, 0, 5, 50, 0, 16, 0, 0, - 0, 0, 0, 70, 0, 16, 0, 0, 0, 0, 0, 54, 0, 0, 8, - 194, 0, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, - 0, 7, 242, 0, 16, 0, 1, 0, 0, 0, 70, 14, 16, 0, 0, - 0, 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, 54, 0, 0, 8, - 226, 0, 16, 0, 1, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, - 0, 7, 242, 0, 16, 0, 1, 0, 0, 0, 70, 14, 16, 0, 1, - 0, 0, 0, 70, 126, 16, 0, 1, 0, 0, 0, 54, 0, 0, 5, - 130, 0, 16, 0, 1, 0, 0, 0, 1, 64, 0, 0, 0, 0, 128, - 63, 56, 0, 0, 8, 242, 0, 16, 0, 1, 0, 0, 0, 70, 14, - 16, 0, 1, 0, 0, 0, 70, 142, 32, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 38, 0, 0, 9, 0, 208, 0, 0, 50, 0, 16, 0, - 0, 0, 0, 0, 70, 0, 16, 0, 0, 0, 0, 0, 70, 128, 32, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 30, 0, 0, 7, 18, 0, - 16, 0, 0, 0, 0, 0, 26, 0, 16, 0, 0, 0, 0, 0, 10, - 0, 16, 0, 0, 0, 0, 0, 34, 0, 0, 8, 34, 0, 16, 0, - 0, 0, 0, 0, 10, 0, 16, 0, 0, 0, 0, 0, 42, 128, 32, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 33, 0, 0, 8, 18, 0, - 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 0, 0, 0, 0, 58, - 128, 32, 0, 0, 0, 0, 0, 1, 0, 0, 0, 55, 0, 0, 12, - 242, 0, 16, 0, 1, 0, 0, 0, 6, 0, 16, 0, 0, 0, 0, - 0, 70, 14, 16, 0, 1, 0, 0, 0, 2, 64, 0, 0, 0, 0, - 128, 63, 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 128, 63, 55, - 0, 0, 12, 242, 0, 16, 0, 0, 0, 0, 0, 86, 5, 16, 0, - 0, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 14, 16, 0, 1, 0, - 0, 0, 29, 0, 0, 7, 18, 0, 16, 0, 1, 0, 0, 0, 1, - 64, 0, 0, 0, 0, 0, 0, 58, 0, 16, 0, 0, 0, 0, 0, - 13, 0, 4, 3, 10, 0, 16, 0, 1, 0, 0, 0, 54, 0, 0, - 5, 242, 32, 16, 0, 0, 0, 0, 0, 70, 14, 16, 0, 0, 0, - 0, 0, 62, 0, 0, 1, 83, 84, 65, 84, 116, 0, 0, 0, 18, - 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, - 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 116, 115, 95, 70, 108, 105, 99, 107, 101, 114, 83, 116, 97, 114, 116, + 84, 104, 114, 101, 115, 104, 111, 108, 100, 0, 0, 0, 2, 0, 1, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 111, 110, 115, + 116, 97, 110, 116, 115, 95, 70, 108, 105, 99, 107, 101, 114, 69, 110, + 100, 84, 104, 114, 101, 115, 104, 111, 108, 100, 0, 99, 111, 110, 115, + 116, 97, 110, 116, 115, 95, 68, 101, 115, 97, 116, 117, 114, 97, 116, + 105, 111, 110, 0, 171, 171, 171, 0, 0, 3, 0, 1, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 99, 111, 110, 115, 116, 97, 110, + 116, 115, 95, 85, 110, 117, 115, 101, 100, 0, 171, 171, 171, 1, 0, + 3, 0, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, + 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, 105, + 108, 101, 114, 32, 49, 48, 46, 49, 0, 73, 83, 71, 78, 80, 0, + 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 3, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, 73, 79, 78, 0, 84, 69, 88, 67, 79, + 79, 82, 68, 0, 171, 171, 171, 79, 83, 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, 65, 82, 71, 69, 84, 0, 171, 171, 83, + 72, 68, 82, 92, 5, 0, 0, 64, 0, 0, 0, 87, 1, 0, 0, + 89, 0, 0, 4, 70, 142, 32, 0, 0, 0, 0, 0, 3, 0, 0, + 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, 0, 0, 68, 68, + 0, 0, 88, 16, 0, 4, 0, 112, 16, 0, 1, 0, 0, 0, 85, + 85, 0, 0, 98, 16, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 104, 0, 0, + 2, 4, 0, 0, 0, 65, 0, 0, 5, 50, 0, 16, 0, 0, 0, + 0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 27, 0, 0, 5, 50, + 0, 16, 0, 0, 0, 0, 0, 70, 0, 16, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 194, 0, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, + 0, 0, 45, 0, 0, 7, 242, 0, 16, 0, 1, 0, 0, 0, 70, + 14, 16, 0, 0, 0, 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 226, 0, 16, 0, 1, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, + 0, 0, 45, 0, 0, 7, 242, 0, 16, 0, 1, 0, 0, 0, 70, + 14, 16, 0, 1, 0, 0, 0, 70, 126, 16, 0, 1, 0, 0, 0, + 56, 0, 0, 9, 242, 0, 16, 0, 2, 0, 0, 0, 70, 142, 32, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 142, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 54, 0, 0, 5, 130, 0, 16, 0, 1, + 0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 56, 0, 0, 7, + 242, 0, 16, 0, 1, 0, 0, 0, 70, 14, 16, 0, 1, 0, 0, + 0, 70, 14, 16, 0, 2, 0, 0, 0, 38, 0, 0, 9, 0, 208, + 0, 0, 50, 0, 16, 0, 0, 0, 0, 0, 70, 0, 16, 0, 0, + 0, 0, 0, 70, 128, 32, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 30, 0, 0, 7, 18, 0, 16, 0, 0, 0, 0, 0, 26, 0, 16, + 0, 0, 0, 0, 0, 10, 0, 16, 0, 0, 0, 0, 0, 34, 0, + 0, 8, 34, 0, 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 0, + 0, 0, 0, 42, 128, 32, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 33, 0, 0, 8, 18, 0, 16, 0, 0, 0, 0, 0, 10, 0, 16, + 0, 0, 0, 0, 0, 58, 128, 32, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 55, 0, 0, 12, 242, 0, 16, 0, 1, 0, 0, 0, 86, + 5, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 14, 16, + 0, 1, 0, 0, 0, 60, 0, 0, 7, 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, 0, 0, 0, 0, 26, 0, 16, 0, 0, + 0, 0, 0, 55, 0, 0, 12, 242, 0, 16, 0, 0, 0, 0, 0, + 6, 0, 16, 0, 0, 0, 0, 0, 70, 14, 16, 0, 1, 0, 0, + 0, 2, 64, 0, 0, 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, + 128, 63, 0, 0, 128, 63, 57, 0, 0, 8, 18, 0, 16, 0, 1, + 0, 0, 0, 10, 128, 32, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, 0, 0, 31, 0, 4, 3, 10, 0, 16, + 0, 1, 0, 0, 0, 29, 0, 0, 10, 114, 0, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, 28, 46, 77, 59, 28, 46, 77, 59, 28, + 46, 77, 59, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, + 56, 0, 0, 10, 114, 0, 16, 0, 2, 0, 0, 0, 70, 2, 16, + 0, 0, 0, 0, 0, 2, 64, 0, 0, 82, 184, 78, 65, 82, 184, + 78, 65, 82, 184, 78, 65, 0, 0, 0, 0, 47, 0, 0, 5, 114, + 0, 16, 0, 3, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, + 56, 0, 0, 10, 114, 0, 16, 0, 3, 0, 0, 0, 70, 2, 16, + 0, 3, 0, 0, 0, 2, 64, 0, 0, 85, 85, 213, 62, 85, 85, + 213, 62, 85, 85, 213, 62, 0, 0, 0, 0, 25, 0, 0, 5, 114, + 0, 16, 0, 3, 0, 0, 0, 70, 2, 16, 0, 3, 0, 0, 0, + 50, 0, 0, 15, 114, 0, 16, 0, 3, 0, 0, 0, 70, 2, 16, + 0, 3, 0, 0, 0, 2, 64, 0, 0, 61, 10, 135, 63, 61, 10, + 135, 63, 61, 10, 135, 63, 0, 0, 0, 0, 2, 64, 0, 0, 174, + 71, 97, 189, 174, 71, 97, 189, 174, 71, 97, 189, 0, 0, 0, 0, + 55, 0, 0, 9, 114, 0, 16, 0, 1, 0, 0, 0, 70, 2, 16, + 0, 1, 0, 0, 0, 70, 2, 16, 0, 2, 0, 0, 0, 70, 2, + 16, 0, 3, 0, 0, 0, 16, 0, 0, 10, 130, 0, 16, 0, 1, + 0, 0, 0, 70, 2, 16, 0, 1, 0, 0, 0, 2, 64, 0, 0, + 154, 153, 153, 62, 154, 153, 25, 63, 205, 204, 204, 61, 0, 0, 0, + 0, 0, 0, 0, 9, 18, 0, 16, 0, 2, 0, 0, 0, 10, 128, + 32, 128, 65, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, + 64, 0, 0, 0, 0, 128, 63, 56, 0, 0, 8, 130, 0, 16, 0, + 1, 0, 0, 0, 58, 0, 16, 0, 1, 0, 0, 0, 10, 128, 32, + 0, 0, 0, 0, 0, 2, 0, 0, 0, 50, 0, 0, 9, 114, 0, + 16, 0, 1, 0, 0, 0, 70, 2, 16, 0, 1, 0, 0, 0, 6, + 0, 16, 0, 2, 0, 0, 0, 246, 15, 16, 0, 1, 0, 0, 0, + 29, 0, 0, 10, 114, 0, 16, 0, 2, 0, 0, 0, 2, 64, 0, + 0, 230, 174, 37, 61, 230, 174, 37, 61, 230, 174, 37, 61, 0, 0, + 0, 0, 70, 2, 16, 0, 1, 0, 0, 0, 56, 0, 0, 10, 114, + 0, 16, 0, 3, 0, 0, 0, 70, 2, 16, 0, 1, 0, 0, 0, + 2, 64, 0, 0, 145, 131, 158, 61, 145, 131, 158, 61, 145, 131, 158, + 61, 0, 0, 0, 0, 0, 0, 0, 10, 114, 0, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, 1, 0, 0, 0, 2, 64, 0, 0, 174, + 71, 97, 61, 174, 71, 97, 61, 174, 71, 97, 61, 0, 0, 0, 0, + 56, 0, 0, 10, 114, 0, 16, 0, 1, 0, 0, 0, 70, 2, 16, + 0, 1, 0, 0, 0, 2, 64, 0, 0, 110, 167, 114, 63, 110, 167, + 114, 63, 110, 167, 114, 63, 0, 0, 0, 0, 47, 0, 0, 5, 114, + 0, 16, 0, 1, 0, 0, 0, 70, 2, 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 114, 0, 16, 0, 1, 0, 0, 0, 70, 2, 16, + 0, 1, 0, 0, 0, 2, 64, 0, 0, 154, 153, 25, 64, 154, 153, + 25, 64, 154, 153, 25, 64, 0, 0, 0, 0, 25, 0, 0, 5, 114, + 0, 16, 0, 1, 0, 0, 0, 70, 2, 16, 0, 1, 0, 0, 0, + 55, 0, 0, 9, 114, 0, 16, 0, 0, 0, 0, 0, 70, 2, 16, + 0, 2, 0, 0, 0, 70, 2, 16, 0, 3, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, 21, 0, 0, 1, 29, 0, 0, 7, 18, + 0, 16, 0, 1, 0, 0, 0, 1, 64, 0, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, 0, 0, 13, 0, 4, 3, 10, 0, 16, + 0, 1, 0, 0, 0, 54, 0, 0, 5, 242, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, 0, 0, 0, 0, 62, 0, 0, 1, 83, + 84, 65, 84, 116, 0, 0, 0, 42, 0, 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 2, 0, 0, 0, 22, 0, 0, 0, 4, 0, 0, + 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, + 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, }; namespace GpBinarizedShaders diff --git a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp index 81a7d29..a0c891c 100644 --- a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp +++ b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp @@ -1094,6 +1094,8 @@ void GpDisplayDriverD3D11::DrawSurface(IGpDisplayDriverSurface *surface, int32_t pConstantsData.m_flickerStart = -2; } + pConstantsData.m_desaturation = effects->m_desaturation; + if (effects->m_darken) for (int i = 0; i < 3; i++) pConstantsData.m_modulation[i] = 0.5f; diff --git a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h index a0bf30b..a7d2577 100644 --- a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h +++ b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h @@ -74,6 +74,9 @@ private: int32_t m_flickerAxis[2]; int32_t m_flickerStart; int32_t m_flickerEnd; + + float m_desaturation; + float m_unused[3]; }; struct ScaleQuadPixelConstants diff --git a/PortabilityLayer/PLCore.cpp b/PortabilityLayer/PLCore.cpp index 3c431f5..c8cbcad 100644 --- a/PortabilityLayer/PLCore.cpp +++ b/PortabilityLayer/PLCore.cpp @@ -503,12 +503,6 @@ void GetMouse(Window *window, Point *point) point->v = relativePos.m_y; } -Boolean Button() -{ - PL_NotYetImplemented(); - return false; -} - Boolean StillDown() { return PortabilityLayer::InputManager::GetInstance()->GetKeys()->m_mouse.Get(GpMouseButtons::kLeft); diff --git a/PortabilityLayer/WindowManager.cpp b/PortabilityLayer/WindowManager.cpp index 67d30e8..7817af2 100644 --- a/PortabilityLayer/WindowManager.cpp +++ b/PortabilityLayer/WindowManager.cpp @@ -110,6 +110,13 @@ namespace PortabilityLayer static const RGBAColor kLightColor; }; + struct WindowEffects + { + WindowEffects(); + + float m_desaturationLevel; + }; + class WindowImpl final : public Window { public: @@ -140,7 +147,12 @@ namespace PortabilityLayer void SetTitle(const PLPasStr &str); const PascalStr<255> &GetTitle() const; + WindowEffects &GetEffects(); + const WindowEffects &GetEffects() const; + private: + WindowEffects m_effects; + WindowImpl *m_windowAbove; WindowImpl *m_windowBelow; @@ -175,6 +187,8 @@ namespace PortabilityLayer void FlickerWindowIn(Window *window, int32_t velocity) override; void FlickerWindowOut(Window *window, int32_t velocity) override; + void SetWindowDesaturation(Window *window, float desaturationLevel) override; + void SetResizeInProgress(Window *window, const PortabilityLayer::Vec2i &size) override; void ClearResizeInProgress() override; @@ -786,6 +800,12 @@ namespace PortabilityLayer surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2), midColor); } + //--------------------------------------------------------------------------- + WindowEffects::WindowEffects() + : m_desaturationLevel(0.0f) + { + } + //--------------------------------------------------------------------------- WindowImpl::WindowImpl() : m_windowAbove(nullptr) @@ -974,6 +994,18 @@ namespace PortabilityLayer return m_title; } + WindowEffects &WindowImpl::GetEffects() + { + return m_effects; + } + + const WindowEffects &WindowImpl::GetEffects() const + { + return m_effects; + } + + + WindowManagerImpl::WindowManagerImpl() : m_windowStackTop(nullptr) , m_windowStackBottom(nullptr) @@ -1318,6 +1350,12 @@ namespace PortabilityLayer m_flickerWindow = nullptr; } + + void WindowManagerImpl::SetWindowDesaturation(Window *window, float desaturationLevel) + { + static_cast(window)->GetEffects().m_desaturationLevel = desaturationLevel; + } + void WindowManagerImpl::SetResizeInProgress(Window *window, const PortabilityLayer::Vec2i &size) { ResolveCachingColor blackColor = StdColors::Black(); @@ -1500,6 +1538,8 @@ namespace PortabilityLayer if (m_exclusiveWindow != nullptr && m_exclusiveWindow != window) effects.m_darken = true; + effects.m_desaturation = window->GetEffects().m_desaturationLevel; + bool hasFlicker = (m_flickerWindow == window); DrawSurface &graf = *window->GetDrawSurface(); diff --git a/PortabilityLayer/WindowManager.h b/PortabilityLayer/WindowManager.h index ea221df..eab6943 100644 --- a/PortabilityLayer/WindowManager.h +++ b/PortabilityLayer/WindowManager.h @@ -41,6 +41,8 @@ namespace PortabilityLayer virtual void FlickerWindowIn(Window *window, int32_t velocity) = 0; virtual void FlickerWindowOut(Window *window, int32_t velocity) = 0; + virtual void SetWindowDesaturation(Window *window, float desaturationLevel) = 0; + virtual void SetResizeInProgress(Window *window, const PortabilityLayer::Vec2i &size) = 0; virtual void ClearResizeInProgress() = 0; diff --git a/ShaderSrc/DrawQuadPaletteP.hlsl b/ShaderSrc/DrawQuadPaletteP.hlsl index 8ee2dc3..67054ad 100644 --- a/ShaderSrc/DrawQuadPaletteP.hlsl +++ b/ShaderSrc/DrawQuadPaletteP.hlsl @@ -1,5 +1,6 @@ #include "DrawQuad.h" #include "DrawQuadPixelConstants.h" +#include "Functions.h" SamplerState nearestNeighborSampler : register(s0); Texture2D surfaceTexture : register(t0); @@ -20,7 +21,10 @@ SDrawQuadPixelOutput PSMain(SDrawQuadPixelInput input) { SDrawQuadPixelOutput result; int2 pixelCoordinate = int2(floor(input.texCoord.xy)); - result.color = ApplyFlicker(pixelCoordinate, float4(SamplePixel(int2(floor(input.texCoord.xy))), 1.0) * constants_Modulation); + result.color = float4(SamplePixel(int2(floor(input.texCoord.xy))), 1.0); + result.color *= constants_Modulation; + result.color = ApplyFlicker(pixelCoordinate, constants_FlickerStartThreshold, constants_FlickerEndThreshold, result.color * constants_Modulation); + result.color = ApplyDesaturation(constants_Desaturation, result.color); if (result.color.a <= 0.0) discard; diff --git a/ShaderSrc/DrawQuadPixelConstants.h b/ShaderSrc/DrawQuadPixelConstants.h index 368f549..dff0f41 100644 --- a/ShaderSrc/DrawQuadPixelConstants.h +++ b/ShaderSrc/DrawQuadPixelConstants.h @@ -5,15 +5,7 @@ cbuffer SDrawQuadPixelConstants : register(b0) int2 constants_FlickerAxis; int constants_FlickerStartThreshold; int constants_FlickerEndThreshold; + + float constants_Desaturation; + float3 constants_Unused; }; - -float4 ApplyFlicker(int2 coordinate, float4 color) -{ - int flickerTotal = dot(constants_FlickerAxis, coordinate); - if (flickerTotal < constants_FlickerStartThreshold) - return float4(0, 0, 0, 0); - else if (flickerTotal >= constants_FlickerEndThreshold) - return color; - else - return float4(1, 1, 1, 1); -} diff --git a/ShaderSrc/Functions.h b/ShaderSrc/Functions.h new file mode 100644 index 0000000..7bfc071 --- /dev/null +++ b/ShaderSrc/Functions.h @@ -0,0 +1,59 @@ +float SRGBToLinear(float v) +{ + if (v <= 0.04045) + return v * (1.0 / 12.92); + else + return pow(((v + 0.055) * (1.0 / 1.055)), 2.4); +} + +float2 SRGBToLinear(float2 v) +{ + return float2(SRGBToLinear(v.x), SRGBToLinear(v.y)); +} + +float3 SRGBToLinear(float3 v) +{ + return float3(SRGBToLinear(v.x), SRGBToLinear(v.y), SRGBToLinear(v.z)); +} + +float LinearToSRGB(float v) +{ + if (v <= 0.0031308) + return 12.92 * v; + else + return 1.055 * pow(v, 1.0 / 2.4) - 0.055; +} + +float2 LinearToSRGB(float2 v) +{ + return float2(LinearToSRGB(v.x), LinearToSRGB(v.y)); +} + +float3 LinearToSRGB(float3 v) +{ + return float3(LinearToSRGB(v.x), LinearToSRGB(v.y), LinearToSRGB(v.z)); +} + +float4 ApplyFlicker(int2 coordinate, int startThreshold, int endThreshold, float4 color) +{ + int flickerTotal = dot(constants_FlickerAxis, coordinate); + if (flickerTotal < startThreshold) + return float4(0, 0, 0, 0); + else if (flickerTotal >= endThreshold) + return color; + + return float4(1, 1, 1, 1); +} + +float4 ApplyDesaturation(float desaturation, float4 color) +{ + if (desaturation == 0.0) + return color; + + float3 srgbColor = LinearToSRGB(color.rgb); + float grayLevel = dot(srgbColor, float3(3.0, 6.0, 1.0) / 10.0); + + srgbColor = srgbColor * (1.0 - desaturation) + float3(grayLevel, grayLevel, grayLevel) * desaturation; + + return float4(SRGBToLinear(srgbColor), color.a); +}