more work
This commit is contained in:
@@ -25,7 +25,7 @@ public class DistanceTracker {
|
|||||||
this.tracker = tracker;
|
this.tracker = tracker;
|
||||||
|
|
||||||
//NOTE: This is in our render distance units, to convert to chunks at lvl 0 multiply by 2
|
//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)->{
|
this.rings[0] = new TransitionRing2D(5, DIST, (x,z)->{
|
||||||
if (true) {
|
if (true) {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package me.cortex.voxelmon.core;
|
package me.cortex.voxelmon.core;
|
||||||
|
|
||||||
import me.cortex.voxelmon.core.rendering.AbstractFarWorldRenderer;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import me.cortex.voxelmon.core.rendering.Gl46FarWorldRenderer;
|
import me.cortex.voxelmon.core.rendering.*;
|
||||||
import me.cortex.voxelmon.core.rendering.RenderTracker;
|
|
||||||
import me.cortex.voxelmon.core.rendering.SharedIndexBuffer;
|
|
||||||
import me.cortex.voxelmon.core.rendering.building.BuiltSectionGeometry;
|
import me.cortex.voxelmon.core.rendering.building.BuiltSectionGeometry;
|
||||||
import me.cortex.voxelmon.core.rendering.building.RenderGenerationService;
|
import me.cortex.voxelmon.core.rendering.building.RenderGenerationService;
|
||||||
import me.cortex.voxelmon.core.util.DebugUtil;
|
import me.cortex.voxelmon.core.util.DebugUtil;
|
||||||
@@ -29,6 +27,9 @@ import org.lwjgl.system.MemoryUtil;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
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
|
//Core class that ingests new data from sources and updates the required systems
|
||||||
|
|
||||||
//3 primary services:
|
//3 primary services:
|
||||||
@@ -50,7 +51,9 @@ public class VoxelCore {
|
|||||||
private final DistanceTracker distanceTracker;
|
private final DistanceTracker distanceTracker;
|
||||||
private final RenderGenerationService renderGen;
|
private final RenderGenerationService renderGen;
|
||||||
private final RenderTracker renderTracker;
|
private final RenderTracker renderTracker;
|
||||||
|
|
||||||
private final AbstractFarWorldRenderer renderer;
|
private final AbstractFarWorldRenderer renderer;
|
||||||
|
private final PostProcessing postProcessing;
|
||||||
|
|
||||||
|
|
||||||
public VoxelCore() {
|
public VoxelCore() {
|
||||||
@@ -66,6 +69,8 @@ public class VoxelCore {
|
|||||||
|
|
||||||
this.distanceTracker = new DistanceTracker(this.renderTracker, 5);
|
this.distanceTracker = new DistanceTracker(this.renderTracker, 5);
|
||||||
|
|
||||||
|
this.postProcessing = new PostProcessing();
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
|
Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
|
||||||
|
|
||||||
|
|
||||||
@@ -140,66 +145,21 @@ public class VoxelCore {
|
|||||||
DebugUtil.setPositionMatrix(matrices);
|
DebugUtil.setPositionMatrix(matrices);
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
|
|
||||||
/*
|
int boundFB = GlStateManager.getBoundFramebuffer();
|
||||||
for (int i = 0; i < 5; i++) {
|
this.postProcessing.setSize(MinecraftClient.getInstance().getFramebuffer().textureWidth, MinecraftClient.getInstance().getFramebuffer().textureHeight);
|
||||||
for (int y = 0; y < Math.max(1, 10>>i); y++) {
|
this.postProcessing.bindClearFramebuffer();
|
||||||
for (int x = -32; x < 32; x++) {
|
|
||||||
for (int z = -32; z < 32; z++) {
|
//TODO: FIXME: since we just bound the post processing FB the depth information isnt
|
||||||
if (-16 < x && x < 16 && -16 < z && z < 16) {
|
// copied over, we must do this manually and also copy it with respect to the
|
||||||
continue;
|
// near/far planes
|
||||||
}
|
|
||||||
var sec = this.world.getOrLoadAcquire(i, x, y, z);
|
|
||||||
this.renderGen.enqueueTask(sec);
|
|
||||||
sec.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
//DebugRenderUtil.renderAABB(new Box(0,100,0,1,101,1), 0,1,0,0.1f);
|
//TODO: have the renderer also render a bounding full face just like black boarders around lvl 0
|
||||||
//DebugRenderUtil.renderAABB(new Box(1,100,1,2,101,2), 1,0,0,0.1f);
|
// this is cause the terrain might not exist and so all the caves are visible causing hell for the
|
||||||
|
// occlusion culler
|
||||||
|
|
||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.renderer.renderFarAwayOpaque(matrices, cameraX, cameraY, cameraZ);
|
this.renderer.renderFarAwayOpaque(matrices, cameraX, cameraY, cameraZ);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, boundFB);
|
||||||
|
this.postProcessing.renderPost(boundFB);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDebugInfo(List<String> debug) {
|
public void addDebugInfo(List<String> debug) {
|
||||||
@@ -220,6 +180,7 @@ public class VoxelCore {
|
|||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
try {this.renderGen.shutdown();} catch (Exception e) {System.err.println(e);}
|
try {this.renderGen.shutdown();} catch (Exception e) {System.err.println(e);}
|
||||||
try {this.renderer.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);}
|
try {this.world.shutdown();} catch (Exception e) {System.err.println(e);}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ public class GlFramebuffer extends TrackedObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void verify() {
|
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;
|
import static org.lwjgl.opengl.GL45C.glTextureStorage2D;
|
||||||
|
|
||||||
public class GlTexture extends TrackedObject {
|
public class GlTexture extends TrackedObject {
|
||||||
final int id;
|
public final int id;
|
||||||
private final int type;
|
private final int type;
|
||||||
public GlTexture() {
|
public GlTexture() {
|
||||||
this(GL_TEXTURE_2D);
|
this(GL_TEXTURE_2D);
|
||||||
@@ -23,7 +23,7 @@ public class GlTexture extends TrackedObject {
|
|||||||
|
|
||||||
public GlTexture store(int format, int levels, int width, int height) {
|
public GlTexture store(int format, int levels, int width, int height) {
|
||||||
if (this.type == GL_TEXTURE_2D) {
|
if (this.type == GL_TEXTURE_2D) {
|
||||||
glTextureStorage2D(this.id, format, levels, width, height);
|
glTextureStorage2D(this.id, levels, format, width, height);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unknown texture type");
|
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.GlFramebuffer;
|
||||||
import me.cortex.voxelmon.core.gl.GlTexture;
|
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.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 {
|
public class PostProcessing {
|
||||||
private final GlFramebuffer framebuffer;
|
private final GlFramebuffer framebuffer;
|
||||||
@@ -13,6 +26,10 @@ public class PostProcessing {
|
|||||||
private GlTexture colour;
|
private GlTexture colour;
|
||||||
private GlTexture depthStencil;
|
private GlTexture depthStencil;
|
||||||
|
|
||||||
|
private final Shader ssao = Shader.make()
|
||||||
|
.add(ShaderType.COMPUTE, "voxelmon:lod/ssao/ssao.comp")
|
||||||
|
.compile();
|
||||||
|
|
||||||
public PostProcessing() {
|
public PostProcessing() {
|
||||||
this.framebuffer = new GlFramebuffer();
|
this.framebuffer = new GlFramebuffer();
|
||||||
}
|
}
|
||||||
@@ -37,12 +54,25 @@ public class PostProcessing {
|
|||||||
|
|
||||||
//Bind and clears the post processing frame buffer
|
//Bind and clears the post processing frame buffer
|
||||||
public void bindClearFramebuffer() {
|
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
|
//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.WEST.getId();
|
||||||
}
|
}
|
||||||
buildMask |= 1<<Direction.UP.getId();
|
buildMask |= 1<<Direction.UP.getId();
|
||||||
buildMask |= ((1<<6)-1)^(1);
|
//buildMask |= ((1<<6)-1)^(1);
|
||||||
}
|
}
|
||||||
return buildMask;
|
return buildMask;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
|
|||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
//TODO: Add a render cache
|
||||||
public class RenderGenerationService {
|
public class RenderGenerationService {
|
||||||
//TODO: make it accept either a section or section position and have a concurrent hashset to determine if
|
//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
|
// a section is in the build queue
|
||||||
|
|||||||
@@ -73,18 +73,27 @@ void main() {
|
|||||||
if (((stateInfo.biomeTintMsk>>6)&1) == 1) {
|
if (((stateInfo.biomeTintMsk>>6)&1) == 1) {
|
||||||
colour *= vec4(0.247, 0.463, 0.894, 1);
|
colour *= vec4(0.247, 0.463, 0.894, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Apply face tint
|
||||||
|
if (face == 0) {
|
||||||
|
colour.xyz *= vec3(0.75, 0.75, 0.75);
|
||||||
|
} else if (face != 1) {
|
||||||
|
colour.xyz *= vec3((float(face-2)/4)*0.25 + 0.75);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//gl_Position = MVP * vec4(vec3(((cornerIdx)&1)+10,10,((cornerIdx>>1)&1)+10),1);
|
//gl_Position = MVP * vec4(vec3(((cornerIdx)&1)+10,10,((cornerIdx>>1)&1)+10),1);
|
||||||
//uint i = uint(quad>>32);
|
//uint i = uint(quad>>32);
|
||||||
uint i = uint(gl_BaseInstance);
|
//uint i = uint(gl_BaseInstance);
|
||||||
i ^= i>>16;
|
//i ^= i>>16;
|
||||||
i *= 124128573;
|
//i *= 124128573;
|
||||||
i ^= i>>16;
|
//i ^= i>>16;
|
||||||
i *= 4211346123;
|
//i *= 4211346123;
|
||||||
i ^= i>>16;
|
//i ^= i>>16;
|
||||||
i *= 462312435;
|
//i *= 462312435;
|
||||||
i ^= i>>16;
|
//i ^= i>>16;
|
||||||
i *= 542354341;
|
//i *= 542354341;
|
||||||
i ^= i>>16;
|
//i ^= i>>16;
|
||||||
|
|
||||||
//uint i = uint(lodLevel+12)*215387625;
|
//uint i = uint(lodLevel+12)*215387625;
|
||||||
//colour *= vec4(vec3(float((uint(i)>>2)&7)/7,float((uint(i)>>5)&7)/7,float((uint(i)>>8)&7)/7)*0.7+0.3,1);
|
//colour *= vec4(vec3(float((uint(i)>>2)&7)/7,float((uint(i)>>5)&7)/7,float((uint(i)>>8)&7)/7)*0.7+0.3,1);
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#version 460
|
||||||
|
layout(local_size_x = 32, local_size_y = 32, local_size_x = 1) in;
|
||||||
|
|
||||||
|
layout(binding=0,rgba8) restrict uniform image2D colourTexture;
|
||||||
|
layout(binding=1) uniform sampler2D depthTexture;
|
||||||
|
void main() {
|
||||||
|
float d = texture2D(depthTexture, vec2(gl_GlobalInvocationID.xy)/vec2(1024)).x;
|
||||||
|
d = 1/d;
|
||||||
|
d = d/2;
|
||||||
|
imageStore(colourTexture, ivec2(gl_GlobalInvocationID.xy), vec4(d,d,d,1));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user