diff --git a/game/gothic.cpp b/game/gothic.cpp index 8b9d57208..9da8ae7e6 100644 --- a/game/gothic.cpp +++ b/game/gothic.cpp @@ -88,7 +88,7 @@ Gothic::Gothic() { opts.doBindless = CommandLine::inst().isBindless(); } - if(hasBindless() && gpu.compute.maxInvocations>=1024 && gpu.memoryModel) { + if(hasBindless() && gpu.compute.maxInvocations>=1024) { //TODO: productize opts.doVirtualShadow = CommandLine::inst().isVirtualShadow(); } diff --git a/lib/Tempest b/lib/Tempest index d983d85af..fa35c3f10 160000 --- a/lib/Tempest +++ b/lib/Tempest @@ -1 +1 @@ -Subproject commit d983d85af606b275c75ad695219f0deb74c5252e +Subproject commit fa35c3f10e4a38e2f065b862a746cf07e1b5b99f diff --git a/shader/virtual_shadow/vsm_clear.comp b/shader/virtual_shadow/vsm_clear.comp index 8f5b4e06a..cb64474b3 100644 --- a/shader/virtual_shadow/vsm_clear.comp +++ b/shader/virtual_shadow/vsm_clear.comp @@ -23,6 +23,7 @@ void main() { return; imageStore(pageTbl, at, uvec4(0)); + // imageStore(pageTblDepth, at, uvec4(floatBitsToUint(1))); imageStore(pageTblDepth, at, uvec4(0xFFFFFFFF)); if(at==ivec3(0)) { diff --git a/shader/virtual_shadow/vsm_clump_pages.comp b/shader/virtual_shadow/vsm_clump_pages.comp index 9e7d83c83..c5e54b736 100644 --- a/shader/virtual_shadow/vsm_clump_pages.comp +++ b/shader/virtual_shadow/vsm_clump_pages.comp @@ -76,6 +76,10 @@ void main() { const uint lane = gl_LocalInvocationIndex; poolPageTable(); + // if(true) { + // storePageTable(); + // return; + // } if(lane < minX.length()) { minX [lane] = 0xFFFF; diff --git a/shader/virtual_shadow/vsm_cluster_task.comp b/shader/virtual_shadow/vsm_cluster_task.comp index fa47c3e7c..ead8b00a4 100644 --- a/shader/virtual_shadow/vsm_cluster_task.comp +++ b/shader/virtual_shadow/vsm_cluster_task.comp @@ -51,7 +51,7 @@ shared uint vsmMipMask; shared uint anyPageGlob; #endif -bool projectSphere(const vec4 sphere, out vec4 aabb, out float depthMin) { +bool projectSphere(const vec4 sphere, out vec4 aabb, out float depthMax) { const vec3 c = (scene.viewProject * vec4(sphere.xyz, 1)).xyz; const float R = sphere.w; @@ -65,7 +65,7 @@ bool projectSphere(const vec4 sphere, out vec4 aabb, out float depthMin) { float Rx = R * smWidthInv; float Ry = R * smWidthInv; aabb = vec4(c.xy-vec2(Rx,Ry), c.xy+vec2(Rx,Ry)); - depthMin = c.z + Rz; + depthMax = c.z + Rz; // aabb = c.xyxy; return true; } @@ -84,11 +84,11 @@ bool frustrumTest(const vec4 sphere) { } -bool projectCluster(const Cluster cluster, out vec4 aabb, out float depthMin) { +bool projectCluster(const Cluster cluster, out vec4 aabb, out float depthMax) { if(cluster.instanceId==0xFFFFFFFF) - return projectSphere(cluster.sphere, aabb, depthMin); - return projectSphere(cluster.sphere, aabb, depthMin); - // return projectInstance(cluster, aabb, depthMin); + return projectSphere(cluster.sphere, aabb, depthMax); + return projectSphere(cluster.sphere, aabb, depthMax); + // return projectInstance(cluster, aabb, depthMax); } bool emitCluster(const Cluster cluster, uint page) { @@ -236,6 +236,30 @@ void pullPages(uint mip) { barrier(); } +bool pageHiZTest(vec4 aabb, float depthMax, const ivec3 at, const ivec2 sz) { + aabb /= (1u << at.z); + aabb = aabb*0.5+0.5; // [0..1] + aabb = aabb*VSM_PAGE_TBL_SIZE; + + ivec4 iaabb = ivec4(ivec2(floor(aabb.xy)), ivec2(ceil(aabb.zw))+1); + iaabb.xy = max(iaabb.xy, ivec2(at.xy)); + iaabb.zw = min(iaabb.zw, ivec2(at.xy+sz)); + iaabb.zw = min(iaabb.zw, ivec2(VSM_PAGE_TBL_SIZE)); + + for(int x=iaabb.x; x=1) return; //imageAtomicStore(pageTbl, at, 1u, gl_ScopeDevice, gl_StorageSemanticsNone, gl_SemanticsRelaxed); @@ -101,7 +101,7 @@ void insertHiZ(ivec3 at, float z) { cur = (v > cur) ? v : cur; } // imageAtomicAdd(pageTbl, ivec3(0), 1u); //counter - storeVal(cur); + storeHiZValue(cur); } void flushHiZ() { @@ -111,7 +111,7 @@ void flushHiZ() { const uint v = pageHiZ[lane]; if(v==0xFFFFFFFF) return; - storeVal(v); + storeHiZValue(v); } #else shared uint pageHiZ[NumThreads]; @@ -120,7 +120,7 @@ void setupHiZ() { pageHiZ[lane] = 0xFFFFFFFF; } -void insertHiZ(ivec3 at, float z) { +void markPage(ivec3 at, float z) { if(z<0 || z>=1) return; @@ -136,7 +136,7 @@ void insertHiZ(ivec3 at, float z) { return; // update same entry // imageAtomicAdd(pageTbl, ivec3(0), 1u); //counter - storeVal(v); + storeHiZValue(v); } void flushHiZ() { @@ -144,7 +144,7 @@ void flushHiZ() { const uint v = pageHiZ[lane]; if(v==0xFFFFFFFF) return; - storeVal(v); + storeHiZValue(v); } #endif @@ -180,10 +180,6 @@ int shadowLod(vec2 dx, vec2 dy) { return max(0, int(minLod + bias + 0.5)); } -void markPage(ivec2 pageI, int mip, float depth) { - insertHiZ(ivec3(pageI, mip), depth); - } - void realMain() { const ivec2 size = textureSize(depth, 0); if(any(greaterThanEqual(pixelPos, size))) @@ -213,7 +209,7 @@ void realMain() { return; ivec2 pageI = ivec2((page*0.5+0.5)*VSM_PAGE_TBL_SIZE); - markPage(pageI, mip, shPos0.z); + markPage(ivec3(pageI, mip), shPos0.z); } void main() {