ITS WORKING EVEN MORE
This commit is contained in:
@@ -183,7 +183,7 @@ public class VoxelCore {
|
||||
this.renderer.renderFarAwayOpaque(viewport);
|
||||
|
||||
//Compute the SSAO of the rendered terrain
|
||||
this.postProcessing.computeSSAO(projection, matrices);
|
||||
//this.postProcessing.computeSSAO(projection, matrices);
|
||||
|
||||
//We can render the translucent directly after as it is the furthest translucent objects
|
||||
this.renderer.renderFarAwayTranslucent(viewport);
|
||||
|
||||
@@ -23,11 +23,17 @@ public class PrintfInjector implements IShaderProcessor {
|
||||
private final HashMap<Integer, String> idToPrintfStringMap = new HashMap<>();
|
||||
private final int bindingIndex;
|
||||
private final Consumer<String> callback;
|
||||
private final Runnable preRun;
|
||||
public PrintfInjector(int bufferSize, int bufferBindingIndex, Consumer<String> callback) {
|
||||
this(bufferSize, bufferBindingIndex, callback, null);
|
||||
}
|
||||
|
||||
public PrintfInjector(int bufferSize, int bufferBindingIndex, Consumer<String> callback, Runnable pre) {
|
||||
this.textBuffer = new GlBuffer(bufferSize*4L+4);
|
||||
nglClearNamedBufferData(this.textBuffer.id, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, 0);
|
||||
this.bindingIndex = bufferBindingIndex;
|
||||
this.callback = callback;
|
||||
this.preRun = pre;
|
||||
}
|
||||
|
||||
private static int findNextCall(String src, int after) {
|
||||
@@ -183,6 +189,13 @@ public class PrintfInjector implements IShaderProcessor {
|
||||
|
||||
private void processResult(long ptr, long size) {
|
||||
int total = MemoryUtil.memGetInt(ptr); ptr += 4;
|
||||
if (total == 0) {
|
||||
return;
|
||||
}
|
||||
if (this.preRun != null) {
|
||||
this.preRun.run();
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
List<Character> types = new ArrayList<>();
|
||||
while (cnt < total) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import me.cortex.voxy.client.core.model.ModelManager;
|
||||
import me.cortex.voxy.client.core.rendering.building.BuiltSection;
|
||||
import me.cortex.voxy.client.core.rendering.building.RenderDataFactory;
|
||||
import me.cortex.voxy.client.core.rendering.building.RenderGenerationService;
|
||||
import me.cortex.voxy.client.core.rendering.hierarchical.DebugRenderer;
|
||||
import me.cortex.voxy.client.core.rendering.hierarchical.HierarchicalOcclusionRenderer;
|
||||
import me.cortex.voxy.client.core.rendering.hierarchical.INodeInteractor;
|
||||
import me.cortex.voxy.client.core.rendering.hierarchical.MeshManager;
|
||||
@@ -56,11 +57,17 @@ public class Gl46HierarchicalRenderer implements IRenderInterface<Gl46Hierarchic
|
||||
private final MeshManager meshManager = new MeshManager();
|
||||
|
||||
private final List<String> printfQueue = new ArrayList<>();
|
||||
private final PrintfInjector printf = new PrintfInjector(100000, 10, this.printfQueue::add);
|
||||
private final PrintfInjector printf = new PrintfInjector(100000, 10, line->{
|
||||
if (line.startsWith("LOG")) {
|
||||
System.err.println(line);
|
||||
}
|
||||
this.printfQueue.add(line);
|
||||
}, this.printfQueue::clear);
|
||||
|
||||
private final GlBuffer renderSections = new GlBuffer(100_000 * 4 + 4).zero();
|
||||
|
||||
|
||||
private final DebugRenderer debugRenderer = new DebugRenderer();
|
||||
|
||||
private final ConcurrentLinkedDeque<Mapper.StateEntry> blockStateUpdates = new ConcurrentLinkedDeque<>();
|
||||
private final ConcurrentLinkedDeque<Mapper.BiomeEntry> biomeUpdates = new ConcurrentLinkedDeque<>();
|
||||
@@ -150,6 +157,8 @@ public class Gl46HierarchicalRenderer implements IRenderInterface<Gl46Hierarchic
|
||||
var i = new int[1];
|
||||
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, i);
|
||||
this.sectionSelector.doHierarchicalTraversalSelection(viewport, i[0], this.renderSections);
|
||||
|
||||
this.debugRenderer.render(viewport, this.sectionSelector.getNodeDataBuffer(), this.renderSections);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,12 +174,6 @@ public class Gl46HierarchicalRenderer implements IRenderInterface<Gl46Hierarchic
|
||||
public void addDebugData(List<String> debug) {
|
||||
debug.add("Printf Queue: ");
|
||||
debug.addAll(this.printfQueue);
|
||||
for (String a : this.printfQueue) {
|
||||
if (a.startsWith("LOG")) {
|
||||
System.err.println(a);
|
||||
}
|
||||
}
|
||||
this.printfQueue.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -244,5 +247,6 @@ public class Gl46HierarchicalRenderer implements IRenderInterface<Gl46Hierarchic
|
||||
this.meshManager.free();
|
||||
this.sectionSelector.free();
|
||||
this.printf.free();
|
||||
this.debugRenderer.free();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package me.cortex.voxy.client.core.rendering.hierarchical;
|
||||
|
||||
import me.cortex.voxy.client.core.gl.GlBuffer;
|
||||
import me.cortex.voxy.client.core.gl.shader.Shader;
|
||||
import me.cortex.voxy.client.core.gl.shader.ShaderType;
|
||||
import me.cortex.voxy.client.core.rendering.AbstractFarWorldRenderer;
|
||||
import me.cortex.voxy.client.core.rendering.Gl46HierarchicalViewport;
|
||||
import me.cortex.voxy.client.core.rendering.SharedIndexBuffer;
|
||||
import me.cortex.voxy.client.core.rendering.util.UploadStream;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_TRIANGLES;
|
||||
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
|
||||
import static org.lwjgl.opengl.GL15.GL_ELEMENT_ARRAY_BUFFER;
|
||||
import static org.lwjgl.opengl.GL15C.glBindBuffer;
|
||||
import static org.lwjgl.opengl.GL30.*;
|
||||
import static org.lwjgl.opengl.GL31.GL_UNIFORM_BUFFER;
|
||||
import static org.lwjgl.opengl.GL40.GL_DRAW_INDIRECT_BUFFER;
|
||||
import static org.lwjgl.opengl.GL40.glDrawElementsIndirect;
|
||||
import static org.lwjgl.opengl.GL42.glMemoryBarrier;
|
||||
import static org.lwjgl.opengl.GL43.*;
|
||||
|
||||
public class DebugRenderer {
|
||||
private final Shader debugShader = Shader.make()
|
||||
.add(ShaderType.VERTEX, "voxy:lod/hierarchical/debug/node_outline.vert")
|
||||
.add(ShaderType.FRAGMENT, "voxy:lod/hierarchical/debug/frag.frag")
|
||||
.compile();
|
||||
private final Shader setupShader = Shader.make()
|
||||
.add(ShaderType.COMPUTE, "voxy:lod/hierarchical/debug/setup.comp")
|
||||
.compile();
|
||||
|
||||
private final GlBuffer uniformBuffer = new GlBuffer(1024).zero();
|
||||
private final GlBuffer drawBuffer = new GlBuffer(1024).zero();
|
||||
|
||||
private void uploadUniform(Gl46HierarchicalViewport viewport) {
|
||||
long ptr = UploadStream.INSTANCE.upload(this.uniformBuffer, 0, 1024);
|
||||
int sx = MathHelper.floor(viewport.cameraX)>>5;
|
||||
int sy = MathHelper.floor(viewport.cameraY)>>5;
|
||||
int sz = MathHelper.floor(viewport.cameraZ)>>5;
|
||||
|
||||
new Matrix4f(viewport.projection).mul(viewport.modelView).getToAddress(ptr); ptr += 4*4*4;
|
||||
|
||||
MemoryUtil.memPutInt(ptr, sx); ptr += 4;
|
||||
MemoryUtil.memPutInt(ptr, sy); ptr += 4;
|
||||
MemoryUtil.memPutInt(ptr, sz); ptr += 4;
|
||||
MemoryUtil.memPutInt(ptr, viewport.width); ptr += 4;
|
||||
|
||||
var innerTranslation = new Vector3f((float) (viewport.cameraX-(sx<<5)), (float) (viewport.cameraY-(sy<<5)), (float) (viewport.cameraZ-(sz<<5)));
|
||||
innerTranslation.getToAddress(ptr); ptr += 4*3;
|
||||
|
||||
MemoryUtil.memPutInt(ptr, viewport.height); ptr += 4;
|
||||
}
|
||||
|
||||
public void render(Gl46HierarchicalViewport viewport, GlBuffer nodeData, GlBuffer nodeList) {
|
||||
this.uploadUniform(viewport);
|
||||
UploadStream.INSTANCE.commit();
|
||||
|
||||
this.setupShader.bind();
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, this.drawBuffer.id);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, nodeList.id);
|
||||
glDispatchCompute(1,1,1);
|
||||
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT|GL_COMMAND_BARRIER_BIT);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
this.debugShader.bind();
|
||||
glBindVertexArray(AbstractFarWorldRenderer.STATIC_VAO);
|
||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, this.drawBuffer.id);
|
||||
GL15.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE_BYTE.id());
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, this.uniformBuffer.id);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, nodeData.id);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, nodeList.id);
|
||||
glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_BYTE, 0);
|
||||
}
|
||||
|
||||
public void free() {
|
||||
this.drawBuffer.free();
|
||||
this.uniformBuffer.free();
|
||||
this.debugShader.free();
|
||||
this.setupShader.free();
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,9 @@ public class HierarchicalOcclusionRenderer {
|
||||
glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT);
|
||||
this.hierarchicalTraversal.bind();
|
||||
|
||||
//Clear the render counter
|
||||
nglClearNamedBufferSubData(renderSelectionResult.id, GL_R32UI, 0, 4, GL_RED_INTEGER, GL_UNSIGNED_INT, 0);
|
||||
|
||||
{
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, this.uniformBuffer.id);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, this.nodeManager.nodeBuffer.id);
|
||||
@@ -119,19 +122,19 @@ public class HierarchicalOcclusionRenderer {
|
||||
nglClearNamedBufferSubData(this.nodeQueueB.id, GL_R32UI, 0, 4, GL_RED_INTEGER, GL_UNSIGNED_INT, 0);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, this.nodeQueueA.id);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, this.nodeQueueB.id);
|
||||
glDispatchCompute(16,1,1);
|
||||
glDispatchCompute(8*8,1,1);
|
||||
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
|
||||
|
||||
nglClearNamedBufferSubData(this.nodeQueueA.id, GL_R32UI, 0, 4, GL_RED_INTEGER, GL_UNSIGNED_INT, 0);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, this.nodeQueueB.id);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, this.nodeQueueA.id);
|
||||
glDispatchCompute(32,1,1);
|
||||
glDispatchCompute(8*8*8,1,1);
|
||||
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
|
||||
|
||||
nglClearNamedBufferSubData(this.nodeQueueB.id, GL_R32UI, 0, 4, GL_RED_INTEGER, GL_UNSIGNED_INT, 0);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, this.nodeQueueA.id);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, this.nodeQueueB.id);
|
||||
glDispatchCompute(64,1,1);
|
||||
glDispatchCompute(8*8*8*8,1,1);
|
||||
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
|
||||
}
|
||||
|
||||
@@ -147,4 +150,8 @@ public class HierarchicalOcclusionRenderer {
|
||||
this.nodeManager.free();
|
||||
glDeleteSamplers(this.hizSampler);
|
||||
}
|
||||
|
||||
public GlBuffer getNodeDataBuffer() {
|
||||
return this.nodeManager.nodeBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +221,12 @@ public class NodeManager {
|
||||
// the request queue only needs to supply the node id, since if its an inner node, it must be requesting for a mesh, while if its a leaf node, it must be requesting for children
|
||||
private void processRequestQueue(long ptr, long size) {
|
||||
int count = MemoryUtil.memGetInt(ptr); ptr += 4;
|
||||
if (count > REQUEST_QUEUE_SIZE*1.5) {
|
||||
System.err.println("CORRUPTED PROCESS REQUEST, IGNORING (had count of: "+count+")");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
int requestOp = MemoryUtil.memGetInt(ptr + i*4L);
|
||||
int node = requestOp&NODE_MSK;
|
||||
@@ -414,7 +420,8 @@ public class NodeManager {
|
||||
|
||||
this.pushNode(id);//request it to be uploaded
|
||||
} else {
|
||||
//The section was empty, so just remove/skip it
|
||||
//The section was empty, so just remove/skip it, but remove it from the map
|
||||
this.pos2meshId.remove(request.childPositions[i]);
|
||||
}
|
||||
}
|
||||
if (cnt == 0) {
|
||||
@@ -443,7 +450,9 @@ public class NodeManager {
|
||||
flags |= this.isEmptyNode(id)?2:0;
|
||||
flags |= Math.max(0, this.getNodeChildCnt(id)-1)<<2;
|
||||
|
||||
int a = this.getNodeMesh(id)|((flags&0xFF)<<24);
|
||||
//TODO: PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK PUT BACK
|
||||
//int a = this.getNodeMesh(id)|((flags&0xFF)<<24);
|
||||
int a = id|((flags&0xFF)<<24);
|
||||
int b = this.getNodeChildPtr(id)|(((flags>>8)&0xFF)<<24);
|
||||
System.out.println("Setting mesh " + this.getNodeMesh(id) + " for node " + id);
|
||||
MemoryUtil.memPutInt(dst, a); dst += 4;
|
||||
@@ -468,7 +477,6 @@ public class NodeManager {
|
||||
DownloadStream.INSTANCE.download(this.requestQueue, this::processRequestQueue);
|
||||
DownloadStream.INSTANCE.commit();
|
||||
nglClearNamedBufferSubData(this.requestQueue.id, GL_R32UI, 0, 4, GL_RED_INTEGER, GL_UNSIGNED_INT, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 1) in flat vec4 colour;
|
||||
layout(location = 0) out vec4 outColour;
|
||||
void main() {
|
||||
outColour = colour;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#version 450
|
||||
#extension GL_ARB_shader_draw_parameters : require
|
||||
|
||||
layout(binding = 0, std140) uniform SceneUniform {
|
||||
mat4 VP;
|
||||
ivec3 camSecPos;
|
||||
uint screenW;
|
||||
vec3 camSubSecPos;
|
||||
uint screenH;
|
||||
};
|
||||
|
||||
#define NODE_DATA_INDEX 1
|
||||
#import <voxy:lod/hierarchical/node.glsl>
|
||||
|
||||
layout(binding = 2, std430) restrict buffer NodeList {
|
||||
uint count;
|
||||
uint nodeQueue[];
|
||||
};
|
||||
|
||||
layout(location = 1) out flat vec4 colour;
|
||||
|
||||
void main() {
|
||||
UnpackedNode node;
|
||||
unpackNode(node, nodeQueue[gl_InstanceID]);
|
||||
|
||||
vec4 base = VP*vec4(vec3(((node.pos<<node.lodLevel)-camSecPos)<<5)-camSubSecPos, 1);
|
||||
|
||||
vec4 pos = base + (VP*vec4(ivec3(gl_VertexID&1, (gl_VertexID>>2)&1, (gl_VertexID>>1)&1)<<(5+node.lodLevel), 1));
|
||||
|
||||
gl_Position = pos;
|
||||
|
||||
uint hash = node.nodeId*1231421+123141;
|
||||
hash ^= hash>>16;
|
||||
hash = hash*1231421+123141;
|
||||
hash ^= hash>>16;
|
||||
hash = hash * 1827364925 + 123325621;
|
||||
colour = vec4(float(hash&15u)/15, float((hash>>4)&15u)/15, float((hash>>8)&15u)/15, 1);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#version 460 core
|
||||
layout(local_size_x=1, local_size_y=1) in;
|
||||
|
||||
|
||||
layout(binding = 0, std430) restrict buffer DrawCmd {
|
||||
uint count;
|
||||
uint instanceCount;
|
||||
uint firstIndex;
|
||||
int baseVertex;
|
||||
uint baseInstance;
|
||||
};
|
||||
|
||||
layout(binding = 1, std430) restrict buffer NodeList {
|
||||
uint nodeCount;
|
||||
uint nodes[];
|
||||
};
|
||||
|
||||
void main() {
|
||||
count = 6 * 2 * 3;
|
||||
instanceCount = nodeCount;
|
||||
firstIndex = (1<<8)*6;
|
||||
baseVertex = 0;
|
||||
baseInstance = 0;
|
||||
}
|
||||
@@ -92,5 +92,5 @@ void markRequested(inout UnpackedNode node) {
|
||||
}
|
||||
|
||||
void debugDumpNode(in UnpackedNode node) {
|
||||
printf("Node %d, %d@[%d,%d,%d], flags: %d, mesh: %d, ChildPtr: %d", node.nodeId, node.lodLevel, node.pos.x, node.pos.y, node.pos.z, node.flags, node.meshPtr, node.childPtr);
|
||||
//printf("Node %d, %d@[%d,%d,%d], flags: %d, mesh: %d, ChildPtr: %d", node.nodeId, node.lodLevel, node.pos.x, node.pos.y, node.pos.z, node.flags, node.meshPtr, node.childPtr);
|
||||
}
|
||||
Reference in New Issue
Block a user