Fixed lighting graphical issues

This commit is contained in:
josua 2020-06-30 10:11:08 +10:00
parent afd16a7389
commit 55ea5e6c55
4 changed files with 21 additions and 18 deletions

View File

@ -8,7 +8,7 @@ import projectzombie.Main;
public class Camera
{
public int cx, cy;
public double x, y;
public double angle = 45;
private Matrix4 matrix;
@ -20,11 +20,9 @@ public class Camera
Vec3d pos = Main.player.getPos();
angle = Main.player.angle;
cx = MathHelpers.floor((pos.x - 0.5) / 16.0) + 1;
cy = MathHelpers.floor((pos.z - 0.5) / 16.0) + 1;
x = pos.x - 0.5;
y = pos.z - 0.5;
identity = Matrix4.multiply(identity, Matrix4.translate(
MathHelpers.mod(-pos.x + 0.5, 16), 0, MathHelpers.mod(-pos.z + 0.5, 16)));
identity = Matrix4.multiply(identity, Matrix4.rotate(angle + 180, 0, 1, 0));
identity = Matrix4.multiply(identity, Matrix4.rotate(-45, 1, 0, 0));
identity = Matrix4.multiply(identity, Matrix4.translate(0, 0, -16));

View File

@ -129,8 +129,8 @@ public class DisplayLighting
}
Main.worker.processLighting(lights, size, size,
MathHelpers.floor(ppos.x / 16) - Chunk.RENDER_DISTANCE,
MathHelpers.floor(ppos.y / 16) - Chunk.RENDER_DISTANCE);
MathHelpers.floor(ppos.x / 16.0) - Chunk.RENDER_DISTANCE,
MathHelpers.floor(ppos.y / 16.0) - Chunk.RENDER_DISTANCE);
}
private static void calculateLight(Layer layer, Lighting lighting, float[] pixels, int x, int y, float level)
@ -299,16 +299,19 @@ public class DisplayLighting
GL33.glGenerateMipmap(GL33.GL_TEXTURE_2D);
int cx = 0, cy = 0;
// Set the texture location data
GL33.glUniform2f(Main.window.glsl_lightmap_size, lighting.w, lighting.h);
if(Camera.camera != null) {
cx = Camera.camera.cx;
cy = Camera.camera.cy;
GL33.glUniform2f(Main.window.glsl_lightmap_offset,
(float)(lighting.x * 16 - Camera.camera.x - 0.5),
(float)(lighting.y * 16 - Camera.camera.y - 0.5));
}
else {
System.out.println("CAMERA IS NULL");
}
// Set the texture location data
GL33.glUniform2f(Main.window.glsl_lightmap_offset, (lighting.x - cx) * 16 - 0.5f, (lighting.y - cy) * 16 - 0.5f);
GL33.glUniform2f(Main.window.glsl_lightmap_size, lighting.w, lighting.h);
}
public static void clearLighting()

View File

@ -66,8 +66,8 @@ public class DisplayRender
{
Model model = player.getModel();
model.setModel(Matrix4.translate(
(ppos.x - Camera.camera.cx * 16) - 0.5, ppos.y,
(ppos.z - Camera.camera.cy * 16) - 0.5));
ppos.x - Camera.camera.x - 0.5, ppos.y,
ppos.z - Camera.camera.y - 0.5));
model.render();
}
}

View File

@ -3,6 +3,8 @@ package projectzombie.world.chunk;
import java.util.ArrayList;
import java.util.Random;
import org.lwjgl.opengl.GL33;
import bdf.classes.IBdfClassManager;
import bdf.types.BdfArray;
import bdf.types.BdfNamedList;
@ -206,8 +208,8 @@ public class Chunk implements IBdfClassManager
// Render the model
model.setModel(Matrix4.translate(
(pos.x - Camera.camera.cx * 16) - 0.5, pos.y,
(pos.z - Camera.camera.cy * 16) - 0.5));
pos.x - Camera.camera.x - 0.5, pos.y,
pos.z - Camera.camera.y - 0.5));
model.render();
}
}
@ -290,7 +292,7 @@ public class Chunk implements IBdfClassManager
}
// Render all the tiles in the chunk as a block
model.setModel(Matrix4.translate((c_pos.x - Camera.camera.cx) * 16, 0, (c_pos.y - Camera.camera.cy) * 16));
model.setModel(Matrix4.translate(c_pos.x * 16 - Camera.camera.x, 0, c_pos.y * 16 - Camera.camera.y));
model.render();
renderEntities(entities.toArray());