From 40ed4b87090f6ae4466214c43a852f61b3ed528d Mon Sep 17 00:00:00 2001 From: Terraformer9x <83795041+Terraformer9x@users.noreply.github.com> Date: Thu, 2 May 2024 02:21:31 -0400 Subject: [PATCH 1/7] Define `g_dxBias_` in DriectGraphics --- source/GcLib/directx/DirectGraphics.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/GcLib/directx/DirectGraphics.hpp b/source/GcLib/directx/DirectGraphics.hpp index 4635f7f6..4ba8dc46 100644 --- a/source/GcLib/directx/DirectGraphics.hpp +++ b/source/GcLib/directx/DirectGraphics.hpp @@ -55,6 +55,7 @@ namespace directx { static DirectGraphics* thisBase_; public: static float g_dxCoordsMul_; + static constexpr float g_dxBias_ = 0.5; protected: D3DPRESENT_PARAMETERS d3dppFull_; D3DPRESENT_PARAMETERS d3dppWin_; From d8283dc5d05cde31555be55bd0076be17674aba7 Mon Sep 17 00:00:00 2001 From: Terraformer9x <83795041+Terraformer9x@users.noreply.github.com> Date: Thu, 2 May 2024 02:24:08 -0400 Subject: [PATCH 2/7] Remove bias adjustments in DxObject.cpp --- source/GcLib/directx/DxObject.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/GcLib/directx/DxObject.cpp b/source/GcLib/directx/DxObject.cpp index 9d620b37..20143974 100644 --- a/source/GcLib/directx/DxObject.cpp +++ b/source/GcLib/directx/DxObject.cpp @@ -246,9 +246,8 @@ D3DXVECTOR3 DxScriptPrimitiveObject2D::GetVertexPosition(size_t index) { RenderObjectTLX* obj = GetRenderObject(); VERTEX_TLX* vert = obj->GetVertex(index); - constexpr float bias = 0.5f; - res.x = vert->position.x + bias; - res.y = vert->position.y + bias; + res.x = vert->position.x; + res.y = vert->position.y; res.z = 0; return res; From 7f6a7305893da700bdfea81365c82d79e4cd3a83 Mon Sep 17 00:00:00 2001 From: Terraformer9x <83795041+Terraformer9x@users.noreply.github.com> Date: Thu, 2 May 2024 02:25:18 -0400 Subject: [PATCH 3/7] Add new bias adjustments in DxText.cpp --- source/GcLib/directx/DxText.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/GcLib/directx/DxText.cpp b/source/GcLib/directx/DxText.cpp index b5e7f9db..57a1cf39 100644 --- a/source/GcLib/directx/DxText.cpp +++ b/source/GcLib/directx/DxText.cpp @@ -735,6 +735,9 @@ void DxTextRenderObject::Render(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY D3DXMATRIX matWorld = RenderObject::CreateWorldMatrixText2D(center, scale_, angX, angY, angZ, position, bias, bCamera ? &DirectGraphics::GetBase()->GetCamera2D()->GetMatrix() : nullptr); + + matWorld._41 -= DirectGraphics::g_dxBias_; + matWorld._42 -= DirectGraphics::g_dxBias_; sprite->SetPermitCamera(false); sprite->SetShader(shader_); From bbaddb1458fb2ca8eb406090acfdafc5ff327c07 Mon Sep 17 00:00:00 2001 From: Terraformer9x <83795041+Terraformer9x@users.noreply.github.com> Date: Thu, 2 May 2024 02:26:12 -0400 Subject: [PATCH 4/7] Add new bias adjustments in MetasequoiaMesh.cpp --- source/GcLib/directx/MetasequoiaMesh.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/GcLib/directx/MetasequoiaMesh.cpp b/source/GcLib/directx/MetasequoiaMesh.cpp index 40c65e66..2430a138 100644 --- a/source/GcLib/directx/MetasequoiaMesh.cpp +++ b/source/GcLib/directx/MetasequoiaMesh.cpp @@ -523,6 +523,9 @@ void MetasequoiaMesh::Render(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, c D3DXMATRIX mat = RenderObject::CreateWorldMatrix(position_, scale_, angX, angY, angZ, &camera->GetIdentity(), bCoordinate2D_); device->SetTransform(D3DTS_WORLD, &mat); + + mat._41 -= DirectGraphics::g_dxBias_; + mat._42 -= DirectGraphics::g_dxBias_; { size_t i = 0; From 6e00dc5567954470c722ad198a61aa80234cd54f Mon Sep 17 00:00:00 2001 From: Terraformer9x <83795041+Terraformer9x@users.noreply.github.com> Date: Thu, 2 May 2024 02:33:44 -0400 Subject: [PATCH 5/7] Add new bias adjustments RenderObject.cpp, as well as remove old bias adjustments --- source/GcLib/directx/RenderObject.cpp | 45 +++++++++++++++------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/source/GcLib/directx/RenderObject.cpp b/source/GcLib/directx/RenderObject.cpp index ecf899a9..b85f4bcd 100644 --- a/source/GcLib/directx/RenderObject.cpp +++ b/source/GcLib/directx/RenderObject.cpp @@ -418,6 +418,9 @@ void RenderObjectTLX::Render(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, c else { matWorld = camera->GetMatrix(); } + + matWorld._41 -= DirectGraphics::g_dxBias_; + matWorld._42 -= DirectGraphics::g_dxBias_; RenderObjectTLX::Render(matWorld); } @@ -551,9 +554,8 @@ void RenderObjectTLX::SetVertexPosition(size_t index, float x, float y, float z, x *= DirectGraphics::g_dxCoordsMul_; y *= DirectGraphics::g_dxCoordsMul_; - constexpr float bias = -0.5f; - vertex->position.x = x + bias; - vertex->position.y = y + bias; + vertex->position.x = x; + vertex->position.y = y; vertex->position.z = z; vertex->position.w = w; } @@ -631,6 +633,9 @@ void RenderObjectLX::Render(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, co D3DXMatrixIdentity(&matWorld); else matWorld = *matRelative_; } + + matWorld._41 -= DirectGraphics::g_dxBias_; + matWorld._42 -= DirectGraphics::g_dxBias_; RenderObjectLX::Render(matWorld); } @@ -761,9 +766,8 @@ void RenderObjectLX::SetVertexPosition(size_t index, float x, float y, float z) x *= DirectGraphics::g_dxCoordsMul_; y *= DirectGraphics::g_dxCoordsMul_; - constexpr float bias = -0.5f; - vertex->position.x = x + bias; - vertex->position.y = y + bias; + vertex->position.x = x; + vertex->position.y = y; vertex->position.z = z; } void RenderObjectLX::SetVertexUV(size_t index, float u, float v) { @@ -971,9 +975,8 @@ void RenderObjectNX::SetVertexPosition(size_t index, float x, float y, float z) x *= DirectGraphics::g_dxCoordsMul_; y *= DirectGraphics::g_dxCoordsMul_; - constexpr float bias = -0.5f; - vertex->position.x = x + bias; - vertex->position.y = y + bias; + vertex->position.x = x; + vertex->position.y = y; vertex->position.z = z; } void RenderObjectNX::SetVertexUV(size_t index, float u, float v) { @@ -1029,13 +1032,11 @@ void Sprite2D::SetVertex(const DxRect& rcSrc, const DxRect& rcDest, SetAlpha(ColorAccess::GetColorA(color)); } DxRect Sprite2D::GetDestinationRect() { - constexpr float bias = -0.5f; - VERTEX_TLX* vertexLeftTop = GetVertex(0); VERTEX_TLX* vertexRightBottom = GetVertex(3); - DxRect rect(vertexLeftTop->position.x - bias, vertexLeftTop->position.y - bias, - vertexRightBottom->position.x - bias, vertexRightBottom->position.y - bias); + DxRect rect(vertexLeftTop->position.x, vertexLeftTop->position.y, + vertexRightBottom->position.x, vertexRightBottom->position.y); return rect; } @@ -1105,8 +1106,11 @@ void SpriteList2D::Render(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, cons D3DXMATRIX matWorld; if (bCloseVertexList_) - matWorld = RenderObject::CreateWorldMatrix2D(position_, scale_, - angX, angY, angZ, bCamera ? &camera->GetMatrix() : nullptr); + { + matWorld = RenderObject::CreateWorldMatrix2D(position_, scale_, angX, angY, angZ, bCamera ? &camera->GetMatrix() : nullptr); + matWorld._41 -= DirectGraphics::g_dxBias_; + matWorld._42 -= DirectGraphics::g_dxBias_; + } vertCopy_ = vertex_; { @@ -1235,6 +1239,8 @@ void SpriteList2D::AddVertex(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, c D3DXMATRIX matWorld = RenderObject::CreateWorldMatrix2D(position_, scale_, angX, angY, angZ, nullptr); + matWorld._41 -= DirectGraphics::g_dxBias_; + matWorld._42 -= DirectGraphics::g_dxBias_; int* ptrSrc = reinterpret_cast(&rcSrc_); double* ptrDst = reinterpret_cast(&rcDest_); @@ -1246,15 +1252,14 @@ void SpriteList2D::AddVertex(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, c vt.texcoord.y = (float)ptrSrc[iVert | 0b1] / height; D3DXVECTOR4 vPos; - - constexpr float bias = -0.5f; + vPos.x = (float)ptrDst[(iVert & 0b1) << 1]; vPos.y = (float)ptrDst[iVert | 0b1]; vPos.z = 1.0f; vPos.w = 1.0f; - vPos.x = vPos.x * DirectGraphics::g_dxCoordsMul_ + bias; - vPos.y = vPos.y * DirectGraphics::g_dxCoordsMul_ + bias; + vPos.x = vPos.x * DirectGraphics::g_dxCoordsMul_; + vPos.y = vPos.y * DirectGraphics::g_dxCoordsMul_; D3DXVec3TransformCoord((D3DXVECTOR3*)&vPos, (D3DXVECTOR3*)&vPos, &matWorld); vt.position = vPos; @@ -1531,7 +1536,7 @@ void ParticleRendererBase::AddInstance() { } VERTEX_INSTANCE instance; instance.diffuse_color = instColor_; - instance.xyz_pos_x_scale = D3DXVECTOR4(instPosition_.x, instPosition_.y, instPosition_.z, instScale_.x); + instance.xyz_pos_x_scale = D3DXVECTOR4(instPosition_.x - DirectGraphics::g_dxBias_, instPosition_.y - DirectGraphics::g_dxBias_, instPosition_.z, instScale_.x); instance.yz_scale_xy_ang = D3DXVECTOR4(instScale_.y, instScale_.z, -instAngle_.x, -instAngle_.y); instance.z_ang_extra = D3DXVECTOR4(-instAngle_.z, instUserData_.x, instUserData_.y, instUserData_.z); instanceData_[countInstance_++] = instance; From 9f8d8346528b92b67a91ca77f94f98115c4cd6fd Mon Sep 17 00:00:00 2001 From: Terraformer9x <83795041+Terraformer9x@users.noreply.github.com> Date: Thu, 2 May 2024 02:35:17 -0400 Subject: [PATCH 6/7] Add new bias adjustments in StgShot.cpp As well as remove an unusual bias variable that seemingly did nothing --- source/TouhouDanmakufu/Common/StgShot.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/TouhouDanmakufu/Common/StgShot.cpp b/source/TouhouDanmakufu/Common/StgShot.cpp index 3fcf9f39..567911ad 100644 --- a/source/TouhouDanmakufu/Common/StgShot.cpp +++ b/source/TouhouDanmakufu/Common/StgShot.cpp @@ -1014,13 +1014,11 @@ StgShotData* StgShotObject::_GetShotData(int id) { } void StgShotObject::_SetVertexPosition(VERTEX_TLX* vertex, float x, float y, float z, float w) { - constexpr float bias = 0.0f; - x *= DirectGraphics::g_dxCoordsMul_; y *= DirectGraphics::g_dxCoordsMul_; - vertex->position.x = x + bias; - vertex->position.y = y + bias; + vertex->position.x = x; + vertex->position.y = y; vertex->position.z = z; vertex->position.w = w; } @@ -1609,6 +1607,8 @@ void StgNormalShotObject::Render(BlendMode targetBlend) { sposx = roundf(sposx); sposy = roundf(sposy); } + sposx -= DirectGraphics::g_dxBias_; + sposy -= DirectGraphics::g_dxBias_; float scaleX = 1.0f; float scaleY = 1.0f; @@ -3240,4 +3240,4 @@ void StgShotPatternGeneratorObject::FireSet(void* scriptData, StgStageController } } } -} \ No newline at end of file +} From 05b0bfb921d05f186c36fdd50f2708d28e06cfdb Mon Sep 17 00:00:00 2001 From: Terraformer9x <83795041+Terraformer9x@users.noreply.github.com> Date: Thu, 2 May 2024 02:36:20 -0400 Subject: [PATCH 7/7] Update the bias adjustments to the new ones in GcLibImpl.cpp --- source/TouhouDanmakufu/DnhExecutor/GcLibImpl.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/source/TouhouDanmakufu/DnhExecutor/GcLibImpl.cpp b/source/TouhouDanmakufu/DnhExecutor/GcLibImpl.cpp index d2f72391..b43b228f 100644 --- a/source/TouhouDanmakufu/DnhExecutor/GcLibImpl.cpp +++ b/source/TouhouDanmakufu/DnhExecutor/GcLibImpl.cpp @@ -276,14 +276,13 @@ void EApplication::_RenderDisplay() { std::array verts; auto _Render = [](IDirect3DDevice9* device, VERTEX_TLX* verts, const D3DXMATRIX* mat) { - constexpr float bias = -0.5f; for (size_t iVert = 0; iVert < 4; ++iVert) { VERTEX_TLX* vertex = (VERTEX_TLX*)verts + iVert; vertex->diffuse_color = 0xffffffff; D3DXVECTOR4* vPos = &vertex->position; - vPos->x += bias; - vPos->y += bias; + vPos->x -= DirectGraphics::g_dxBias_; + vPos->y -= DirectGraphics::g_dxBias_; D3DXVec3TransformCoord((D3DXVECTOR3*)vPos, (D3DXVECTOR3*)vPos, mat); } @@ -343,11 +342,10 @@ void EApplication::_RenderDisplay() { verts[3] = VERTEX_TLX(D3DXVECTOR4(scW, scH, 0, 1), 0xffffffff, D3DXVECTOR2(scW / texW, scH / texH)); { - constexpr float bias = -0.5f; for (size_t iVert = 0; iVert < 4; ++iVert) { D3DXVECTOR4* vPos = &verts[iVert].position; - vPos->x += bias; - vPos->y += bias; + vPos->x -= DirectGraphics::g_dxBias_; + vPos->y -= DirectGraphics::g_dxBias_; } }