Prof-Butts / xwa_ddraw_d3d11

Direct3D 11 implementation of DDraw.dll for XWA with VR support and New Shaders
MIT License
6 stars 4 forks source link

Scissor bug fix #65

Open JeremyAnsel opened 2 years ago

JeremyAnsel commented 2 years ago

Hello, Here is a suggestion about the reported scissor bug.

In D3dRenderer.h, I suggest to add D3D11_RECT scissor; to the DrawCommand struct.

In D3dRenderer.h, I suggest to add void GetScissorRect(D3D11_RECT* scissor); to the D3dRenderer class.

In XwaD3dRendererHook.cpp, I suggest to add this function:

void D3dRenderer::GetScissorRect(D3D11_RECT* scissor)
{
    unsigned short scissorLeft = *(unsigned short*)0x07D5244;
    unsigned short scissorTop = *(unsigned short*)0x07CA354;
    unsigned short scissorWidth = *(unsigned short*)0x08052B8;
    unsigned short scissorHeight = *(unsigned short*)0x07B33BC;
    float scaleX = _viewport.Width / _deviceResources->_displayWidth;
    float scaleY = _viewport.Height / _deviceResources->_displayHeight;

    // The scissor is in screen coordinates.
    scissor->left = (LONG)(_viewport.TopLeftX + scissorLeft * scaleX + 0.5f);
    scissor->top = (LONG)(_viewport.TopLeftY + scissorTop * scaleY + 0.5f);
    scissor->right = scissor->left + (LONG)(scissorWidth * scaleX + 0.5f);
    scissor->bottom = scissor->top + (LONG)(scissorHeight * scaleY + 0.5f);}

In EffectsRenderer.cpp, I suggest to add GetScissorRect(&command.scissor); before _LaserDrawCommands.push_back(command);.

In EffectsRenderer.cpp, I suggest to add GetScissorRect(&command.scissor); before _TransparentDrawCommands.push_back(command);.

In EffectsRenderer.cpp, I suggest to add GetScissorRect(&command.scissor); before _ShadowMapDrawCommands.push_back(command);.

In EffectsRenderer.cpp, I suggest to add that in the RenderLasers method before RenderScene();:

_deviceResources->InitScissorRect(&command.scissor);

In EffectsRenderer.cpp, I suggest to add that in the RenderTransparency method before RenderScene();:

_deviceResources->InitScissorRect(&command.scissor);

In EffectsRenderer.cpp, I suggest to add that in the RenderHangarShadowMap method before context->DrawIndexed(_trianglesCount * 3, 0, 0);:

_deviceResources->InitScissorRect(&command.scissor);

In EffectsRenderer.cpp, I suggest to add that in the MainSceneHook method before RenderScene();:

D3D11_RECT scissor{};
GetScissorRect(&scissor);
_deviceResources->InitScissorRect(&scissor);

In EffectsRenderer.cpp, I suggest to remove these lines in the RenderScene method:

    unsigned short scissorLeft = *(unsigned short*)0x07D5244;
    unsigned short scissorTop = *(unsigned short*)0x07CA354;
    unsigned short scissorWidth = *(unsigned short*)0x08052B8;
    unsigned short scissorHeight = *(unsigned short*)0x07B33BC;
    float scaleX = _viewport.Width / _deviceResources->_displayWidth;
    float scaleY = _viewport.Height / _deviceResources->_displayHeight;
    D3D11_RECT scissor{};
    // The scissor is in screen coordinates.
    scissor.left = (LONG)(_viewport.TopLeftX + scissorLeft * scaleX + 0.5f);
    scissor.top = (LONG)(_viewport.TopLeftY + scissorTop * scaleY + 0.5f);
    scissor.right = scissor.left + (LONG)(scissorWidth * scaleX + 0.5f);
    scissor.bottom = scissor.top + (LONG)(scissorHeight * scaleY + 0.5f);
    _deviceResources->InitScissorRect(&scissor);