Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions bmedll/Hudwarp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ ID3D11PixelShader* pPixelShader;
#define MAINVP 0
D3D11_VIEWPORT viewport{ 0 };

// render hud at 1440p on 1080p and similar scale
#define HUD_RENDER_RES 1.333f

HudwarpProcess::HudwarpProcess(ID3D11Device* pDevice, ID3D11DeviceContext** ppID3D11DeviceContext) : m_pDevice(pDevice), m_pContext(*ppID3D11DeviceContext)
{
// Initialize shaders
Expand Down Expand Up @@ -70,8 +73,8 @@ HudwarpProcess::HudwarpProcess(ID3D11Device* pDevice, ID3D11DeviceContext** ppID
m_height = *reinterpret_cast<unsigned int*>(vguimatsurfacedllBaseAddress + 0x290DD8 + 4);

// We add a border to the texture so that the HUD can't get cut off by the texture boundaries
unsigned int widthWithBorder = m_width * (1.0f + HUD_TEX_BORDER_SIZE * 2.0f);
unsigned int heightWithBorder = m_height * (1.0f + HUD_TEX_BORDER_SIZE * 2.0f);
unsigned int widthWithBorder = m_width * (1.0f + HUD_TEX_BORDER_SIZE * 2.0f) * HUD_RENDER_RES;
unsigned int heightWithBorder = m_height * (1.0f + HUD_TEX_BORDER_SIZE * 2.0f) * HUD_RENDER_RES;

// Setup the texture descriptor
D3D11_TEXTURE2D_DESC textureDesc;
Expand Down Expand Up @@ -125,6 +128,7 @@ HudwarpProcess::HudwarpProcess(ID3D11Device* pDevice, ID3D11DeviceContext** ppID
mOrtho = XMMatrixOrthographicLH(1.0f, 1.0f, 0.0f, 1.0f);
ConstantBuffer cb;
cb.mProjection = mOrtho;
cb.aspectRatio = (float)m_width / (float)m_height;
cb.xWarp = 0.0f;
cb.xScale = 1.0f;
cb.yWarp = 0.0f;
Expand Down Expand Up @@ -246,8 +250,8 @@ void HudwarpProcess::Resize(unsigned int w, unsigned int h)
m_height = *reinterpret_cast<unsigned int*>(vguimatsurfacedllBaseAddress + 0x290DD8 + 4);

// We add a border to the texture so that the HUD can't get cut off by the texture boundaries
unsigned int widthWithBorder = m_width * (1.0f + HUD_TEX_BORDER_SIZE * 2.0f);
unsigned int heightWithBorder = m_height * (1.0f + HUD_TEX_BORDER_SIZE * 2.0f);
unsigned int widthWithBorder = m_width * (1.0f + HUD_TEX_BORDER_SIZE * 2.0f) * HUD_RENDER_RES;
unsigned int heightWithBorder = m_height * (1.0f + HUD_TEX_BORDER_SIZE * 2.0f) * HUD_RENDER_RES;

// Setup the texture descriptor
D3D11_TEXTURE2D_DESC textureDesc;
Expand All @@ -263,6 +267,20 @@ void HudwarpProcess::Resize(unsigned int w, unsigned int h)
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;

// Update the constant buffer
ConstantBuffer cb;
cb.mProjection = mOrtho;
cb.aspectRatio = (float)m_width / (float)m_height;
cb.xWarp = m_hudwarpSettings.xWarp;
cb.xScale = m_hudwarpSettings.xScale;
cb.yWarp = m_hudwarpSettings.yWarp;
cb.yScale = m_hudwarpSettings.yScale;
cb.viewDist = m_hudwarpSettings.viewDist;

m_pContext->UpdateSubresource(m_pConstantBuffer, 0, 0, &cb, 0, 0);

m_shouldUpdateConstantBuffer = false;

// Create the render texture
m_pDevice->CreateTexture2D(&textureDesc, NULL, &m_pRenderTexture);

Expand All @@ -289,6 +307,7 @@ void HudwarpProcess::Resize(unsigned int w, unsigned int h)
void HudwarpProcess::UpdateSettings(HudwarpSettings* hudwarpSettings)
{
m_hudwarpSettings = *hudwarpSettings;
m_shouldUpdateConstantBuffer = true;
}

void HudwarpProcess::Begin()
Expand Down Expand Up @@ -357,16 +376,21 @@ void HudwarpProcess::Finish()
m_pContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

// Update the constant buffer
ConstantBuffer cb;
cb.mProjection = mOrtho;
cb.aspectRatio = (float)m_width / (float)m_height;
cb.xWarp = m_hudwarpSettings.xWarp;
cb.xScale = m_hudwarpSettings.xScale;
cb.yWarp = m_hudwarpSettings.yWarp;
cb.yScale = m_hudwarpSettings.yScale;
cb.viewDist = m_hudwarpSettings.viewDist;

m_pContext->UpdateSubresource(m_pConstantBuffer, 0, 0, &cb, 0, 0);
if (m_shouldUpdateConstantBuffer)
{
ConstantBuffer cb;
cb.mProjection = mOrtho;
cb.aspectRatio = (float)m_width / (float)m_height;
cb.xWarp = m_hudwarpSettings.xWarp;
cb.xScale = m_hudwarpSettings.xScale;
cb.yWarp = m_hudwarpSettings.yWarp;
cb.yScale = m_hudwarpSettings.yScale;
cb.viewDist = m_hudwarpSettings.viewDist;

m_pContext->UpdateSubresource(m_pConstantBuffer, 0, 0, &cb, 0, 0);

m_shouldUpdateConstantBuffer = false;
}

// Set shader resources
m_pContext->VSSetConstantBuffers(0, 1, &m_pConstantBuffer);
Expand Down
7 changes: 5 additions & 2 deletions bmedll/Hudwarp.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class HudwarpProcess
ID3D11InputLayout* m_pVertexLayout = nullptr;
ID3D11Buffer* m_pIndexBuffer = nullptr;
ID3D11Buffer* m_pConstantBuffer = nullptr;
bool m_shouldUpdateConstantBuffer = false;

ID3D11RasterizerState* m_pCWcullMode = NULL;

Expand Down Expand Up @@ -77,8 +78,10 @@ struct Vertex
XMFLOAT2 texCoord;
};

// Must match hudScale in shader
// Used for hudScale in shader, prevents cut off HUD
// These values must match or the HUD will end up scaled wrong
#define HUD_TEX_BORDER_SIZE 0.025f
#define HUD_TEX_BORDER_SIZE_STR "0.025f"

constexpr const char* hudwarpShader = R"(
cbuffer ConstantBuffer : register(b0)
Expand Down Expand Up @@ -116,7 +119,7 @@ sampler Sampler : register(s0);
float2 UndoHudTexBorder(float2 texCoord)
{
// IMPORTANT: must match value of HUD_TEX_BORDER_SIZE
float hudTexBorderSize = 0.025f;
float hudTexBorderSize = )" HUD_TEX_BORDER_SIZE_STR R"(;

float hudScale = 1.0f + 2.0f * hudTexBorderSize;
float hudOffset = 0.5f - (0.5f / hudScale);
Expand Down
Loading