Skip to content
Open
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
528 changes: 124 additions & 404 deletions src/main/java/rs117/hd/HdPlugin.java

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions src/main/java/rs117/hd/config/UIScalingMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import static org.lwjgl.opengl.GL33C.*;
import rs117.hd.utils.texture.GLSamplerMode;

@Getter
@RequiredArgsConstructor
public enum UIScalingMode {
NEAREST("Nearest", GL_NEAREST),
LINEAR("Bilinear", GL_LINEAR),
MITCHELL("Mitchell", GL_NEAREST),
CATMULL_ROM("Catmull-Rom", GL_NEAREST),
XBR("xBR", GL_NEAREST),
HYBRID("Hybrid", GL_LINEAR);
NEAREST("Nearest", GLSamplerMode.NEAREST_CLAMP),
LINEAR("Bilinear", GLSamplerMode.LINEAR_CLAMP),
MITCHELL("Mitchell", GLSamplerMode.NEAREST_CLAMP),
CATMULL_ROM("Catmull-Rom", GLSamplerMode.NEAREST_CLAMP),
XBR("xBR", GLSamplerMode.NEAREST_CLAMP),
HYBRID("Hybrid", GLSamplerMode.LINEAR_CLAMP);

private final String name;
public final int glSamplingFunction;
public final GLSamplerMode glSamplingMode;

@Override
public String toString()
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/rs117/hd/overlays/ShaderOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import rs117.hd.opengl.shader.ShaderProgram;
import rs117.hd.opengl.shader.ShaderTemplate;
import rs117.hd.utils.ShaderRecompile;
import rs117.hd.utils.texture.GLTexture;

import static org.lwjgl.opengl.GL33C.*;
import static rs117.hd.utils.MathUtils.*;
Expand Down Expand Up @@ -377,17 +378,17 @@ private void updateTransform() {
if (isFullscreen()) {
shader.uniTransform.set(0, 0, 1, 1);
} else {
int[] resolution = plugin.getUiResolution();
if (resolution == null)
GLTexture texUI = plugin.getTexUi();
if (texUI == null)
return;
var bounds = getBounds();
// Calculate translation and scale in NDC
float[] rect = { bounds.x + 1, bounds.y + 1, bounds.width - 1, bounds.height - 1 };
rect[0] += rect[0] + rect[2];
rect[1] += rect[1] + rect[3];
for (int i = 0; i < 2; i++) {
rect[i * 2] /= resolution[0];
rect[i * 2 + 1] /= resolution[1];
rect[i * 2] /= texUI.getWidth();
rect[i * 2 + 1] /= texUI.getHeight();
rect[i] -= 1;
}
rect[1] *= -1;
Expand Down
64 changes: 28 additions & 36 deletions src/main/java/rs117/hd/renderer/legacy/LegacyRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import rs117.hd.utils.buffer.GpuIntBuffer;
import rs117.hd.utils.buffer.SharedGLBuffer;
import rs117.hd.utils.jobs.JobSystem;
import rs117.hd.utils.texture.GLAttachmentSlot;
import rs117.hd.utils.texture.GLTexture;

import static org.lwjgl.opencl.CL10.*;
import static org.lwjgl.opengl.GL33C.*;
Expand All @@ -67,6 +69,7 @@
import static rs117.hd.HdPlugin.NEAR_PLANE;
import static rs117.hd.HdPlugin.ORTHOGRAPHIC_ZOOM;
import static rs117.hd.HdPlugin.TEXTURE_UNIT_TILE_HEIGHT_MAP;
import static rs117.hd.HdPlugin.TILED_LIGHTING_TILE_SIZE;
import static rs117.hd.HdPlugin.checkGLErrors;
import static rs117.hd.HdPluginConfig.*;
import static rs117.hd.utils.MathUtils.*;
Expand Down Expand Up @@ -744,14 +747,19 @@ public void drawScene(double cameraX, double cameraY, double cameraZ, double cam

// Perform tiled lighting culling before the compute memory barrier, so it's performed asynchronously
if (plugin.configTiledLighting) {
plugin.updateTiledLightingFbo();
assert plugin.fboTiledLighting != 0;
assert plugin.fboTiledLighting != null;

frameTimer.begin(Timer.DRAW_TILED_LIGHTING);
frameTimer.begin(Timer.RENDER_TILED_LIGHTING);

glViewport(0, 0, plugin.tiledLightingResolution[0], plugin.tiledLightingResolution[1]);
glBindFramebuffer(GL_FRAMEBUFFER, plugin.fboTiledLighting);
int[] tiledLightingResolution = max(ivec(1), round(divide(vec(plugin.fboScene.getWidth(), plugin.fboScene.getHeight()), TILED_LIGHTING_TILE_SIZE)));
if (plugin.fboTiledLighting.resize(tiledLightingResolution[0], tiledLightingResolution[1])) {
plugin.uboGlobal.tiledLightingResolution.set(tiledLightingResolution);
plugin.uboGlobal.upload();
}

glViewport(0, 0, plugin.fboTiledLighting.getWidth(), plugin.fboTiledLighting.getHeight());
glBindFramebuffer(GL_FRAMEBUFFER, plugin.fboTiledLighting.getFboId());

glBindVertexArray(plugin.vaoTri);

Expand All @@ -761,10 +769,11 @@ public void drawScene(double cameraX, double cameraY, double cameraZ, double cam
glDrawArrays(GL_TRIANGLES, 0, 3);
} else {
glDrawBuffer(GL_COLOR_ATTACHMENT0);
int layerCount = plugin.configDynamicLights.getTiledLightingLayers();
final int layerCount = plugin.configDynamicLights.getTiledLightingLayers();
final GLTexture texTiledLighting = plugin.fboTiledLighting.getColorTexture(GLAttachmentSlot.COLOR0);
for (int layer = 0; layer < layerCount; layer++) {
plugin.tiledLightingShaderPrograms.get(layer).use();
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, plugin.texTiledLighting, 0, layer);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texTiledLighting.getWidth(), 0, layer);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
}
Expand Down Expand Up @@ -1078,13 +1087,13 @@ public void draw(int overlayColor) {
plugin.uboGlobal.colorFilterFade.set(clamp(timeSinceChange / COLOR_FILTER_FADE_DURATION, 0, 1));
}

if (plugin.configShadowsEnabled && plugin.fboShadowMap != 0
if (plugin.configShadowsEnabled && plugin.fboShadowMap != null
&& environmentManager.currentDirectionalStrength > 0) {
frameTimer.begin(Timer.RENDER_SHADOWS);

// Render to the shadow depth map
glViewport(0, 0, plugin.shadowMapResolution, plugin.shadowMapResolution);
glBindFramebuffer(GL_FRAMEBUFFER, plugin.fboShadowMap);
glViewport(0, 0, plugin.fboShadowMap.getWidth(), plugin.fboShadowMap.getHeight());
glBindFramebuffer(GL_FRAMEBUFFER, plugin.fboShadowMap.getFboId());
glClearDepth(1);
glClear(GL_DEPTH_BUFFER_BIT);
glDepthFunc(GL_LEQUAL);
Expand Down Expand Up @@ -1134,13 +1143,13 @@ public void draw(int overlayColor) {
plugin.uboGlobal.upload();
sceneProgram.use();

glBindFramebuffer(GL_DRAW_FRAMEBUFFER, plugin.fboScene);
if (plugin.msaaSamples > 1) {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, plugin.fboScene.getFboId());
if (plugin.fboScene.getSamples() > 1) {
glEnable(GL_MULTISAMPLE);
} else {
glDisable(GL_MULTISAMPLE);
}
glViewport(0, 0, plugin.sceneResolution[0], plugin.sceneResolution[1]);
glViewport(0, 0, plugin.fboScene.getWidth(), plugin.fboScene.getHeight());

// Clear scene
frameTimer.begin(Timer.CLEAR_SCENE);
Expand Down Expand Up @@ -1216,35 +1225,18 @@ public void draw(int overlayColor) {
glDepthMask(true);
glUseProgram(0);

glBindFramebuffer(GL_READ_FRAMEBUFFER, plugin.fboScene);
if (plugin.fboSceneResolve != 0) {
// Blit from the scene FBO to the multisample resolve FBO
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, plugin.fboSceneResolve);
glBlitFramebuffer(
0, 0, plugin.sceneResolution[0], plugin.sceneResolution[1],
0, 0, plugin.sceneResolution[0], plugin.sceneResolution[1],
GL_COLOR_BUFFER_BIT, GL_NEAREST
);
glBindFramebuffer(GL_READ_FRAMEBUFFER, plugin.fboSceneResolve);
}

// Blit from the resolved FBO to the default FBO
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, plugin.awtContext.getFramebuffer(false));
glBlitFramebuffer(
0,
0,
plugin.sceneResolution[0],
plugin.sceneResolution[1],
glBindFramebuffer(GL_READ_FRAMEBUFFER, plugin.fboScene.getFboId());
plugin.fboScene.blitTo(
plugin.fboBackBuffer,
GLAttachmentSlot.COLOR0,
GLAttachmentSlot.BACK_LEFT,
plugin.sceneViewport[0],
plugin.sceneViewport[1],
plugin.sceneViewport[0] + plugin.sceneViewport[2],
plugin.sceneViewport[1] + plugin.sceneViewport[3],
GL_COLOR_BUFFER_BIT,
config.sceneScalingMode().glFilter
);
config.sceneScalingMode().glFilter);
} else {
glClearColor(0, 0, 0, 1f);
glClear(GL_COLOR_BUFFER_BIT);
plugin.fboBackBuffer.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
}

plugin.drawUi(overlayColor);
Expand Down
90 changes: 31 additions & 59 deletions src/main/java/rs117/hd/renderer/zone/ZoneRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import rs117.hd.utils.buffer.GpuIntBuffer;
import rs117.hd.utils.collections.ConcurrentPool;
import rs117.hd.utils.jobs.JobSystem;
import rs117.hd.utils.texture.GLAttachmentSlot;

import static net.runelite.api.Constants.*;
import static net.runelite.api.Perspective.*;
Expand All @@ -76,6 +77,7 @@
import static rs117.hd.HdPlugin.COLOR_FILTER_FADE_DURATION;
import static rs117.hd.HdPlugin.NEAR_PLANE;
import static rs117.hd.HdPlugin.ORTHOGRAPHIC_ZOOM;
import static rs117.hd.HdPlugin.TILED_LIGHTING_TILE_SIZE;
import static rs117.hd.HdPlugin.checkGLErrors;
import static rs117.hd.HdPluginConfig.*;
import static rs117.hd.renderer.zone.WorldViewContext.VAO_OPAQUE;
Expand All @@ -89,7 +91,7 @@ public class ZoneRenderer implements Renderer {
public static final int FRAMES_IN_FLIGHT = 3;

private static int TEXTURE_UNIT_COUNT = HdPlugin.TEXTURE_UNIT_COUNT;
public static final int TEXTURE_UNIT_TEXTURED_FACES = GL_TEXTURE0 + TEXTURE_UNIT_COUNT++;
public static final int TEXTURE_UNIT_TEXTURED_FACES = GL_TEXTURE1 + TEXTURE_UNIT_COUNT++;

private static int UNIFORM_BLOCK_COUNT = HdPlugin.UNIFORM_BLOCK_COUNT;
public static final int UNIFORM_BLOCK_WORLD_VIEWS = UNIFORM_BLOCK_COUNT++;
Expand Down Expand Up @@ -451,7 +453,7 @@ private void preSceneDrawTopLevel(
// Snap Position to Shadow Texel Grid to prevent shimmering
directionalCamera.transformPoint(sceneCenter, sceneCenter);

float texelSize = (float) directionalSize / plugin.shadowMapResolution;
float texelSize = (float) directionalSize / plugin.fboShadowMap.getWidth();
sceneCenter[0] = (float) floor(sceneCenter[0] / texelSize + 0.5f) * texelSize;
sceneCenter[1] = (float) floor(sceneCenter[1] / texelSize + 0.5f) * texelSize;

Expand Down Expand Up @@ -668,27 +670,29 @@ private void tiledLightingPass() {
if (!plugin.configTiledLighting || plugin.configDynamicLights == DynamicLights.NONE)
return;

plugin.updateTiledLightingFbo();
assert plugin.fboTiledLighting != 0;
assert plugin.fboTiledLighting != null;

frameTimer.begin(Timer.DRAW_TILED_LIGHTING);
frameTimer.begin(Timer.RENDER_TILED_LIGHTING);

renderState.framebuffer.set(GL_FRAMEBUFFER, plugin.fboTiledLighting);
renderState.viewport.set(0, 0, plugin.tiledLightingResolution[0], plugin.tiledLightingResolution[1]);
int[] tiledLightingResolution = max(ivec(1), round(divide(vec(plugin.fboScene.getWidth(), plugin.fboScene.getHeight()), TILED_LIGHTING_TILE_SIZE)));
if (plugin.fboTiledLighting.resize(tiledLightingResolution[0], tiledLightingResolution[1])) {
plugin.uboGlobal.tiledLightingResolution.set(tiledLightingResolution);
plugin.uboGlobal.upload();
}
renderState.vao.setVao(plugin.vaoTri);

if (plugin.tiledLightingImageStoreProgram.isValid()) {
plugin.fboTiledLighting.bind(renderState, GL_DRAW_FRAMEBUFFER);
renderState.program.set(plugin.tiledLightingImageStoreProgram);
renderState.drawBuffer.set(GL_NONE);
renderState.apply();
glDrawArrays(GL_TRIANGLES, 0, 3);
} else {
renderState.drawBuffer.set(GL_COLOR_ATTACHMENT0);
int layerCount = plugin.configDynamicLights.getTiledLightingLayers();
final int layerCount = plugin.configDynamicLights.getTiledLightingLayers();
for (int layer = 0; layer < layerCount; layer++) {
plugin.fboTiledLighting.bind(renderState, GL_DRAW_FRAMEBUFFER, GLAttachmentSlot.COLOR0, layer);
renderState.program.set(plugin.tiledLightingShaderPrograms.get(layer));
renderState.framebufferTextureLayer.set(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, plugin.texTiledLighting, 0, layer);
renderState.apply();
glDrawArrays(GL_TRIANGLES, 0, 3);
}
Expand All @@ -699,19 +703,15 @@ private void tiledLightingPass() {
}

private void directionalShadowPass() {
if(plugin.fboShadowMap == null)
return;

final boolean shouldRenderShadows =
plugin.configShadowsEnabled &&
plugin.fboShadowMap != 0 &&
environmentManager.currentDirectionalStrength > 0;

if (shouldRenderShadows || shouldClearShadowFbo) {
// Render to the shadow depth map
renderState.framebuffer.set(GL_FRAMEBUFFER, plugin.fboShadowMap);
renderState.viewport.set(0, 0, plugin.shadowMapResolution, plugin.shadowMapResolution);
renderState.apply();

glClearDepth(1);
glClear(GL_DEPTH_BUFFER_BIT);
plugin.fboShadowMap.clearDepth(1.0f);
shouldClearShadowFbo = false;
}

Expand All @@ -720,6 +720,7 @@ private void directionalShadowPass() {

frameTimer.begin(Timer.RENDER_SHADOWS);

plugin.fboShadowMap.bind(renderState, GL_DRAW_FRAMEBUFFER);
renderState.enable.set(GL_DEPTH_TEST);
renderState.disable.set(GL_CULL_FACE);
renderState.depthFunc.set(GL_LEQUAL);
Expand All @@ -741,33 +742,23 @@ private void scenePass() {
sceneProgram.use();

frameTimer.begin(Timer.DRAW_SCENE);
renderState.framebuffer.set(GL_DRAW_FRAMEBUFFER, plugin.fboScene);
if (plugin.msaaSamples > 1) {
renderState.enable.set(GL_MULTISAMPLE);
} else {
renderState.disable.set(GL_MULTISAMPLE);
}
renderState.viewport.set(0, 0, plugin.sceneResolution[0], plugin.sceneResolution[1]);
renderState.ido.set(indirectDrawCmds.id);
renderState.apply();

// Clear scene
frameTimer.begin(Timer.CLEAR_SCENE);

float[] fogColor = ColorUtils.linearToSrgb(environmentManager.currentFogColor);
float[] gammaCorrectedFogColor = pow(fogColor, plugin.getGammaCorrection());
glClearColor(
plugin.fboScene.clear(
gammaCorrectedFogColor[0],
gammaCorrectedFogColor[1],
gammaCorrectedFogColor[2],
1f
);
glClearDepth(0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1f,
0.0f);
frameTimer.end(Timer.CLEAR_SCENE);

frameTimer.begin(Timer.RENDER_SCENE);

plugin.fboScene.bind(renderState, GL_DRAW_FRAMEBUFFER);
renderState.ido.set(indirectDrawCmds.id);
renderState.enable.set(GL_BLEND);
renderState.enable.set(GL_CULL_FACE);
renderState.enable.set(GL_DEPTH_TEST);
Expand Down Expand Up @@ -1072,37 +1063,18 @@ public void draw(int overlayColor) {
scenePass();
}

if (sceneFboValid && plugin.sceneResolution != null && plugin.sceneViewport != null) {
glBindFramebuffer(GL_READ_FRAMEBUFFER, plugin.fboScene);
if (plugin.fboSceneResolve != 0) {
// Blit from the scene FBO to the multisample resolve FBO
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, plugin.fboSceneResolve);
glBlitFramebuffer(
0, 0, plugin.sceneResolution[0], plugin.sceneResolution[1],
0, 0, plugin.sceneResolution[0], plugin.sceneResolution[1],
GL_COLOR_BUFFER_BIT, GL_NEAREST
);
glBindFramebuffer(GL_READ_FRAMEBUFFER, plugin.fboSceneResolve);
}

// Blit from the resolved FBO to the default FBO
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, plugin.awtContext.getFramebuffer(false));
glBlitFramebuffer(
0,
0,
plugin.sceneResolution[0],
plugin.sceneResolution[1],
if (sceneFboValid && plugin.fboScene != null && plugin.sceneViewport != null) {
plugin.fboScene.blitTo(
plugin.fboBackBuffer,
GLAttachmentSlot.COLOR0,
GLAttachmentSlot.BACK_LEFT,
plugin.sceneViewport[0],
plugin.sceneViewport[1],
plugin.sceneViewport[0] + plugin.sceneViewport[2],
plugin.sceneViewport[1] + plugin.sceneViewport[3],
GL_COLOR_BUFFER_BIT,
config.sceneScalingMode().glFilter
);
config.sceneScalingMode().glFilter);
} else {
glBindFramebuffer(GL_FRAMEBUFFER, plugin.awtContext.getFramebuffer(false));
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
plugin.fboBackBuffer.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
}

plugin.drawUi(overlayColor);
Expand All @@ -1128,7 +1100,7 @@ public void draw(int overlayColor) {
log.error("Unable to swap buffers:", ex);
}

glBindFramebuffer(GL_FRAMEBUFFER, plugin.awtContext.getFramebuffer(false));
glBindFramebuffer(GL_FRAMEBUFFER, plugin.fboBackBuffer.getFboId());

frameTimer.endFrameAndReset();
checkGLErrors();
Expand Down
Loading