Added smooth lighting

This commit is contained in:
josua 2020-06-22 12:22:11 +10:00
parent 878410abbf
commit 4f9cb191c4
26 changed files with 207 additions and 115 deletions

View File

@ -76,7 +76,7 @@ public class Main
LayerGenerators.init(); LayerGenerators.init();
// Create the display // Create the display
window = new DisplayWindow("Project Zombie"); window = new DisplayWindow();
window.init(); window.init();
// Load the resources // Load the resources
@ -109,5 +109,8 @@ public class Main
// Start the mainloop // Start the mainloop
menu = new MenuMain(); menu = new MenuMain();
mainloop.start(); mainloop.start();
// Kill the worker thread
worker.kill();
} }
} }

View File

@ -10,7 +10,9 @@ import org.lwjgl.opengl.GL33;
import gl_engine.matrix.Matrix4; import gl_engine.matrix.Matrix4;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Layers;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.util.math.ColorRange;
import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.chunk.ChunkEventHandler;
public class DisplayRender public class DisplayRender
@ -25,9 +27,11 @@ public class DisplayRender
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1); GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
GL33.glUniform2f(Main.window.glsl_tex_cut, 0, 0); GL33.glUniform2f(Main.window.glsl_tex_cut, 0, 0);
GL33.glUniform3f(Main.window.glsl_day_low, 0.1f, 0, 0); ColorRange range = Main.world.getLayer().layergen.getLightLevel();
GL33.glUniform3f(Main.window.glsl_day_high, 1, 1, 1);
GL33.glUniform3f(Main.window.glsl_src_low, 0, 0.1f, 0); GL33.glUniform3f(Main.window.glsl_day_low, (float)range.min.x, (float)range.min.y, (float)range.min.z);
GL33.glUniform3f(Main.window.glsl_day_high, (float)range.max.x, (float)range.max.y, (float)range.max.z);
GL33.glUniform3f(Main.window.glsl_src_low, 0, 0, 0);
GL33.glUniform3f(Main.window.glsl_src_high, 1, 1, 1); GL33.glUniform3f(Main.window.glsl_src_high, 1, 1, 1);
if(Main.menu.doGameRender) if(Main.menu.doGameRender)

View File

@ -90,13 +90,17 @@ public class DisplayRenderUI
camera = Matrix4.identity(); camera = Matrix4.identity();
projection = Matrix4.scale(new Vec3d(0.1/GlHelpers.getAspectRatio(), 0.1, 1)); projection = Matrix4.scale(new Vec3d(0.1/GlHelpers.getAspectRatio(), 0.1, 1));
GL33.glUniform3f(Main.window.glsl_day_low, 1, 1, 1);
GL33.glUniform3f(Main.window.glsl_day_high, 1, 1, 1);
GL33.glUniform3f(Main.window.glsl_src_low, 1, 1, 1);
GL33.glUniform3f(Main.window.glsl_src_high, 1, 1, 1);
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, projection.getArray()); GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, projection.getArray());
GL33.glUniformMatrix4fv(Main.window.glsl_camera, true, camera.getArray()); GL33.glUniformMatrix4fv(Main.window.glsl_camera, true, camera.getArray());
GL33.glDisable(GL33.GL_DEPTH_TEST); GL33.glDisable(GL33.GL_DEPTH_TEST);
if(Main.menu.doGameRender && Main.menu.showIngameGUI) if(Main.menu.doGameRender && Main.menu.showIngameGUI) {
{
renderGameGui(); renderGameGui();
} }

View File

@ -27,6 +27,8 @@ public class DisplayStatsEventHandler implements IMainloopTask
fps = DisplayWindow.fps; fps = DisplayWindow.fps;
DisplayWindow.fps = 0; DisplayWindow.fps = 0;
Main.worker.updateTime();
} }

View File

