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
11 changes: 11 additions & 0 deletions schemas/model_overrides.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@
"type": "boolean",
"description": "Disable priority sorting, instead sorting solely based on distance. Useful for new models where Jagex provide incorrect priorities."
},
"modelOffsetRelative": {
"type": "boolean",
"description": "Applies model offset relative to the models orientation."
},
"modelOffset": {
"type": "array",
"description": "XYZ Offset applied in world space by default, modelOffsetRelative enables rotating the offset by the models orientation",
"items": {
"type": "integer"
}
},
"materialOverrides": {
"type": "object",
"description": "A subset of options can be tweaked separately for specific materials of the model.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ private void uploadTempModel(
SceneUploader sceneUploader = SceneUploader.POOL.acquire();
FacePrioritySorter facePrioritySorter = shouldSort ? FacePrioritySorter.POOL.acquire() : null
) {
final int preOrientation = HDUtils.getModelPreOrientation(gameObject.getConfig());
shouldSort &= sceneUploader.preprocessTempModel(
worldProjection,
plugin.cameraFrustum,
Expand All @@ -313,6 +314,7 @@ private void uploadTempModel(
modelOverride,
m,
isPlayer,
preOrientation,
orientation,
x, y, z
);
Expand All @@ -321,7 +323,6 @@ private void uploadTempModel(
if (shouldSort && !isSquashed)
facePrioritySorter.sortModelFaces(visibleFaces, m);

final int preOrientation = HDUtils.getModelPreOrientation(gameObject.getConfig());
if (culledFaces.length > 0 &&
modelOverride.castShadows &&
plugin.configShadowMode != ShadowMode.OFF &&
Expand Down Expand Up @@ -565,6 +566,7 @@ private void uploadDynamicModel(
SceneUploader sceneUploader = SceneUploader.POOL.acquire();
FacePrioritySorter facePrioritySorter = shouldSort ? FacePrioritySorter.POOL.acquire() : null
) {
final int preOrientation = HDUtils.getModelPreOrientation(HDUtils.getObjectConfig(tileObject));
shouldSort &= sceneUploader.preprocessTempModel(
projection,
plugin.cameraFrustum,
Expand All @@ -575,11 +577,11 @@ private void uploadDynamicModel(
modelOverride,
m,
false,
preOrientation,
orient,
x, y, z
);

final int preOrientation = HDUtils.getModelPreOrientation(HDUtils.getObjectConfig(tileObject));
final boolean isSquashed = ctx.uboWorldViewStruct != null && ctx.uboWorldViewStruct.isSquashed();
if (shouldSort && !isSquashed)
facePrioritySorter.sortModelFaces(visibleFaces, m, true);
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/rs117/hd/renderer/zone/SceneUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public interface OnBeforeProcessTileFunc {
private final Material[] faceMaterials = new Material[MAX_FACE_COUNT];
private final UvType[] faceUVTypes = new UvType[MAX_FACE_COUNT];

private final int[] modelOffset = new int[3];
private final float[] projected = new float[4];

// Lazily initialized staging buffers, only used by uploadTempModel
Expand Down Expand Up @@ -772,13 +773,14 @@ private void uploadZoneRenderable(
assert uz < 25 : uz;
}
try {
modelOverride.applyModelOffset(modelOffset, preOrientation, orient);
zone.addAlphaModel(
plugin,
materialManager,
zone.glVaoA,
zone.tboF.getTexId(),
model, modelOverride, alphaStart, alphaEnd,
x - basex, y, z - basez,
(x - basex) + modelOffset[0], y + modelOffset[1], (z - basez) + modelOffset[2],
lx, lz, ux, uz,
rid, level, id
);
Expand Down Expand Up @@ -1396,6 +1398,11 @@ private int uploadStaticModel(
orientCos = COSINE[orientation];
}

modelOverride.applyModelOffset(modelOffset, preOrientation, orientation);
x += modelOffset[0];
y += modelOffset[1];
z += modelOffset[2];

for (int v = 0, vertexOffset = 0; v < vertexCount; ++v) {
int vx = (int) vertexX[v];
int vy = (int) vertexY[v];
Expand Down Expand Up @@ -1716,6 +1723,7 @@ public boolean preprocessTempModel(
ModelOverride modelOverride,
Model model,
boolean sortAllFaces,
int preOrientation,
int orientation,
int x, int y, int z
) {
Expand All @@ -1741,6 +1749,11 @@ public boolean preprocessTempModel(
orientCosf = COSINE[orientation] / 65536f;
}

modelOverride.applyModelOffset(modelOffset, preOrientation, orientation);
x += modelOffset[0];
y += modelOffset[1];
z += modelOffset[2];

boolean shouldSort = true;
boolean allVertsVisible = true;
for (int v = 0, vertexOffset = 0; v < vertexCount; ++v) {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/rs117/hd/scene/model_overrides/ModelOverride.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public class ModelOverride
public boolean invertDisplacementStrength = false;
public int depthBias = -1;
public boolean disablePrioritySorting = false;
public boolean modelOffsetRelative = false;
public int[] modelOffset = { 0, 0, 0, };

@JsonAdapter(AABB.ArrayAdapter.class)
public AABB[] hideInAreas = {};
Expand Down Expand Up @@ -249,6 +251,8 @@ public ModelOverride copy() {
invertDisplacementStrength,
depthBias,
disablePrioritySorting,
modelOffsetRelative,
modelOffset,
hideInAreas,
materialOverrides,
colorOverrides,
Expand Down Expand Up @@ -625,6 +629,25 @@ public void revertRotation(Model model) {
}
}

public void applyModelOffset(int[] result, int preOrientation, int orientation) {
int offsetX = modelOffset[0];
int offsetY = modelOffset[1];
int offsetZ = modelOffset[2];

if (modelOffsetRelative && (offsetX != 0 || offsetZ != 0) && (preOrientation != 0 || orientation != 0)) {
final int offsetOrientSin = SINE[mod(orientation != 0 ? orientation : preOrientation, 2048)];
final int offsetOrientCos = COSINE[mod(orientation != 0 ? orientation : preOrientation, 2048)];

final int offsetXTemp = offsetX;
offsetX = offsetZ * offsetOrientSin + offsetXTemp * offsetOrientCos >> 16;
offsetZ = offsetZ * offsetOrientCos - offsetXTemp * offsetOrientSin >> 16;
}

result[0] = offsetX;
result[1] = offsetY;
result[2] = offsetZ;
}

@Nullable
public final ModelOverride testColorOverrides(int ahsl) {
ModelOverride override = null;
Expand Down