Skip to content

Commit

Permalink
reset interpolated right normal if viewer changed
Browse files Browse the repository at this point in the history
  • Loading branch information
nstlaurent committed Jun 13, 2024
1 parent a543fa3 commit 40e0727
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class EntityRenderer : IDisposable
private bool m_alwaysFlood;
private int m_spriteClipMin;
private float m_spriteClipFactorMax;
private float m_zNear;
private bool m_disposed;
private int m_lastViewerEntityId;

public EntityRenderer(IConfig config, LegacyGLTextureManager textureManager)
{
Expand All @@ -58,6 +58,7 @@ public EntityRenderer(IConfig config, LegacyGLTextureManager textureManager)
public void UpdateTo(IWorld world)
{
m_alwaysFlood = world.Config.Render.AlwaysFloodFillFlats;
m_lastViewerEntityId = -1;
}

public void Clear(IWorld world)
Expand Down Expand Up @@ -172,7 +173,7 @@ public unsafe void RenderEntity(Entity entity, in Vec2D position)
{
if (m_renderPositions.TryGetValue(entityPos, out int count))
{
double nudge = (NudgeFactor * Renderer.ZNearMax / m_zNear) * count * Math.Sqrt(entity.RenderDistanceSquared);
double nudge = NudgeFactor * count * Math.Sqrt(entity.RenderDistanceSquared);
double angle = Math.Atan2(centerBottom.Y - position.Y, centerBottom.X - position.X);
nudgeAmount.X = Math.Cos(angle) * nudge;
nudgeAmount.Y = Math.Sin(angle) * nudge;
Expand Down Expand Up @@ -228,11 +229,15 @@ public unsafe void RenderEntity(Entity entity, in Vec2D position)

public void Start(RenderInfo renderInfo)
{
m_zNear = Renderer.GetZNear(renderInfo);
m_transferHeightView = renderInfo.TransferHeightView;
m_prevViewRightNormal = m_viewRightNormal;
m_viewRightNormal = renderInfo.Camera.Direction.XY.RotateRight90().Unit();
m_transferHeightView = renderInfo.TransferHeightView;
if (m_lastViewerEntityId != renderInfo.ViewerEntity.Id)
m_prevViewRightNormal = m_viewRightNormal;

m_program.ViewRightNormal(m_viewRightNormal);
m_program.PrevViewRightNormal(m_prevViewRightNormal);
m_lastViewerEntityId = renderInfo.ViewerEntity.Id;
}

private void SetUniforms(RenderInfo renderInfo)
Expand Down

0 comments on commit 40e0727

Please sign in to comment.