@ -1,12 +1,9 @@
package projectzombie.display; package projectzombie.display;
import static org.lwjgl.opengl.GL11.GL_FLOAT; import static org.lwjgl.opengl.GL11.GL_FLOAT;
import static org.lwjgl.opengl.GL11.GL_RGBA;
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
import static org.lwjgl.opengl.GL20.glEnableVertexAttribArray; import static org.lwjgl.opengl.GL20.glEnableVertexAttribArray;
import static org.lwjgl.opengl.GL20.glVertexAttribPointer; import static org.lwjgl.opengl.GL20.glVertexAttribPointer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
@ -15,7 +12,6 @@ import org.lwjgl.opengl.GL33;
import gl_engine.graphics.GraphicsHelpers; import gl_engine.graphics.GraphicsHelpers;
import gl_engine.graphics.GraphicsShader; import gl_engine.graphics.GraphicsShader;
import gl_engine.texture.TextureRef3D;
import mainloop.task.IMainloopTask; import mainloop.task.IMainloopTask;
import projectzombie.display.lighting.TileLighting; import projectzombie.display.lighting.TileLighting;
import projectzombie.init.Resources; import projectzombie.init.Resources;
@ -27,11 +23,9 @@ import projectzombie.input.KeyCharCallback;
import projectzombie.input.MouseButtonCallback; import projectzombie.input.MouseButtonCallback;
import projectzombie.input.ScrollWheelCallback; import projectzombie.input.ScrollWheelCallback;
import projectzombie.mainloop.MainloopEventHandler; import projectzombie.mainloop.MainloopEventHandler;
import projectzombie.model.Model;
public class DisplayWindow implements IMainloopTask public class DisplayWindow implements IMainloopTask
{ {
private String name;
private long window; private long window;
private long monitor; private long monitor;
private int width; private int width;
@ -58,6 +52,9 @@ public class DisplayWindow implements IMainloopTask
public int glsl_src_low; public int glsl_src_low;
public int glsl_src_high; public int glsl_src_high;
public int glsl_lightmap_offset;
public int glsl_lightmap_size;
public int getWidth() { public int getWidth() {
return this.width; return this.width;
} }
@ -74,10 +71,6 @@ public class DisplayWindow implements IMainloopTask
height = h; height = h;
} }
public DisplayWindow(String name) {
this.name = name;
}
public void init() public void init()
{ {
// Initialize GLFW // Initialize GLFW
@ -132,6 +125,9 @@ public class DisplayWindow implements IMainloopTask
glsl_src_low = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_src_low"); glsl_src_low = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_src_low");
glsl_src_high = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_src_high"); glsl_src_high = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_src_high");
glsl_lightmap_offset = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap_offset");
glsl_lightmap_size = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap_size");
int glsl_atlas = GL33.glGetUniformLocation(environmentRenderer.program, "atlas"); int glsl_atlas = GL33.glGetUniformLocation(environmentRenderer.program, "atlas");
int glsl_lightmap = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap"); int glsl_lightmap = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap");

View File

