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
4 changes: 4 additions & 0 deletions src/main/java/rs117/hd/HdPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
import rs117.hd.utils.ResourcePath;
import rs117.hd.utils.ShaderRecompile;
import rs117.hd.utils.buffer.GLBuffer;
import rs117.hd.utils.buffer.GLTextureBuffer;
import rs117.hd.utils.jobs.GenericJob;
import rs117.hd.utils.jobs.JobSystem;

Expand Down Expand Up @@ -901,8 +902,10 @@ public ShaderIncludes getShaderIncludes() {
var includes = new ShaderIncludes()
.addIncludePath(SHADER_PATH)
.addInclude("VERSION_HEADER", OSType.getOSType() == OSType.Linux ? LINUX_VERSION_HEADER : WINDOWS_VERSION_HEADER)
.define("TEXEL_SIZE", GLTextureBuffer.isRGBASupported() ? 4 : 3)
.define("UI_SCALING_MODE", config.uiScalingMode())
.define("COLOR_BLINDNESS", config.colorBlindness())
.define("DITHER_FADE", config.ditherFading())
.define("APPLY_COLOR_FILTER", configColorFilter != ColorFilter.NONE)
.define("MATERIAL_COUNT", MaterialManager.MATERIALS.length)
.define("WATER_TYPE_COUNT", waterTypeManager.uboWaterTypes.getCount())
Expand Down Expand Up @@ -1814,6 +1817,7 @@ public void processPendingConfigChanges() {
case KEY_WIREFRAME:
case KEY_SHADOW_FILTERING:
case KEY_WINDOWS_HDR_CORRECTION:
case KEY_DITHER_FADING:
recompilePrograms = true;
break;
case KEY_ANTI_ALIASING_MODE:
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/rs117/hd/HdPluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,22 @@ default boolean flashingEffects()
return false;
}

String KEY_DITHER_FADING = "ditherFading";
@ConfigItem(
keyName = KEY_DITHER_FADING,
name = "Dither Fading",
description = "Whether to dither fade near plane geometry that would normally clip.",
position = 16,
section = generalSettings
)
default boolean ditherFading() { return true; }

@ConfigItem(
keyName = "fSaturation",
name = "Saturation",
description = "Controls the saturation of the final rendered image.<br>" +
"Intended to be kept between 0% and 120%.",
position = 16,
position = 17,
section = generalSettings
)
@Units(Units.PERCENT)
Expand All @@ -339,7 +349,7 @@ default Saturation oldSaturationDropdown()
name = "Contrast",
description = "Controls the contrast of the final rendered image.<br>" +
"Intended to be kept between 90% and 110%.",
position = 17,
position = 18,
section = generalSettings
)
@Units(Units.PERCENT)
Expand All @@ -366,7 +376,7 @@ default Contrast oldContrastDropdown()
description =
"Controls the brightness of the game, excluding UI.<br>" +
"Adjust until the circle on the left is barely visible.",
position = 18,
position = 19,
section = generalSettings
)
default int brightness() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/rs117/hd/opengl/shader/SceneShaderProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import static rs117.hd.HdPlugin.TEXTURE_UNIT_GAME;
import static rs117.hd.HdPlugin.TEXTURE_UNIT_SHADOW_MAP;
import static rs117.hd.HdPlugin.TEXTURE_UNIT_TILED_LIGHTING_MAP;
import static rs117.hd.renderer.zone.ZoneRenderer.TEXTURE_UNIT_MODEL_DATA;
import static rs117.hd.renderer.zone.ZoneRenderer.TEXTURE_UNIT_TEXTURED_FACES;

