Work on the funny
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
struct BlockModel {
|
||||
uint faceData[6];
|
||||
uint flagsA;
|
||||
uint colourTint;
|
||||
uint _pad[8];
|
||||
};
|
||||
|
||||
struct SectionMeta {
|
||||
uint posA;
|
||||
uint posB;
|
||||
uint AABB;
|
||||
uint ptr;
|
||||
uint cntA;
|
||||
uint cntB;
|
||||
uint cntC;
|
||||
uint cntD;
|
||||
};
|
||||
|
||||
//TODO: see if making the stride 2*4*4 bytes or something cause you get that 16 byte write
|
||||
struct DrawCommand {
|
||||
uint count;
|
||||
uint instanceCount;
|
||||
uint firstIndex;
|
||||
int baseVertex;
|
||||
uint baseInstance;
|
||||
};
|
||||
|
||||
layout(binding = 0) uniform sampler2D blockModelAtlas;
|
||||
|
||||
#ifndef Quad
|
||||
#define Quad ivec2
|
||||
#endif
|
||||
layout(binding = 1, std430) readonly restrict buffer QuadBuffer {
|
||||
Quad quadData[];
|
||||
};
|
||||
|
||||
layout(binding = 2, std430) restrict buffer DrawBuffer {
|
||||
DrawCommand drawCmd;
|
||||
};
|
||||
|
||||
#ifndef Quad
|
||||
#define MESHLET_ACCESS readonly writeonly
|
||||
#endif
|
||||
layout(binding = 3, std430) MESHLET_ACCESS restrict buffer MeshletListData {
|
||||
uint meshlets[];
|
||||
};
|
||||
|
||||
layout(binding = 4, std430) readonly restrict buffer SectionBuffer {
|
||||
SectionMeta sectionData[];
|
||||
};
|
||||
|
||||
#ifndef VISIBILITY_ACCESS
|
||||
#define VISIBILITY_ACCESS readonly
|
||||
#endif
|
||||
layout(binding = 5, std430) VISIBILITY_ACCESS restrict buffer VisibilityBuffer {
|
||||
uint visibilityData[];
|
||||
};
|
||||
|
||||
layout(binding = 6, std430) readonly restrict buffer ModelBuffer {
|
||||
BlockModel modelData[];
|
||||
};
|
||||
|
||||
layout(binding = 7, std430) readonly restrict buffer ModelColourBuffer {
|
||||
uint colourData[];
|
||||
};
|
||||
|
||||
layout(binding = 8, std430) readonly restrict buffer LightingBuffer {
|
||||
uint lightData[];
|
||||
};
|
||||
|
||||
vec4 getLighting(uint index) {
|
||||
uvec4 arr = uvec4(lightData[index]);
|
||||
arr = arr>>uvec4(16,8,0,24);
|
||||
arr = arr & uvec4(0xFF);
|
||||
return vec4(arr)*vec4(1.0f/255.0f);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#version 450
|
||||
#define MESHLET_ACCESS writeonly
|
||||
#import <voxy:lod/quad_format.glsl>
|
||||
#import <voxy:lod/gl46mesh/bindings.glsl>
|
||||
#import <voxy:lod/section.glsl>
|
||||
#define extractMeshletStart extractQuadStart
|
||||
layout(local_size_x = 64) in;
|
||||
#define QUADS_PER_MESHLET 126
|
||||
|
||||
void emitMeshlets(inout uint mli, inout uint meshletPtr, uint mskedCnt, uint cnt) {
|
||||
for (;mskedCnt != 0; mskedCnt--,mli++) {
|
||||
meshlets[mli] = meshletPtr + (mskedCnt-1);
|
||||
}
|
||||
meshletPtr += cnt;
|
||||
}
|
||||
|
||||
void main() {
|
||||
if (gl_GlobalInvocationID.x == 0) {
|
||||
//Setup the remaining state of the drawElementsIndirect command
|
||||
drawCmd.count = QUADS_PER_MESHLET*6;
|
||||
drawCmd.firstIndex = 0;
|
||||
drawCmd.baseVertex = 0;
|
||||
drawCmd.baseInstance = 0;
|
||||
}
|
||||
if (gl_GlobalInvocationID.x >= sectionCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Check the occlusion data from last frame
|
||||
bool shouldRender = visibilityData[gl_GlobalInvocationID.x] == frameId - 1;
|
||||
if (shouldRender) {
|
||||
SectionMeta meta = sectionData[gl_GlobalInvocationID.x];
|
||||
uint detail = extractDetail(meta);
|
||||
ivec3 ipos = extractPosition(meta);
|
||||
|
||||
ivec3 relative = ipos-(baseSectionPos>>detail);
|
||||
|
||||
uint a = ((meta.cntA>>16)&0xFFFF);
|
||||
uint u = (meta.cntB &0xFFFF) * uint(relative.y>-1);
|
||||
uint d = ((meta.cntB>>16)&0xFFFF) * uint(relative.y<1 );
|
||||
uint s = (meta.cntC &0xFFFF) * uint(relative.z>-1);
|
||||
uint n = ((meta.cntC>>16)&0xFFFF) * uint(relative.z<1 );
|
||||
uint w = (meta.cntD &0xFFFF) * uint(relative.x>-1);
|
||||
uint e = ((meta.cntD>>16)&0xFFFF) * uint(relative.x<1 );
|
||||
uint total = a + u + d + s + n + w + e;
|
||||
|
||||
uint mli = atomicAdd(drawCmd.instanceCount, total);//meshletListIndex
|
||||
|
||||
uint meshletPtr = extractMeshletStart(meta);
|
||||
|
||||
emitMeshlets(mli, meshletPtr, a, a);
|
||||
emitMeshlets(mli, meshletPtr, u, (meta.cntB &0xFFFF));
|
||||
emitMeshlets(mli, meshletPtr, d, ((meta.cntB>>16)&0xFFFF));
|
||||
emitMeshlets(mli, meshletPtr, s, (meta.cntC &0xFFFF));
|
||||
emitMeshlets(mli, meshletPtr, n, ((meta.cntC>>16)&0xFFFF));
|
||||
emitMeshlets(mli, meshletPtr, w, (meta.cntD &0xFFFF));
|
||||
emitMeshlets(mli, meshletPtr, e, ((meta.cntD>>16)&0xFFFF));
|
||||
//TODO: also increment a secondary atomic buffer that can be used to do a compute pass over all meshlets (need to basicly divide the meshletCounter by the computes workGroup size)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#version 450
|
||||
void main() {
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#version 450
|
||||
void main() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#version 460 core
|
||||
layout(location = 0) out vec4 outColour;
|
||||
void main() {
|
||||
outColour = vec4(1,0,0,1);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#version 450
|
||||
#define MESHLET_ACCESS readonly
|
||||
#define QUADS_PER_MESHLET 126
|
||||
//There are 16 bytes of metadata at the start of the meshlet
|
||||
#define MESHLET_SIZE (QUADS_PER_MESHLET+2)
|
||||
#import <voxy:lod/quad_format.glsl>
|
||||
#import <voxy:lod/gl46mesh/bindings.glsl>
|
||||
#import <voxy:lod/section.glsl>
|
||||
|
||||
uvec2 meshletPosition;
|
||||
Quad quad;
|
||||
bool setupMeshlet() {
|
||||
gl_CullDistance[0] = 1;
|
||||
//TODO: replace with vertexAttribute that has a divisor of 1
|
||||
uint data = meshlets[gl_InstanceID];
|
||||
if (data == uint(-1)) {//Came across a culled meshlet
|
||||
gl_CullDistance[0] = -1;
|
||||
//Since the primative is culled, dont need to do any more work or set any values as the primative is discarded
|
||||
// we dont need to care about undefined values
|
||||
return true;
|
||||
}
|
||||
|
||||
uint baseId = (data*QUADS_PER_MESHLET);
|
||||
uint quadIndex = baseId + (gl_VertexID>>2) + 2;
|
||||
meshletPosition = geometryPool[baseId];
|
||||
quad = geometryPool[quadIndex];
|
||||
if (isQuadEmpty(quad)) {
|
||||
gl_CullDistance[0] = -1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void main() {
|
||||
if (setupMeshlet()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,10 @@ uint extractLightId(uint64_t quad) {
|
||||
return Eu32(quad, 8, 55);
|
||||
}
|
||||
|
||||
bool isQuadEmpty(uint64_t quad) {
|
||||
return quad == uint64_t(0);
|
||||
}
|
||||
|
||||
#else
|
||||
//TODO: FIXME, ivec2 swaps around the data of the x and y cause its written in little endian
|
||||
|
||||
@@ -69,4 +73,8 @@ uint extractBiomeId(ivec2 quad) {
|
||||
uint extractLightId(ivec2 quad) {
|
||||
return Eu32v(quad, 8, 55);
|
||||
}
|
||||
|
||||
bool isQuadEmpty(ivec2 quad) {
|
||||
return all(equal(quad, ivec2(0)));
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user