gpu: improve model visible check

This method checks if the model is on screen by projecting points at the model
extremes to screen and seeing if they are in the viewport bounds.

When doing this, it offsets the model height for the top of the viewport check,
but does not offset the bottom of the model for the bottom viewport check. This
offsets the bottom height to the model y position before doing this check,
which improves the test on models which are beneath the tile they are placed on.
This is most noticible in the Karamja dungeon and Hydra dungeon which has
objects for the lava instead of tiles, and they are placed at y=0 with some or
all of the model being below that.
This commit is contained in:
Adam
2021-10-09 16:01:33 -04:00
parent 5dd1132d07
commit 37608d1e64

View File

@@ -1454,38 +1454,42 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
/**
* Check is a model is visible and should be drawn.
*/
private boolean isVisible(Model model, int orientation, int pitchSin, int pitchCos, int yawSin, int yawCos, int _x, int _y, int _z, long hash)
private boolean isVisible(Model model, int pitchSin, int pitchCos, int yawSin, int yawCos, int x, int y, int z)
{
final int XYZMag = model.getXYZMag();
model.calculateBoundsCylinder();
final int xzMag = model.getXYZMag();
final int bottomY = model.getBottomY();
final int zoom = client.get3dZoom();
final int modelHeight = model.getModelHeight();
int Rasterizer3D_clipMidX2 = client.getRasterizer3D_clipMidX2();
int Rasterizer3D_clipNegativeMidX = client.getRasterizer3D_clipNegativeMidX();
int Rasterizer3D_clipNegativeMidY = client.getRasterizer3D_clipNegativeMidY();
int Rasterizer3D_clipMidY2 = client.getRasterizer3D_clipMidY2();
int Rasterizer3D_clipMidX2 = client.getRasterizer3D_clipMidX2(); // width / 2
int Rasterizer3D_clipNegativeMidX = client.getRasterizer3D_clipNegativeMidX(); // -width / 2
int Rasterizer3D_clipNegativeMidY = client.getRasterizer3D_clipNegativeMidY(); // -height / 2
int Rasterizer3D_clipMidY2 = client.getRasterizer3D_clipMidY2(); // height / 2
int var11 = yawCos * _z - yawSin * _x >> 16;
int var12 = pitchSin * _y + pitchCos * var11 >> 16;
int var13 = pitchCos * XYZMag >> 16;
int var14 = var12 + var13;
if (var14 > 50)
int var11 = yawCos * z - yawSin * x >> 16;
int var12 = pitchSin * y + pitchCos * var11 >> 16;
int var13 = pitchCos * xzMag >> 16;
int depth = var12 + var13;
if (depth > 50)
{
int var15 = _z * yawSin + yawCos * _x >> 16;
int var16 = (var15 - XYZMag) * zoom;
if (var16 / var14 < Rasterizer3D_clipMidX2)
int rx = z * yawSin + yawCos * x >> 16;
int var16 = (rx - xzMag) * zoom;
if (var16 / depth < Rasterizer3D_clipMidX2)
{
int var17 = (var15 + XYZMag) * zoom;
if (var17 / var14 > Rasterizer3D_clipNegativeMidX)
int var17 = (rx + xzMag) * zoom;
if (var17 / depth > Rasterizer3D_clipNegativeMidX)
{
int var18 = pitchCos * _y - var11 * pitchSin >> 16;
int var19 = pitchSin * XYZMag >> 16;
int var20 = (var18 + var19) * zoom;
if (var20 / var14 > Rasterizer3D_clipNegativeMidY)
int ry = pitchCos * y - var11 * pitchSin >> 16;
int yheight = pitchSin * xzMag >> 16;
int ybottom = (pitchCos * bottomY >> 16) + yheight; // use bottom height instead of y pos for height
int var20 = (ry + ybottom) * zoom;
if (var20 / depth > Rasterizer3D_clipNegativeMidY)
{
int var21 = (pitchCos * modelHeight >> 16) + var19;
int var22 = (var18 - var21) * zoom;
return var22 / var14 < Rasterizer3D_clipMidY2;
int ytop = (pitchCos * modelHeight >> 16) + yheight;
int var22 = (ry - ytop) * zoom;
return var22 / depth < Rasterizer3D_clipMidY2;
}
}
}
@@ -1521,9 +1525,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
renderable.setModelHeight(model.getModelHeight());
}
model.calculateBoundsCylinder();
if (!isVisible(model, orientation, pitchSin, pitchCos, yawSin, yawCos, x, y, z, hash))
if (!isVisible(model, pitchSin, pitchCos, yawSin, yawCos, x, y, z))
{
return;
}
@@ -1551,9 +1553,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
{
Model model = (Model) renderable;
model.calculateBoundsCylinder();
if (!isVisible(model, orientation, pitchSin, pitchCos, yawSin, yawCos, x, y, z, hash))
if (!isVisible(model, pitchSin, pitchCos, yawSin, yawCos, x, y, z))
{
return;
}
@@ -1589,9 +1589,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
renderable.setModelHeight(model.getModelHeight());
}
model.calculateBoundsCylinder();
if (!isVisible(model, orientation, pitchSin, pitchCos, yawSin, yawCos, x, y, z, hash))
if (!isVisible(model, pitchSin, pitchCos, yawSin, yawCos, x, y, z))
{
return;
}