@ -1,10 +1,5 @@
package projectzombie.display.lighting; package projectzombie.display.lighting;
import static org.lwjgl.opengl.GL11.GL_RGBA;
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
import static org.lwjgl.opengl.GL12.GL_TEXTURE_3D;
import static org.lwjgl.opengl.GL12.glTexImage3D;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
@ -13,14 +8,10 @@ import org.lwjgl.opengl.GL33;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.MathHelpers; import gl_engine.MathHelpers;
import gl_engine.range.Range4i;
import gl_engine.vec.Vec2i; import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec4i;
import mainloop.task.IMainloopTask;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
import projectzombie.mainloop.MainloopHelpers;
import projectzombie.util.math.TileState; import projectzombie.util.math.TileState;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.chunk.ChunkEventHandler;
@ -28,30 +19,71 @@ import projectzombie.world.layer.Layer;
public class TileLighting public class TileLighting
{ {
public static boolean lighting_dirty = false; private static class LightingTask {
float[] b;
int w, h;
int x, y;
}
private static boolean lighting_dirty = false;
public static int lightmap; public static int lightmap;
private static LightingTask task;
public static void setDirty() {
lighting_dirty = true;
}
public synchronized static LightingTask getTask() {
LightingTask t = task;
task = null;
return t;
}
public synchronized static void setTask(LightingTask task) {
TileLighting.task = task;
}
public TileLighting() { public TileLighting() {
lightmap = GL33.glGenTextures(); lightmap = GL33.glGenTextures();
} }
public static void update() public static void update()
{ {
{
LightingTask task = getTask();
if(task != null)
{
GL33.glBindTexture(GL33.GL_TEXTURE_2D, lightmap);
GL33.glTexImage2D(GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB, task.w, task.h, 0, GL33.GL_RGB, GL33.GL_FLOAT, task.b);
GL33.glGenerateMipmap(GL33.GL_TEXTURE_2D);
Main.window.environmentRenderer.use();
GL33.glUniform2f(Main.window.glsl_lightmap_offset, task.x * 16 - 1, task.y * 16 - 1);
GL33.glUniform2f(Main.window.glsl_lightmap_size, task.w, task.h);
}
}
if(Camera.camera == null) return; if(Camera.camera == null) return;
if(!ChunkEventHandler.loaded) return; if(!ChunkEventHandler.loaded) return;
Layer layer = Main.world.getLayer(); Layer layer = Main.world.getLayer();
EntityPlayer player = Main.player; EntityPlayer player = Main.player;
boolean dirty = false; boolean dirty = lighting_dirty;
for(int cx=-Chunk.RENDER_DISTANCE;cx<=Chunk.RENDER_DISTANCE;cx++) {
for(int cy=-Chunk.RENDER_DISTANCE;cy<=Chunk.RENDER_DISTANCE;cy++) { if(!dirty)
Vec2i cpos = new Vec2i( {
cx + MathHelpers.floor(player.pos.x / 16), for(int cx=-Chunk.RENDER_DISTANCE;cx<=Chunk.RENDER_DISTANCE;cx++) {
cy + MathHelpers.floor(player.pos.y / 16)); for(int cy=-Chunk.RENDER_DISTANCE;cy<=Chunk.RENDER_DISTANCE;cy++) {
Chunk chunk = layer.chunks.get(cpos); Vec2i cpos = new Vec2i(
if(chunk.isLightDirty()) { cx + MathHelpers.floor(player.pos.x / 16),
chunk.resetLightDirty(); cy + MathHelpers.floor(player.pos.y / 16));
dirty = true; Chunk chunk = layer.chunks.get(cpos);
if(chunk.isLightDirty()) {
chunk.resetLightDirty();
dirty = true;
}
} }
} }
} }
@ -60,6 +92,7 @@ public class TileLighting
return; return;
} }
lighting_dirty = false;
int size = (Chunk.RENDER_DISTANCE * 2 + 1) * 16; int size = (Chunk.RENDER_DISTANCE * 2 + 1) * 16;
float[] lights = new float[size * size * 3]; float[] lights = new float[size * size * 3];
@ -102,7 +135,9 @@ public class TileLighting
} }
} }
Main.worker.processLighting(lights, size, size); Main.worker.processLighting(lights, size, size,
MathHelpers.floor(player.pos.x / 16) - Chunk.RENDER_DISTANCE,
MathHelpers.floor(player.pos.y / 16) - Chunk.RENDER_DISTANCE);
} }
public static void updateLighting(BdfObject bdf) public static void updateLighting(BdfObject bdf)
@ -111,6 +146,8 @@ public class TileLighting
float[] light = nl.get("light").getFloatArray(); float[] light = nl.get("light").getFloatArray();
int width = nl.get("w").getInteger(); int width = nl.get("w").getInteger();
int height = nl.get("h").getInteger(); int height = nl.get("h").getInteger();
int x = nl.get("x").getInteger();
int y = nl.get("y").getInteger();
float[] pixels = new float[width*height*3]; float[] pixels = new float[width*height*3];
@ -119,7 +156,13 @@ public class TileLighting
pixels[i*3+1] = light[i*2+1]; pixels[i*3+1] = light[i*2+1];
} }
GL33.glBindTexture(GL33.GL_TEXTURE_2D, lightmap); LightingTask task = new LightingTask();
GL33.glTexImage2D(GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB, width, height, 0, GL33.GL_RGB, GL33.GL_FLOAT, light); task.w = width;
task.h = height;
task.b = pixels;
task.x = x;
task.y = y;
setTask(task);
} }
} }

