Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
}

repositories {
mavenLocal()
maven {
url = 'https://repo.runelite.net'
content {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/rs117/hd/HdPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ public class HdPlugin extends Plugin {
public boolean enableFreezeFrame;
public boolean orthographicProjection;
public boolean freezeCulling;
public boolean showCulling;

@Getter
private boolean isPluginStopPending;
Expand Down
117 changes: 117 additions & 0 deletions src/main/java/rs117/hd/opengl/GLPrimitives.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package rs117.hd.opengl;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import lombok.Value;
import org.lwjgl.system.MemoryStack;
import rs117.hd.utils.buffer.GLBuffer;

import static org.lwjgl.opengl.GL15.GL_ARRAY_BUFFER;
import static org.lwjgl.opengl.GL15.GL_STATIC_DRAW;

public class GLPrimitives {

@Value
public static class Mesh {
GLBuffer vbo;
GLBuffer ebo;
int indexCount;

public void destroy() {
vbo.destroy();
ebo.destroy();
}
}

public static Mesh buildCube(MemoryStack stack) {
FloatBuffer vertices = stack.mallocFloat(24).put(new float[]{
-1,-1,-1, 1,-1,-1, 1, 1,-1, -1, 1,-1,
-1,-1, 1, 1,-1, 1, 1, 1, 1, -1, 1, 1
}).flip();

IntBuffer indices = stack.mallocInt(36).put(new int[]{
0, 1, 2, 0, 2, 3,
4, 6, 5, 4, 7, 6,
0, 3, 7, 0, 7, 4,
1, 5, 6, 1, 6, 2,
0, 4, 5, 0, 5, 1,
3, 2, 6, 3, 6, 7
}).flip();

return new Mesh(
new GLBuffer("VBO::Cube", GL_ARRAY_BUFFER, GL_STATIC_DRAW).initialize(vertices),
new GLBuffer.EBO("EBO::Cube", GL_STATIC_DRAW).initialize(indices),
36
);
}

public static Mesh buildSphere(MemoryStack stack, int stacks, int slices) {
FloatBuffer vertices = stack.mallocFloat((stacks + 1) * (slices + 1) * 3);
for (int s = 0; s <= stacks; s++) {
float phi = (float) (Math.PI * s / stacks);
for (int sl = 0; sl <= slices; sl++) {
float theta = (float) (2 * Math.PI * sl / slices);
vertices.put((float) (Math.sin(phi) * Math.cos(theta)));
vertices.put((float) Math.cos(phi));
vertices.put((float) (Math.sin(phi) * Math.sin(theta)));
}
}
vertices.flip();

int indexCount = stacks * slices * 6;
IntBuffer indices = stack.mallocInt(indexCount);
for (int s = 0; s < stacks; s++) {
for (int sl = 0; sl < slices; sl++) {
int cur = s * (slices + 1) + sl;
int next = cur + (slices + 1);
indices.put(cur ).put(next ).put(cur + 1);
indices.put(cur + 1).put(next ).put(next + 1);
}
}
indices.flip();

return new Mesh(
new GLBuffer("VBO::Sphere", GL_ARRAY_BUFFER, GL_STATIC_DRAW).initialize(vertices),
new GLBuffer.EBO("EBO::Sphere", GL_STATIC_DRAW).initialize(indices),
indexCount
);
}

public static Mesh buildLine(MemoryStack stack) {
FloatBuffer vertices = stack.mallocFloat(24).put(new float[]{
-1,-1, 0, 1,-1, 0, 1, 1, 0, -1, 1, 0,
0,-1,-1, 0,-1, 1, 0, 1, 1, 0, 1,-1
}).flip();

IntBuffer indices = stack.mallocInt(12).put(new int[]{
0, 1, 2, 0, 2, 3,
4, 5, 6, 4, 6, 7
}).flip();

return new Mesh(
new GLBuffer("VBO::Line", GL_ARRAY_BUFFER, GL_STATIC_DRAW).initialize(vertices),
new GLBuffer.EBO("EBO::Line", GL_STATIC_DRAW).initialize(indices),
12
);
}

public static Mesh buildQuad(MemoryStack stack) {
FloatBuffer vertices = stack.mallocFloat(12).put(new float[]{
0, 0, 0,
1, 0, 0,
1, 1, 0,
0, 1, 0
}).flip();

IntBuffer indices = stack.mallocInt(6).put(new int[]{
0, 1, 2,
0, 2, 3
}).flip();

return new Mesh(
new GLBuffer("VBO::Quad", GL_ARRAY_BUFFER, GL_STATIC_DRAW).initialize(vertices),
new GLBuffer.EBO("EBO::Quad", GL_STATIC_DRAW).initialize(indices),
6
);
}
}
49 changes: 49 additions & 0 deletions src/main/java/rs117/hd/opengl/shader/DebugDrawShaderProgram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package rs117.hd.opengl.shader;

import java.io.IOException;
import rs117.hd.renderer.zone.passes.DebugDrawPass.PrimitiveDrawType;

import static org.lwjgl.opengl.GL20C.GL_FRAGMENT_SHADER;
import static org.lwjgl.opengl.GL20C.GL_VERTEX_SHADER;

public abstract class DebugDrawShaderProgram extends ShaderProgram {
private final PrimitiveDrawType type;

public DebugDrawShaderProgram(PrimitiveDrawType type) {
super(t -> t
.add(GL_VERTEX_SHADER, "debug_draw_vert.glsl")
.add(GL_FRAGMENT_SHADER, "debug_draw_frag.glsl"));
this.type = type;
}

@Override
public void compile(ShaderIncludes includes) throws ShaderException, IOException {
super.compile(includes.copy().define("PRIMITIVE_TYPE", type.ordinal()));
}

public static class DebugDrawCubeShaderProgram extends DebugDrawShaderProgram {
public DebugDrawCubeShaderProgram() {
super(PrimitiveDrawType.AABB);
}
}

public static class DebugDrawSphereShaderProgram extends DebugDrawShaderProgram {
public DebugDrawSphereShaderProgram() {
super(PrimitiveDrawType.SPHERE);
}
}

public static class DebugDrawLineShaderProgram extends DebugDrawShaderProgram {
public DebugDrawLineShaderProgram() {
super(PrimitiveDrawType.LINE);
}
}

public static class DebugDrawTextShaderProgram extends DebugDrawShaderProgram {
public final Uniform1f uniCharScale = addUniform1f("charScale");

public DebugDrawTextShaderProgram() {
super(PrimitiveDrawType.TEXT);
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/rs117/hd/opengl/uniforms/UniformBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ private void markWaterLine(int position, int size) {
dirtyHighTide = max(dirtyHighTide, position + size);
}

protected void setSize(int size) {
assert properties.isEmpty() : "Uniform buffer size can only be set, if your not using addStruct() or addProperty()!";
this.size = size;
}

public void write(int position, int x) {
dataInt.put(x);
markWaterLine(position, 4);
}

public void initialize() {
if (data != null)
destroy();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/rs117/hd/overlays/TileInfoOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ private String getModelInfo(Renderable r) {
case MODE_TILE_INFO:
return isStatic ? " <col=#00ff00>static</col>" :
isDynamic ? " <col=#ff0000>dynamic</col>" :
" <col=#ffff00>maybe dynamic</col>";
" <col=#ffff00>maybe dynamic</col>";
case MODE_MODEL_INFO:
int[] faceColors = model.getFaceColors1();
byte[] faceTransparencies = model.getFaceTransparencies();
Expand Down Expand Up @@ -1046,9 +1046,9 @@ private static int getHeight(SceneContext ctx, int localX, int localY, int plane
int x = localX & (LOCAL_TILE_SIZE - 1);
int y = localY & (LOCAL_TILE_SIZE - 1);
int var8 = x * tileHeights[plane][sceneExX + 1][sceneExY] +
(LOCAL_TILE_SIZE - x) * tileHeights[plane][sceneExX][sceneExY] >> LOCAL_COORD_BITS;
(LOCAL_TILE_SIZE - x) * tileHeights[plane][sceneExX][sceneExY] >> LOCAL_COORD_BITS;
int var9 = x * tileHeights[plane][sceneExX + 1][sceneExY + 1] +
(LOCAL_TILE_SIZE - x) * tileHeights[plane][sceneExX][sceneExY + 1] >> LOCAL_COORD_BITS;
(LOCAL_TILE_SIZE - x) * tileHeights[plane][sceneExX][sceneExY + 1] >> LOCAL_COORD_BITS;
return y * var9 + (LOCAL_TILE_SIZE - y) * var8 >> 7;
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/rs117/hd/overlays/Timer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public enum Timer {
DRAW_TILED_LIGHTING,
DRAW_SUBMIT,

// RENDER_PASSES
TILED_LIGHTING_PASS,
DIRECTIONAL_PASS,
SCENE_PASS,
DEBUG_DRAW_PASS,

// Miscellaneous
SWAP_BUFFERS,
EXECUTE_COMMAND_BUFFER,
Expand Down Expand Up @@ -71,6 +77,7 @@ public enum Timer {
RENDER_SHADOWS(GPU_TIMER),
RENDER_SCENE(GPU_TIMER),
RENDER_UI(GPU_TIMER, "Render UI"),
RENDER_DEBUG_DRAW(GPU_TIMER),
;

public static final Timer[] TIMERS = values();
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/rs117/hd/renderer/zone/ModelStreamingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import rs117.hd.config.ShadowMode;
import rs117.hd.overlays.FrameTimer;
import rs117.hd.overlays.Timer;
import rs117.hd.renderer.zone.passes.RenderPass;
import rs117.hd.renderer.zone.passes.RenderPipeline;
import rs117.hd.scene.ModelOverrideManager;
import rs117.hd.scene.SceneCullingManager;
import rs117.hd.scene.model_overrides.ModelOverride;
import rs117.hd.utils.HDUtils;
import rs117.hd.utils.ModelHash;
Expand Down Expand Up @@ -71,6 +74,9 @@ public class ModelStreamingManager {
@Inject
private ZoneRenderer renderer;

@Inject
private RenderPipeline renderPipeline;

private final ArrayList<AsyncCachedModel> pending = new ArrayList<>();
private final StreamingContext[] streamingContexts = new StreamingContext[RL_RENDER_THREADS + 1];
private int numRenderThreads = -1;
Expand Down Expand Up @@ -213,23 +219,18 @@ public void drawTemp(

final int modelClassification = renderer.sceneCamera.classifySphere(
objectWorldPos[0], objectWorldPos[1], objectWorldPos[2], m.getRadius());
boolean isOffScreen = modelClassification == -1;
boolean isOnScreen = modelClassification != -1;
// Additional Culling checks to help reduce dynamic object perf impact when off-screen
if (isOffScreen && (
!modelOverride.castShadows ||
!renderer.directionalShadowCasterVolume.intersectsPoint(
(int) objectWorldPos[0],
(int) objectWorldPos[1],
(int) objectWorldPos[2]
)
)) {
return;
if (!isOnScreen) {
isOnScreen = renderPipeline.dynamicInFrustum.execute(ctx, r, m, modelOverride, x, y, z);
if(!isOnScreen)
return;
}
streamingContext.renderableCount++;

final boolean hasAlpha =
(m.getFaceTransparencies() != null || modelOverride.mightHaveTransparency) &&
(!sceneManager.isRoot(ctx) || zone.inSceneFrustum);
(!sceneManager.isRoot(ctx) || zone.isVisible(renderer.sceneCamera));
final Zone.AlphaModel alphaModel = hasAlpha ?
zone.requestTempAlphaModel(
modelOverride,
Expand Down Expand Up @@ -372,8 +373,7 @@ public void uploadTempModel(

if (culledFaces.length > 0 &&
modelOverride.castShadows &&
plugin.configShadowMode != ShadowMode.OFF &&
(!sceneManager.isRoot(ctx) || zone != null && zone.inShadowFrustum)
plugin.configShadowMode != ShadowMode.OFF
) {
final DynamicModelVAO.View shadowView = ctx.beginDraw(VAO_SHADOW, culledFaces.length);
sceneUploader.uploadTempModel(
Expand Down
Loading