From 73c5a0ff4a2e0e69ad37aa553f53eb4a044f539e Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 4 Mar 2023 23:12:12 +0800 Subject: [PATCH 1/6] Updated shadow shaders --- Assets/Shaders/DeferredComposite_CS.glsl | 2 +- Assets/Shaders/DeferredComposite_CS.shshaderb | Bin 10101 -> 10085 bytes Assets/Shaders/ShadowMap_FS.glsl | 8 +++++++- Assets/Shaders/ShadowMap_FS.shshaderb | Bin 789 -> 1229 bytes 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index 12352d4d..2cf33ae1 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -83,7 +83,7 @@ float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV return 0.0f; } else - return 0.3f; + return 1.0f; // return step (fragPosLightPOV.z, ); } diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index a5197b3bb424b07718a21240adc9134a72f08195..e0b019b110f203343587a12900cb4cdfacd2b8c4 100644 GIT binary patch literal 10085 zcmZ{n36xw_5r$tfGd&>$LS*0KBvFX$fk1!&AqxzV2}uluh-m1{^h_Fhy2qZL37`n5 zxC^))*W)?CCGLVN?kFO-EAG3v@4JEv;`hCGD?a+@B}M)9SKX?*_uc#Y&A_EcX8Guu zxu`$OW@NLoy|SmwD7bmqOqeWFFG25_RdRc9Xw%Sflbw;{mY#fqk$Y!7s@yl1m_BeX zGG47W<#!?bz{}0cv33#P!`zwRPf)0r>VrdD2iLD396D#~@WjN{$<9@c+SW$BS=%~N zZ`X!9_34^%vr2LG=5S+bq#V#kM7e%n)}PIx#!$VvsZ*O+Ji26g@ei(#`g@?KtBoAb z1~*zez`d+D%eL3Ywxh6TX9uHKR~y5dwpT}5J2qDvQ?;Uv+9<#1Gk#qgof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assets/Shaders/ShadowMap_FS.glsl index b19a32a6..59904b5e 100644 --- a/Assets/Shaders/ShadowMap_FS.glsl +++ b/Assets/Shaders/ShadowMap_FS.glsl @@ -7,6 +7,12 @@ layout(location = 0) out vec4 shadowMap; void main() { + float depth = gl_FragCoord.z; + + float dx = dFdx(depth); + float dy = dFdy(depth); + + float moment2 = depth * depth + 0.25f * (dx * dx + dy * dy); // shadowMap = vec4 (0.0f, 0.0f, gl_FragCoord.z, 1.0f); - shadowMap = vec4 (gl_FragCoord.z, gl_FragCoord.z * gl_FragCoord.z, 0.0f, 1.0f); + shadowMap = vec4 (gl_FragCoord.z, moment2, 0.0f, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/ShadowMap_FS.shshaderb b/Assets/Shaders/ShadowMap_FS.shshaderb index 709a2ecc8a2443df79dbbed62ab544a4ac5cc464..78d304c1c888675793ea571220284d752acb2677 100644 GIT binary patch literal 1229 zcmZ9K-A@xi6vao{@=*k;2>5Lg#SfGag2u#%L4$oM!Ke?uP1f#GR@>cmyH$C^2mdkS zyZ$-8n0S86Oj6zCX3jbH%)K*rr}3j|%C9oEGGWXqQ#Ui_{)uGHm@z5FOq=m?ZM9#w z*9S$ozV%=O%dDxCPCRpF!cdCn2XR7TTCu8V$cL^5LKRgt=DRjk&6H`i?ar%bb`WJj z9u$!s90p;O+w|T0s8bC7^(Yl5UE2$i?l9;^c58DZ3pyWEXOcR*Z{OG?O@>K)kmh~+ zaTxUCgE-2Suaj@>@3-2!wv%OcP#pCl+l!OPhHlTL3Kjv8umjNT7E zsk?+xRvc=rX-?d^+p{n7p!+;c^H5ZJMYELe%LzUQJ_1+Gl5jumM@g|MUMuIt4AReg zL8e?w9%>SEjx*D%3ch(wlX)(elQkt?6dsq>ETdY^o!O%;sos>s+@&dA*UCRcf9yE@ z&=$l`Yi%m{)*PP^rZ4+vwc@2ddDcq`V~)4U-xT7d`1lem)>yiT@c3m%Xt@t(eQFExc8nH#_Rb7$G_>Eoav$h54!hU7N)1?R~+|ycqe$! zz2}-Ry*+O_?)NN<<3a!GdS4f&7CG-*5#~RW^S&FxoRb`PWY%bY*0+TJpY?5N=>9x+ dgxU8}e~CA9Pk{%Wcf#ACHgAaBAHBXuioZ{gZEXMm delta 327 zcmZvWJqp4=6og+k#`u?*_>(B22(j}5f<&+q6u~Pf7Iq32mR24hEH)m-8+Zhd5^yHQ z&V_G(=DjyNukyVZcr{b9Wva*)F{C1nbdz9Vl_6J?-MelHujj*df4r=>C%rU!{e=`V zb?_Y)zN;Jnb^SD=ID`U2DS`qRVlUz3chsl(o8Ht|ui!L*tzEV91KhaAsL&?`q`wuc!H^rv;7r4L)>k1I|(3ARY5{fCpG(k`T<06nUMjm?G)~ Fd;m-c7byS$ -- 2.40.1 From 826df94c96d9576a0a27930c699058097b961916 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Mon, 6 Mar 2023 00:02:06 +0800 Subject: [PATCH 2/6] Shadows WIP --- Assets/Shaders/Anim_VS.glsl | 9 +- Assets/Shaders/Anim_VS.shshaderb | Bin 6053 -> 6505 bytes Assets/Shaders/DeferredComposite_CS.glsl | 32 +++-- Assets/Shaders/DeferredComposite_CS.shshaderb | Bin 10085 -> 11109 bytes Assets/Shaders/ShadowMapBlur_CS.glsl | 58 +++++++++ Assets/Shaders/ShadowMapBlur_CS.shshaderb | Bin 0 -> 4569 bytes .../Shaders/ShadowMapBlur_CS.shshaderb.shmeta | 3 + Assets/Shaders/ShinyHighlight_FS.glsl | 3 +- Assets/Shaders/ShinyHighlight_FS.shshaderb | Bin 5273 -> 5397 bytes Assets/Shaders/TestCube_FS.glsl | 7 +- Assets/Shaders/TestCube_FS.shshaderb | Bin 2557 -> 2913 bytes Assets/Shaders/TestCube_VS.glsl | 9 +- Assets/Shaders/TestCube_VS.shshaderb | Bin 4133 -> 4585 bytes .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 112 ++++++++++-------- .../MiddleEnd/Interface/SHGraphicsSystem.h | 1 + .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 19 +-- .../MiddleEnd/Lights/SHLightingSubSystem.h | 5 +- .../RenderGraph/SHRenderGraphNode.cpp | 1 + 18 files changed, 183 insertions(+), 76 deletions(-) create mode 100644 Assets/Shaders/ShadowMapBlur_CS.glsl create mode 100644 Assets/Shaders/ShadowMapBlur_CS.shshaderb create mode 100644 Assets/Shaders/ShadowMapBlur_CS.shshaderb.shmeta diff --git a/Assets/Shaders/Anim_VS.glsl b/Assets/Shaders/Anim_VS.glsl index 2213b2fd..5282f062 100644 --- a/Assets/Shaders/Anim_VS.glsl +++ b/Assets/Shaders/Anim_VS.glsl @@ -20,10 +20,11 @@ layout(location = 0) out struct vec2 uv; // location = 1 vec4 normal; // location = 2 vec4 worldPos; // location = 3 + vec3 worldNormal; // location = 4 } Out; // material stuff -layout(location = 4) out struct +layout(location = 5) out struct { int materialIndex; uint eid; @@ -61,11 +62,13 @@ void main() // uvs for texturing in fragment shader Out.uv = aUV; - mat3 transposeInv = mat3 (transpose(inverse(modelViewMat))); + mat3 mvTransInv = mat3 (transpose(inverse(modelViewMat))); + mat3 modelTransInv = mat3 (transpose(inverse(worldTransform))); // normals are also in view space - Out.normal.rgb = transposeInv * aNormal.rgb; + Out.normal.rgb = mvTransInv * aNormal.rgb; Out.normal.rgb = normalize (Out.normal.rgb); + Out.worldNormal = normalize (modelTransInv * aNormal); // Compute bone matrix mat4 boneMatrix = BoneMatrices.data[firstBoneIndex + aBoneIndices[0]] * aBoneWeights[0]; diff --git a/Assets/Shaders/Anim_VS.shshaderb b/Assets/Shaders/Anim_VS.shshaderb index 6318555888e0c1f04b668c241c14b5ab73baa8b8..41ddaec30d51d8329f421590fc375cb48161e8fd 100644 GIT binary patch literal 6505 zcmZ9Pd3ao96^C!uVgrjX5wU$wussq zuqZ_+;J(Fu-}fDH!F}KNy6^a>|M)z<@11+n`}E^Ee82NM%XiLqzB_@A-49K&)z!Ir zNs@FVOOsQQ|Fo%OdD01!Bz;M5whs;O7+yEinpk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C2f@aeKVohG%PS6T)tHx~8zUDnuK>#{j)<9L5BtzxiCBxd_4S;5oAT~k zpI0Gr(bLy}{Z@KU+{=xKKJugFonpQT@hs0re3Q}Z6s*6)wQgdTi@2M?5$8LMxM{F) z)^D7CauJt-Bd!UKxIqORN|^#HsN-Ul|;`xo5%!N$r( z><7U5Y74&)f{pbK1ot7Zv2qdnVX(g1!tWzsV+SkTN5RI*MeMy`eYN@b#XjDLxEE_O zw?5HNZPBay!PS0#4BdWukHhByuzd9ML9lW1(a(p#(a#6L(T9(NwT+f{@Dt!AB=Xn6 zpG4%NpPvF7Cm(q}4X*a{Gw5=TIIquwjdjG?d=9Lyw($Er*jRfP+!w&c%0=uK!TM?o zzb}D}wRgdN8EmXv#C`>=ueR{}D%jX+Kfi`+9n_cQXGAIf1M~JO_3C{>Mr?kpBby10FX3 diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index 2cf33ae1..18f53de4 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -2,6 +2,7 @@ struct DirectionalLightStruct { + vec4 directionWorld; vec3 direction; uint isActive; uint cullingMask; @@ -22,7 +23,7 @@ layout(local_size_x = 16, local_size_y = 16) in; layout(set = 3, binding = 0, rgba32f) uniform image2D positions; layout(set = 3, binding = 1, rgba32f) uniform image2D normals; layout(set = 3, binding = 2, rgba8) uniform image2D albedo; -layout(set = 3, binding = 3, r32ui) uniform uimage2D lightLayerData; +layout(set = 3, binding = 3, rgba32ui) uniform uimage2D lightLayerData; layout(set = 3, binding = 4, r8) uniform image2D ssaoBlurredImage; layout(set = 3, binding = 5, rgba8) uniform image2D positionWorldSpace; layout(set = 3, binding = 6, rgba8) uniform image2D targetImage; @@ -54,7 +55,7 @@ float LinStep (float val, float low, float high) return clamp ((val - low)/(high - low), 0.0f, 1.0f); } -float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV) +float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV, vec3 worldNormal, vec3 lightDir) { // clip space for fragment from light view space vec4 fragPosLightPOV = lightPV * worldSpaceFragPos; @@ -69,6 +70,13 @@ float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV if (converted.x < 0.0f || converted.x > 1.0f || converted.y < 0.0f || converted.y > 1.0f) return 1.0f; + float returnVal = 0.0f; + + float worldNormalDotLight = dot (normalize (worldNormal), normalize(lightDir)); + + if (worldNormalDotLight < 0.0f) + return 0.7f; + if (fragPosLightPOV.z > moments.x && fragPosLightPOV.w > 0.0f) { float p = step (fragPosLightPOV.z, moments.x); @@ -76,15 +84,19 @@ float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV float d = fragPosLightPOV.z - moments.x; float pMax = LinStep (variance / (variance + (d * d)), 0.9f, 1.0f); - return min (max (p, pMax), 1.0f); + + returnVal = min (max (p, pMax) + 0.7f, 1.0f); + + return returnVal; + } else if (fragPosLightPOV.z > 1.0f) { return 0.0f; } - else - return 1.0f; - // return step (fragPosLightPOV.z, ); + + return 1.0f; + } void main() @@ -104,8 +116,12 @@ void main() // normal of fragment vec3 normalView = imageLoad(normals, globalThread).rgb; + uvec4 lightLayerAndNormal = imageLoad (lightLayerData, globalThread); + // light layer index - uint lightLayer = imageLoad (lightLayerData, globalThread).r; + uint lightLayer = lightLayerAndNormal.x; + + vec3 worldNormal = vec3 (unpackHalf2x16 (lightLayerAndNormal.y).xy, unpackHalf2x16 (lightLayerAndNormal.z).x); vec3 fragColor = vec3 (0.0f); @@ -138,7 +154,7 @@ void main() if ((DirLightData.dLightData[i].shadowData & uint(1)) == 1) { // calculate shadow map here - fragColor *= CalcShadowValue (shadowMaps[0], positionWorld, DirLightData.dLightData[i].pvMatrix).xxx; + fragColor.rgb *= CalcShadowValue (shadowMaps[0], positionWorld, DirLightData.dLightData[i].pvMatrix, worldNormal, DirLightData.dLightData[i].directionWorld.xyz).xxx; } } } diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index e0b019b110f203343587a12900cb4cdfacd2b8c4..57401b13063ae5536870be4281bf45663baf213c 100644 GIT binary patch literal 11109 zcmZ{o37DN_b;rLXvjhlB2umOkXF!rz0wg3XF^~`v7@`vr3G zEHmOtAnlDRMoiIrMTMIV106^9MDNbdHl|-JDbB8{k5^Jt?Kxa z;pMA~Ke$fDKL9;dspt4WaJ{h;+`)XaY)5Tm2MT*mc0780r9QZIM`ft7b6cf8SzR)5 z`tsFN!z)*h4zFAZSdmK}-wvJZ@s~0vaBU>61xvwKT z7F}n&)|PFI*O@Jd*ozy@(Y(IS?6`>8P-_B->dM^0;UZIi-hFe?|1|i)#@JM~*{TlZ zu^rhO^k`$WI@X%V#~8qFR$G(JG3JxUbZ3L;yvAbO4UJZwmiSrO&G?GBbY{E3QAvE0r2ZrP!^l=Hy_j$feJga>aD>@%8DR zXf>;2Bdz={TbI0b)h5=Zr%EvodFvXStn=6z*;JXhF5jm^;mhL}yHWJfXRGA1h<)nH z<`#WQta~skI~l%M>)F{^V6L){w&^u3&rQE=dfn4Obq@M;Py4{Z|E{?i-#$0@LcSx< zlV6wp)=!_$^YN)ol~%Ks-{lyi3%)o@G3VLYD&pJcQ(i0mwxQChcrI5L{YtFkc4zD1 zi`e2~)NaflW%#-nj|PoHtloA>Toxbm~7-e!-t+08clChUocO2en5 zb={Ke^Xrq%W_4)eXk{clXS%Z6@ihjnWly(Vc*XP`>&osZ^QnjR-UHvNG)Jnfg6yMS z-z|SQ&$jus^;^$H zuCRf$6ALxXNy~Y@BF>uSW|uhg$oZb`BdhshZaxpJ&0N;1-3zvvGw#3rZNV8Y=eI_1 zG4>H9F2${mzxB!4&v@^7xjyY)d@*P5kS+RKi=4Dv)F&79x$hC@ zIL7sqICIM_%ejs`pL?xDKd~|AwQ=3p$hopm-I(IZT%7Ny(#;(^*ayydw-;OI*t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-?6=3VQHsh^fALD3;eHha~UXIv@IQnRT?c*{e);Ix{kC-QeyZ50DCm-MU zli(T135fIcdsmxieUWPlY_9S-oyL}rm>nsmyzf`S$w$mp|0CvVIC= 0 && uv.y >= 0 && uv.x < imageSize.x && uv.y < imageSize.y) + { + return imageLoad (shadowMap, uv); + } + + return vec4 (0.0f); +} + +shared vec4 sharedPixels[16 + BLUR_WIDTH - 1][16 + BLUR_WIDTH - 1]; + +void main() +{ + ivec2 globalThread = ivec2 (gl_GlobalInvocationID.xy); + ivec2 localThread = ivec2 (gl_LocalInvocationID.xy); + ivec2 inputImageSize = imageSize(shadowMap); + + // Load color into shared memory + ivec2 start = ivec2 (gl_WorkGroupID) * ivec2 (gl_WorkGroupSize) - (BLUR_HALF_WIDTH); + for (int i = localThread.x; i < SHM_WIDTH; i += int (gl_WorkGroupSize.x)) + { + for (int j = localThread.y; j < SHM_WIDTH; j += int (gl_WorkGroupSize.y)) + { + vec4 value = GetShadowMapValue (start + ivec2 (i, j), inputImageSize); + sharedPixels[i][j] = value; + } + } + + // wait for all shared memory to load + barrier(); + + ivec2 shmStart = ivec2 (localThread + (BLUR_HALF_WIDTH)); + + vec4 sum = vec4 (0.0f); + for (int i = -BLUR_HALF_WIDTH; i <= BLUR_HALF_WIDTH; ++i) + { + for (int j = -BLUR_HALF_WIDTH; j <= BLUR_HALF_WIDTH; ++j) + { + vec4 sharedVal = sharedPixels[shmStart.x + i][shmStart.y + j]; + sum += sharedVal; + } + } + + sum /= (BLUR_WIDTH * BLUR_WIDTH); + imageStore(shadowMapBlurred, globalThread, sum); +} \ No newline at end of file diff --git a/Assets/Shaders/ShadowMapBlur_CS.shshaderb b/Assets/Shaders/ShadowMapBlur_CS.shshaderb new file mode 100644 index 0000000000000000000000000000000000000000..d02afaf1c4385f91bf082bc5cae9570086ea2cd9 GIT binary patch literal 4569 zcmZ9O3!9Zy700&>XBa@a3ItLO-c2GvGGd~qy+q6q& zq;y`Il`csCnxxYFGz}&ddQH}A(X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?Hw_nI`aJmT%O-wvE?G4J~`LNz4MO5e%=7PpY6OB_wy!lW{MojdwmPucw=I(a^_lt z{u^>O+rGWOBR6K--2XtV)la;!`sF_2MO}~h{~hDzAbzuvFLNdx=<`eX0T zVUAgVj@c{%%fFuA%o4ENV&pyYE=BwKe)N3?ku$eAa$f|te);|_$Ci)Wp9RaA+gV2* z^*hXV9{O{Lb?n=CYuHC8+Rr|W`8?8z*oQd!SOK<=@*Xe7mXDZAz|N-}b1Alb{GGcD z>^gaS?L=Ek9lc%-wio+1-ahR0O0=K78gm6A=X!DUaTR##%)S68A2C;h?X^7DmDuvp z>leYUlegEXrH)=#f$gOeG2TAxbv4@0UXA$@B4@ASxVP)T*JRs!do5z`JM(?K4s4A4 Q|5&SS4s&U*M|*$&4|n0d!2kdN literal 0 HcmV?d00001 diff --git a/Assets/Shaders/ShadowMapBlur_CS.shshaderb.shmeta b/Assets/Shaders/ShadowMapBlur_CS.shshaderb.shmeta new file mode 100644 index 00000000..cc90d5c9 --- /dev/null +++ b/Assets/Shaders/ShadowMapBlur_CS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: ShadowMapBlur_CS +ID: 38004013 +Type: 2 diff --git a/Assets/Shaders/ShinyHighlight_FS.glsl b/Assets/Shaders/ShinyHighlight_FS.glsl index bb41a0fb..be26f866 100644 --- a/Assets/Shaders/ShinyHighlight_FS.glsl +++ b/Assets/Shaders/ShinyHighlight_FS.glsl @@ -57,7 +57,7 @@ layout (std430, set = 2, binding = 0) buffer MaterialProperties // For mater layout(location = 0) out vec4 position; layout(location = 1) out uint outEntityID; -layout(location = 2) out uint lightLayerIndices; +layout(location = 2) out uvec4 lightLayerIndices; layout(location = 3) out vec4 normals; layout(location = 4) out vec4 albedo; layout(location = 5) out vec4 worldSpacePosition; @@ -76,7 +76,6 @@ void main() worldSpacePosition = In.worldPos; outEntityID = In2.eid; - lightLayerIndices = In2.lightLayerIndex; // float vpHeight = float (In2.screenSpacePos.y) - MatProp.data[In2.materialIndex].highlightPosition; // bring the frame of reference to the object's screen space pos diff --git a/Assets/Shaders/ShinyHighlight_FS.shshaderb b/Assets/Shaders/ShinyHighlight_FS.shshaderb index 408bba83d06bbbc37f21629ca6e54476d96e147a..572f3b31d0ed23942fb76dda3dfd28153ef4d70c 100644 GIT binary patch delta 922 zcmZ8gOKTHR82#pzu}w8@+M<>55lpEH1vjM?D+M7fRPeEAbjZL$2;SW&UxNzyO@CSI#^o|5CoPOUq-($|5N#D)9y*6=nY+SPA*kxbD zl2JJ=$8RRyk8~k_1p56i_ne|D>&V;nu%UF|PL*n4E!7CqcwgObw)G$P$BZYQ9737Gs#(SvpM0^MiD@Xdbdv4N~K6rxztKoratt3%gSM9-9?~$eZ{)Nu6vB|MA|KQ}B zg`Ao@q|qd`Q$rffQ5!Q_ZigCARUDzl*($ajAzlG+f`7v06CvaD902yNFoT9l~hSMB1@`s4@ z;^N>kcc%?j8K3;eYlEM~i?+9j2d(S#XJ$Lh*t7vG;a%TB+yoYZY2Y>%@h<#s zo4^v*@-lT`9$*h^D*$_Wr3hfXW4JO}Vsj^;hVjvF8ByQ0K*KGIt{8&Jz^)&yw>da=x9HX2BkEYKgvC MnzObByQNw0FQhwmj{pDw delta 837 zcmYk4OG`pQ7=}lW=bSEf11TtwN+^n`RYW(#2&^EAD7ruw(@~F=9n5MIxM&gWilIgH z2ig>byM95N+O}>{`~E@iYjem?UT5a{zWFYrxBYj0t8z&2D<~2n|i(@o0 z-i?bud!@r}dSC#Ra~BV4(2kUU>{ox|IPfwEdo_gmsO#C{fJ|XQVf~`qQ)60TU5fA7 zi4-}kyu|i7PC%0sV0U ze~tOZp%SB~KzATU_d<;B!MY2P$MEBDh&^Z&V$3cy2Qij|Bq91QkdNmSv<;C*F&zJX zWL~_)9xNyFx>y>3@Lac=!JaIJbe#4O;tR0&BIJ#f$DY0`6y}IW5bu(^x;d9zJvEK^ K66NovA@dhK(P&8k diff --git a/Assets/Shaders/TestCube_FS.glsl b/Assets/Shaders/TestCube_FS.glsl index 90b1922c..678ffb0e 100644 --- a/Assets/Shaders/TestCube_FS.glsl +++ b/Assets/Shaders/TestCube_FS.glsl @@ -17,10 +17,11 @@ layout(location = 0) in struct vec2 uv; // location = 1 vec4 normal; // location = 2 vec4 worldPos; // location = 3 + vec3 worldNormal; // location = 4 } In; // material stuff -layout(location = 4) flat in struct +layout(location = 5) flat in struct { int materialIndex; uint eid; @@ -35,7 +36,7 @@ layout (std430, set = 2, binding = 0) buffer MaterialProperties // For mater layout(location = 0) out vec4 position; layout(location = 1) out uint outEntityID; -layout(location = 2) out uint lightLayerIndices; +layout(location = 2) out uvec4 lightLayerIndices; layout(location = 3) out vec4 normals; layout(location = 4) out vec4 albedo; layout(location = 5) out vec4 worldSpacePosition; @@ -48,5 +49,5 @@ void main() worldSpacePosition = In.worldPos; outEntityID = In2.eid; - lightLayerIndices = In2.lightLayerIndex; + lightLayerIndices = uvec4 (In2.lightLayerIndex, packHalf2x16 (In.worldNormal.xy), packHalf2x16 (vec2 (In.worldNormal.z, 1.0f)), 1); } \ No newline at end of file diff --git a/Assets/Shaders/TestCube_FS.shshaderb b/Assets/Shaders/TestCube_FS.shshaderb index 2974523d7405e05bdcf30d419f0663694bcc271b..5374023a8a56c4d4726e2a1768556e058c308433 100644 GIT binary patch literal 2913 zcmZ9MTXz#x6vt1=#aeDf1Vp5!t=0=#Yb}T(U}|d!1{w&``ZQ~rIkcnGnK+qL`sRz@ zNPY3mPvwhi`TtGMDZ#VW&c6N6-uvvmC$l>zO?fIO7GE)D%FLM4=7+J#oHHk6F(v=w z^)dg`@xR1p%(Ursp9Y&dPlCt}`*}PlvOI{>$UcwLJ#*63%loZPud_TXqUE*gD}+8{ zDrE*@pH;r9ICK!kDUMe~XGBV2-ViN`z7jP>Ezzv*gIB?lDyq_$zZI;io2^dJe7qhE z?I6sf;t8T1E(U|1X_Hb~;s22q?VQ+#O2RmO3+IPE8+XcABpV)ETJ zQ!C#-$cAwdXJs#HdfzF%k5iZ5%ZD~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;&LDfKFG;41T5G;(_oN3gAe~ diff --git a/Assets/Shaders/TestCube_VS.glsl b/Assets/Shaders/TestCube_VS.glsl index 1b45c333..07b89b6b 100644 --- a/Assets/Shaders/TestCube_VS.glsl +++ b/Assets/Shaders/TestCube_VS.glsl @@ -20,11 +20,12 @@ layout(location = 0) out struct vec2 uv; // location = 1 vec4 normal; // location = 2 vec4 worldPos; // location = 3 + vec3 worldNormal; // location = 4 } Out; // material stuff -layout(location = 4) out struct +layout(location = 5) out struct { int materialIndex; uint eid; @@ -57,11 +58,13 @@ void main() // uvs for texturing in fragment shader Out.uv = aUV; - mat3 transposeInv = mat3 (transpose(inverse(modelViewMat))); + mat3 mvTransInv = mat3 (transpose(inverse(modelViewMat))); + mat3 modelTransInv = mat3 (transpose(inverse(worldTransform))); // normals are also in view space - Out.normal.rgb = transposeInv * aNormal.rgb; + Out.normal.rgb = mvTransInv * aNormal.rgb; Out.normal.rgb = normalize (Out.normal.rgb); + Out.worldNormal = normalize (modelTransInv * aNormal); // clip space for rendering gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); diff --git a/Assets/Shaders/TestCube_VS.shshaderb b/Assets/Shaders/TestCube_VS.shshaderb index 1bb76ec42331e3ece2cf26e15e72fbbb613e2633..e607761c64bec9e2e8ee7eabc6921c6bed9b9f1b 100644 GIT binary patch literal 4585 zcmZ9Nd3zI86vn4*5|Dk7Ma7!5Xi*f9rJ~3VhGL;XN>Ne6m<(YsnZ#ro7EwVFccpdz zI(`yAhX43HzP~$j!aUqQZ_hdJS?;;pWayu@o*N^><4Zhm$Xn*E^!`dHZ>={h#`BhY z1t-hX=cjk{;`)xg`*sns${TT!#H{w#IX$QUEkBGfmI*6`$AuS#J;J1LT4)IOg+<{v z;Sb?YVMKq!l7FjcP8G`2)$+_tdHQ6v*6CDx@y%vXZH7@$t%u#97Ki)C+3BC>tuHOErT!6kc`n1Z)e@vU|}XwHSf^)r5) z)X96#N;&Sgg0AmE6#ff{URC zSD!=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Oh4aXYbvj9U|TlImop~1db1H=oJw;wu;Dsj*sPdRWdnvOO}K05xC`e zO)@!nf8;>N2Rm=zP0@r1J2}S0-x7hF{*Gkc!rzL)eprMLI63JJnE8Jo84R7-`cTA7 zUsHTT{38(<%dn3ngKdO1h5NoP85`$odfYiM){OoO zafdfVbAiNs9?ohp^OA`nzs1~?3=XldRb#%8P7IjEd?^_mVp+_r&Tv)wS0ZX5H@@_V zw+PO;@%dT=W_S9nWWHg{31|6Egb(;R3J1+2X1_$b{Qo#Nh{KalJ}hwFmtWXFb3Vj2;{m zUlL7-n0uS`<$#-hPde|~zFGGr;{$GU@j&u%k@fzeWH6RtKS>6ohlc$eFzU1K(l3&U j#~=F%(X;TLewEDr_}D!@l3a+^i|7qHe*bBw6QchCv)4p1 diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index bbbbd1dd..54e5a1ff 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -141,25 +141,28 @@ namespace SHADE //SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/Trajectory_VS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/Trajectory_FS.glsl", false); + //SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMapBlur_CS.glsl", false); + //SHAssetManager::CompileAsset("../../Assets/Shaders/Anim_VS.glsl", false); // Load Built In Shaders - static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); - static constexpr AssetID VS_ANIM = 47911992; animtVertShader = SHResourceManager::LoadOrGet(VS_ANIM); - static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet(FS_DEFAULT); - static constexpr AssetID VS_DEBUG = 48002439; debugVertShader = SHResourceManager::LoadOrGet(VS_DEBUG); - static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet(FS_DEBUG); - static constexpr AssetID VS_DEBUG_MESH = 42127043; debugMeshVertShader = SHResourceManager::LoadOrGet(VS_DEBUG_MESH); - static constexpr AssetID CS_COMPOSITE = 45072428; deferredCompositeShader = SHResourceManager::LoadOrGet(CS_COMPOSITE); - static constexpr AssetID SSAO = 38430899; ssaoShader = SHResourceManager::LoadOrGet(SSAO); - static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet(SSAO_BLUR); - static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet(TEXT_VS); - static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet(TEXT_FS); - static constexpr AssetID RENDER_SC_VS = 48082949; renderToSwapchainVS = SHResourceManager::LoadOrGet(RENDER_SC_VS); - static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet(RENDER_SC_FS); - static constexpr AssetID SHADOW_MAP_VS = 44646107; shadowMapVS = SHResourceManager::LoadOrGet(SHADOW_MAP_VS); - static constexpr AssetID SHADOW_MAP_FS = 45925790; shadowMapFS = SHResourceManager::LoadOrGet(SHADOW_MAP_FS); - static constexpr AssetID TRAJECTORY_VS = 41042628; trajectoryVS = SHResourceManager::LoadOrGet(TRAJECTORY_VS); - static constexpr AssetID TRAJECTORY_FS = 45635685; trajectoryFS = SHResourceManager::LoadOrGet(TRAJECTORY_FS); + static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); + static constexpr AssetID VS_ANIM = 47911992; animtVertShader = SHResourceManager::LoadOrGet(VS_ANIM); + static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet(FS_DEFAULT); + static constexpr AssetID VS_DEBUG = 48002439; debugVertShader = SHResourceManager::LoadOrGet(VS_DEBUG); + static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet(FS_DEBUG); + static constexpr AssetID VS_DEBUG_MESH = 42127043; debugMeshVertShader = SHResourceManager::LoadOrGet(VS_DEBUG_MESH); + static constexpr AssetID CS_COMPOSITE = 45072428; deferredCompositeShader = SHResourceManager::LoadOrGet(CS_COMPOSITE); + static constexpr AssetID SSAO = 38430899; ssaoShader = SHResourceManager::LoadOrGet(SSAO); + static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet(SSAO_BLUR); + static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet(TEXT_VS); + static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet(TEXT_FS); + static constexpr AssetID RENDER_SC_VS = 48082949; renderToSwapchainVS = SHResourceManager::LoadOrGet(RENDER_SC_VS); + static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet(RENDER_SC_FS); + static constexpr AssetID SHADOW_MAP_VS = 44646107; shadowMapVS = SHResourceManager::LoadOrGet(SHADOW_MAP_VS); + static constexpr AssetID SHADOW_MAP_FS = 45925790; shadowMapFS = SHResourceManager::LoadOrGet(SHADOW_MAP_FS); + static constexpr AssetID TRAJECTORY_VS = 41042628; trajectoryVS = SHResourceManager::LoadOrGet(TRAJECTORY_VS); + static constexpr AssetID TRAJECTORY_FS = 45635685; trajectoryFS = SHResourceManager::LoadOrGet(TRAJECTORY_FS); + static constexpr AssetID SHADOW_BLUR_CS = 38004013; shadowMapBlurCS = SHResourceManager::LoadOrGet(SHADOW_BLUR_CS); } @@ -217,7 +220,7 @@ namespace SHADE renderGraph->AddResource("Albedo", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second); renderGraph->AddResource("Depth Buffer", { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT }, true, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); renderGraph->AddResource("Entity ID", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, true, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); - renderGraph->AddResource("Light Layer Indices", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); + renderGraph->AddResource("Light Layer Indices And World Normals", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); renderGraph->AddResource("Scene", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE, SH_RENDER_GRAPH_RESOURCE_FLAGS::SHARED }, true, windowDims.first, windowDims.second); renderGraph->AddResource("SSAO", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR8Unorm); renderGraph->AddResource("SSAO Blur", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, true, windowDims.first, windowDims.second, vk::Format::eR8Unorm); @@ -231,7 +234,7 @@ namespace SHADE { "Position", "Entity ID", - "Light Layer Indices", + "Light Layer Indices And World Normals", "Normals", "Albedo", "Depth Buffer", @@ -248,7 +251,7 @@ namespace SHADE auto gBufferSubpass = gBufferNode->AddSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS.data(), worldViewport, worldRenderer); gBufferSubpass->AddColorOutput("Position"); gBufferSubpass->AddColorOutput("Entity ID"); - gBufferSubpass->AddColorOutput("Light Layer Indices"); + gBufferSubpass->AddColorOutput("Light Layer Indices And World Normals"); gBufferSubpass->AddColorOutput("Normals"); gBufferSubpass->AddColorOutput("Albedo"); gBufferSubpass->AddColorOutput("Position World Space"); @@ -258,7 +261,7 @@ namespace SHADE auto gBufferVfxSubpass = gBufferNode->AddSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_VFX_SUBPASS.data(), worldViewport, worldRenderer); gBufferVfxSubpass->AddColorOutput("Position"); gBufferVfxSubpass->AddColorOutput("Entity ID"); - gBufferVfxSubpass->AddColorOutput("Light Layer Indices"); + gBufferVfxSubpass->AddColorOutput("Light Layer Indices And World Normals"); gBufferVfxSubpass->AddColorOutput("Normals"); gBufferVfxSubpass->AddColorOutput("Albedo"); gBufferVfxSubpass->AddColorOutput("Position World Space"); @@ -314,7 +317,7 @@ namespace SHADE auto deferredCompositeNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data(), { "Position", - "Light Layer Indices", + "Light Layer Indices And World Normals", "Normals", "Albedo", "Scene", @@ -327,7 +330,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data(), deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Position World Space", "Scene", "Object VFX"}, {}, SHLightingSubSystem::MAX_SHADOWS); + auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data(), deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices And World Normals", "SSAO Blur", "Position World Space", "Scene", "Object VFX"}, {}, SHLightingSubSystem::MAX_SHADOWS); deferredCompositeCompute->AddPreComputeFunction([=](Handle cmdBuffer, uint32_t frameIndex) { lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer); @@ -669,21 +672,21 @@ namespace SHADE #endif } - //static bool shadowAdded = false; + static bool shadowAdded = false; - //if (shadowAdded == false && SHInputManager::GetKey(SHInputManager::SH_KEYCODE::B)) - //{ - // shadowAdded = true; - // auto& lightComps = SHComponentManager::GetDense(); - // //if (lightComps.size() > 2) - // //{ - // // lightComps[2].SetEnableShadow(true); - // //} - // for (auto& comp : lightComps) - // { - // comp.SetEnableShadow(true); - // } - //} + if (shadowAdded == false && SHInputManager::GetKey(SHInputManager::SH_KEYCODE::B)) + { + shadowAdded = true; + auto& lightComps = SHComponentManager::GetDense(); + if (lightComps.size() > 2) + { + lightComps[2].SetEnableShadow(true); + } + for (auto& comp : lightComps) + { + comp.SetEnableShadow(true); + } + } renderGraph->Begin(frameIndex); auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex); @@ -866,6 +869,7 @@ namespace SHADE auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); std::string depthResourceName = "ShadowMap_Depth " + std::to_string(EVENT_DATA->lightEntity); std::string shadowMapResourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); + std::string shadowMapBlurredResourceName = "ShadowMap Blurred" + std::to_string(EVENT_DATA->lightEntity); Handle companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS); if (EVENT_DATA->generateRenderer) @@ -878,17 +882,31 @@ namespace SHADE lightComp->SetShadowMapIndex (lightingSubSystem->GetNumShadowMaps()); } + // Add the shadow map resource to the graph renderGraph->AddResource(depthResourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH}, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eD32Sfloat); - renderGraph->AddResource(shadowMapResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eR32G32B32A32Sfloat); + renderGraph->AddResource(shadowMapResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eR32G32B32A32Sfloat); + renderGraph->AddResource(shadowMapBlurredResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eR32G32B32A32Sfloat); + + // link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer. - auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, {depthResourceName.c_str(), shadowMapResourceName.c_str()}, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data()); + auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, {depthResourceName.c_str(), shadowMapResourceName.c_str(), shadowMapBlurredResourceName.c_str()}, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data()); // Add a subpass to render to that shadow map - auto newSubpass = shadowMapNode->RuntimeAddSubpass(shadowMapResourceName + " Subpass", shadowMapViewport, lightComp->GetRenderer()); - newSubpass->AddColorOutput(shadowMapResourceName); - newSubpass->AddDepthOutput(depthResourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH); + auto shadowMapDrawSubpass = shadowMapNode->RuntimeAddSubpass(shadowMapResourceName + " Subpass", shadowMapViewport, lightComp->GetRenderer()); + shadowMapDrawSubpass->AddColorOutput(shadowMapResourceName); + shadowMapDrawSubpass->AddDepthOutput(depthResourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH); + + // add dummy subpass to transition the shadow map images for compute shader usage + //auto dummySubpass = shadowMapNode->RuntimeAddSubpass(shadowMapResourceName + "Dummy", {}, {}); + //dummySubpass->AddGeneralColorOutput(shadowMapResourceName); + //dummySubpass->AddGeneralColorOutput(shadowMapBlurredResourceName); + + // add compute pass to blur shadow ma + shadowMapNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, shadowMapBlurCS, { shadowMapResourceName.c_str(), shadowMapBlurredResourceName.c_str() }); + //shadowMapNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, shadowMapBlurCS, { shadowMapBlurredResourceName.c_str(), shadowMapResourceName.c_str() }); + //shadowMapNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, shadowMapBlurCS, { shadowMapResourceName.c_str(), shadowMapBlurredResourceName.c_str() }); // regenerate the node shadowMapNode->RuntimeStandaloneRegenerate(); @@ -905,16 +923,16 @@ namespace SHADE tempLibrary.Init(device); tempLibrary.CreateGraphicsPipelines ( - { shadowMapVS, shadowMapFS }, shadowMapNode->GetRenderpass(), newSubpass, + { shadowMapVS, shadowMapFS }, shadowMapNode->GetRenderpass(), shadowMapDrawSubpass, SHGraphicsPredefinedData::SystemType::BATCHING, SHGraphicsPredefinedData::GetShadowMapViState(), rasterState ); - shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, shadowMapFS, newSubpass }); + shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, shadowMapFS, shadowMapDrawSubpass }); } - newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline + shadowMapDrawSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline - // add the shadow map to the lighting system - uint32_t const NEW_SHADOW_MAP_INDEX = lightingSubSystem->AddShadowMap(renderGraph->GetRenderGraphResource(shadowMapResourceName), EVENT_DATA->lightEntity); + // add the shadow map and the blurred version to the lighting system + uint32_t const NEW_SHADOW_MAP_INDEX = lightingSubSystem->AddShadowMap(renderGraph->GetRenderGraphResource(shadowMapBlurredResourceName), EVENT_DATA->lightEntity); auto nodeCompute = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data())->GetNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data()); nodeCompute->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, lightingSubSystem->GetViewSamplerLayout(NEW_SHADOW_MAP_INDEX), NEW_SHADOW_MAP_INDEX); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 0b98f843..33227f8f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -481,6 +481,7 @@ namespace SHADE Handle shadowMapFS; Handle trajectoryVS; Handle trajectoryFS; + Handle shadowMapBlurCS; // Fonts Handle testFont; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index cace495c..cd308487 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -53,7 +53,8 @@ namespace SHADE SHVec4 transformedDir = SHMatrix::Transpose(viewMat) * SHVec4(lightData.direction[0], lightData.direction[1], lightData.direction[2], 0.0f); lightPtr->cullingMask = lightData.cullingMask; - lightPtr->direction = SHVec3 (transformedDir.x, transformedDir.y, transformedDir.z); + lightPtr->directionWorld = SHVec4 (lightData.direction.x, lightData.direction.y, lightData.direction.z, 1.0f); + lightPtr->direction = SHVec3(transformedDir.x, transformedDir.y, transformedDir.z); //lightPtr->direction = lightData.direction; lightPtr->diffuseColor = lightData.color; lightPtr->active = lightComp->isActive; @@ -601,14 +602,14 @@ namespace SHADE } - uint32_t SHLightingSubSystem::AddShadowMap(Handle newShadowMap, EntityID lightEntity) noexcept + uint32_t SHLightingSubSystem::AddShadowMap(Handle newShadowMapBlurred, EntityID lightEntity) noexcept { // Add to container of shadow maps shadowMapIndexing.emplace(lightEntity, static_cast (shadowMaps.size())); - shadowMaps.emplace_back(newShadowMap); + shadowMaps.emplace_back(newShadowMapBlurred); // Just use the image view stored in the resource - Handle const NEW_IMAGE_VIEW = newShadowMap->GetImageView(); + Handle const NEW_IMAGE_VIEW = newShadowMapBlurred->GetImageView(); // Prepare to write to descriptor shadowMapImageSamplers.emplace_back(NEW_IMAGE_VIEW, shadowMapSampler, vk::ImageLayout::eShaderReadOnlyOptimal); @@ -634,13 +635,13 @@ namespace SHADE // add to barriers shadowMapMemoryBarriers.push_back (vk::ImageMemoryBarrier { - .srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite | vk::AccessFlagBits::eColorAttachmentRead, + .srcAccessMask = vk::AccessFlagBits::eShaderWrite, .dstAccessMask = vk::AccessFlagBits::eShaderRead, - .oldLayout = vk::ImageLayout::eColorAttachmentOptimal, - .newLayout = vk::ImageLayout::eShaderReadOnlyOptimal, + .oldLayout = vk::ImageLayout::eGeneral, + .newLayout = vk::ImageLayout::eGeneral, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, - .image = newShadowMap->GetImage()->GetVkImage(), + .image = newShadowMapBlurred->GetImage()->GetVkImage(), .subresourceRange = vk::ImageSubresourceRange { .aspectMask = vk::ImageAspectFlagBits::eColor, @@ -658,7 +659,7 @@ namespace SHADE void SHLightingSubSystem::PrepareShadowMapsForRead(Handle cmdBuffer) noexcept { // Issue barrier to transition shadow maps for reading in compute shader - cmdBuffer->PipelineBarrier(vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eComputeShader, {}, {}, {}, shadowMapMemoryBarriers); + cmdBuffer->PipelineBarrier(vk::PipelineStageFlagBits::eComputeShader, vk::PipelineStageFlagBits::eComputeShader, {}, {}, {}, shadowMapMemoryBarriers); } //void SHLightingSubSystem::HandleResize(Handle compute) noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index 69b00f2c..3613f762 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -28,6 +28,9 @@ namespace SHADE // Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU. struct SHDirectionalLightData { + //! Direction of the light + SHVec4 directionWorld; + //! Direction of the light SHVec3 direction; @@ -213,7 +216,7 @@ namespace SHADE void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; void Exit (void) noexcept; void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; - uint32_t AddShadowMap (Handle newShadowMap, EntityID lightEntity) noexcept; + uint32_t AddShadowMap (Handle newShadowMapBlurred, EntityID lightEntity) noexcept; void PrepareShadowMapsForRead (Handle cmdBuffer) noexcept; //void HandleResize (Handle compute) noexcept; //void RemoveShadowMap (uint32_t index) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 34bfe8cd..36d2e20a 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -798,6 +798,7 @@ namespace SHADE /***************************************************************************/ void SHRenderGraphNode::RuntimeStandaloneRegenerate(void) noexcept { + AddDummySubpassIfNeeded(); StandaloneConfigureAttDesc(false); ConfigureSubpasses(); CreateRenderpass(); -- 2.40.1 From b6b2c75fc3b228bce3958e77e999fcbce72cb152 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Tue, 7 Mar 2023 17:39:51 +0800 Subject: [PATCH 3/6] Implemented Shadows (f0kin finally) --- Assets/Shaders/ShinyHighlight_FS.glsl | 8 ++++-- Assets/Shaders/ShinyHighlight_FS.shshaderb | Bin 5397 -> 5733 bytes Assets/Shaders/ShinyHighlight_VS.glsl | 9 ++++--- Assets/Shaders/ShinyHighlight_VS.shshaderb | Bin 5705 -> 6141 bytes .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 16 ++++++------ .../src/Graphics/RenderGraph/SHSubpass.cpp | 23 ++++++++++-------- .../src/Graphics/RenderGraph/SHSubpass.h | 7 +++--- 7 files changed, 38 insertions(+), 25 deletions(-) diff --git a/Assets/Shaders/ShinyHighlight_FS.glsl b/Assets/Shaders/ShinyHighlight_FS.glsl index be26f866..18f979fe 100644 --- a/Assets/Shaders/ShinyHighlight_FS.glsl +++ b/Assets/Shaders/ShinyHighlight_FS.glsl @@ -32,10 +32,11 @@ layout(location = 0) in struct vec2 uv; // location = 1 vec4 normal; // location = 2 vec4 worldPos; // location = 3 + vec3 worldNormal; // location = 4 } In; // material stuff -layout(location = 4) flat in struct +layout(location = 5) flat in struct { int materialIndex; uint eid; @@ -72,10 +73,11 @@ void main() { position = In.vertPos; normals = In.normal; - albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv); + albedo = vec4 (texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv).xyz, 1.0f); worldSpacePosition = In.worldPos; outEntityID = In2.eid; + lightLayerIndices = uvec4 (In2.lightLayerIndex, 0, 0, 1); // float vpHeight = float (In2.screenSpacePos.y) - MatProp.data[In2.materialIndex].highlightPosition; // bring the frame of reference to the object's screen space pos @@ -100,4 +102,6 @@ void main() } else objectVFX = vec4(0.0f, 0.0f, 0.0f, 1.0f); + + objectVFX.a = 1.0f; } \ No newline at end of file diff --git a/Assets/Shaders/ShinyHighlight_FS.shshaderb b/Assets/Shaders/ShinyHighlight_FS.shshaderb index 572f3b31d0ed23942fb76dda3dfd28153ef4d70c..a3a6230df5e550a976d687e26fd3bab001c76575 100644 GIT binary patch literal 5733 zcmZ9O`*&2;6~`}RCV>zhR>WG{Gy#jYSgI6XMT0@YByE&vD4?|+FEcmEmC4-k&YcAM z0Fhd$wzieNpJLw?r4O`-wRZWFe?k9~u0GakSHGWg&rU9LV6Xk%-@VU1`|NYhoosk? zQ{YC=$}N3Cup;OW)&_seso<($rI^6!*EZ(*b+6x)?hjT4(^ChlV}}n^>ruOw#;q(# zt8ud)9gCZ@!J44g&96*OPi}8#_3b-vyM@&2f*!X5x!3DoNgA0C<0g(_$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w|>A-i77AP4>9tA*YAjyLebO zZ;}{%)!2i=_-9ocb0;Kl?-|+T;LX{-AC(PH{9$P@@w~OqIDU0a?&7f(e!%@Mf|<)5;_Z#==JL+I z;P~EJyg}CEPJeO5H{k9WnDyxMmn8jtjyylE8+1Z;Q(}F_XZ;{|%ln`5YsH?+gz5X7 z1ddw3^AhTQQR{;jB*ehyK1bqtoAabFb1wKfCuPHNmuyZd8~z!^3`#Fb$OBKWLeE)G zGGREwxoqCx(|&$iHXL!x#|LM9D;$6Ao$H8$x4xCKt#A0K*VgOG#&2hLS~lmvJ>mOj zac5-XvweM8Hs3Ay=X|YSkxf2)#(hmTJl{_0=lcO?d7qNao(!LpO^mJcv}|I|Ntl0D z8qVUMkzJkttT6Mff6vJ#2A=unrQzrwcl8Cy1xfXue%|3mMBdR~&S zZe2n=Yf{(ur5V&k%*&ErNvI2(e(-&MMPfDnPyzL1{&SCsvwU!t?-#PkH>0z< zRr;3_xT-MkE$`!uIXBLTvohb?va3E~{;SIFm+(7Jt?ZMrR&t+m4oR=8*uxcjeZ?NB z*c)WC_9kiD!)DpU7`|RMc@4iuHo2`QH^?Ri-eR`MCb!|OvdL+4Zj?<7ynQ=vl1(mr qHt)T%son6+va4&qPna0^7kpoCkxedq_FZ_tZ1#okf7&mYUj83_h%5sD diff --git a/Assets/Shaders/ShinyHighlight_VS.glsl b/Assets/Shaders/ShinyHighlight_VS.glsl index c0268737..483af1f0 100644 --- a/Assets/Shaders/ShinyHighlight_VS.glsl +++ b/Assets/Shaders/ShinyHighlight_VS.glsl @@ -17,6 +17,7 @@ layout(location = 0) out struct vec2 uv; // location = 1 vec4 normal; // location = 2 vec4 worldPos; // location = 3 + vec3 worldNormal; // location = 4 } Out; @@ -36,7 +37,7 @@ struct GenericData }; // material stuff -layout(location = 4) out struct +layout(location = 5) out struct { int materialIndex; uint eid; @@ -76,11 +77,13 @@ void main() // uvs for texturing in fragment shader Out.uv = aUV; - mat3 transposeInv = mat3 (transpose(inverse(modelViewMat))); + mat3 mvTransInv = mat3 (transpose(inverse(modelViewMat))); + mat3 modelTransInv = mat3 (transpose(inverse(worldTransform))); // normals are also in view space - Out.normal.rgb = transposeInv * aNormal.rgb; + Out.normal.rgb = mvTransInv * aNormal.rgb; Out.normal.rgb = normalize (Out.normal.rgb); + Out.worldNormal = normalize (modelTransInv * aNormal); // Get center of object in world position vec4 worldPos = vec4(worldTransform[3][0], worldTransform[3][1], worldTransform[3][2], 1.0f); diff --git a/Assets/Shaders/ShinyHighlight_VS.shshaderb b/Assets/Shaders/ShinyHighlight_VS.shshaderb index 9818708504495b5706c860c5448aa90b2077dc57..95eac304277d9591e76c296a0c74bea47b4eb2ad 100644 GIT binary patch literal 6141 zcmZ9O>w8>P6^BogCMnQTpi)q2O%uS@LahR|inQqk(_$dOhE_!l$C;CK>SSh|Owtxn zT4@#UwBGNaNG;y)R}}GzBKpVp!7o0K?|bH~3U`RMH# z9!QcE$)(AfuuY0xjgC3J@r|eT$Rf!`F}R8 zHB?rEwO~EC8QcPPfV;p9cm_NVUH~tGe}P{9^)Nq2(v?&*IyN;rK0Z2j=TxQDnwsmJ ztY=g8S|gjP*4kO6Q(MUNTUGL_H7fP_YT2O=k8)jotZ^x8IQo-;MR_*uWbIm7KiH^d zCvuw=*p(#7YSl$w>#Nshj&{b7T zo9%javYj^Orkm|q_tu-d2Hs(=kQcIc$7b}?3pwkUUs&?7h6WkZx?F$mV-0!!yo*b` zXPNW&bOT(|yG4KVTD@cGVHV6z6#ehb?_7G{;oLrfeRd%)`e1_^+{^uP_IHVfUzy+2 zba9=&ALsl0(@!Bz4O!4Sv!yGOSCzvULJ<`?IQEcQjLrL?)^8~>QfV0 zyW2EltXbZnEv}Mv$-9@F=b|2}J;*EU)~wC_VB1%(wf5J#_dDN@Hus}#zFuFnd47Hi z9QM<1LOPi?sJFQ1{rNW{-P>&VQfifqSJgc?zZ*G!ByY|l@3&;S)}HGWF+S+g;vH_x zW4pTFr^~=rpnW~F_Eq2jwfJTn!`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UVrVr=Xj5QMs|ID+`|FpzktiYJK-MH L_4_Z~*bn{(aS`y8 diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 54e5a1ff..999337ae 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -128,7 +128,7 @@ namespace SHADE SHFreetypeInstance::Init(); - //SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false); + SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false); @@ -865,12 +865,13 @@ namespace SHADE // we need to wait for the device to finish using the graph first device->WaitIdle(); - auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; - auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); - std::string depthResourceName = "ShadowMap_Depth " + std::to_string(EVENT_DATA->lightEntity); - std::string shadowMapResourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); + auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; + auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); + std::string depthResourceName = "ShadowMap_Depth " + std::to_string(EVENT_DATA->lightEntity); + std::string shadowMapResourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); std::string shadowMapBlurredResourceName = "ShadowMap Blurred" + std::to_string(EVENT_DATA->lightEntity); - Handle companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS); + Handle gBufferWriteSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS); + Handle gBufferWriteVfxSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_VFX_SUBPASS); if (EVENT_DATA->generateRenderer) { @@ -929,7 +930,8 @@ namespace SHADE ); shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, shadowMapFS, shadowMapDrawSubpass }); } - shadowMapDrawSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline + shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteSubpass, shadowMapPipeline); // set companion subpass and pipeline + shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteVfxSubpass, shadowMapPipeline); // set companion subpass and pipeline // add the shadow map and the blurred version to the lighting system uint32_t const NEW_SHADOW_MAP_INDEX = lightingSubSystem->AddShadowMap(renderGraph->GetRenderGraphResource(shadowMapBlurredResourceName), EVENT_DATA->lightEntity); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 14a5d864..db78c5aa 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -77,7 +77,7 @@ namespace SHADE , name { rhs.name } , viewport {rhs.viewport} , renderer {rhs.renderer} - , companionSubpass {rhs.companionSubpass} + , companionSubpasses {std::move (rhs.companionSubpasses)} , dummyPipelineLayout{rhs.dummyPipelineLayout} { @@ -115,7 +115,7 @@ namespace SHADE name = std::move(rhs.name); renderer = rhs.renderer; viewport = rhs.viewport; - companionSubpass = rhs.companionSubpass; + companionSubpasses = rhs.companionSubpasses; dummyPipelineLayout = rhs.dummyPipelineLayout; @@ -237,17 +237,19 @@ namespace SHADE BindInputDescriptorSets (commandBuffer, descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_RESOURCE), frameIndex); - // If companion subpass is not a valid handle, render super batch normally - if (!companionSubpass.companion) + if (companionSubpasses.empty()) { // Draw all the batches superBatch->Draw(commandBuffer, frameIndex); } else { - // if not bind pipeline for companion and and execute draw command - commandBuffer->BindPipeline(companionSubpass.pipeline); - companionSubpass.companion->superBatch->Draw(commandBuffer, frameIndex, false); + for (auto& companion : companionSubpasses) + { + // if not bind pipeline for companion and and execute draw command + commandBuffer->BindPipeline(companion.pipeline); + companion.subpass->superBatch->Draw(commandBuffer, frameIndex, false); + } } } @@ -493,10 +495,11 @@ namespace SHADE subpassIndex = index; } - void SHSubpass::SetCompanionSubpass(Handle companion, Handle pipeline) noexcept + void SHSubpass::AddCompanionSubpass(Handle companion, Handle pipeline) noexcept { - companionSubpass.companion = companion; - companionSubpass.pipeline = pipeline; + companionSubpasses.push_back(CompanionSubpass{companion, pipeline}); + //companionSubpass.companion = companion; + //companionSubpass.pipeline = pipeline; } /***************************************************************************/ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index 1300ee2b..640ccb2d 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -33,7 +33,7 @@ namespace SHADE struct CompanionSubpass { // subpass whose data will be borrowed to draw - Handle companion; + Handle subpass; // Pipeline that will be used for all the draw calls from all batches of the companion subpass Handle pipeline; @@ -114,7 +114,8 @@ namespace SHADE //! Optional component to a companion subpass. If the subpass handle of this object //! is valid, the subpass will be drawn using this companion's data. - CompanionSubpass companionSubpass; + //CompanionSubpass companionSubpass; + std::vector companionSubpasses; private: /*-----------------------------------------------------------------------*/ @@ -165,7 +166,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - void SetCompanionSubpass (Handle companion, Handle pipeline) noexcept; + void AddCompanionSubpass (Handle companion, Handle pipeline) noexcept; Handle GetParentNode(void) const noexcept; SHSubPassIndex GetIndex() const noexcept; -- 2.40.1 From ff4c294313cf3bb9f1b09338af92283b93560f7a Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Tue, 7 Mar 2023 18:43:59 +0800 Subject: [PATCH 4/6] Added dynamic flags for render graph nodes and light comp shadow flags --- .../Inspector/SHEditorComponentView.hpp | 1 + .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 16 ---------------- .../MiddleEnd/Lights/SHLightComponent.cpp | 6 ++++++ .../MiddleEnd/Lights/SHLightComponent.h | 1 + .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 2 +- .../src/Graphics/RenderGraph/SHRenderGraph.cpp | 6 +++++- .../Graphics/RenderGraph/SHRenderGraphNode.cpp | 18 +++++++++++++++++- .../Graphics/RenderGraph/SHRenderGraphNode.h | 13 ++++++++++++- 8 files changed, 43 insertions(+), 20 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 8adb45b5..9ebd47bc 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -470,6 +470,7 @@ namespace SHADE SHEditorWidgets::DragVec3("Direction", { "X", "Y", "Z" }, [component]() {return component->GetDirection(); }, [component](SHVec3 const& vec) {component->SetDirection(vec); }); SHEditorWidgets::ColorPicker("Color", [component]() {return component->GetColor(); }, [component](SHVec4 const& rgba) {component->SetColor(rgba); }); SHEditorWidgets::DragFloat("Strength", [component]() {return component->GetStrength(); }, [component](float const& value) {component->SetStrength(value); }); + SHEditorWidgets::CheckBox("Casting Shadows", [comp = component]() {return comp->GetEnableShadow(); }, [comp = component](bool b) {comp->SetEnableShadow(b);}); } else { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 999337ae..69b4503c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -672,22 +672,6 @@ namespace SHADE #endif } - static bool shadowAdded = false; - - if (shadowAdded == false && SHInputManager::GetKey(SHInputManager::SH_KEYCODE::B)) - { - shadowAdded = true; - auto& lightComps = SHComponentManager::GetDense(); - if (lightComps.size() > 2) - { - lightComps[2].SetEnableShadow(true); - } - for (auto& comp : lightComps) - { - comp.SetEnableShadow(true); - } - } - renderGraph->Begin(frameIndex); auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index 6943ec09..61552614 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -190,6 +190,11 @@ namespace SHADE return renderer; } + bool SHLightComponent::GetEnableShadow(void) const noexcept + { + return lightData.castShadows; + } + } RTTR_REGISTRATION @@ -212,5 +217,6 @@ RTTR_REGISTRATION .property("Color", &SHLightComponent::GetColor, &SHLightComponent::SetColor) .property("Layer", &SHLightComponent::GetCullingMask, &SHLightComponent::SetCullingMask) .property("Strength", &SHLightComponent::GetStrength, &SHLightComponent::SetStrength) + .property("Casting Shadows", &SHLightComponent::GetEnableShadow, &SHLightComponent::SetEnableShadow) ; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h index 4974f3f5..a90d23b0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h @@ -69,6 +69,7 @@ namespace SHADE //uint32_t GetIndexInBuffer (void) const noexcept; float GetStrength (void) const noexcept; Handle GetRenderer (void) const noexcept; + bool GetEnableShadow (void) const noexcept; RTTR_ENABLE() }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index cd308487..f89582fc 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -526,7 +526,7 @@ namespace SHADE if (auto renderer = light.GetRenderer()) { //SHMatrix orthoMatrix = SHMatrix::OrthographicRH() - renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(12.0f, 12.0f, 1.0f, 80.0f)); + renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(15.0f, 15.0f, 1.0f, 80.0f)); } auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index e4e6889c..04d4af0b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -479,7 +479,7 @@ namespace SHADE // get target node auto targetNode = nodes.begin() + nodeIndexing.at(nodeToAddAfter); - auto node = nodes.insert(targetNode, renderGraphStorage->resourceHub->Create(nodeName, renderGraphStorage, std::move(descInitParams), std::vector>())); + auto node = nodes.insert(targetNode, renderGraphStorage->resourceHub->Create(nodeName, renderGraphStorage, std::move(descInitParams), std::vector>(), true)); ReindexNodes (); return *node; @@ -583,6 +583,10 @@ namespace SHADE for (auto& node : nodes) { + // if node is dynamic check for active flag + if ((node->isDynamic) ? !node->dynamicIsActive : false) + continue; + if (node->renderpass) { // bind static global data diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 36d2e20a..2f316c79 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -292,7 +292,7 @@ namespace SHADE */ /***************************************************************************/ - SHRenderGraphNode::SHRenderGraphNode(std::string nodeName, Handle renderGraphStorage, std::vector attDescInitParams, std::vector> predecessors) noexcept + SHRenderGraphNode::SHRenderGraphNode(std::string nodeName, Handle renderGraphStorage, std::vector attDescInitParams, std::vector> predecessors, bool inIsDynamic) noexcept : graphStorage{ renderGraphStorage} , renderpass{} , framebuffers{} @@ -305,6 +305,8 @@ namespace SHADE , configured{ false } , nodeComputes{} , name { std::move(nodeName) } + , dynamicIsActive {true} // default set to true + , isDynamic{inIsDynamic} { // pipeline library initialization pipelineLibrary.Init(graphStorage->logicalDevice); @@ -368,6 +370,8 @@ namespace SHADE , nodeComputes{ std::move(rhs.nodeComputes) } , name { std::move(rhs.name) } , ISelfHandle{std::move(rhs)} + , dynamicIsActive {rhs.dynamicIsActive} + , isDynamic {rhs.isDynamic} { rhs.renderpass = {}; @@ -393,6 +397,8 @@ namespace SHADE spDeps = std::move(rhs.spDeps); nodeComputes = std::move(rhs.nodeComputes); name = std::move(rhs.name); + dynamicIsActive = rhs.dynamicIsActive; + isDynamic = rhs.isDynamic; rhs.renderpass = {}; @@ -805,6 +811,11 @@ namespace SHADE CreateFramebuffer(); } + void SHRenderGraphNode::SetDynamicActive(bool active) noexcept + { + dynamicIsActive = active; + } + /***************************************************************************/ /*! @@ -850,4 +861,9 @@ namespace SHADE return {}; } + bool SHRenderGraphNode::GetDynamicActive(void) const noexcept + { + return dynamicIsActive; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index b070b8fa..2877fdee 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -80,6 +80,13 @@ namespace SHADE //! Whether or not the node has been configured already or not bool configured; + //! Whether or not the rendergraph should be executed. Should ONLY be used for dynamic + //! nodes that are independent from other nodes. + bool dynamicIsActive; + + //! True if the function is dynamic + bool isDynamic; + //! Manages batching for this RenderPass SHBatcher batcher; @@ -101,7 +108,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ /*-----------------------------------------------------------------------*/ - SHRenderGraphNode(std::string nodeName, Handle renderGraphStorage, std::vector attDescInitParams, std::vector> predecessors) noexcept; + SHRenderGraphNode(std::string nodeName, Handle renderGraphStorage, std::vector attDescInitParams, std::vector> predecessors, bool inIsDynamic = false) noexcept; SHRenderGraphNode(SHRenderGraphNode&& rhs) noexcept; SHRenderGraphNode& operator= (SHRenderGraphNode&& rhs) noexcept; @@ -123,11 +130,15 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ + void SetDynamicActive(bool active) noexcept; + Handle GetRenderpass(void) const noexcept; Handle GetSubpass(std::string_view subpassName) const noexcept; Handle GetResource (uint32_t resourceIndex) const noexcept; std::vector> const& GetResources (void) const noexcept; Handle GetNodeCompute (std::string nodeComputeName) const noexcept; + bool GetDynamicActive (void) const noexcept; + friend class SHRenderGraph; }; -- 2.40.1 From 64e60a511438f07bcc4ee6c1115be64ef6b0a6cc Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 8 Mar 2023 09:38:07 +0800 Subject: [PATCH 5/6] Added editor functionality for lights to enable shadows --- SHADE_Engine/src/Events/SHEventDefines.h | 1 + .../src/Graphics/Events/SHGraphicsEvents.h | 13 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 169 +++++++++++------- .../MiddleEnd/Interface/SHGraphicsSystem.h | 1 + .../MiddleEnd/Lights/SHLightComponent.cpp | 19 +- .../MiddleEnd/Lights/SHLightComponent.h | 2 + .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 110 +++++++----- .../MiddleEnd/Lights/SHLightingSubSystem.h | 22 +-- .../Graphics/RenderGraph/SHRenderGraph.cpp | 22 ++- .../src/Graphics/RenderGraph/SHRenderGraph.h | 1 + .../RenderGraph/SHRenderGraphNode.cpp | 16 ++ .../Graphics/RenderGraph/SHRenderGraphNode.h | 11 +- .../src/Graphics/RenderGraph/SHSubpass.cpp | 35 +++- .../src/Graphics/RenderGraph/SHSubpass.h | 1 + 14 files changed, 290 insertions(+), 133 deletions(-) diff --git a/SHADE_Engine/src/Events/SHEventDefines.h b/SHADE_Engine/src/Events/SHEventDefines.h index a7447be0..e03dfd82 100644 --- a/SHADE_Engine/src/Events/SHEventDefines.h +++ b/SHADE_Engine/src/Events/SHEventDefines.h @@ -30,4 +30,5 @@ constexpr SHEventIdentifier SH_BUTTON_RELEASE_EVENT { 21 }; constexpr SHEventIdentifier SH_BUTTON_HOVER_ENTER_EVENT { 22 }; constexpr SHEventIdentifier SH_BUTTON_HOVER_EXIT_EVENT { 23 }; constexpr SHEventIdentifier SH_ASSET_COMPILE_EVENT { 24 }; +constexpr SHEventIdentifier SH_LIGHT_DELETE_EVENT { 25 }; diff --git a/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h b/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h index 51cd7aa2..e8f00c8a 100644 --- a/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h +++ b/SHADE_Engine/src/Graphics/Events/SHGraphicsEvents.h @@ -6,13 +6,16 @@ namespace SHADE { - struct SHLightEnableShadowEvent + struct SHLightShadowEvent { //! We need to get the light component and initialize the relevant variables. EntityID lightEntity; //! Generate a renderer for the light component - bool generateRenderer; + bool firstEnable; + + //! True when light is set enable shadow + bool enableShadow; }; struct SHWindowResizeEvent @@ -23,4 +26,10 @@ namespace SHADE // New height when window resizes uint32_t resizeHeight; }; + + struct SHDeleteLightEvent + { + //! Entity of the light we are deleting + EntityID lightEntity; + }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 69b4503c..22f0423d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -537,12 +537,21 @@ namespace SHADE ReceiverPtr lightEnableShadowReceivePtr = std::dynamic_pointer_cast(lightEnableShadowReceiver); SHEventManager::SubscribeTo(SH_GRAPHICS_LIGHT_ENABLE_SHADOW_EVENT, lightEnableShadowReceivePtr); + std::shared_ptr> lightDeleteEvent + { + std::make_shared>(this, &SHGraphicsSystem::ReceiveLightDeleteEvent) + }; + ReceiverPtr lightDeleteReceivePtr = std::dynamic_pointer_cast(lightDeleteEvent); + SHEventManager::SubscribeTo(SH_ASSET_COMPILE_EVENT, lightDeleteReceivePtr); + + std::shared_ptr> compileAssetReceiever { std::make_shared>(this, &SHGraphicsSystem::ReceiveCompileAssetEvent) }; ReceiverPtr compileAssetReceivePtr = std::dynamic_pointer_cast(compileAssetReceiever); SHEventManager::SubscribeTo(SH_ASSET_COMPILE_EVENT, compileAssetReceivePtr); + } void SHGraphicsSystem::InitGenericDataAndTexturesDescSet(void) noexcept @@ -846,10 +855,7 @@ namespace SHADE SHEventHandle SHGraphicsSystem::ReceiveLightEnableShadowEvent(SHEventPtr eventPtr) noexcept { - // we need to wait for the device to finish using the graph first - device->WaitIdle(); - - auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; + auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); std::string depthResourceName = "ShadowMap_Depth " + std::to_string(EVENT_DATA->lightEntity); std::string shadowMapResourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); @@ -857,71 +863,112 @@ namespace SHADE Handle gBufferWriteSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS); Handle gBufferWriteVfxSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_VFX_SUBPASS); - if (EVENT_DATA->generateRenderer) + if (EVENT_DATA->enableShadow) { - // Create new renderer for the light component and give it to the light component - Handle newRenderer = resourceManager.Create(device, swapchain->GetNumImages(), descPool, SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC); - lightComp->SetRenderer (newRenderer); + // When the light first enables shadow rendering, we need to prepare the relevant objects to render shadows; namely renderpasses and subpasses, pipelines and descriptor sets + if (EVENT_DATA->firstEnable) + { + // we need to wait for the device to finish using the graph first + device->WaitIdle(); - // assign shadow map index to light component - lightComp->SetShadowMapIndex (lightingSubSystem->GetNumShadowMaps()); + // Create new renderer for the light component and give it to the light component + Handle newRenderer = resourceManager.Create(device, swapchain->GetNumImages(), descPool, SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC); + lightComp->SetRenderer(newRenderer); + + // assign shadow map index to light component + lightComp->SetShadowMapIndex(lightingSubSystem->GetNumShadowMaps()); + + + // Add the shadow map resource to the graph + renderGraph->AddResource(depthResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eD32Sfloat); + renderGraph->AddResource(shadowMapResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eR32G32B32A32Sfloat); + renderGraph->AddResource(shadowMapBlurredResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eR32G32B32A32Sfloat); + + + + // link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer. + auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, { depthResourceName.c_str(), shadowMapResourceName.c_str(), shadowMapBlurredResourceName.c_str() }, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data()); + + // Add a subpass to render to that shadow map + auto shadowMapDrawSubpass = shadowMapNode->RuntimeAddSubpass(shadowMapResourceName + " Subpass", shadowMapViewport, lightComp->GetRenderer()); + shadowMapDrawSubpass->AddColorOutput(shadowMapResourceName); + shadowMapDrawSubpass->AddDepthOutput(depthResourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH); + + // add compute pass to blur shadow ma + shadowMapNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, shadowMapBlurCS, { shadowMapResourceName.c_str(), shadowMapBlurredResourceName.c_str() }); + + // regenerate the node + shadowMapNode->RuntimeStandaloneRegenerate(); + + // Create pipeline from new renderpass and subpass if it's not created yet + if (!shadowMapPipeline) + { + SHPipelineLibrary tempLibrary{}; + Handle rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data()); + + SHRasterizationState rasterState{}; + rasterState.cull_mode = vk::CullModeFlagBits::eBack; + + tempLibrary.Init(device); + tempLibrary.CreateGraphicsPipelines + ( + { shadowMapVS, shadowMapFS }, shadowMapNode->GetRenderpass(), shadowMapDrawSubpass, + SHGraphicsPredefinedData::SystemType::BATCHING, + SHGraphicsPredefinedData::GetShadowMapViState(), rasterState + ); + shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, shadowMapFS, shadowMapDrawSubpass }); + } + shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteSubpass, shadowMapPipeline); // set companion subpass and pipeline + shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteVfxSubpass, shadowMapPipeline); // set companion subpass and pipeline + + // add the shadow map and the blurred version to the lighting system + uint32_t const NEW_SHADOW_MAP_INDEX = lightingSubSystem->AddShadowMap(renderGraph->GetRenderGraphResource(shadowMapBlurredResourceName), EVENT_DATA->lightEntity); + + // Get deferred composite node compute and modify descriptor set + auto nodeCompute = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data())->GetNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data()); + nodeCompute->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, lightingSubSystem->GetViewSamplerLayout(NEW_SHADOW_MAP_INDEX), NEW_SHADOW_MAP_INDEX); + } + else + { + // get the shadow map node + renderGraph->GetNode (SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName)->SetDynamicActive(true); + } + } + else + { + // get the shadow map node + renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName)->SetDynamicActive(false); } + return eventPtr->handle; + } - // Add the shadow map resource to the graph - renderGraph->AddResource(depthResourceName, {SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH}, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eD32Sfloat); - renderGraph->AddResource(shadowMapResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eR32G32B32A32Sfloat); - renderGraph->AddResource(shadowMapBlurredResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eR32G32B32A32Sfloat); + SHEventHandle SHGraphicsSystem::ReceiveLightDeleteEvent(SHEventPtr eventPtr) noexcept + { + // we need to wait for the device to finish using the graph first + device->WaitIdle(); - - - // link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer. - auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, {depthResourceName.c_str(), shadowMapResourceName.c_str(), shadowMapBlurredResourceName.c_str()}, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data()); - - // Add a subpass to render to that shadow map - auto shadowMapDrawSubpass = shadowMapNode->RuntimeAddSubpass(shadowMapResourceName + " Subpass", shadowMapViewport, lightComp->GetRenderer()); - shadowMapDrawSubpass->AddColorOutput(shadowMapResourceName); - shadowMapDrawSubpass->AddDepthOutput(depthResourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH); - - // add dummy subpass to transition the shadow map images for compute shader usage - //auto dummySubpass = shadowMapNode->RuntimeAddSubpass(shadowMapResourceName + "Dummy", {}, {}); - //dummySubpass->AddGeneralColorOutput(shadowMapResourceName); - //dummySubpass->AddGeneralColorOutput(shadowMapBlurredResourceName); - - // add compute pass to blur shadow ma - shadowMapNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, shadowMapBlurCS, { shadowMapResourceName.c_str(), shadowMapBlurredResourceName.c_str() }); - //shadowMapNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, shadowMapBlurCS, { shadowMapBlurredResourceName.c_str(), shadowMapResourceName.c_str() }); - //shadowMapNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, shadowMapBlurCS, { shadowMapResourceName.c_str(), shadowMapBlurredResourceName.c_str() }); - - // regenerate the node - shadowMapNode->RuntimeStandaloneRegenerate(); - - // Create pipeline from new renderpass and subpass if it's not created yet - if (!shadowMapPipeline) - { - SHPipelineLibrary tempLibrary{}; - Handle rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data()); - - SHRasterizationState rasterState{}; - rasterState.cull_mode = vk::CullModeFlagBits::eBack; - - tempLibrary.Init(device); - tempLibrary.CreateGraphicsPipelines - ( - { shadowMapVS, shadowMapFS }, shadowMapNode->GetRenderpass(), shadowMapDrawSubpass, - SHGraphicsPredefinedData::SystemType::BATCHING, - SHGraphicsPredefinedData::GetShadowMapViState(), rasterState - ); - shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, shadowMapFS, shadowMapDrawSubpass }); - } - shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteSubpass, shadowMapPipeline); // set companion subpass and pipeline - shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteVfxSubpass, shadowMapPipeline); // set companion subpass and pipeline + auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; + auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); - // add the shadow map and the blurred version to the lighting system - uint32_t const NEW_SHADOW_MAP_INDEX = lightingSubSystem->AddShadowMap(renderGraph->GetRenderGraphResource(shadowMapBlurredResourceName), EVENT_DATA->lightEntity); + if (lightComp && lightComp->GetShadowMapIndex()) + { + std::string depthResourceName = "ShadowMap_Depth " + std::to_string(EVENT_DATA->lightEntity); + std::string shadowMapResourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); + std::string shadowMapBlurredResourceName = "ShadowMap Blurred" + std::to_string(EVENT_DATA->lightEntity); + + // Remove render graph node + renderGraph->RemoveNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName); + + // Remove render graph resource + renderGraph->RemoveResource(depthResourceName); + renderGraph->RemoveResource(shadowMapResourceName); + renderGraph->RemoveResource(shadowMapBlurredResourceName); + + // Register light component shadow map index into light system as recyclable + lightingSubSystem->RemoveShadowMap (EVENT_DATA->lightEntity); + } - auto nodeCompute = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data())->GetNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data()); - nodeCompute->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, lightingSubSystem->GetViewSamplerLayout(NEW_SHADOW_MAP_INDEX), NEW_SHADOW_MAP_INDEX); return eventPtr->handle; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 33227f8f..68752a6e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -182,6 +182,7 @@ namespace SHADE /* Light functions */ /*-----------------------------------------------------------------------*/ SHEventHandle ReceiveLightEnableShadowEvent (SHEventPtr eventPtr) noexcept; + SHEventHandle ReceiveLightDeleteEvent (SHEventPtr eventPtr) noexcept; /*-----------------------------------------------------------------------*/ /* Asset Events */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index 61552614..5e95c6ad 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -113,15 +113,21 @@ namespace SHADE lightData.castShadows = flag; // If the flag is true - if (flag && lightData.shadowMapIndex == SHLightData::INVALID_SHADOW_MAP_INDEX) + if (flag) { // Create new event and broadcast it - SHLightEnableShadowEvent newEvent; + SHLightShadowEvent newEvent; newEvent.lightEntity = GetEID(); - newEvent.generateRenderer = static_cast(!renderer); - SHEventManager::BroadcastEvent(newEvent, SH_GRAPHICS_LIGHT_ENABLE_SHADOW_EVENT); + // If shadow map index is invalid, that means light is enabling shadow for the first time. + newEvent.firstEnable = (lightData.shadowMapIndex == SHLightData::INVALID_SHADOW_MAP_INDEX); + + // pass the flag to the event + newEvent.enableShadow = flag; + + SHEventManager::BroadcastEvent(newEvent, SH_GRAPHICS_LIGHT_ENABLE_SHADOW_EVENT); } + } void SHLightComponent::SetRenderer(Handle newRenderer) noexcept @@ -195,6 +201,11 @@ namespace SHADE return lightData.castShadows; } + uint32_t SHLightComponent::GetShadowMapIndex(void) const noexcept + { + return lightData.shadowMapIndex; + } + } RTTR_REGISTRATION diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h index a90d23b0..a24b5ede 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h @@ -70,6 +70,8 @@ namespace SHADE float GetStrength (void) const noexcept; Handle GetRenderer (void) const noexcept; bool GetEnableShadow (void) const noexcept; + uint32_t GetShadowMapIndex (void) const noexcept; + RTTR_ENABLE() }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index f89582fc..27685d69 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -599,39 +599,15 @@ namespace SHADE { //Bind descriptor set(We bind at an offset because the buffer holds NUM_FRAME_BUFFERS sets of data). cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::COMPUTE, setIndex, { dynamicOffsets[frameIndex] }); - } uint32_t SHLightingSubSystem::AddShadowMap(Handle newShadowMapBlurred, EntityID lightEntity) noexcept { - // Add to container of shadow maps - shadowMapIndexing.emplace(lightEntity, static_cast (shadowMaps.size())); - shadowMaps.emplace_back(newShadowMapBlurred); + uint32_t usedIndex = 0; // Just use the image view stored in the resource Handle const NEW_IMAGE_VIEW = newShadowMapBlurred->GetImageView(); - // Prepare to write to descriptor - shadowMapImageSamplers.emplace_back(NEW_IMAGE_VIEW, shadowMapSampler, vk::ImageLayout::eShaderReadOnlyOptimal); - - // Update descriptor set - //static constexpr uint32_t SHADOW_MAP_DESC_SET_INDEX = 0; - //uint32_t const SHADOW_MAP_DESC_ARRAY_INDEX = static_cast(shadowMapImageSamplers.size()) - 1u; - //shadowMapDescriptorSet->ModifyWriteDescImage - //( - // SHADOW_MAP_DESC_SET_INDEX, - // SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, - // shadowMapImageSamplers[SHADOW_MAP_DESC_ARRAY_INDEX], - // SHADOW_MAP_DESC_ARRAY_INDEX - //); - - //// TODO: Definitely can be optimized by writing a function that modifies a specific descriptor in the array - //shadowMapDescriptorSet->UpdateDescriptorSetImages - //( - // SHADOW_MAP_DESC_SET_INDEX, - // SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA - //); - // add to barriers shadowMapMemoryBarriers.push_back (vk::ImageMemoryBarrier { @@ -652,8 +628,68 @@ namespace SHADE } }); + if (recyclableIndices.empty()) + { + shadowMaps.emplace_back(newShadowMapBlurred); + + // Prepare to write to descriptor + shadowMapImageSamplers.emplace_back(NEW_IMAGE_VIEW, shadowMapSampler, vk::ImageLayout::eShaderReadOnlyOptimal); + + // Add to container of shadow maps + shadowMapIndexing.emplace(lightEntity, static_cast (shadowMaps.size())); + + usedIndex = static_cast(shadowMapImageSamplers.size()) - 1u; + } + else + { + uint32_t usedIndex = recyclableIndices.top(); + recyclableIndices.pop(); + + // Recycle the slot in the vector of shadow maps + shadowMaps[usedIndex] = newShadowMapBlurred; + + // register indexing for shadow maps + shadowMapIndexing.emplace(lightEntity, usedIndex); + + // Recycle the slot in the vector of image view, samplers and layout + shadowMapImageSamplers[usedIndex] = std::make_tuple(NEW_IMAGE_VIEW, shadowMapSampler, vk::ImageLayout::eShaderReadOnlyOptimal); + } + + // return new index of shadow map - return static_cast(shadowMapImageSamplers.size()) - 1u; + return usedIndex; + } + + void SHLightingSubSystem::RemoveShadowMap(EntityID lightEntity) noexcept + { + auto* lightComp = SHComponentManager::GetComponent(lightEntity); + + if (lightComp && shadowMapIndexing.contains(lightEntity)) + { + uint32_t shadowMapIndex = shadowMapIndexing[lightEntity]; + + // Recycle the shadow map index used by the component + RecycleShadowMapIndex(lightComp); + + // Not removed from container, can recycle + shadowMaps[shadowMapIndex] = {}; + + // Not removed from container, can recycle + shadowMapImageSamplers[shadowMapIndex] = {}; + + // Remove from barriers + shadowMapMemoryBarriers.erase(shadowMapMemoryBarriers.begin() + shadowMapIndex); + + // remove from map for indexing + shadowMapIndexing.erase(lightEntity); + } + } + + void SHLightingSubSystem::RecycleShadowMapIndex(SHLightComponent* lightComp) noexcept + { + // if index is recyclable, recycle it + if (lightComp && lightComp->GetShadowMapIndex() != SHLightData::INVALID_SHADOW_MAP_INDEX) + recyclableIndices.push (lightComp->GetShadowMapIndex()); } void SHLightingSubSystem::PrepareShadowMapsForRead(Handle cmdBuffer) noexcept @@ -662,28 +698,6 @@ namespace SHADE cmdBuffer->PipelineBarrier(vk::PipelineStageFlagBits::eComputeShader, vk::PipelineStageFlagBits::eComputeShader, {}, {}, {}, shadowMapMemoryBarriers); } - //void SHLightingSubSystem::HandleResize(Handle compute) noexcept - //{ - // uint32_t const NUM_SHADOW_MAPS = static_cast(shadowMaps.size()); - // for (uint32_t i = 0; i < NUM_SHADOW_MAPS; ++i) - // { - // // Just use the image view stored in the resource - // Handle const NEW_IMAGE_VIEW = shadowMaps[i]->GetImageView(); - - // // set new image view - // std::get>(shadowMapImageSamplers[i]) = NEW_IMAGE_VIEW; - - // // Set image for barrier - // shadowMapMemoryBarriers[i].image = shadowMaps[i]->GetImage()->GetVkImage(); - // } - - // if (NUM_SHADOW_MAPS > 0) - // { - // // modify descriptors in render graph node compute - // compute->ModifyWriteDescImageComputeResource (SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, shadowMapImageSamplers); - // } - //} - Handle SHLightingSubSystem::GetLightDataDescriptorSet(void) const noexcept { return lightingDataDescSet; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index 3613f762..652b8226 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -9,6 +9,7 @@ #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" #include "Graphics/RenderGraph/SHRenderGraphResource.h" #include "ECS_Base/SHECSMacros.h" +#include namespace SHADE @@ -183,10 +184,6 @@ namespace SHADE //! Shadow maps for every light that casts a shadow Order here doesn't matter. We just want to store it std::vector> shadowMaps; - //! Descriptor sets required to be given to the compute shader for shadow calculation. This will be a descriptor array. - //! It will also be preallocated. - //Handle shadowMapDescriptorSet; - //! Combined image samplers for the texture descriptors std::vector, Handle, vk::ImageLayout>> shadowMapImageSamplers; @@ -194,6 +191,9 @@ namespace SHADE //! to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) std::vector shadowMapMemoryBarriers; + //! recycled indices after deleting lights with shadows + std::stack recyclableIndices; + //! Resource hub from Graphics System SHResourceHub* resourceHub; @@ -212,12 +212,14 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - void Init (Handle device, Handle descPool, SHResourceHub* rh, Handle inShadowMapSampler) noexcept; - void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; - void Exit (void) noexcept; - void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; - uint32_t AddShadowMap (Handle newShadowMapBlurred, EntityID lightEntity) noexcept; - void PrepareShadowMapsForRead (Handle cmdBuffer) noexcept; + void Init (Handle device, Handle descPool, SHResourceHub* rh, Handle inShadowMapSampler) noexcept; + void Run (SHMatrix const& viewMat, uint32_t frameIndex) noexcept; + void Exit (void) noexcept; + void BindDescSet (Handle cmdBuffer, uint32_t setIndex, uint32_t frameIndex) noexcept; + uint32_t AddShadowMap (Handle newShadowMapBlurred, EntityID lightEntity) noexcept; + void RemoveShadowMap (EntityID lightEntity) noexcept; + void RecycleShadowMapIndex (SHLightComponent* lightComp) noexcept; + void PrepareShadowMapsForRead (Handle cmdBuffer) noexcept; //void HandleResize (Handle compute) noexcept; //void RemoveShadowMap (uint32_t index) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 04d4af0b..34206e5b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -81,7 +81,8 @@ namespace SHADE renderGraphStorage->logicalDevice->WaitIdle(); - uint64_t handleID = renderGraphStorage->graphResources->at (resourceName).GetId().Raw; + auto resourceHdl = renderGraphStorage->graphResources->at(resourceName); + uint64_t handleID = resourceHdl.GetId().Raw; // Record nodes that will be affected std::vector affectedNodes{}; @@ -89,7 +90,7 @@ namespace SHADE // Detach resource from all nodes if applicable for (uint32_t i = 0; i < nodes.size(); ++i) { - if (nodes[i]->DetachResource(resourceName, handleID)) + if (nodes[i] && nodes[i]->DetachResource(resourceName, handleID)) affectedNodes.emplace_back(i); } @@ -109,6 +110,8 @@ namespace SHADE renderGraphStorage->graphResources->at(resourceName).Free(); renderGraphStorage->graphResources->erase (resourceName); + + resourceHdl.Free (); /* * IMPORTANT NOTES * @@ -121,6 +124,21 @@ namespace SHADE */ } + void SHRenderGraph::RemoveNode(std::string nodeName) noexcept + { + if (nodeIndexing.contains(nodeName)) + { + // wait for device to stop + renderGraphStorage->logicalDevice->WaitIdle(); + + // Get handle to node since it exists + auto nodeHdl = nodes[nodeIndexing[nodeName]]; + + nodeHdl.Free(); + nodeIndexing.erase(nodeName); + } + } + void SHRenderGraph::LinkNonOwningResource(Handle resourceOrigin, std::string resourceName) noexcept { // resource to link diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 0ae30015..42d829b0 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -112,6 +112,7 @@ namespace SHADE ); void RemoveResource (std::string resourceName) noexcept; + void RemoveNode (std::string nodeName) noexcept; void LinkNonOwningResource ( diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 2f316c79..53363a63 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -405,6 +405,22 @@ namespace SHADE return *this; } + SHRenderGraphNode::~SHRenderGraphNode(void) noexcept + { + if (renderpass) + renderpass.Free(); + + for (auto& framebuffer : framebuffers) + framebuffer.Free(); + + for (auto& subpass : subpasses) + subpass.Free(); + + // Too tired to test, its nearing end of milestone 3.... + //for (auto& nc : nodeComputes) + // nc.Free(); + } + /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index 2877fdee..971a84ae 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -111,6 +111,7 @@ namespace SHADE SHRenderGraphNode(std::string nodeName, Handle renderGraphStorage, std::vector attDescInitParams, std::vector> predecessors, bool inIsDynamic = false) noexcept; SHRenderGraphNode(SHRenderGraphNode&& rhs) noexcept; SHRenderGraphNode& operator= (SHRenderGraphNode&& rhs) noexcept; + ~SHRenderGraphNode (void) noexcept; /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ @@ -132,12 +133,12 @@ namespace SHADE /*-----------------------------------------------------------------------*/ void SetDynamicActive(bool active) noexcept; - Handle GetRenderpass(void) const noexcept; - Handle GetSubpass(std::string_view subpassName) const noexcept; - Handle GetResource (uint32_t resourceIndex) const noexcept; + Handle GetRenderpass(void) const noexcept; + Handle GetSubpass(std::string_view subpassName) const noexcept; + Handle GetResource (uint32_t resourceIndex) const noexcept; std::vector> const& GetResources (void) const noexcept; - Handle GetNodeCompute (std::string nodeComputeName) const noexcept; - bool GetDynamicActive (void) const noexcept; + Handle GetNodeCompute (std::string nodeComputeName) const noexcept; + bool GetDynamicActive (void) const noexcept; friend class SHRenderGraph; }; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index db78c5aa..ca13155d 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -80,6 +80,14 @@ namespace SHADE , companionSubpasses {std::move (rhs.companionSubpasses)} , dummyPipelineLayout{rhs.dummyPipelineLayout} { + superBatch = std::move(rhs.superBatch); + rhs.superBatch = {}; + + inputDescriptorLayout = std::move(rhs.inputDescriptorLayout); + rhs.inputDescriptorLayout = {}; + + dummyPipelineLayout = std::move(rhs.dummyPipelineLayout); + rhs.dummyPipelineLayout = {}; } @@ -101,7 +109,6 @@ namespace SHADE subpassIndex = std::move(rhs.subpassIndex); parentNode = std::move(rhs.parentNode); - superBatch = std::move(rhs.superBatch); colorReferences = std::move(rhs.colorReferences); depthReferences = std::move(rhs.depthReferences); inputReferences = std::move(rhs.inputReferences); @@ -118,10 +125,36 @@ namespace SHADE companionSubpasses = rhs.companionSubpasses; dummyPipelineLayout = rhs.dummyPipelineLayout; + superBatch = std::move(rhs.superBatch); + rhs.superBatch = {}; + + inputDescriptorLayout = std::move(rhs.inputDescriptorLayout); + rhs.inputDescriptorLayout = {}; + + dummyPipelineLayout = std::move(rhs.dummyPipelineLayout); + rhs.dummyPipelineLayout = {}; return *this; } + SHSubpass::~SHSubpass(void) noexcept + { + graphStorage->logicalDevice->WaitIdle(); + + for (auto& set : inputImageDescriptorSets) + set.Free(); + + if (inputDescriptorLayout) + inputDescriptorLayout.Free(); + + if (dummyPipelineLayout) + dummyPipelineLayout.Free(); + + // not working + //if (superBatch) + // superBatch.Free(); + } + /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index 640ccb2d..7f843773 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -130,6 +130,7 @@ namespace SHADE SHSubpass(const std::string& name, Handle inViewport, Handle inRenderer, Handle renderGraphStorage, Handle const& parent, uint32_t index, std::unordered_map const* mapping) noexcept; SHSubpass(SHSubpass&& rhs) noexcept; SHSubpass& operator=(SHSubpass&& rhs) noexcept; + ~SHSubpass(void) noexcept; /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ -- 2.40.1 From 2bba48b09f9d489d2ffd0f37ae34db98162ff1aa Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 8 Mar 2023 10:02:51 +0800 Subject: [PATCH 6/6] Accounted for deletion of lights - Not entirely urgent, but removal of resources from render graph fails. Need a valid check of handles. --- SHADE_Engine/src/Events/SHEventDefines.h | 2 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 12 ++++++------ .../Graphics/MiddleEnd/Lights/SHLightComponent.cpp | 8 ++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/SHADE_Engine/src/Events/SHEventDefines.h b/SHADE_Engine/src/Events/SHEventDefines.h index e03dfd82..cdef68b9 100644 --- a/SHADE_Engine/src/Events/SHEventDefines.h +++ b/SHADE_Engine/src/Events/SHEventDefines.h @@ -30,5 +30,5 @@ constexpr SHEventIdentifier SH_BUTTON_RELEASE_EVENT { 21 }; constexpr SHEventIdentifier SH_BUTTON_HOVER_ENTER_EVENT { 22 }; constexpr SHEventIdentifier SH_BUTTON_HOVER_EXIT_EVENT { 23 }; constexpr SHEventIdentifier SH_ASSET_COMPILE_EVENT { 24 }; -constexpr SHEventIdentifier SH_LIGHT_DELETE_EVENT { 25 }; +constexpr SHEventIdentifier SH_GRAPHICS_LIGHT_DELETE_EVENT { 25 }; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 22f0423d..d41e93d1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -542,7 +542,7 @@ namespace SHADE std::make_shared>(this, &SHGraphicsSystem::ReceiveLightDeleteEvent) }; ReceiverPtr lightDeleteReceivePtr = std::dynamic_pointer_cast(lightDeleteEvent); - SHEventManager::SubscribeTo(SH_ASSET_COMPILE_EVENT, lightDeleteReceivePtr); + SHEventManager::SubscribeTo(SH_GRAPHICS_LIGHT_DELETE_EVENT, lightDeleteReceivePtr); std::shared_ptr> compileAssetReceiever @@ -951,19 +951,19 @@ namespace SHADE auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); - if (lightComp && lightComp->GetShadowMapIndex()) + if (lightComp && lightComp->GetShadowMapIndex() != SHLightData::INVALID_SHADOW_MAP_INDEX) { std::string depthResourceName = "ShadowMap_Depth " + std::to_string(EVENT_DATA->lightEntity); std::string shadowMapResourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); std::string shadowMapBlurredResourceName = "ShadowMap Blurred" + std::to_string(EVENT_DATA->lightEntity); // Remove render graph node - renderGraph->RemoveNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName); + //renderGraph->RemoveNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName); // Remove render graph resource - renderGraph->RemoveResource(depthResourceName); - renderGraph->RemoveResource(shadowMapResourceName); - renderGraph->RemoveResource(shadowMapBlurredResourceName); + //renderGraph->RemoveResource(depthResourceName); + //renderGraph->RemoveResource(shadowMapResourceName); + //renderGraph->RemoveResource(shadowMapBlurredResourceName); // Register light component shadow map index into light system as recyclable lightingSubSystem->RemoveShadowMap (EVENT_DATA->lightEntity); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index 5e95c6ad..f8578647 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -21,6 +21,14 @@ namespace SHADE void SHLightComponent::OnDestroy(void) { + if (lightData.shadowMapIndex != SHLightData::INVALID_SHADOW_MAP_INDEX) + { + // Create new event and broadcast it + SHDeleteLightEvent newEvent; + newEvent.lightEntity = GetEID(); + + SHEventManager::BroadcastEvent(newEvent, SH_GRAPHICS_LIGHT_DELETE_EVENT); + } } -- 2.40.1