it works!

This commit is contained in:
mcrcortex
2024-07-16 00:14:53 +10:00
parent 0ff2db1881
commit 72e35557a4
9 changed files with 175 additions and 28 deletions

View File

@@ -4,6 +4,7 @@
#define REQUEST_QUEUE_INDEX 3
#define RENDER_QUEUE_INDEX 4
#define TRANSFORM_ARRAY_INDEX 5
#define NEXT_NODE_QUEUE_INDEX 6
//Samplers
#define HIZ_BINDING_INDEX 0

View File

@@ -76,6 +76,10 @@ uint getChildCount(in UnpackedNode node) {
return ((node.flags >> 2)&7U)+1;
}
uint getChildPtr(in UnpackedNode node) {
return node.childPtr;
}
uint getTransformIndex(in UnpackedNode node) {
return (node.flags >> 5)&31u;
}

View File

@@ -47,7 +47,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)*32,1));//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),1))*(32<<node.lodLevel);//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
@@ -78,5 +78,5 @@ bool isCulledByHiz() {
//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(screenW), float(screenH));
return (size.x*size.y*screenW*screenH) > (64*64F);
return (size.x*size.y*screenW*screenH) > decendSSS;
}

View File

@@ -23,6 +23,7 @@ layout(binding = SCENE_UNIFORM_INDEX, std140) uniform SceneUniform {
uint screenH;
uint requestQueueMaxSize;
uint renderQueueMaxSize;
float decendSSS;
};
layout(binding = NODE_QUEUE_INDEX, std430) restrict buffer NodeQueue {
@@ -40,6 +41,11 @@ layout(binding = RENDER_QUEUE_INDEX, std430) restrict buffer RenderQueue {
uint[] renderQueue;
};
layout(binding = NEXT_NODE_QUEUE_INDEX, std430) restrict buffer NextNodeQueue {
uint nextNodeQueueIndex;
uint[] nextNodeQueue;
};
/*
layout(binding = 2, std430) restrict buffer QueueData {
@@ -78,7 +84,7 @@ layout(binding = 2, std430) restrict buffer QueueData {
void addRequest(inout UnpackedNode node) {
if (!hasRequested(node)) {
printf("requested");
printf("LOG: Request %d %d %d %d", node.nodeId, node.flags, node.meshPtr, node.childPtr);
//TODO: maybe try using only 1 variable and it being <0 being bad
if (requestQueueIndex < requestQueueMaxSize) {
//Mark node as having a request submitted to prevent duplicate submissions
@@ -90,10 +96,16 @@ void addRequest(inout UnpackedNode node) {
void enqueueChildren(in UnpackedNode node) {
//printf("children");
uint children = getChildCount(node);
uint ptr = getChildPtr(node);
uint widx = atomicAdd(nextNodeQueueIndex, children);
for (int i = 0; i < children; i++) {
nextNodeQueue[widx+i] = ptr+i;
}
}
void enqueueSelfForRender(in UnpackedNode node) {
//printf("render");
printf("render %d@[%d,%d,%d]", node.lodLevel, node.pos.x, node.pos.y, node.pos.z);
if (renderQueueIndex < renderQueueMaxSize) {
renderQueue[atomicAdd(renderQueueIndex, 1)] = getMesh(node);
}
@@ -101,15 +113,18 @@ void enqueueSelfForRender(in UnpackedNode node) {
//TODO: need to add an empty mesh, as a parent node might not have anything to render but the children do??
void main() {
UnpackedNode node;
if (gl_GlobalInvocationID.x>=nodeQueueSize) {
return;
}
UnpackedNode node;
//Setup/unpack the node
unpackNode(node, nodeQueue[gl_GlobalInvocationID.x]);
//TODO: check the node is OK first??? maybe?
//Compute screenspace
setupScreenspace(node);
//printf("Node %d@[%d,%d,%d] - %d - %f", node.lodLevel, node.pos.x, node.pos.y, node.pos.z, node.flags, (size.x*size.y*screenW*screenH));
//debugDumpNode(node);
@@ -117,14 +132,17 @@ void main() {
//printf("HizCulled");
//We are done here, dont do any more, the issue is the shader barriers maybe
// its culled, maybe just mark it as culled?
printf("Cull");
} 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");
enqueueChildren(node);
} else {
//printf("B");
addRequest(node);
//TODO: use self mesh (is error state if it doesnt have one since all leaf nodes should have a mesh)
// Basicly guarenteed to have a mesh, if it doesnt it is very very bad and incorect since its a violation of the graph properties
@@ -133,8 +151,10 @@ void main() {
}
} else {
if (hasMesh(node)) {
//printf("C");
enqueueSelfForRender(node);
} else {
//printf("D");
//!! not ideal, we want to render this mesh but dont have it. If we havent sent a request
// then send a request for a mesh for this node.
addRequest(node);