public class SceneShaderProgram extends ShaderProgram {
protected final UniformTexture uniTextureArray = addUniformTexture("textureArray");
protected final UniformTexture uniShadowMap = addUniformTexture("shadowMap");
protected final UniformTexture uniTiledLightingTextureArray = addUniformTexture("tiledLightingArray");
protected final UniformTexture uniTextureFaces = addUniformTexture("textureFaces");
protected final UniformTexture uniModelData = addUniformTexture("modelData");

public SceneShaderProgram() {
super(t -> t
Expand All @@ -25,12 +27,14 @@ protected void initialize() {
uniShadowMap.set(TEXTURE_UNIT_SHADOW_MAP);
uniTiledLightingTextureArray.set(TEXTURE_UNIT_TILED_LIGHTING_MAP);
uniTextureFaces.set(TEXTURE_UNIT_TEXTURED_FACES);
uniModelData.set(TEXTURE_UNIT_MODEL_DATA);
}

public static class Legacy extends SceneShaderProgram {
Legacy() {
shaderTemplate.add(GL_GEOMETRY_SHADER, "scene_geom.glsl");
uniTextureFaces.ignoreMissing = true;
uniModelData.ignoreMissing = true;
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/rs117/hd/opengl/shader/ShadowShaderProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import static org.lwjgl.opengl.GL33C.*;
import static rs117.hd.HdPlugin.TEXTURE_UNIT_GAME;
import static rs117.hd.renderer.zone.ZoneRenderer.TEXTURE_UNIT_MODEL_DATA;
import static rs117.hd.renderer.zone.ZoneRenderer.TEXTURE_UNIT_TEXTURED_FACES;

public abstract class ShadowShaderProgram extends ShaderProgram {
protected final UniformTexture uniTextureArray = addUniformTexture("textureArray");
protected final UniformTexture uniTextureFaces = addUniformTexture("textureFaces");
protected final UniformTexture uniModelData = addUniformTexture("modelData");

protected ShadowMode mode;

Expand All @@ -23,6 +25,7 @@ public abstract class ShadowShaderProgram extends ShaderProgram {
protected void initialize() {
uniTextureArray.set(TEXTURE_UNIT_GAME);
uniTextureFaces.set(TEXTURE_UNIT_TEXTURED_FACES);
uniModelData.set(TEXTURE_UNIT_MODEL_DATA);
}

@Override
Expand All @@ -47,6 +50,8 @@ public static class Legacy extends ShadowShaderProgram {
public Legacy setMode(ShadowMode mode) {
this.mode = mode;
uniTextureArray.ignoreMissing = mode != ShadowMode.DETAILED;
uniTextureFaces.ignoreMissing = true;
uniModelData.ignoreMissing = true;
return this;
}

Expand Down
49 changes: 33 additions & 16 deletions src/main/java/rs117/hd/renderer/zone/DynamicModelVAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static rs117.hd.HdPlugin.NVIDIA_GPU;
import static rs117.hd.HdPlugin.SUPPORTS_INDIRECT_DRAW;
import static rs117.hd.HdPlugin.SUPPORTS_STORAGE_BUFFERS;
import static rs117.hd.renderer.zone.ZoneRenderer.TEXTURE_UNIT_MODEL_DATA;
import static rs117.hd.renderer.zone.ZoneRenderer.TEXTURE_UNIT_TEXTURED_FACES;
import static rs117.hd.utils.MathUtils.*;
import static rs117.hd.utils.buffer.GLBuffer.STORAGE_IMMUTABLE;
Expand All @@ -37,20 +38,23 @@ public class DynamicModelVAO implements Destructible {
// Metadata format
// worldViewIndex int
// dummy sceneOffset ivec2 for macOS workaround
static final int METADATA_SIZE = 12;
// fade float
static final int METADATA_SIZE = 16;

@Getter
private int vao;

private final GLBuffer vboRender;
private final GLBuffer vboStaging;
private final GLTextureBuffer tbo;
private final GLTextureBuffer tboF;
private final GLTextureBuffer tboM;

private final ArrayDeque<View> usedViews = new ArrayDeque<>();
private final ArrayDeque<View> freeViews = new ArrayDeque<>();

private final GLMappedBufferIntWriter vboWriter;
private final GLMappedBufferIntWriter tboWriter;
private final GLMappedBufferIntWriter tboFWriter;
private final GLMappedBufferIntWriter tboMWriter;

private boolean isMapped = false;
private int[] drawOffsets = new int[16];
Expand Down Expand Up @@ -81,15 +85,18 @@ public class DynamicModelVAO implements Destructible {
}
this.vboWriter = new GLMappedBufferIntWriter(this.vboStaging);

this.tbo = new GLTextureBuffer("VAO::TBO::" + name, GL_STREAM_DRAW, STORAGE_PERSISTENT | STORAGE_IMMUTABLE | STORAGE_WRITE);
this.tboWriter = new GLMappedBufferIntWriter(this.tbo);
this.tboF = new GLTextureBuffer("VAO::TexturedFaces::" + name, GL_STREAM_DRAW, STORAGE_PERSISTENT | STORAGE_IMMUTABLE | STORAGE_WRITE);
this.tboM = new GLTextureBuffer("VAO::ModelData::" + name, GL_STREAM_DRAW, STORAGE_PERSISTENT | STORAGE_IMMUTABLE | STORAGE_WRITE);
this.tboFWriter = new GLMappedBufferIntWriter(this.tboF);
this.tboMWriter = new GLMappedBufferIntWriter(this.tboM);
}

public boolean hasStagingBuffer() { return vboRender != vboStaging; }

void initialize() {
vao = glGenVertexArrays();
tbo.initialize(INITIAL_SIZE);
tboF.initialize(INITIAL_SIZE);
tboM.initialize(INITIAL_SIZE);
vboRender.initialize(INITIAL_SIZE);
if (vboRender != vboStaging)
vboStaging.initialize(INITIAL_SIZE);
Expand Down Expand Up @@ -143,7 +150,8 @@ void bindRenderVAO() {

void map() {
vboWriter.map(false);
tboWriter.map(false);
tboFWriter.map(false);
tboMWriter.map(false);

reset();
isMapped = true;
Expand All @@ -152,7 +160,8 @@ void map() {
synchronized void unmap(boolean coalesce) {
final int renderVBOId = vboRender.id;
long vboWrittenBytes = vboWriter.flush();
tboWriter.flush();
tboFWriter.flush();
tboMWriter.flush();

if (drawRangeCount > 0) {
mergeRanges();
Expand Down Expand Up @@ -192,10 +201,12 @@ synchronized void unmap(boolean coalesce) {
@Override
public void destroy() {
vboWriter.destroy();
tboWriter.destroy();
tboFWriter.destroy();
tboMWriter.destroy();
vboRender.destroy();
vboStaging.destroy();
tbo.destroy();
tboF.destroy();
tboM.destroy();

if (vao != 0)
glDeleteVertexArrays(vao);
Expand Down Expand Up @@ -231,9 +242,11 @@ public synchronized View beginDraw(int drawIdx, int faceCount) {
if (view == null)
view = new View();
view.vbo = vboWriter.reserve(faceCount * 3 * VERT_SIZE_INTS);
view.tbo = tboWriter.reserve(faceCount * 9);
view.tboF = tboFWriter.reserve(faceCount * 4);
view.tboM = tboMWriter.reserve(Zone.MODEL_DATA_SIZE / Integer.BYTES);
view.vao = vao;
view.tboTexId = tbo.getTexId();
view.tboFId = tboF.getTexId();
view.tboMId = tboM.getTexId();
view.drawIdx = drawIdx;

return view;
Expand All @@ -252,7 +265,8 @@ private synchronized void endDraw(View view) {

// Clear ReservedViews before returning to pool
view.vbo = null;
view.tbo = null;
view.tboF = null;
view.tboM = null;

usedViews.add(view);
}
Expand Down Expand Up @@ -280,7 +294,8 @@ void draw(CommandBuffer cmd) {
return;

cmd.BindVertexArray(vao);
cmd.BindTextureUnit(GL_TEXTURE_BUFFER, tbo.getTexId(), TEXTURE_UNIT_TEXTURED_FACES);
cmd.BindTextureUnit(GL_TEXTURE_BUFFER, tboF.getTexId(), TEXTURE_UNIT_TEXTURED_FACES);
cmd.BindTextureUnit(GL_TEXTURE_BUFFER, tboM.getTexId(), TEXTURE_UNIT_MODEL_DATA);

if (drawRangeCount == 1) {
if (GL_CAPS.OpenGL40 && SUPPORTS_INDIRECT_DRAW) {
Expand All @@ -307,9 +322,11 @@ void reset() {

public final class View {
public ReservedView vbo;
public ReservedView tbo;
public ReservedView tboF;
public ReservedView tboM;
public int vao;
public int tboTexId;
public int tboFId;
public int tboMId;
private int drawIdx;

public int getStartOffset() {
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/rs117/hd/renderer/zone/ModelStreamingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ public void drawTemp(Projection worldProjection, Scene scene, GameObject gameObj
int zz = (gameObject.getY() >> 10) + offset;
Zone zone = ctx.zones[zx][zz];

if(!zone.initialized || zone.fadingAlpha > 1.0f)
return;

m.calculateBoundsCylinder();

final float[] objectWorldPos = vec4(streamingContext.objectWorldPos, x, y, z, 1.0f);
Expand Down Expand Up @@ -328,12 +331,15 @@ private void uploadTempModel(
(!sceneManager.isRoot(ctx) || zone.inShadowFrustum)
) {
final DynamicModelVAO.View shadowView = ctx.beginDraw(VAO_SHADOW, culledFaces.length);
int shadowModelIdx = SceneUploader.writeDynamicModelData(shadowView.tboM, x, y, z, m, modelOverride, zone);
sceneUploader.uploadTempModel(
culledFaces,
m,
modelOverride,
preOrientation,
orientation,
shadowModelIdx,
shadowModelIdx,
true,
shadowView,
shadowView
Expand All @@ -351,12 +357,17 @@ private void uploadTempModel(
final DynamicModelVAO.View opaqueView = ctx.beginDraw(isPlayer ? VAO_PLAYER : VAO_OPAQUE, drawIndex, opaqueFaceCount);
final DynamicModelVAO.View alphaView = alphaFaceCount > 0 ? ctx.beginDraw(VAO_ALPHA, alphaFaceCount) : opaqueView;

final int opaqueModelIdx = SceneUploader.writeDynamicModelData(opaqueView.tboM, x, y, z, m, modelOverride, zone);
final int alphaModelIdx = alphaFaceCount > 0 ? SceneUploader.writeDynamicModelData(alphaView.tboM, x, y, z, m, modelOverride, zone) : opaqueModelIdx;

sceneUploader.uploadTempModel(
visibleFaces,
m,
modelOverride,
preOrientation,
orientation,
opaqueModelIdx,
alphaModelIdx,
isSquashed,
opaqueView,
alphaView
Expand Down Expand Up @@ -401,7 +412,7 @@ public void drawDynamic(
int zz = (z >> 10) + offset;
Zone zone = ctx.zones[zx][zz];

if (!zone.initialized)
if (!zone.initialized || zone.fadingAlpha > 1.0f)
return;

final StreamingContext streamingContext = context(renderThreadId);
Expand Down Expand Up @@ -590,12 +601,15 @@ private void uploadDynamicModel(
(!sceneManager.isRoot(ctx) || zone.inShadowFrustum)
) {
final DynamicModelVAO.View shadowView = ctx.beginDraw(VAO_SHADOW, culledFaces.length);
final int shadowModelIdx = SceneUploader.writeDynamicModelData(shadowView.tboM, x, y, z, m, modelOverride, zone);
sceneUploader.uploadTempModel(
culledFaces,
m,
modelOverride,
preOrientation,
orient,
shadowModelIdx,
shadowModelIdx,
true,
shadowView,
shadowView
Expand All @@ -610,12 +624,17 @@ private void uploadDynamicModel(
final DynamicModelVAO.View opaqueView = ctx.beginDraw(VAO_OPAQUE, drawIndex, opaqueFaceCount);
final DynamicModelVAO.View alphaView = alphaFaceCount > 0 ? ctx.beginDraw(VAO_ALPHA, alphaFaceCount) : opaqueView;

final int opaqueModelIdx = SceneUploader.writeDynamicModelData(opaqueView.tboM, x, y, z, m, modelOverride, zone);
final int alphaModelIdx = alphaFaceCount > 0 ? SceneUploader.writeDynamicModelData(alphaView.tboM, x, y, z, m, modelOverride, zone) : opaqueModelIdx;

sceneUploader.uploadTempModel(
visibleFaces,
m,
modelOverride,
preOrientation,
orient,
opaqueModelIdx,
alphaModelIdx,
isSquashed,
opaqueView,
alphaView
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/rs117/hd/renderer/zone/SceneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,17 +589,19 @@ public synchronized void loadScene(WorldView worldView, Scene scene) {
}
}

long timeMs = System.currentTimeMillis();
//long timeMs = System.currentTimeMillis();
for (SortedZone sorted : sortedZones) {
Zone newZone = injector.getInstance(Zone.class);
newZone.dirty = sorted.zone.dirty;
if (staggerLoad) {
if(!sorted.zone.cull)
newZone.fadingAlpha = saturate(sorted.dist / 15.0f) * 3.0f; // Fade in new chunks that are appearing out of the fog

// Reuse the old zone while uploading a correct one
sorted.zone.cull = false;
sorted.zone.uploadJob = ZoneUploadJob
.build(ctx, nextSceneContext, newZone, false, sorted.x, sorted.z);
sorted.zone.uploadJob.revealAfterTimestampMs =
timeMs + ceil(clamp(sorted.dist / 15.0f, 0.25f, 1.5f) * 1000.0f);
.build(ctx, nextSceneContext, newZone, false, sorted.x, sorted.z)
.queue(ctx.streamingGroup, generateSceneDataTask);
} else {
nextZones[sorted.x][sorted.z] = newZone;
ZoneUploadJob
Expand Down
Loading