View File

@ -1,6 +1,5 @@
package projectzombie.entity; package projectzombie.entity;
import bdf.classes.IBdfClassManager;
import bdf.types.BdfArray; import bdf.types.BdfArray;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
@ -86,7 +85,7 @@ public class EntityContainer extends Entity implements EntityHoldsEntities
{ {
Entity e = entities[i]; Entity e = entities[i];
if(e.getID() == -1) { if(e == null || e.getID() == -1) {
continue; continue;
} }

View File

@ -5,7 +5,6 @@ import bdf.types.BdfObject;
import gl_engine.MathHelpers; import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.entity.particle.ParticleSmoke;
import projectzombie.entity.particle.ParticleSpark; import projectzombie.entity.particle.ParticleSpark;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.Model; import projectzombie.model.Model;

View File

@ -1,7 +1,5 @@
package projectzombie.entity.particle; package projectzombie.entity.particle;
import java.util.Random;
import gl_engine.MathHelpers; import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;

View File

@ -2,7 +2,6 @@ package projectzombie.entity.particle;
import java.util.Random; import java.util.Random;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.entity.EntityHeight; import projectzombie.entity.EntityHeight;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;

View File

@ -9,7 +9,6 @@ import projectzombie.entity.EntityHeight;
import projectzombie.entity.EntityParticle; import projectzombie.entity.EntityParticle;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.util.math.random.RandomHelpers;
import projectzombie.world.chunk.Chunk; import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer; import projectzombie.world.layer.Layer;

View File

@ -4,8 +4,10 @@ import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import gl_engine.MathHelpers; import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i;
import mainloop.task.IMainloopTask; import mainloop.task.IMainloopTask;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.lighting.TileLighting;
import projectzombie.entity.Entity; import projectzombie.entity.Entity;
import projectzombie.entity.EntityAlive; import projectzombie.entity.EntityAlive;
import projectzombie.entity.EntityBullet; import projectzombie.entity.EntityBullet;
@ -16,7 +18,6 @@ import projectzombie.entity.particle.ParticleBreak;
import projectzombie.init.Items; import projectzombie.init.Items;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.inventory.Inventory; import projectzombie.inventory.Inventory;
import projectzombie.items.spawner.ItemSpawnZombie;
import projectzombie.menu.MenuDeath; import projectzombie.menu.MenuDeath;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.settings.Cheats; import projectzombie.settings.Cheats;
@ -53,6 +54,8 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
public double angle; public double angle;
public double speed; public double speed;
private Vec2i last_chunk;
public EntityPlayer(BdfObject bdf) { public EntityPlayer(BdfObject bdf) {
super(bdf); super(bdf);
} }
@ -106,7 +109,8 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
inventory = new Inventory(10); inventory = new Inventory(10);
inventory.addItem(new ItemStack(Items.SPAWN_ZOMBIE, 99, (short)0)); inventory.addItem(new ItemStack(Items.SPAWN_ZOMBIE, 99, (short)0));
inventory.addItem(new ItemStack(Items.AMMO, 999, (short)0)); inventory.addItem(new ItemStack(Items.AMMO, 99, (short)0));
inventory.addItem(new ItemStack(Items.LANTERN, 99, (short)0));
} }
@Override @Override
@ -132,6 +136,11 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
{ {
chunk = layer.getChunk(pos); chunk = layer.getChunk(pos);
if(chunk != null && (last_chunk == null || !chunk.c_pos.equal(last_chunk))) {
last_chunk = chunk.c_pos;
TileLighting.setDirty();
}
if(dead) return; if(dead) return;
// Handle player deaths // Handle player deaths

View File

@ -1,7 +1,31 @@
package projectzombie.input; package projectzombie.input;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.GLFW_KEY_0;
import static projectzombie.input.GameInput.*; import static org.lwjgl.glfw.GLFW.GLFW_KEY_1;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_2;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_3;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_4;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_5;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_6;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_7;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_8;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_9;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_A;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_D;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_E;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_F11;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_Q;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_S;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
import static projectzombie.input.GameInput.backButton_last;
import static projectzombie.input.GameInput.fireGun;
import static projectzombie.input.GameInput.moveDown;
import static projectzombie.input.GameInput.moveLeft;
import static projectzombie.input.GameInput.moveRight;
import static projectzombie.input.GameInput.moveUp;
import static projectzombie.input.GameInput.move_last;
import org.lwjgl.glfw.GLFWKeyCallbackI; import org.lwjgl.glfw.GLFWKeyCallbackI;

View File

@ -1,12 +1,7 @@
package projectzombie.items; package projectzombie.items;
import projectzombie.entity.Entity;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.model.ModelItem; import projectzombie.model.ModelItem;
import projectzombie.util.math.ItemStack;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ItemAmmo extends Item public class ItemAmmo extends Item
{ {

View File

@ -4,10 +4,8 @@ import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.DisplayRenderUI;
import projectzombie.init.Models; import projectzombie.init.Models;
import projectzombie.input.InputMode; import projectzombie.input.InputMode;
import projectzombie.model.Model;
import projectzombie.model.ModelGui; import projectzombie.model.ModelGui;
import projectzombie.text.Text; import projectzombie.text.Text;
import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.GlHelpers;

View File

@ -2,8 +2,6 @@ package projectzombie.menu.gui;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.text.Text;
import projectzombie.util.gl.GlHelpers;
public class Label implements GUIComponent public class Label implements GUIComponent
{ {

View File

@ -3,7 +3,6 @@ package projectzombie.menu.gui;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import gl_engine.vec.Vec4d; import gl_engine.vec.Vec4d;
import projectzombie.util.gl.GlHelpers;
public class Overlay implements GUIComponent public class Overlay implements GUIComponent
{ {

View File

@ -1,12 +1,9 @@
package projectzombie.text; package projectzombie.text;
import gl_engine.matrix.Matrix4; import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.init.Resources; import projectzombie.init.Resources;
import projectzombie.model.Model; import projectzombie.model.Model;
import projectzombie.model.ModelGui; import projectzombie.model.ModelGui;
import projectzombie.util.gl.GlHelpers;
public class Text public class Text
{ {

View File

@ -1,24 +1,5 @@
package projectzombie.util.gl; package projectzombie.util.gl;
import static org.lwjgl.opengl.GL11.GL_ALPHA;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_CULL_FACE;
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glColor3d;
import static org.lwjgl.opengl.GL11.glColor4d;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotated;
import static org.lwjgl.opengl.GL11.glTranslated;
import static org.lwjgl.opengl.GL11.glVertex2d;
import static org.lwjgl.opengl.GL11.glVertex3d;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.DisplayRenderUI; import projectzombie.display.DisplayRenderUI;

View File

@ -5,17 +5,17 @@ import gl_engine.vec.Vec3d;
public class ColorRange public class ColorRange
{ {
Vec3d colorMin, colorMax; public Vec3d min, max;
public ColorRange(Vec3d colorMin, Vec3d colorMax) { public ColorRange(Vec3d colorMin, Vec3d colorMax) {
this.colorMin = colorMin; this.min = colorMin;
this.colorMax = colorMax; this.max = colorMax;
} }
public Vec3d getColor(double v) { public Vec3d getColor(double v) {
return new Vec3d( return new Vec3d(
MathHelpers.map(v, 0, 1, colorMin.x, colorMax.x), MathHelpers.map(v, 0, 1, min.x, max.x),
MathHelpers.map(v, 0, 1, colorMin.y, colorMax.y), MathHelpers.map(v, 0, 1, min.y, max.y),
MathHelpers.map(v, 0, 1, colorMin.z, colorMax.z)); MathHelpers.map(v, 0, 1, min.z, max.z));
} }
} }

View File

@ -2,13 +2,11 @@ package projectzombie.worker;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.ProcessBuilder.Redirect; import java.lang.ProcessBuilder.Redirect;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import bdf.data.BdfDatabase; import bdf.data.BdfDatabase;
import bdf.types.BdfIndent;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import projectzombie.display.lighting.TileLighting; import projectzombie.display.lighting.TileLighting;
@ -21,6 +19,8 @@ public class Worker extends Thread
InputStream in; InputStream in;
OutputStream out; OutputStream out;
boolean running = true;
public Worker() throws IOException public Worker() throws IOException
{ {
pb = new ProcessBuilder("java", "-jar", "worker.jar"); pb = new ProcessBuilder("java", "-jar", "worker.jar");
@ -36,7 +36,7 @@ public class Worker extends Thread
public void processLighting(float[] lights, int width, int height) public void processLighting(float[] lights, int width, int height, int x, int y)
{ {
BdfObject bdf = new BdfObject(); BdfObject bdf = new BdfObject();
BdfNamedList nl = bdf.getNamedList(); BdfNamedList nl = bdf.getNamedList();
@ -44,7 +44,24 @@ public class Worker extends Thread
nl.set("light", BdfObject.withFloatArray(lights)); nl.set("light", BdfObject.withFloatArray(lights));
nl.set("w", BdfObject.withInteger(width)); nl.set("w", BdfObject.withInteger(width));
nl.set("h", BdfObject.withInteger(height)); nl.set("h", BdfObject.withInteger(height));
nl.set("x", BdfObject.withInteger(x));
nl.set("y", BdfObject.withInteger(y));
sendData(bdf);
}
public void updateTime()
{
BdfObject bdf = new BdfObject();
BdfNamedList nl = bdf.getNamedList();
nl.set("task", BdfObject.withString("time"));
nl.set("millis", BdfObject.withLong(System.currentTimeMillis()));
sendData(bdf);
}
private void sendData(BdfObject bdf)
{
byte[] data = bdf.serialize().getBytes(); byte[] data = bdf.serialize().getBytes();
ByteBuffer size_buff = ByteBuffer.allocate(4); ByteBuffer size_buff = ByteBuffer.allocate(4);
@ -88,15 +105,24 @@ public class Worker extends Thread
case "light": case "light":
TileLighting.updateLighting(bdf); TileLighting.updateLighting(bdf);
break; break;
default:
Thread.sleep(10);
} }
System.out.println("Hello"); if(!running) {
return;
}
} }
} }
catch(IOException e) catch(IOException | InterruptedException e)
{ {
} }
} }
public void kill() {
process.destroy();
running = false;
}
} }

View File

@ -8,6 +8,7 @@ import bdf.types.BdfNamedList;
import bdf.types.BdfObject; import bdf.types.BdfObject;
import projectzombie.Main; import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.display.lighting.TileLighting;
import projectzombie.entity.player.EntityPlayer; import projectzombie.entity.player.EntityPlayer;
import projectzombie.time.GameTimer; import projectzombie.time.GameTimer;
import projectzombie.world.chunk.ChunkEventHandler; import projectzombie.world.chunk.ChunkEventHandler;
@ -30,8 +31,11 @@ public class World implements IBdfClassManager
loaded.spawnRandomEntities(); loaded.spawnRandomEntities();
} }
public void setLayer(int id) { public void setLayer(int id)
{
ChunkEventHandler.loaded = false; ChunkEventHandler.loaded = false;
TileLighting.setDirty();
this.loaded = layers.get(id); this.loaded = layers.get(id);
} }

View File

@ -1,11 +1,8 @@
package projectzombie.world.chunk; package projectzombie.world.chunk;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random; import java.util.Random;
import org.lwjgl.opengl.GL33;
import bdf.classes.IBdfClassManager; import bdf.classes.IBdfClassManager;
import bdf.types.BdfArray; import bdf.types.BdfArray;
import bdf.types.BdfNamedList; import bdf.types.BdfNamedList;
@ -17,7 +14,6 @@ import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i; import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d; import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.display.Camera; import projectzombie.display.Camera;
import projectzombie.entity.Entity; import projectzombie.entity.Entity;
import projectzombie.entity.EntityAlive; import projectzombie.entity.EntityAlive;
@ -261,12 +257,19 @@ public class Chunk implements IBdfClassManager
{ {
for(int i2=0;i2<Model.SIZE;i2++) for(int i2=0;i2<Model.SIZE;i2++)
{ {
if(i2 == 8) { switch(i2)
verticies[upto * Model.SIZE + i2 ] = pos.x + pos.y * 16; {
} case 8:
verticies[upto * Model.SIZE + i2 ] = pos.x;
else { continue;
case 10:
verticies[upto * Model.SIZE + i2 ] = pos.y;
continue;
default:
verticies[upto * Model.SIZE + i2 ] = fv[v * Model.SIZE + i2 ]; verticies[upto * Model.SIZE + i2 ] = fv[v * Model.SIZE + i2 ];
continue;
} }
} }
@ -281,12 +284,19 @@ public class Chunk implements IBdfClassManager
{ {
for(int i2=0;i2<Model.SIZE;i2++) for(int i2=0;i2<Model.SIZE;i2++)
{ {
if(i2 == 8) { switch(i2)
verticies[upto * Model.SIZE + i2 ] = pos.x + pos.y * 16; {
} case 8:
verticies[upto * Model.SIZE + i2 ] = pos.x;
else { continue;
case 10:
verticies[upto * Model.SIZE + i2 ] = pos.y;
continue;
default:
verticies[upto * Model.SIZE + i2 ] = bv[v * Model.SIZE + i2 ]; verticies[upto * Model.SIZE + i2 ] = bv[v * Model.SIZE + i2 ];
continue;
} }
} }

View File

@ -11,7 +11,7 @@ uniform vec4 color;
void main() void main()
{ {
FragColor = texture(atlas, pTexture) * color;// * vec4(pLighting, 1); FragColor = texture(atlas, pTexture) * color * vec4(pLighting, 1);
discard(FragColor.a == 0 || (pPos.x > tex_cut.y && tex_cut.x > 0.5)); discard(FragColor.a == 0 || (pPos.x > tex_cut.y && tex_cut.x > 0.5));
} }

View File

@ -22,6 +22,9 @@ uniform vec3 lighting_day_high;
uniform vec3 lighting_src_low; uniform vec3 lighting_src_low;
uniform vec3 lighting_src_high; uniform vec3 lighting_src_high;
uniform vec2 lightmap_offset;
uniform vec2 lightmap_size;
float map(float x, float in_min, float in_max, float out_min, float out_max) { float map(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
} }
@ -67,19 +70,21 @@ void main()
{ {
int type = int(aFlags.z); int type = int(aFlags.z);
int chunk_offset_id = int(aChunkOffset.x);
vec2 chunk_offset = vec2(mod(chunk_offset_id, 16), chunk_offset_id / 16);
mat4 do_rotation = rotated; mat4 do_rotation = rotated;
mat4 no_rotation = mat4(1); mat4 no_rotation = mat4(1);
gl_Position = vec4(aPos, 1) * (mod(type, 2) == 1 ? do_rotation : no_rotation) * vec4 pos = vec4(aPos, 1) * (mod(type, 2) == 1 ? do_rotation : no_rotation) *
translate(vec3(chunk_offset.x, 0, chunk_offset.y)) * model * camera * projection; translate(aChunkOffset) * model;
gl_Position = pos * camera * projection;
pTexture = vec3(aTex.x, getTexY(), aTex.z); pTexture = vec3(aTex.x, getTexY(), aTex.z);
pPos = aPos; pPos = aPos;
vec4 light = texture(lightmap, vec2(0.5, 0.5)); vec4 light = texture(lightmap, vec2(
map(floor(pos.x), lightmap_offset.x, lightmap_offset.x + lightmap_size.x, 0, 1),
map(floor(pos.z), lightmap_offset.y, lightmap_offset.y + lightmap_size.y, 0, 1)));
vec3 light_day = mapVec(light.r, 0, 1, lighting_day_low, lighting_day_high); vec3 light_day = mapVec(light.r, 0, 1, lighting_day_low, lighting_day_high);
vec3 light_src = mapVec(light.g, 0, 1, lighting_src_low, lighting_src_high); vec3 light_src = mapVec(light.g, 0, 1, lighting_src_low, lighting_src_high);

Binary file not shown.