gpu: split camera position from model position

This commit is contained in:
Adam
2018-11-21 15:26:49 -05:00
committed by Adam
parent 67f0672799
commit fd6b67fae2
3 changed files with 16 additions and 14 deletions

View File

@@ -691,10 +691,6 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
y = 0;
z = tileY * Perspective.LOCAL_TILE_SIZE;
x -= client.getCameraX2();
y -= client.getCameraY2();
z -= client.getCameraZ2();
GpuIntBuffer b = modelBufferUnordered;
++unorderedModels;
@@ -721,10 +717,6 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
y = 0;
z = tileY * Perspective.LOCAL_TILE_SIZE;
x -= client.getCameraX2();
y -= client.getCameraY2();
z -= client.getCameraZ2();
GpuIntBuffer b = modelBufferUnordered;
++unorderedModels;
@@ -858,7 +850,10 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
.put(client.getCameraPitch())
.put(centerX)
.put(centerY)
.put(client.getScale());
.put(client.getScale())
.put(client.getCameraX2())
.put(client.getCameraY2())
.put(client.getCameraZ2());
uniformBuffer.flip();
gl.glBufferSubData(gl.GL_UNIFORM_BUFFER, 0, uniformBuffer.limit() * Integer.BYTES, uniformBuffer);
@@ -1266,7 +1261,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
buffer.put(tc);
buffer.put(targetBufferOffset);
buffer.put(FLAG_SCENE_BUFFER | (model.getRadius() << 12) | orientation);
buffer.put(x).put(y).put(z);
buffer.put(x + client.getCameraX2()).put(y + client.getCameraY2()).put(z + client.getCameraZ2());
targetBufferOffset += tc * 3;
}
@@ -1309,7 +1304,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
buffer.put(len / 3);
buffer.put(targetBufferOffset);
buffer.put((model.getRadius() << 12) | orientation);
buffer.put(x).put(y).put(z);
buffer.put(x + client.getCameraX2()).put(y + client.getCameraY2()).put(z + client.getCameraZ2());
tempOffset += len;
if (hasUv)

View File

@@ -32,6 +32,9 @@
int centerX;
int centerY;
int zoom;
int cameraX;
int cameraY;
int cameraZ;
ivec2 sinCosTable[2048];
};

View File

@@ -37,6 +37,9 @@ layout(std140) uniform uniforms {
int centerX;
int centerY;
int zoom;
int cameraX;
int cameraY;
int cameraZ;
ivec2 sinCosTable[2048];
};
@@ -52,9 +55,10 @@ out vec4 fUv;
#include to_screen.glsl
void main() {
ivec3 screenA = toScreen(vPosition[0], cameraYaw, cameraPitch, centerX, centerY, zoom);
ivec3 screenB = toScreen(vPosition[1], cameraYaw, cameraPitch, centerX, centerY, zoom);
ivec3 screenC = toScreen(vPosition[2], cameraYaw, cameraPitch, centerX, centerY, zoom);
ivec3 cameraPos = ivec3(cameraX, cameraY, cameraZ);
ivec3 screenA = toScreen(vPosition[0] - cameraPos, cameraYaw, cameraPitch, centerX, centerY, zoom);
ivec3 screenB = toScreen(vPosition[1] - cameraPos, cameraYaw, cameraPitch, centerX, centerY, zoom);
ivec3 screenC = toScreen(vPosition[2] - cameraPos, cameraYaw, cameraPitch, centerX, centerY, zoom);
if (-screenA.z < 50 || -screenB.z < 50 || -screenC.z < 50) {
// the client does not draw a triangle if any vertex distance is <50