Skip to content

Commit

Permalink
Fix weapon shadow flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
yohjimane committed Aug 5, 2023
1 parent 900c327 commit fa6781e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/xrGame/HudItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ void CHudItem::PlaySound(pcstr alias, const Fvector& position, u8 index)
{
m_sounds.PlaySound(alias, position, object().H_Root(), !!GetHUDmode(), false, index);
}

//-Alundaio

void CHudItem::renderable_Render(u32 context_id, IRenderable* root)
{
UpdateXForm();

const bool _hud_render = root && root->renderable_HUD() && GetHUDmode();

if (_hud_render && !IsHidden())
Expand Down
21 changes: 8 additions & 13 deletions src/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define ROTATION_TIME 0.25f

BOOL b_toggle_weapon_aim = FALSE;
extern float g_first_person_body_offset;

static class CUIWpnScopeXmlManager : public CUIResetNotifier, public pureAppEnd
{
Expand Down Expand Up @@ -187,6 +188,13 @@ void CWeapon::UpdateXForm()
mRes.mulA_43(E->XFORM());
}

if (auto actorOwner = smart_cast<CActor*>(H_Parent()))
if ((psActorFlags.test(AF_FIRST_PERSON_BODY)) && actorOwner->active_cam() == eacFirstEye)
{
Fvector camdir = { actorOwner->cam_Active()->Direction().x, 0.f, actorOwner->cam_Active()->Direction().z }; // ignore Y (vertical) value
mRes.c.add(camdir.normalize().mul(g_first_person_body_offset)); // push model back so it doesn't look weird (default value: -0.75f)
}

UpdatePosition(mRes);
}

Expand Down Expand Up @@ -911,21 +919,8 @@ void CWeapon::EnableActorNVisnAfterZoom()
}

bool CWeapon::need_renderable() { return !(IsZoomed() && ZoomTexture() && !IsRotatingToZoom()); }

extern float g_first_person_body_offset;
void CWeapon::renderable_Render(u32 context_id, IRenderable* root)
{
if (auto actorOwner = smart_cast<CActor*>(H_Parent()))
{
if ((psActorFlags.test(AF_FIRST_PERSON_BODY)) && actorOwner->active_cam() == eacFirstEye)
{
Fvector camdir = { actorOwner->cam_Active()->Direction().x, 0.f, actorOwner->cam_Active()->Direction().z }; // ignore Y (vertical) value
Fmatrix trans = XFORM();
trans.c.add(camdir.normalize().mul(g_first_person_body_offset)); // push model back so it doesn't look weird (default value: -0.75f)
XFORM().translate_over(trans.c); // move our original weapon to where our first person body is, so shadow render in correct place
}
}

ScopeLock lock{ &render_lock };

UpdateXForm();
Expand Down

0 comments on commit fa6781e

Please sign in to comment.