diff --git a/rendering/CommonRenderDevice.cpp b/rendering/CommonRenderDevice.cpp index 5637fa2..ad3066a 100644 --- a/rendering/CommonRenderDevice.cpp +++ b/rendering/CommonRenderDevice.cpp @@ -50,10 +50,12 @@ void CommonRenderDevice::method_44() { void CommonRenderDevice::createSiblingScene( RenderViewport *viewport, CommonRenderTarget *renderTarget, - CommonDepthBuffer *depthBuffer) + CommonDepthBuffer *depthBuffer, + CommonRenderTarget *sourceColor, + CommonDepthBuffer *sourceDepth) { // TODO - createSubScene(viewport, renderTarget, depthBuffer); + createSubScene(viewport, renderTarget, depthBuffer, sourceColor, sourceDepth); // TODO } diff --git a/rendering/CommonRenderDevice.h b/rendering/CommonRenderDevice.h index 3977ddc..5295cae 100644 --- a/rendering/CommonRenderDevice.h +++ b/rendering/CommonRenderDevice.h @@ -64,12 +64,16 @@ public: virtual CommonScene *createSubScene( RenderViewport *renderViewport, CommonRenderTarget *renderTarget, - CommonDepthBuffer *depthBuffer) = 0; - virtual void createSiblingScene( + CommonDepthBuffer *depthBuffer, + CommonRenderTarget *sourceColor, + CommonDepthBuffer *sourceDepth) = 0; + virtual void createSiblingScene( // CreatePartition RenderViewport *renderViewport, CommonRenderTarget *renderTarget, - CommonDepthBuffer *depthBuffer); - virtual void finishScene() = 0; // 50 + CommonDepthBuffer *depthBuffer, + CommonRenderTarget *sourceColor, + CommonDepthBuffer *sourceDepth); + virtual void finishScene() = 0; // 50, EndScene virtual void method_54(); virtual uint32_t getSceneCreationCount(); // frame count, basically virtual CommonScene *getScene(); diff --git a/rendering/CommonScene.cpp b/rendering/CommonScene.cpp index c771f60..bedc762 100644 --- a/rendering/CommonScene.cpp +++ b/rendering/CommonScene.cpp @@ -11,15 +11,19 @@ CommonScene::CommonScene( CommonRenderTarget *renderTarget, CommonDepthBuffer *depthBuffer, /* ... */ + CommonRenderTarget *sourceColor, + CommonDepthBuffer *sourceDepth, RenderGlobalState *globalState, /* ... */ RenderPasses *renderPasses) : renderTarget(renderTarget), + depthBuffer(depthBuffer), + sourceColor(sourceColor), + sourceDepth(sourceDepth), parentScene(parentScene), nextScene(nullptr), prevScene(nullptr), - depthBuffer(depthBuffer), numSubScenes(0) { this->viewport = *viewport; diff --git a/rendering/CommonScene.h b/rendering/CommonScene.h index a18009a..218a0dd 100644 --- a/rendering/CommonScene.h +++ b/rendering/CommonScene.h @@ -70,8 +70,8 @@ public: CommonRenderTarget *renderTarget; //3F0 CommonDepthBuffer *depthBuffer; // 3F4 // uint32_t dword3F8; - // uint32_t dword3FC; - // uint32_t dword400; + CommonRenderTarget *sourceColor; //3FC + CommonDepthBuffer *sourceDepth; // 400 CommonScene *parentScene; // 404 CommonScene *nextScene; // 408 CommonScene *prevScene; // 40C @@ -122,6 +122,8 @@ public: CommonRenderTarget *renderTarget, CommonDepthBuffer *depthBuffer, /* ... */ + CommonRenderTarget *sourceColor, + CommonDepthBuffer *sourceDepth, RenderGlobalState *globalState, /* ... */ RenderPasses *renderPasses); diff --git a/rendering/PCDX11RenderDevice.cpp b/rendering/PCDX11RenderDevice.cpp index 8512381..f54b731 100644 --- a/rendering/PCDX11RenderDevice.cpp +++ b/rendering/PCDX11RenderDevice.cpp @@ -139,16 +139,19 @@ void PCDX11RenderDevice::createDefaultVertexAttribLayouts() { attrs.push_back({VertexAttributeA::kTexcoord1, 0xffff, 1, 0}); attrs.push_back({VertexAttributeA::kTexcoord2, 0xffff, 1, 0}); drawVertexDecls[0] = VertexDecl::Create(attrs.data(), attrs.size(), /*stride=*/ 0); + drawVertexDecls[0]->hash0 |= 1; // HACK attrs.clear(); attrs.push_back({VertexAttributeA::kPosition, 0xffff, 2, 0}); attrs.push_back({VertexAttributeA::kColor1, 0xffff, 4, 0}); attrs.push_back({VertexAttributeA::kTexcoord0, 0xffff, 1, 0}); // HACK drawVertexDecls[5] = VertexDecl::Create(attrs.data(), attrs.size(), /*stride=*/ 0); + drawVertexDecls[5]->hash0 |= 5; // HACK attrs.clear(); attrs.push_back({VertexAttributeA::kPosition, 0xffff, 2, 0}); drawVertexDecls[6] = VertexDecl::Create(attrs.data(), attrs.size(), /*stride=*/ 0); + drawVertexDecls[6]->hash0 |= 6; // HACK PCDX11VertexShader *vs; @@ -339,10 +342,12 @@ void PCDX11RenderDevice::method_30() { // TODO } -CommonScene *PCDX11RenderDevice::createSubScene( +CommonScene *PCDX11RenderDevice::createSubScene( // 48 RenderViewport *viewport, CommonRenderTarget *renderTarget, - CommonDepthBuffer *depthBuffer + CommonDepthBuffer *depthBuffer, + CommonRenderTarget *sourceColor, + CommonDepthBuffer *sourceDepth ) { sceneCreationCount++; // TODO @@ -352,6 +357,8 @@ CommonScene *PCDX11RenderDevice::createSubScene( viewport, renderTarget, depthBuffer, + sourceColor, + sourceDepth, getGlobalState(), &renderPasses); scene7C = scene; diff --git a/rendering/PCDX11RenderDevice.h b/rendering/PCDX11RenderDevice.h index dbd7975..5b1d8c1 100644 --- a/rendering/PCDX11RenderDevice.h +++ b/rendering/PCDX11RenderDevice.h @@ -126,7 +126,9 @@ public: CommonScene *createSubScene( RenderViewport *renderViewport, CommonRenderTarget *renderTarget, - CommonDepthBuffer *depthBuffer) override; + CommonDepthBuffer *depthBuffer, + CommonRenderTarget *sourceColor, + CommonDepthBuffer *sourceDepth) override; void finishScene() override; void getSceneRenderTarget() override; void method_64() override; diff --git a/rendering/PCDX11Scene.cpp b/rendering/PCDX11Scene.cpp index 0f69317..68b3da1 100644 --- a/rendering/PCDX11Scene.cpp +++ b/rendering/PCDX11Scene.cpp @@ -21,6 +21,12 @@ void PCDX11Scene::draw(uint32_t funcSetIndex, IRenderDrawable *other) { auto& sceneBuffer = stateManager->accessCommonCB(1); sceneBuffer.assignRow(27, globalState.m_aParams, 16); // TODO + + if (sourceColor) + stateManager->m_renderTarget->copyFromTexture(static_cast(sourceColor)); + if (sourceDepth) + stateManager->m_depthBuffer->copyFromTexture(static_cast(sourceDepth)); // not implemented in original binary + if (drawableListsAndMasks) { drawableListsAndMasks->renderPasses->sortAndDraw( drawableListsAndMasks->passType, diff --git a/rendering/PCDX11Scene.h b/rendering/PCDX11Scene.h index 8873f7a..42fa2b8 100644 --- a/rendering/PCDX11Scene.h +++ b/rendering/PCDX11Scene.h @@ -15,11 +15,13 @@ public: CommonRenderTarget *renderTarget, CommonDepthBuffer *depthBuffer, /* ... */ + CommonRenderTarget *sourceColor, + CommonDepthBuffer *sourceDepth, RenderGlobalState *globalState, /* ... */ RenderPasses *renderPasses) : - CommonScene(renderDevice, parentScene, viewport, renderTarget, depthBuffer, globalState, renderPasses), + CommonScene(renderDevice, parentScene, viewport, renderTarget, depthBuffer, sourceColor, sourceDepth, globalState, renderPasses), renderDevice(static_cast(renderDevice)) { // TODO diff --git a/rendering/surfaces/PCDX11DefaultRenderTarget.cpp b/rendering/surfaces/PCDX11DefaultRenderTarget.cpp index 09ca89d..93f90df 100644 --- a/rendering/surfaces/PCDX11DefaultRenderTarget.cpp +++ b/rendering/surfaces/PCDX11DefaultRenderTarget.cpp @@ -44,6 +44,8 @@ ID3D11RenderTargetView *PCDX11DefaultRenderTarget::getRenderTargetView() { } void PCDX11DefaultRenderTarget::copyFromTexture(PCDX11RenderTarget *sourceRT) { + // used from PCDX11Scene::draw when it has been constructed with sourceColor != nullptr + if (sourceRT->method_3C()) sourceRT->method_40(); diff --git a/spinnycube.cpp b/spinnycube.cpp index e75a996..f24bf4a 100644 --- a/spinnycube.cpp +++ b/spinnycube.cpp @@ -440,7 +440,8 @@ int spinnyCube(HWND window, bool mouseLook = false; bool useFrustumCulling = true; bool drawCellBoxes = false; - bool applyFXAA = false; + bool applyFXAA = true; + bool pointlessCopy = true; cdc::Vector cameraPos{0, 0, 0}; /////////////////////////////////////////////////////////////////////////////////////////////// @@ -704,7 +705,7 @@ int spinnyCube(HWND window, cdc::PCDX11RenderTarget *tempRenderTarget = nullptr; - if (applyFXAA) + if (applyFXAA && !pointlessCopy) tempRenderTarget = static_cast(renderDevice->dx11_createRenderTarget( 100, 100, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, 0x18, 0)); @@ -712,8 +713,10 @@ int spinnyCube(HWND window, renderDevice->beginRenderList(nullptr); auto *scene = renderDevice->createSubScene( &renderViewport, - applyFXAA ? tempRenderTarget : renderContext->renderTarget2C, - renderContext->depthBuffer); + tempRenderTarget ? tempRenderTarget : renderContext->renderTarget2C, + renderContext->depthBuffer, + nullptr, + nullptr); scene->viewMatrix = viewMatrix; cdc::OrthonormalInverse3x4(&renderViewport.viewMatrix, viewMatrix); @@ -933,23 +936,50 @@ int spinnyCube(HWND window, } if (applyFXAA) { - renderDevice->finishScene(); - tempRenderTarget->getRenderTexture11()->createRenderTargetView(); + if (pointlessCopy) { + tempRenderTarget = static_cast(renderDevice->dx11_createRenderTarget( + 100, 100, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, 0x18, 0)); + tempRenderTarget->getRenderTexture11()->createRenderTargetView(); - auto *fxaaDrawable = new (renderDevice, 0) cdc::PCDX11FXAADrawable( - renderDevice, - /*quality*/ 0, - /*texture*/ tempRenderTarget->getRenderTexture(), - /*renderTarget*/ renderContext->renderTarget2C, - /*flags*/ 0, - /*sortZ*/ 0.0f); - - // now draw to the real buffer - renderDevice->createSubScene( - &renderViewport, - renderContext->renderTarget2C, - renderContext->depthBuffer); - renderDevice->recordDrawable(fxaaDrawable, /*mask=*/ 0x100, 0); + auto *fxaaDrawable = new (renderDevice, 0) cdc::PCDX11FXAADrawable( + renderDevice, + /*quality*/ 0, + /*texture*/ renderContext->renderTarget2C->getRenderTexture(), + /*renderTarget*/ tempRenderTarget, + /*flags*/ 0, + /*sortZ*/ 0.0f); + + renderDevice->recordDrawable(fxaaDrawable, /*mask=*/ 0x100, 0); + renderDevice->finishScene(); + + // restart the scene to cause a (pointless) copy + renderDevice->createSubScene( + &renderViewport, + renderContext->renderTarget2C, + renderContext->depthBuffer, + tempRenderTarget, + nullptr); + } else { + renderDevice->finishScene(); + tempRenderTarget->getRenderTexture11()->createRenderTargetView(); + + auto *fxaaDrawable = new (renderDevice, 0) cdc::PCDX11FXAADrawable( + renderDevice, + /*quality*/ 0, + /*texture*/ tempRenderTarget->getRenderTexture(), + /*renderTarget*/ renderContext->renderTarget2C, + /*flags*/ 0, + /*sortZ*/ 0.0f); + + // now draw to the real buffer + renderDevice->createSubScene( + &renderViewport, + renderContext->renderTarget2C, + renderContext->depthBuffer, + nullptr, + nullptr); + renderDevice->recordDrawable(fxaaDrawable, /*mask=*/ 0x100, 0); + } } renderDevice->recordDrawable(&imGuiDrawable, /*mask=*/ 0x100, /*addToParent=*/ 0);