aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-21 00:45:16 +0200
committermakamys <makamys@outlook.com>2022-06-21 02:42:38 +0200
commit6a028dc59c739c0bd6fd02ccc3bd7f5f5428ea5a (patch)
tree6cdb9e2dbd03e71949f7dcb4d479573a5f078dde /src
parentc2e64488dadcee9a69335042b9dccec7460af4b9 (diff)
downloadNeodymium-6a028dc59c739c0bd6fd02ccc3bd7f5f5428ea5a.tar.gz
Neodymium-6a028dc59c739c0bd6fd02ccc3bd7f5f5428ea5a.tar.bz2
Neodymium-6a028dc59c739c0bd6fd02ccc3bd7f5f5428ea5a.zip
Actually implement face culling
Diffstat (limited to 'src')
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index b4e0607..9ca74d4 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -85,6 +85,10 @@ public class NeoRenderer {
private double lastSortY = Double.NaN;
private double lastSortZ = Double.NaN;
+ private double interpX;
+ private double interpY;
+ private double interpZ;
+
private long lastGCTime = -1;
private long lastSaveTime = -1;
private long gcInterval = 10 * 1000;
@@ -132,6 +136,12 @@ public class NeoRenderer {
}
if(rendererActive && renderWorld) {
+ Entity rve = Minecraft.getMinecraft().renderViewEntity;
+
+ interpX = rve.lastTickPosX + (rve.posX - rve.lastTickPosX) * alpha;
+ interpY = rve.lastTickPosY + (rve.posY - rve.lastTickPosY) * alpha + rve.getEyeHeight();
+ interpZ = rve.lastTickPosZ + (rve.posZ - rve.lastTickPosZ) * alpha;
+
if(frameCount % Config.sortFrequency == 0) {
sort();
}
@@ -179,7 +189,7 @@ public class NeoRenderer {
piFirst[i].limit(sentMeshes[i].size());
piCount[i].limit(sentMeshes[i].size());
for(Mesh mesh : sentMeshes[i]) {
- if(mesh.visible && (Config.maxMeshesPerFrame == -1 || renderedMeshes < Config.maxMeshesPerFrame)) {
+ if(isNormalMeshVisible(mesh) && mesh.visible && (Config.maxMeshesPerFrame == -1 || renderedMeshes < Config.maxMeshesPerFrame)) {
renderedMeshes++;
renderedQuads += mesh.quadCount;
piFirst[i].put(mesh.iFirst);
@@ -191,6 +201,25 @@ public class NeoRenderer {
}
}
+ private boolean isNormalMeshVisible(Mesh mesh) {
+ switch(mesh.normal) {
+ case POSITIVE_X:
+ return interpX > ((mesh.x + 0) * 16.0);
+ case NEGATIVE_X:
+ return interpX < ((mesh.x + 1) * 16.0);
+ case POSITIVE_Y:
+ return interpY > ((mesh.y + 0) * 16.0);
+ case NEGATIVE_Y:
+ return interpY < ((mesh.y + 1) * 16.0);
+ case POSITIVE_Z:
+ return interpZ > ((mesh.z + 0) * 16.0);
+ case NEGATIVE_Z:
+ return interpZ < ((mesh.z + 1) * 16.0);
+ default:
+ return true;
+ }
+ }
+
private void mainLoop() {
while(!farChunks.isEmpty()) {
NeoChunk lodChunk = receiveFarChunk(farChunks.remove());
@@ -349,11 +378,6 @@ public class NeoRenderer {
float originY = 0;
float originZ = 0;
- Entity rve = Minecraft.getMinecraft().renderViewEntity;
- double interpX = rve.lastTickPosX + (rve.posX - rve.lastTickPosX) * alpha;
- double interpY = rve.lastTickPosY + (rve.posY - rve.lastTickPosY) * alpha + rve.getEyeHeight();
- double interpZ = rve.lastTickPosZ + (rve.posZ - rve.lastTickPosZ) * alpha;
-
glUniform3f(u_playerPos, (float)interpX - originX, (float)interpY - originY, (float)interpZ - originZ);
glUniform1i(u_light, 1);