This commit is contained in:
Adam Jensen 2022-10-21 17:55:01 +01:00
parent f6f7239ea8
commit 482cbab98e
5 changed files with 86 additions and 3 deletions

View File

@ -801,6 +801,48 @@ void PCDX11RenderDevice::drawQuad(
drawQuadInternal(x0, y0, x1, y1, u0, v0, u1, v1, color);
}
void PCDX11RenderDevice::doFXAA(
uint32_t quality,
PCDX11Texture *texture,
PCDX11RenderTarget *renderTarget)
{
if (!scene78) {
printf("scene78 = nullptr\n");
return;
}
if (!scene78->globalState.tex14[5+6]) {
printf("scene78->globalState.tex14[5+6] = nullptr\n");
return;
}
// HACK
texture = static_cast<PCDX11Texture*>(scene78->globalState.tex14[5+6]);
renderTarget = static_cast<PCDX11RenderTarget*>(scene78->renderTarget);
// END HACK
PCDX11StateManager *stateManager = deviceManager->getStateManager();
stateManager->pushRenderTargets(renderTarget, nullptr);
if (quality > 2) quality = 2; // allow 0, 1 and 2
auto *vs = static_cast<PCDX11VertexShaderTable*>(shlib_19->table)->vertexShaders[0];
stateManager->setVertexShader(vs);
auto *ps = static_cast<PCDX11PixelShaderTable*>(shlib_12->table)->pixelShaders[quality];
stateManager->setPixelShader(ps);
stateManager->setTextureAndSampler(0, texture, 1, 0.0f);
stateManager->updateViewport();
stateManager->updateRenderState();
drawQuad(
-1.0f, -1.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
/*color=*/ 0xffffffff,
/*flags=*/ 0,
/*blendMode=*/ 0x7010010,
/*writeDepth=*/ false
);
stateManager->popRenderTargets();
}
CommonRenderDevice *createPCDX11RenderDevice(HWND hwnd, uint width, uint height, bool unknown) {
// createPCDX11DeviceManager(); // already done, else wouldn't have an hwnd
g_renderDevice = new PCDX11RenderDevice(hwnd, width, height/*, unknown*/);

View File

@ -218,6 +218,7 @@ public:
float x0, float y0, float x1, float y1,
float u0, float v0, float u1, float v1,
uint32_t color, uint32_t flags, uint32_t blendMode, bool writeDepth);
void doFXAA(uint32_t quality, PCDX11Texture *texture, PCDX11RenderTarget *renderTarget);
};
CommonRenderDevice *createPCDX11RenderDevice(HWND hwnd, uint width, uint height, bool unknown);

View File

@ -1,9 +1,12 @@
#include "PCDX11FXAADrawable.h"
#include "../PCDX11RenderDevice.h"
namespace cdc {
void PCDX11FXAADrawable::draw(uint32_t funcSetIndex, IRenderDrawable *other) {
// TODO
(void)funcSetIndex;
(void)other;
renderDevice->doFXAA(quality, texture, renderTarget);
}
uint32_t PCDX11FXAADrawable::compare(uint32_t funcSetIndex, IRenderDrawable *other) {

View File

@ -3,12 +3,36 @@
namespace cdc {
class PCDX11RenderDevice;
class PCDX11RenderTarget;
class PCDX11Texture;
class PCDX11FXAADrawable :
public IRenderDrawable
{
uint32_t flags;
PCDX11RenderDevice *renderDevice;
uint32_t quality;
PCDX11RenderTarget *renderTarget;
PCDX11Texture *texture;
public:
PCDX11FXAADrawable(/*TODO*/)
{}
PCDX11FXAADrawable(
PCDX11RenderDevice *renderDevice,
uint32_t quality,
PCDX11Texture *texture,
PCDX11RenderTarget *renderTarget,
uint32_t flags,
float sortZ
) :
flags(flags),
renderDevice(renderDevice),
quality(quality),
renderTarget(renderTarget),
texture(texture)
{
this->sortZ = sortZ;
}
virtual void draw(uint32_t funcSetIndex, IRenderDrawable *other);
virtual uint32_t compare(uint32_t funcSetIndex, IRenderDrawable *other);

View File

@ -38,6 +38,7 @@
#include "rendering/buffers/PCDX11ConstantBufferPool.h"
#include "rendering/buffers/PCDX11IndexBuffer.h"
#include "rendering/buffers/PCDX11UberConstantBuffer.h"
#include "rendering/drawables/PCDX11FXAADrawable.h"
#include "rendering/IPCDeviceManager.h"
#include "rendering/IRenderPassCallback.h"
#include "rendering/PCDX11DeviceManager.h"
@ -356,6 +357,14 @@ int spinnyCube(HWND window,
ImGuiDrawable imGuiDrawable;
cdc::PCDX11FXAADrawable fxaaDrawable(
renderDevice,
/*quality*/ 2,
/*texture*/ nullptr, // HACK
/*renderTarget*/ nullptr, // HACK
/*flags*/ 0,
/*sortZ*/ 0.0f);
///////////////////////////////////////////////////////////////////////////////////////////////
int introShowRange[2] = {0, 99999};
@ -568,6 +577,10 @@ int spinnyCube(HWND window,
// single bottle at origin
rmiDrawable.draw(&bottleWorldMatrix, 0.0f);
// uncomment to apply FXAA to the normal map
// can't apply to the proper color buffer because it'd be read/written at the same time
// renderDevice->recordDrawable(&fxaaDrawable, /*mask=*/ 0x100, 0);
renderDevice->recordDrawable(&imGuiDrawable, /*mask=*/ 0x100, /*addToParent=*/ 0);
renderDevice->finishScene();
renderDevice->endRenderList();