Fixed culling?

This commit is contained in:
mcrcortex
2024-09-24 00:11:10 +10:00
parent f9a8f9b1c2
commit f53a81099e
6 changed files with 32 additions and 16 deletions

View File

@@ -77,8 +77,9 @@ public class RenderService<T extends AbstractSectionRenderer<J, ?>, J extends Vi
world.getMapper().setBiomeCallback(this.modelService::addBiome);
//this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(0, 0,0,0));
//this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, 0,0,0));
this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, 0,0,0));
/*
final int H_WIDTH = 10;
for (int x = -H_WIDTH; x <= H_WIDTH; x++) {
for (int y = 0; y <= 0; y++) {
@@ -86,7 +87,7 @@ public class RenderService<T extends AbstractSectionRenderer<J, ?>, J extends Vi
this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, x, y, z));
}
}
}
}*/
}
public void setup(Camera camera) {

View File

@@ -32,6 +32,7 @@ public class PostProcessing {
private GlTexture colourSSAO;
private GlTexture depthStencil;
private boolean didSSAO;
private final FullscreenBlit setDepth0 = new FullscreenBlit("voxy:post/depth0.frag");
private final FullscreenBlit emptyBlit = new FullscreenBlit("voxy:post/noop.frag");
//private final FullscreenBlit blitTexture = new FullscreenBlit("voxy:post/blit_texture_cutout.frag");
private final FullscreenBlit blitTexture = new FullscreenBlit("voxy:post/blit_texture_depth_cutout.frag");
@@ -93,6 +94,7 @@ public class PostProcessing {
if (this.colour != null) this.colour.free();
if (this.depthStencil != null) this.depthStencil.free();
this.emptyBlit.delete();
this.setDepth0.delete();
this.blitTexture.delete();
this.ssaoComp.free();
}
@@ -121,14 +123,16 @@ public class PostProcessing {
this.emptyBlit.blit();
glColorMask(true,true,true,true);
glDepthMask(true);
//glDisable(GL_DEPTH_TEST);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
//Set depth to 0 w.r.t mask
glStencilFunc(GL_EQUAL, 0, 0xFF);
this.setDepth0.blit();
glDisable(GL_DEPTH_TEST);
//Clear the depth buffer we copied cause else it will interfear with results (not really i think idk)
glClear(GL_DEPTH_BUFFER_BIT);
//Make voxy terrain render only where there isnt mc terrain
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc(GL_EQUAL, 1, 0xFF);

View File

@@ -74,6 +74,8 @@ public class HiZBuffer {
glBindFramebuffer(GL_FRAMEBUFFER, this.fb.id);
glDepthFunc(GL_ALWAYS);
glDepthMask(true);
glEnable(GL_DEPTH_TEST);
//System.err.println("SRC: " + GlTexture.getRawTextureType(srcDepthTex) + " DST: " + this.texture.id);
@@ -100,6 +102,7 @@ public class HiZBuffer {
glTextureParameteri(this.texture.id, GL_TEXTURE_MAX_LEVEL, this.levels-1);//TODO: CHECK IF ITS -1 or -0
glDepthFunc(GL_LEQUAL);
glDisable(GL_DEPTH_TEST);
glBindFramebuffer(GL_FRAMEBUFFER, boundFB);
glViewport(0, 0, width, height);
glBindVertexArray(0);

View File

@@ -21,6 +21,7 @@ vec3 minBB;
vec3 maxBB;
vec2 size;
uint lod;
//Sets up screenspace with the given node id, returns true on success false on failure/should not continue
//Accesses data that is setup in the main traversal and is just shared to here
@@ -34,7 +35,7 @@ void setupScreenspace(in UnpackedNode node) {
vec3 point = VP*(((transform.transform*vec4((node.pos<<node.lodLevel) - transform.originPos.xyz, 1))
+ (transform.worldPos.xyz-camChunkPos))-camSubChunk);
*/
lod = node.lodLevel;
vec4 base = VP*vec4(vec3(((node.pos<<node.lodLevel)-camSecPos)<<5)-camSubSecPos, 1);
@@ -48,7 +49,7 @@ void setupScreenspace(in UnpackedNode node) {
for (int i = 1; i < 8; i++) {
//NOTE!: cant this be precomputed and put in an array?? in the scene uniform??
vec4 pPoint = (VP*vec4(vec3((i&1)!=0,(i&2)!=0,(i&4)!=0),1))*(32<<node.lodLevel);//Size of section is 32x32x32 (need to change it to a bounding box in the future)
vec4 pPoint = (VP*vec4(vec3((i&1)!=0,(i&2)!=0,(i&4)!=0)*(32<<node.lodLevel),1));//Size of section is 32x32x32 (need to change it to a bounding box in the future)
pPoint += base;
vec3 point = pPoint.xyz/pPoint.w;
//TODO: CLIP TO VIEWPORT
@@ -74,7 +75,6 @@ void setupScreenspace(in UnpackedNode node) {
//Checks if the node is implicitly culled (outside frustum)
bool outsideFrustum() {
printf("Cull point (%f %f %f)x(%f %f %f)", maxBB.x, maxBB.y, maxBB.z, minBB.x, minBB.y, minBB.z);
return any(lessThanEqual(maxBB, vec3(0.0f, 0.0f, 0.0f))) || any(lessThanEqual(vec3(1.0f, 1.0f, 1.0f), minBB));
}
@@ -85,11 +85,12 @@ bool isCulledByHiz() {
vec2 ssize = size.xy * vec2(ivec2(screenW, screenH));
float miplevel = ceil(log2(max(max(ssize.x, ssize.y),1)));
vec2 midpoint = (maxBB.xy + minBB.xy)*0.5f;
return textureLod(hizDepthSampler, vec3(midpoint, minBB.z), miplevel) > 0.0001f;
// printf("HiZ sample point culled: (%f,%f)@%f against %f", midpoint.x, midpoint.y, miplevel, minBB.z);
return textureLod(hizDepthSampler, vec3(midpoint, minBB.z), miplevel) < 0.0001f;
}
//Returns if we should decend into its children or not
bool shouldDecend() {
printf("Screen area %f: %f, %f", (size.x*size.y*float(screenW)*float(screenH)), float(size.x), float(size.y));
//printf("Screen area %f: %f, %f", (size.x*size.y*float(screenW)*float(screenH)), float(size.x), float(size.y));
return (size.x*size.y*screenW*screenH) > minSSS;
}

View File

@@ -23,7 +23,7 @@ SIMPLE_QUEUE(uvec2, requestQueue, REQUEST_QUEUE_BINDING);
SIMPLE_QUEUE(uint, renderQueue, RENDER_QUEUE_BINDING);
void addRequest(inout UnpackedNode node) {
printf("Put node decend request");
//printf("Put node decend request");
if (!hasRequested(node)) {
if (requestQueueIndex.x < REQUEST_QUEUE_SIZE) {
uint atomRes = atomicAdd(requestQueueIndex.x, 1);
@@ -59,17 +59,17 @@ void enqueueSelfForRender(in UnpackedNode node) {
void traverse(in UnpackedNode node) {
//Compute screenspace
setupScreenspace(node);
debugDumpNode(node);
//debugDumpNode(node);
if (outsideFrustum() || isCulledByHiz()) {
printf("culled");
//printf("culled");
} else {
//It is visible, TODO: maybe do a more detailed hiz test? (or make it so that )
//Only decend if not a root node
if (node.lodLevel!=0 && shouldDecend()) {
if (hasChildren(node)) {
printf("A");
//printf("A");
enqueueChildren(node);
} else {
printf("B");

View File

@@ -0,0 +1,7 @@
#version 330 core
out vec4 colour;
in vec2 UV;
void main() {
colour = vec4(1,0,1,1);
gl_FragDepth = 0.0f;
}