Skip to content

Commit 51512e2

Browse files
committed
Support Clip Plane
Fixes reflections being incorrect Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>
1 parent 94a9062 commit 51512e2

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

MarathonRecomp/gpu/video.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ struct SharedConstants
218218
float halfPixelOffsetX{};
219219
float halfPixelOffsetY{};
220220
float alphaThreshold{};
221+
bool clipPlaneEnabled{};
222+
float clipPlane[4]{};
221223
};
222224

223225
// Depth bias values here are only used when the render device has
@@ -1386,6 +1388,11 @@ static void ProcSetRenderState(const RenderCommand& cmd)
13861388
g_dirtyStates.renderTargetAndDepthStencil |= g_dirtyStates.pipelineState;
13871389
break;
13881390
}
1391+
case D3DRS_CLIPPLANEENABLE:
1392+
{
1393+
// HACK: Only check for clip pane 0
1394+
SetDirtyValue(g_dirtyStates.sharedConstants, g_sharedConstants.clipPlaneEnabled, (value & 1) == 1);
1395+
}
13891396
}
13901397
}
13911398

@@ -1420,7 +1427,8 @@ static const std::pair<GuestRenderState, PPCFunc*> g_setRenderStateFunctions[] =
14201427
{ D3DRS_CCW_STENCILFAIL, HostToGuestFunction<SetRenderState<D3DRS_CCW_STENCILFAIL>> },
14211428
{ D3DRS_CCW_STENCILZFAIL, HostToGuestFunction<SetRenderState<D3DRS_CCW_STENCILZFAIL>> },
14221429
{ D3DRS_CCW_STENCILPASS, HostToGuestFunction<SetRenderState<D3DRS_CCW_STENCILPASS>> },
1423-
{ D3DRS_CCW_STENCILFUNC, HostToGuestFunction<SetRenderState<D3DRS_CCW_STENCILFUNC>> }
1430+
{ D3DRS_CCW_STENCILFUNC, HostToGuestFunction<SetRenderState<D3DRS_CCW_STENCILFUNC>> },
1431+
{ D3DRS_CLIPPLANEENABLE, HostToGuestFunction<SetRenderState<D3DRS_CLIPPLANEENABLE>> }
14241432
};
14251433

14261434
static std::unique_ptr<RenderShader> g_copyShader;
@@ -5564,6 +5572,17 @@ static void ProcSetPixelShader(const RenderCommand& cmd)
55645572
SetDirtyValue(g_dirtyStates.pipelineState, g_pipelineState.pixelShader, shader);
55655573
}
55665574

5575+
static void SetClipPlane(GuestDevice* device, uint32_t index, const be<float>* plane)
5576+
{
5577+
if (index != 0)
5578+
return;
5579+
5580+
SetDirtyValue(g_dirtyStates.sharedConstants, g_sharedConstants.clipPlane[0], plane[0].get());
5581+
SetDirtyValue(g_dirtyStates.sharedConstants, g_sharedConstants.clipPlane[1], plane[1].get());
5582+
SetDirtyValue(g_dirtyStates.sharedConstants, g_sharedConstants.clipPlane[2], plane[2].get());
5583+
SetDirtyValue(g_dirtyStates.sharedConstants, g_sharedConstants.clipPlane[3], plane[3].get());
5584+
}
5585+
55675586
static std::thread g_renderThread([]
55685587
{
55695588
#ifdef _WIN32
@@ -8209,6 +8228,8 @@ GUEST_FUNCTION_HOOK(sub_82546BD8, SetPixelShader);
82098228

82108229
GUEST_FUNCTION_HOOK(sub_8253B760, IsSet);
82118230

8231+
GUEST_FUNCTION_HOOK(sub_82543CF0, SetClipPlane); // replaced
8232+
82128233
GUEST_FUNCTION_HOOK(sub_82541A78, SetRenderState<D3DRS_ZENABLE>);
82138234
GUEST_FUNCTION_HOOK(sub_82541AC0, SetRenderState<D3DRS_ZWRITEENABLE>);
82148235
GUEST_FUNCTION_HOOK(sub_82541460, SetRenderState<D3DRS_ALPHATESTENABLE>);
@@ -8239,6 +8260,7 @@ GUEST_FUNCTION_HOOK(sub_82541CC8, SetRenderState<D3DRS_CCW_STENCILFAIL>);
82398260
GUEST_FUNCTION_HOOK(sub_82541D08, SetRenderState<D3DRS_CCW_STENCILZFAIL>);
82408261
GUEST_FUNCTION_HOOK(sub_82541D48, SetRenderState<D3DRS_CCW_STENCILPASS>);
82418262
GUEST_FUNCTION_HOOK(sub_82541C98, SetRenderState<D3DRS_CCW_STENCILFUNC>);
8263+
GUEST_FUNCTION_HOOK(sub_82541E38, SetRenderState<D3DRS_CLIPPLANEENABLE>);
82428264

82438265
int GetType(GuestResource* resource) {
82448266
if (resource->type == ResourceType::Texture) return 3;

MarathonRecomp/gpu/video.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ enum GuestRenderState
377377
D3DRS_CCW_STENCILZFAIL = 148,
378378
D3DRS_CCW_STENCILPASS = 152,
379379
D3DRS_CCW_STENCILFUNC = 156,
380+
D3DRS_CLIPPLANEENABLE = 172,
380381
D3DRS_SCISSORTESTENABLE = 200,
381382
D3DRS_SLOPESCALEDEPTHBIAS = 204,
382383
D3DRS_DEPTHBIAS = 208,

0 commit comments

Comments
 (0)