Skip to content

Commit

Permalink
gpu: early frustum cull tiles
Browse files Browse the repository at this point in the history
Co-authored-by: Max Weber <[email protected]>
  • Loading branch information
2 people authored and aHooder committed Dec 12, 2023
1 parent a3217ab commit 85f0b14
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
45 changes: 45 additions & 0 deletions src/main/java/com/gpu/RegionLockerGpuPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class RegionLockerGpuPlugin extends Plugin implements DrawCallbacks
private static final int DEFAULT_DISTANCE = 25;
static final int MAX_DISTANCE = 184;
static final int MAX_FOG_DEPTH = 100;
static final int SCENE_OFFSET = (Constants.EXTENDED_SCENE_SIZE - Constants.SCENE_SIZE) / 2; // offset for sxy -> msxy

@Inject
private Client client;
Expand Down Expand Up @@ -1608,6 +1609,50 @@ public void swapScene(Scene scene)
checkGLErrors();
}

@Override
public boolean tileInFrustum(Scene scene, int pitchSin, int pitchCos, int yawSin, int yawCos, int cameraX, int cameraY, int cameraZ, int plane, int msx, int msy)
{
int[][][] tileHeights = scene.getTileHeights();
int x = ((msx - SCENE_OFFSET) << Perspective.LOCAL_COORD_BITS) + 64 - cameraX;
int z = ((msy - SCENE_OFFSET) << Perspective.LOCAL_COORD_BITS) + 64 - cameraZ;
int y = Math.max(
Math.max(tileHeights[plane][msx][msy], tileHeights[plane][msx][msy + 1]),
Math.max(tileHeights[plane][msx + 1][msy], tileHeights[plane][msx + 1][msy + 1])
) - cameraY;

int radius = 96; // ~ 64 * sqrt(2)

int zoom = client.get3dZoom();
int Rasterizer3D_clipMidX2 = client.getRasterizer3D_clipMidX2();
int Rasterizer3D_clipNegativeMidX = client.getRasterizer3D_clipNegativeMidX();
int Rasterizer3D_clipNegativeMidY = client.getRasterizer3D_clipNegativeMidY();

int var11 = yawCos * z - yawSin * x >> 16;
int var12 = pitchSin * y + pitchCos * var11 >> 16;
int var13 = pitchCos * radius >> 16;
int depth = var12 + var13;
if (depth > 50)
{
int rx = z * yawSin + yawCos * x >> 16;
int var16 = (rx - radius) * zoom;
int var17 = (rx + radius) * zoom;
// left && right
if (var16 < Rasterizer3D_clipMidX2 * depth && var17 > Rasterizer3D_clipNegativeMidX * depth)
{
int ry = pitchCos * y - var11 * pitchSin >> 16;
int ybottom = pitchSin * radius >> 16;
int var20 = (ry + ybottom) * zoom;
// top
if (var20 > Rasterizer3D_clipNegativeMidY * depth)
{
// we don't test the bottom so we don't have to find the height of all the models on the tile
return true;
}
}
}
return false;
}

/**
* Check is a model is visible and should be drawn.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/gpu/SceneUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
import net.runelite.api.Tile;
import net.runelite.api.WallObject;

import static com.gpu.RegionLockerGpuPlugin.SCENE_OFFSET;

@Singleton
@Slf4j
class SceneUploader
{
private static final int SCENE_OFFSET = (Constants.EXTENDED_SCENE_SIZE - Constants.SCENE_SIZE) / 2; // offset for sxy -> msxy

@Inject
private Client client;

Expand Down

0 comments on commit 85f0b14

Please sign in to comment.