more work
This commit is contained in:
@@ -25,7 +25,7 @@ public class DistanceTracker {
|
||||
this.tracker = tracker;
|
||||
|
||||
//NOTE: This is in our render distance units, to convert to chunks at lvl 0 multiply by 2
|
||||
int DIST = 24;
|
||||
int DIST = 16;//24;
|
||||
|
||||
this.rings[0] = new TransitionRing2D(5, DIST, (x,z)->{
|
||||
if (true) {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package me.cortex.voxelmon.core;
|
||||
|
||||
import me.cortex.voxelmon.core.rendering.AbstractFarWorldRenderer;
|
||||
import me.cortex.voxelmon.core.rendering.Gl46FarWorldRenderer;
|
||||
import me.cortex.voxelmon.core.rendering.RenderTracker;
|
||||
import me.cortex.voxelmon.core.rendering.SharedIndexBuffer;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import me.cortex.voxelmon.core.rendering.*;
|
||||
import me.cortex.voxelmon.core.rendering.building.BuiltSectionGeometry;
|
||||
import me.cortex.voxelmon.core.rendering.building.RenderGenerationService;
|
||||
import me.cortex.voxelmon.core.util.DebugUtil;
|
||||
@@ -29,6 +27,9 @@ import org.lwjgl.system.MemoryUtil;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.lwjgl.opengl.ARBFramebufferObject.GL_FRAMEBUFFER;
|
||||
import static org.lwjgl.opengl.ARBFramebufferObject.glBindFramebuffer;
|
||||
|
||||
//Core class that ingests new data from sources and updates the required systems
|
||||
|
||||
//3 primary services:
|
||||
@@ -50,7 +51,9 @@ public class VoxelCore {
|
||||
private final DistanceTracker distanceTracker;
|
||||
private final RenderGenerationService renderGen;
|
||||
private final RenderTracker renderTracker;
|
||||
|
||||
private final AbstractFarWorldRenderer renderer;
|
||||
private final PostProcessing postProcessing;
|
||||
|
||||
|
||||
public VoxelCore() {
|
||||
@@ -66,6 +69,8 @@ public class VoxelCore {
|
||||
|
||||
this.distanceTracker = new DistanceTracker(this.renderTracker, 5);
|
||||
|
||||
this.postProcessing = new PostProcessing();
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
|
||||
|
||||
|
||||
@@ -140,66 +145,21 @@ public class VoxelCore {
|
||||
DebugUtil.setPositionMatrix(matrices);
|
||||
matrices.pop();
|
||||
|
||||
/*
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int y = 0; y < Math.max(1, 10>>i); y++) {
|
||||
for (int x = -32; x < 32; x++) {
|
||||
for (int z = -32; z < 32; z++) {
|
||||
if (-16 < x && x < 16 && -16 < z && z < 16) {
|
||||
continue;
|
||||
}
|
||||
var sec = this.world.getOrLoadAcquire(i, x, y, z);
|
||||
this.renderGen.enqueueTask(sec);
|
||||
sec.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
int boundFB = GlStateManager.getBoundFramebuffer();
|
||||
this.postProcessing.setSize(MinecraftClient.getInstance().getFramebuffer().textureWidth, MinecraftClient.getInstance().getFramebuffer().textureHeight);
|
||||
this.postProcessing.bindClearFramebuffer();
|
||||
|
||||
//TODO: FIXME: since we just bound the post processing FB the depth information isnt
|
||||
// copied over, we must do this manually and also copy it with respect to the
|
||||
// near/far planes
|
||||
|
||||
|
||||
//DebugRenderUtil.renderAABB(new Box(0,100,0,1,101,1), 0,1,0,0.1f);
|
||||
//DebugRenderUtil.renderAABB(new Box(1,100,1,2,101,2), 1,0,0,0.1f);
|
||||
|
||||
|
||||
/*
|
||||
int LEVEL = 4;
|
||||
int SEC_Y = 1>>LEVEL;
|
||||
int X = 47>>LEVEL;
|
||||
int Z = 32>>LEVEL;
|
||||
var section = world.getOrLoadAcquire(LEVEL,X,SEC_Y,Z);
|
||||
var data = section.copyData();
|
||||
int SCALE = 1<<LEVEL;
|
||||
int Y_OFFSET = SEC_Y<<(5+LEVEL);
|
||||
int X_OFFSET = X<<(5+LEVEL);
|
||||
int Z_OFFSET = Z<<(5+LEVEL);
|
||||
for (int y = 0; y < 32; y++) {
|
||||
for (int z = 0; z < 32; z++) {
|
||||
for (int x = 0; x < 32; x++) {
|
||||
var point = data[WorldSection.getIndex(x,y,z)];
|
||||
if (point != 0) {
|
||||
//var colours = world.getMapper().getColours(point);
|
||||
//int colour = colours[Direction.UP.getId()];
|
||||
//DebugUtil.renderAABB(new Box(x*SCALE,y*SCALE+Y_OFFSET,z*SCALE,x*SCALE+SCALE,y*SCALE+SCALE+Y_OFFSET,z*SCALE+SCALE), colour|0xFF);
|
||||
point >>>= 27;
|
||||
DebugUtil.renderAABB(new Box(x*SCALE + X_OFFSET,y*SCALE+Y_OFFSET,z*SCALE+Z_OFFSET,x*SCALE+SCALE + X_OFFSET,y*SCALE+SCALE+Y_OFFSET,z*SCALE+SCALE+Z_OFFSET), (float) (point&7)/7,(float) ((point>>3)&7)/7,(float) ((point>>6)&7)/7,1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
section.release();
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
var points = RingUtil.generatingBoundingCorner2D(4);
|
||||
for (var point : points) {
|
||||
int x = point>>>16;
|
||||
int y = point&0xFFFF;
|
||||
DebugUtil.renderAABB(new Box(x,150,y,x+1,151,y+1), 1,1,0,1);
|
||||
}
|
||||
*/
|
||||
|
||||
//TODO: have the renderer also render a bounding full face just like black boarders around lvl 0
|
||||
// this is cause the terrain might not exist and so all the caves are visible causing hell for the
|
||||
// occlusion culler
|
||||
this.renderer.renderFarAwayOpaque(matrices, cameraX, cameraY, cameraZ);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, boundFB);
|
||||
this.postProcessing.renderPost(boundFB);
|
||||
}
|
||||
|
||||
public void addDebugInfo(List<String> debug) {
|
||||
@@ -220,6 +180,7 @@ public class VoxelCore {
|
||||
public void shutdown() {
|
||||
try {this.renderGen.shutdown();} catch (Exception e) {System.err.println(e);}
|
||||
try {this.renderer.shutdown();} catch (Exception e) {System.err.println(e);}
|
||||
try {this.postProcessing.shutdown();} catch (Exception e) {System.err.println(e);}
|
||||
try {this.world.shutdown();} catch (Exception e) {System.err.println(e);}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ public class GlFramebuffer extends TrackedObject {
|
||||
}
|
||||
|
||||
public void verify() {
|
||||
glCheckNamedFramebufferStatus(this.id, GL_FRAMEBUFFER);
|
||||
int code;
|
||||
if ((code = glCheckNamedFramebufferStatus(this.id, GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
throw new IllegalStateException("Framebuffer incomplete with error code: " + code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import static org.lwjgl.opengl.GL45C.glCreateTextures;
|
||||
import static org.lwjgl.opengl.GL45C.glTextureStorage2D;
|
||||
|
||||
public class GlTexture extends TrackedObject {
|
||||
final int id;
|
||||
public final int id;
|
||||
private final int type;
|
||||
public GlTexture() {
|
||||
this(GL_TEXTURE_2D);
|
||||
@@ -23,7 +23,7 @@ public class GlTexture extends TrackedObject {
|
||||
|
||||
public GlTexture store(int format, int levels, int width, int height) {
|
||||
if (this.type == GL_TEXTURE_2D) {
|
||||
glTextureStorage2D(this.id, format, levels, width, height);
|
||||
glTextureStorage2D(this.id, levels, format, width, height);
|
||||
} else {
|
||||
throw new IllegalStateException("Unknown texture type");
|
||||
}
|
||||
|
||||
@@ -2,9 +2,22 @@ package me.cortex.voxelmon.core.rendering;
|
||||
|
||||
import me.cortex.voxelmon.core.gl.GlFramebuffer;
|
||||
import me.cortex.voxelmon.core.gl.GlTexture;
|
||||
import me.cortex.voxelmon.core.gl.shader.Shader;
|
||||
import me.cortex.voxelmon.core.gl.shader.ShaderType;
|
||||
|
||||
import static org.lwjgl.opengl.ARBFramebufferObject.*;
|
||||
import static org.lwjgl.opengl.GL11.GL_RGBA8;
|
||||
import static org.lwjgl.opengl.ARBShaderImageLoadStore.glBindImageTexture;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL13.*;
|
||||
import static org.lwjgl.opengl.GL15C.GL_READ_ONLY;
|
||||
import static org.lwjgl.opengl.GL15C.GL_READ_WRITE;
|
||||
import static org.lwjgl.opengl.GL30C.GL_R32F;
|
||||
import static org.lwjgl.opengl.GL42C.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT;
|
||||
import static org.lwjgl.opengl.GL42C.glMemoryBarrier;
|
||||
import static org.lwjgl.opengl.GL43C.glDispatchCompute;
|
||||
import static org.lwjgl.opengl.GL44C.glBindImageTextures;
|
||||
import static org.lwjgl.opengl.GL45C.glBlitNamedFramebuffer;
|
||||
import static org.lwjgl.opengl.GL45C.glTextureBarrier;
|
||||
|
||||
public class PostProcessing {
|
||||
private final GlFramebuffer framebuffer;
|
||||
@@ -13,6 +26,10 @@ public class PostProcessing {
|
||||
private GlTexture colour;
|
||||
private GlTexture depthStencil;
|
||||
|
||||
private final Shader ssao = Shader.make()
|
||||
.add(ShaderType.COMPUTE, "voxelmon:lod/ssao/ssao.comp")
|
||||
.compile();
|
||||
|
||||
public PostProcessing() {
|
||||
this.framebuffer = new GlFramebuffer();
|
||||
}
|
||||
@@ -37,12 +54,25 @@ public class PostProcessing {
|
||||
|
||||
//Bind and clears the post processing frame buffer
|
||||
public void bindClearFramebuffer() {
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, this.framebuffer.id);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
//Executes the post processing and emits to whatever framebuffer is currently bound via a blit
|
||||
public void renderPost() {
|
||||
|
||||
public void renderPost(int outputFb) {
|
||||
this.ssao.bind();
|
||||
glBindImageTexture(0, this.colour.id, 0, false,0, GL_READ_WRITE, GL_RGBA8);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, this.depthStencil.id);
|
||||
//glDispatchCompute(this.width/32, this.height/32, 1);
|
||||
glTextureBarrier();
|
||||
glBlitNamedFramebuffer(this.framebuffer.id, outputFb, 0,0, this.width, this.height, 0, 0, this.width, this.height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
this.framebuffer.free();
|
||||
if (this.colour != null) this.colour.free();
|
||||
if (this.depthStencil != null) this.depthStencil.free();
|
||||
this.ssao.free();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ public class RenderTracker {
|
||||
buildMask |= 1<<Direction.WEST.getId();
|
||||
}
|
||||
buildMask |= 1<<Direction.UP.getId();
|
||||
buildMask |= ((1<<6)-1)^(1);
|
||||
//buildMask |= ((1<<6)-1)^(1);
|
||||
}
|
||||
return buildMask;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
//TODO: Add a render cache
|
||||
public class RenderGenerationService {
|
||||
//TODO: make it accept either a section or section position and have a concurrent hashset to determine if
|
||||
// a section is in the build queue
|
||||
|
||||
Reference in New Issue
Block a user