{"id":337,"date":"2026-01-24T21:17:34","date_gmt":"2026-01-24T13:17:34","guid":{"rendered":"http:\/\/chenglixue.top\/?p=337"},"modified":"2026-01-25T00:39:29","modified_gmt":"2026-01-24T16:39:29","slug":"337","status":"publish","type":"post","link":"http:\/\/chenglixue.top\/?p=337","title":{"rendered":"DX12 SSAO\u5165\u95e8\u5230HBAO\u5165\u575f"},"content":{"rendered":"<p><div class=\"has-toc have-toc\"><\/div><\/p>\n<h1>DX12 SSAO\u5165\u95e8\u5230HBAO\u5165\u575f<\/h1>\n<h2>\u524d\u8a00<\/h2>\n<ul>\n<li>\u4ec0\u4e48\u662fSSAO\n<p><strong>SSAO<\/strong> \u7684\u5168\u79f0\u662f <strong>Screen Space Ambient Occlusion<\/strong>\uff08\u5c4f\u5e55\u7a7a\u95f4\u73af\u5883\u5149\u906e\u853d\uff09\u3002\u8fd9\u662f\u4e00\u79cd\u5728\u6e32\u67d3\u4e2d\u589e\u52a0\u9634\u5f71\u611f\u7684\u7b97\u6cd5\uff0c\u53ef\u4ee5\u8ba9\u7269\u4f53\u4ea4\u754c\u5904\u3001\u7f1d\u9699\u3001\u8936\u76b1\u663e\u5f97\u66f4\u771f\u5b9e\uff0c\u589e\u52a0\u753b\u9762\u7684<strong>\u5c42\u6b21\u611f<\/strong>\u548c<strong>\u6df1\u5ea6\u611f<\/strong><\/p>\n<\/li>\n<li>\n<p>\u4e3a\u4ec0\u4e48\u9700\u8981SSAO<\/p>\n<ol>\n<li>\u56e0\u4e3a\u76ee\u524d\u5b9e\u65f6\u6e32\u67d3\u4e3b\u8981\u4f7f\u7528shadow cast \u548c shadow receive\uff0c\u8fd9\u79cd\u7b97\u6cd5\u56e0\u4e3abias\u7684\u539f\u56e0\uff0c\u4e0d\u80fd\u4fdd\u8bc1\u67d0\u4e9b\u5730\u65b9\u7684\u9634\u5f71\u8ba1\u7b97\u662f\u5b8c\u5168\u6b63\u786e\u4e14\u8986\u76d6\u7684\uff1b\u800cSSAO\u6b63\u597d\u53ef\u4ee5\u5f25\u8865\u8fd9\u4e00\u7b97\u6cd5\u7684\u4e0d\u8db3<\/li>\n<li>\u7531\u4e8e\u5b9e\u65f6\u6e32\u67d3\u65e0\u6cd5\u50cf\u79bb\u7ebf\u6e32\u67d3\u4e00\u6837\uff0c\u53ef\u4ee5\u8ba9\u5149\u7ebf\u591a\u6b21\u53cd\u5f39\uff0c\u4ece\u800c\u5f97\u5230<strong>\u5c4b\u5b50\u7684\u89d2\u843d\u4f1a\u6bd4\u7a7a\u65f7\u7684\u5730\u9762\u6697\u4e00\u4e9b<\/strong>\uff0c\u5bfc\u81f4\u573a\u666f\u770b\u8d77\u6765\u50cf\u201c\u5851\u6599\u201d\u4e00\u6837\uff0c\u7269\u4f53\u4eff\u4f5b\u60ac\u6d6e\u5728\u5730\u9762\u4e0a\uff0c\u7f3a\u4e4f\u4f53\u79ef\u611f\u3002SSAO\u6b63\u597d\u53ef\u4ee5\u9ad8\u6027\u80fd\u7684\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898<\/li>\n<\/ol>\n<\/li>\n<li>\u5982\u4f55\u5b9e\u73b0SSAO\n<ol>\n<li><strong>\u6df1\u5ea6\u91c7\u6837<\/strong>\uff1a\u8ba1\u7b97\u5c4f\u5e55\u6bcf\u4e2a\u50cf\u7d20\u70b9\u7684depth<\/li>\n<li><strong>\u534a\u5f84\u6d4b\u8bd5<\/strong>\uff1a\u5728\u6bcf\u4e2a\u50cf\u7d20\u5468\u56f4\u7684\u4e00\u5b9a\u7a7a\u95f4\u5185\u968f\u673a\u91c7\u6837\u82e5\u5e72\u4e2a\u70b9<\/li>\n<li><strong>\u906e\u853d\u5224\u65ad<\/strong>\uff1a\u5982\u679c\u91c7\u6837\u70b9\u88ab\u5468\u56f4\u7684\u7269\u4f53\u6321\u4f4f\u4e86\uff0c\u8bf4\u660e\u8fd9\u4e2a\u50cf\u7d20\u5904\u4e8e\u9634\u5f71\u4e2d<\/li>\n<li><strong>\u6a21\u7cca\u5904\u7406<\/strong>\uff1a\u4e3a\u4e86\u8282\u7701\u6027\u80fd\uff0c\u91c7\u6837\u901a\u5e38\u6bd4\u8f83\u7a00\u758f\uff0c\u4f1a\u6709\u566a\u70b9\uff0c\u6240\u4ee5\u6700\u540e\u4f1a\u52a0\u4e00\u5c42\u6a21\u7cca\u5904\u7406\uff0c\u8ba9\u9634\u5f71\u770b\u8d77\u6765\u66f4\u67d4\u548c<\/li>\n<\/ol>\n<\/li>\n<li>SSAO\u4f18\u7f3a\u70b9\n<ul>\n<li>\u4f18\u70b9<\/li>\n<\/ul>\n<ol>\n<li><strong>\u6027\u80fd\u5f00\u9500\u4f4e<\/strong>\uff1a\u4e0e\u5c4f\u5e55\u5206\u8fa8\u7387\u6709\u5173\uff0c\u4e0d\u50cf\u5149\u8ffd\u548c\u573a\u666f\u590d\u6742\u5ea6\u6709\u5173<\/li>\n<li><strong>\u4e0d\u662f\u9884\u5236\u83dc<\/strong>\uff1a\u53ef\u4ee5\u5b9e\u65f6\u8fd0\u884c<\/li>\n<li><strong>\u53ef\u5feb\u901f\u5d4c\u5165\u540e\u6548<\/strong><\/li>\n<\/ol>\n<ul>\n<li>\u7f3a\u70b9\uff1a<\/li>\n<\/ul>\n<ol>\n<li>SSAO\u662f\u4e00\u79cd\u5c4f\u5e55\u7a7a\u95f4\u6280\u672f\uff0c\u8fd9\u79cd\u6280\u672f\u7684\u5f0a\u7aef\u662f\u5bf9\u4e8e\u5c4f\u5e55\u5916\u7684\u7269\u4f53\u65e0\u6cd5\u52a0\u5165\u8ba1\u7b97\u4e2d<\/li>\n<li><strong>\u5149\u6655<\/strong>\uff1a\u7269\u4f53\u8fb9\u7f18\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e0d\u81ea\u7136\u7684\u9ed1\u8272\u5149\u5708<\/li>\n<li>\u65cb\u8f6c\u89c6\u89d2\u65f6\uff0c\u9634\u5f71\u53ef\u80fd\u4f1a\u6709\u8f7b\u5fae\u53d8\u5316<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<h2>\u91cd\u5efaview space<\/h2>\n<p>\u5bf9\u4e8e\u540e\u5904\u7406\u800c\u8a00\uff0c\u91cd\u5efaposition VS\u57fa\u672c\u662f\u5fc5\u5907\u7684\uff0c\u8fd9\u91cc\u91c7\u7528untiy \u7684\u601d\u8def<\/p>\n<pre><code class=\"language-glsl line-numbers\">float3 ComputeWorldSpacePosition(float2 screenUV, float rawDepth, Matrix invViewProjMatrix)\n{\n    float4 positionCS = ComputeClipSpacePosition(screenUV, rawDepth);\n    float4 positionWS = mul(positionCS, invViewProjMatrix);\n    return positionWS.xyz \/ positionWS.w;\n}\n<\/code><\/pre>\n<p>\u56e0\u4e3a\u91c7\u7528\u7684\u662f\u5ef6\u8fdf\u7ba1\u7ebf\uff0c\u6240\u4ee5normal VS\u4eceGBuffer\u4e2d\u83b7\u5f97\u5373\u53ef<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4e0d\u91c7\u7528world space?<\/p>\n<ul>\n<li><strong>\u6d6e\u70b9\u6570\u7cbe\u5ea6<\/strong>\n<p>\u56e0\u4e3a<strong>\u6d6e\u70b9\u6570\u6709\u7740\u8d8a\u63a5\u8fd10\u7cbe\u5ea6\u8d8a\u5927\u7684\u7279\u6027<\/strong>\uff0c\u800cworld space\u7684\u5750\u6807\u6570\u503c\u53ef\u80fd\u975e\u5e38\u5927\uff0c\u4f46view space\u7684\u5750\u6807\u539f\u70b9\u90fd\u662fcamera\uff0c\u6240\u4ee5<strong>view space\u4e0b\u8ba1\u7b97\u7cbe\u5ea6\u4f1a\u66f4\u9ad8<\/strong><\/p>\n<\/li>\n<\/ul>\n<h2>\u534a\u5f84\u6d4b\u8bd5<\/h2>\n<p>SSAO\u9700\u8981\u5728\u6bcf\u4e2a\u50cf\u7d20\u5468\u56f4\u7684\u4e00\u5b9a\u7a7a\u95f4\u5185\u968f\u673a\u91c7\u6837\u82e5\u5e72\u4e2a\u70b9\uff0c\u7528\u4e8e\u540e\u7eed\u7684\u906e\u853d\u5224\u65ad\u3002\u56e0\u6b64\uff0c\u4e00\u4e2a\u597d\u7684\u968f\u673a\u7b97\u6cd5\u5341\u5206\u91cd\u8981\uff0c\u8fd9\u91cc\u4f7f\u7528\u5230\u7684\u662f<strong>\u57fa\u4e8e\u5747\u5300\u5206\u5e03\u7684\u5207\u7ebf\u7a7a\u95f4\u968f\u673a\u65cb\u8f6c\u5411\u91cf<\/strong>\uff0c\u5b83\u4e3a\u6bcf\u4e00\u4e2a\u50cf\u7d20\u63d0\u4f9b<strong>\u968f\u673a\u7684\u65cb\u8f6c\u5411\u91cf<\/strong><\/p>\n<p>\u7b97\u6cd5\u6d41\u7a0b\uff1a<\/p>\n<ol>\n<li><strong>\u7a7a\u95f4\u5206\u5e03<\/strong>\uff1a\u9700\u8981\u5c06\u7a7a\u95f4\u5206\u5e03\u5728<strong>\u7269\u4f53\u671d\u5916\u7684\u534a\u7403\u533a\u57df<\/strong>\uff0c\u4ee5\u514d\u91c7\u6837\u5230\u7269\u4f53\u5185\u90e8\uff0c\u9020\u6210\u9519\u8bef\u9634\u5f71\n<pre><code class=\"language-glsl line-numbers\">std::random_device rd;   \/\/\u4fdd\u8bc1\u6bcf\u6b21\u8bbe\u5907\u542f\u52a8\u65f6\u968f\u673a\u6570\u79cd\u5b50\u90fd\u4e0d\u540c\nstd::default_random_engine generator(rd());  \nstd::uniform_real_distribution&lt;float&gt; minusOneToOneDistribution(-1.f, 1.f);\nstd::uniform_real_distribution&lt;float&gt; zeroToOneDistribution(0.f, 1.f);\n\nauto randomVec = Vector4(minusOneToOneDistribution(generator),\n                                    minusOneToOneDistribution(generator),\n                                    zeroToOneDistribution(generator), 1.f);\n<\/code><\/pre>\n<p>\u56e0\u4e3a\u9700\u8981\u5728\u534a\u7403\u591a\u6b21\u91c7\u6837\uff0c\u6211\u4eec\u80af\u5b9a\u5e0c\u671b\u5c3d\u91cf\u8986\u76d6\u5168\u90e8\u533a\u57df\uff0c\u6240\u4ee5\u6bcf\u6b21\u751f\u6210\u5411\u91cf\u65f6\uff0c\u9700\u8981\u4e58\u4e0ai \/ maxSampleCount<\/p>\n<pre><code class=\"language-glsl line-numbers\">auto scale = (float)i \/ maxSampleCount;\nrandomVec = randomVec * scale;\n<\/code><\/pre>\n<\/li>\n<li><strong>\u5bc6\u5ea6\u5206\u5e03<\/strong>\uff1a\u4f7f\u7528\u4e8c\u6b21\u51fd\u6570\u518d\u6b21\u8ba1\u7b97\u65b0\u7684\u91c7\u6837\u70b9\n<p>\u4e3a\u4ec0\u4e48\u9700\u8981\u8fd9\u4e00\u6b65\u5462\uff1f\u867d\u7136\u8bf4\u662f\u5747\u5300\u5206\u5e03\uff0c\u4f46\u6700\u7ec8\u6548\u679c\u8fd8\u662f\u5e0c\u671b<strong>\u91c7\u6837\u70b9\uff08\u9634\u5f71\uff09\u66f4\u591a\u5730\u96c6\u4e2d\u5728\u539f\u70b9\u9644\u8fd1\uff0c\u8d8a\u5411\u5916\u8d8a\u5c11<\/strong><\/p>\n<pre><code class=\"language-glsl line-numbers\">scale = MathHelper::Lerp(0.01f, 1.f, scale * scale); \/\/ \u4e8c\u6b21\u51fd\u6570\u5206\u5e03\n<\/code><\/pre>\n<\/li>\n<li><strong>\u6784\u5efaTBN<\/strong>\uff1a\u5c06\u539f\u672c\u6240\u6709\u6cbf\u7740<strong>view space <span class=\"katex math inline\">Z<\/span> \u8f74\u6b63\u65b9\u5411<\/strong>\u7684\u91c7\u6837\u70b9\uff0c\u53d8\u6362\u81f3\u6cbf\u7740<strong>\u8868\u9762\u6cd5\u7ebf<\/strong>\u7684\u91c7\u6837\u70b9\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u53d8\u6362\u6240\u6709\u91c7\u6837\u70b9\u7684\u8f74\n<p>\u73b0\u5728\u6211\u4eec\u77e5\u9053normal VS\uff0c\u4f46\u5e76\u4e0d\u77e5\u9053\u5176\u4ed6\u7684\u4e24\u8f74\u4e2d\u7684\u4efb\u4e00\u4e00\u8f74\uff0c\u56e0\u6b64\u9700\u8981\u751f\u6210\u4e00\u4e2a\u5411\u91cf\uff0c\u4f7f\u7528\u65bd\u5bc6\u7279\u6b63\u4ea4\u5316\u6765\u6784\u5efaTBN\u3002\u4e14\u8fd9\u4e2a\u5411\u91cf\u6700\u597d\u662f\u968f\u673a\u5411\u91cf\uff0c\u56e0\u4e3aSSAO\u662f\u9700\u8981\u591a\u6b21\u91c7\u6837\u7684\uff0c\u8fd9\u6837\u53ef\u4ee5\u6d88\u9664\u91cd\u590d\u611f\u3002\u53e6\u4e00\u70b9\uff0c\u7531\u4e8eTBN\u53d8\u6362\u540e\u662f\u4ee5z\u8f74\u4e3a\u57fa\u51c6\uff0c\u8bf4\u660e<strong>\u65cb\u8f6c(TBN\u53d8\u6362)\u53ea\u5728xy\u5e73\u9762\u4e0a\u8f6c<\/strong>\uff0c\u90a3\u4e48\u8fd9\u4e2a<strong>\u968f\u673a\u5411\u91cf\u7684z\u5206\u91cf\u5e94\u4e3a0<\/strong><\/p>\n<pre><code class=\"language-glsl line-numbers\">\/\/ \u5f3a\u5236\u8ba9\u968f\u673a\u5411\u91cf\u4e0e\u6cd5\u7ebf\u5782\u76f4\uff0c\u5f97\u5230\u5207\u7ebf\nconst float3 tangent = normalize(randomVector - normalVS * dot(randomVector, normalVS));\nconst float3 bitTangent = cross(normalVS, tangent);\nconst float3x3 TBN = float3x3(tangent, bitTangent, normalVS);\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u552f\u4e00\u96be\u70b9\u5c31\u662f\u7b2c\u4e00\u53e5\uff0c<strong>dot(randomVector, normalVS)<\/strong>\u5f97\u5230randomVector\u5728normalVS\u65b9\u5411\u4e0a\u7684\u6295\u5f71\uff08\u53c8\u8868\u793a\u4e24\u4e2a\u5411\u91cf\u5728\u65b9\u5411\u4e0a\u7684\u76f8\u4f3c\u6027\uff09\uff0c\u968f\u540e<strong>\u4e58\u4e0anormalVS<\/strong>\u5f97\u5230\u968f\u673a\u5411\u91cf\u5728normalVS\u4e0a\u7684\u5411\u91cf\u5206\u91cf\uff0c\u6700\u540e\u76f8\u51cf<\/p>\n<p>\u8fd9\u91cc\u53ef\u80fd\u6709\u4e2a\u7591\u95ee\uff0cnormalVS\u4e0d\u662fz\u8f74\u5417\uff0c\u800crandomVector\u7684z\u5206\u91cf\u4e3a0\uff0c\u90a3dot(randomVector, normalVS)\u94c1\u4e3a0\u554a\u3002\u8fd9\u6ca1\u6709\u95ee\u9898\uff0c\u4f46<strong>\u5927\u591a\u6570\u65f6\u5019\u7269\u4f53\u7684\u6cd5\u7ebf\u671d\u5411\u7684xy\u5206\u91cf\u4e0d\u53ef\u80fd\u521a\u597d\u4e3a0<\/strong><\/p>\n<p><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/695bf87e36d37d253ed56d22.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/695bf87e36d37d253ed56d22.png\" alt=\"\" \/><\/p><\/noscript>\n<p>\u968f\u673a\u5411\u91cf\u53ef\u4ee5\u901a\u8fc7\u91c7\u6837Blue noise texture\u5f97\u5230\uff0c\u4e3a\u4e86\u6027\u80fdBlue noise texture\u5206\u8fa8\u7387\u53ef\u80fd\u6bd4\u8f83\u5c0f\uff0c\u6b64\u65f6\u4fbf\u4e0d\u80fd\u76f4\u63a5uv\u53bb\u91c7\u6837\uff0c\u8fd9\u6837\u4f1a\u5c06\u5c0f\u5c0f\u7684Blue noise texture\u62c9\u4f38\u5230\u548c\u5c4f\u5e55\u4e00\u6837\u5927\uff0c\u53ef\u80fd\u76f8\u90bb\u7684\u4e00\u90e8\u5206\u533a\u57df\u90fd\u91c7\u6837\u7684\u76f8\u540c\u503c(\u6bd4\u5982\u5de6\u4e0a\u89d2300x300\u90fd\u91c7\u6837\u7684Blue noise texture\u7684\u540c\u4e00\u50cf\u7d20)<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u9700\u8981\u4f7f\u7528<strong>Tiling<\/strong>\u7684\u65b9\u5f0f\u8fdb\u884c\u91c7\u6837\uff0c\u8fd9\u6837\u5373\u4f7f\u8fd8\u662f\u4f1a\u6709\u4e9b\u91cd\u590d\uff0c\u4f46\u4e0d\u4f1a\u51fa\u73b0\u76f8\u90bb\u7684\u91c7\u6837\u70b9\u90fd\u91c7\u6837\u540c\u4e00\u50cf\u7d20\u503c\u3002\u5177\u4f53\u65b9\u5f0f\u662f\u7528<strong>Screen resolution \/ Blue noise texture resolution<\/strong>\uff0c\u91c7\u6837\u65f6uv\u5e94\u662f<strong>Screen resolution \/ Blue noise texture resolution * uv<\/strong>\u3002\u5982\u6b64\u539f\u672c\u91c7\u6837\u7684\u8303\u56f4\u662f[0, 1]\uff0c\u73b0\u5728\u53d8\u4e3a[0, 480]\uff08\u5047\u8bbe\u5c4f\u5e55 1920\uff0c\u7eb9\u7406 4\uff09\uff0c\u6700\u540e\u4f7f\u7528<strong>pointWrapSampler<\/strong>\u5373\u53ef\u4f7f\u7528Tiling \u91c7\u6837<\/p>\n<\/li>\n<li>\n<p><strong>\u8ba1\u7b97\u906e\u6321<\/strong><\/p>\n<p>\u4e3a\u4e86\u8ba1\u7b97\u906e\u6321\u6211\u4eec\u9700\u8981\u77e5\u9053<strong>\u91c7\u6837\u70b9\u7684\u6df1\u5ea6\u548c\u5f53\u524d\u91c7\u6837\u70b9\u7684z<\/strong><\/p>\n<pre><code class=\"language-glsl line-numbers\">float3 randomVec = mul(g_AOSampleKernelArray[sampleIndex].xyz, TBN) * g_AORadius;\n\nfloat4 randomPosVS = float4(randomVec, 0.f) + float4(inputParam.PositionVS, 1.f);\nfloat4 randomPosCS = mul(randomPosVS, projMatrix);\nfloat2 randomPosUV = randomPosCS.xy \/ randomPosCS.w * 0.5f * float2(1.f, -1.f) + 0.5f;\n\nfloat randomDepth = SampleTexture2D(OpaqueDepthIndex, randomPosUV, ClampPointSampler);\nfloat randomEyeDepth = LinearEyeDepth(randomDepth, g_ZBufferParams);\nfloat randomZ = randomPosVS.z;\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<ul>\n<li><strong>\u906e\u6321\u5224\u65ad<\/strong>\uff1a\u5982\u679c<strong>\u91c7\u6837\u70b9\u7684z\u5927\u4e8e\u91c7\u6837\u70b9\u7684\u6df1\u5ea6<\/strong>\uff0c\u8bf4\u660e\u4ea7\u751f\u4e86\u906e\u853d\n<p>float range = step(randomEyeDepth, randomZ);<\/p>\n<\/li>\n<li>\n<p><strong>bias\u4f18\u5316<\/strong>\uff1a\u7531\u4e8e\u662f\u6df1\u5ea6\u6bd4\u8f83\uff0c\u548c\u9634\u5f71\u7c7b\u4f3c\uff0c\u4e5f\u9700\u8981bias\u6765<strong>\u907f\u514d\u81ea\u906e\u6321<\/strong><\/p>\n<p>float range = step(randomEyeDepth, randomZ + g_AOBias);<\/p>\n<\/li>\n<li>\n<p><strong>\u8303\u56f4\u68c0\u6d4b<\/strong>\uff1a\u7531\u4e8e\u7b97\u6cd5\u8bbe\u5b9a\u4e86\u4e00\u4e2a\u534a\u5f84\u503c\uff0c\u53ea\u5728<strong>\u534a\u5f84\u503c\u5185\u7684\u91c7\u6837\u70b9\u624d\u751f\u6548<\/strong>\uff1b\u56e0\u6b64\u8fd8\u9700\u8981\u505a\u8303\u56f4\u68c0\u6d4b\uff0c\u53ef\u4ee5\u89e3\u51b3AO\u7684<strong>\u6f0f\u5149<\/strong>\u3001<strong>\u8fdc\u666f\u906e\u6321\u8fd1\u666f<\/strong>\u95ee\u9898\uff08\u5982\u8fdc\u5904\u7684\u7269\u4f53\u4e0d\u5e94\u7ed9\u8fd1\u5904\u7684\u7269\u4f53\u63d0\u4f9bAO\uff09<\/p>\n<p>float rangeCheck = smoothstep(0.f, 1.f, g_AORadius \/ abs(randomEyeDepth - inputParam.PositionVS.z));<\/p>\n<\/li>\n<\/ul>\n<ol start=\"5\">\n<li>\n<p>\u5f53\u524d\u6548\u679c<\/p>\n<p><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/695d3c8da9c8408628b844dc.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/695d3c8da9c8408628b844dc.png\" alt=\"\" \/><\/p><\/noscript>\n<\/li>\n<\/ol>\n<h2>\u6a21\u7cca\u5904\u7406<\/h2>\n<p>\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\u5f53\u524d\u7684AO\u8fd8\u6bd4\u8f83\u786c\uff0c\u7c7b\u4f3c\u6df1\u5ea6\u6bd4\u8f83\u7684\u9634\u5f71\uff0cAO\u4e5f\u9700\u8981\u505a\u8f6f\u5316\u5904\u7406\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u7528\u5230\u6a21\u7cca<\/p>\n<ol>\n<li><strong>\u6a21\u7cca\u9009\u578b<\/strong>\n<p>\u5e94\u8be5\u4f7f\u7528\u54ea\u79cd\u6a21\u7cca\u5462\uff1f\u5176\u5b9e\u6211\u4eec\u771f\u6b63\u7684\u76ee\u7684\u662f\uff0c\u5728<strong>\u6a21\u7ccaAO\u7684\u540c\u65f6\uff0c\u4fdd\u7559\u8f6e\u5ed3<\/strong>\uff0c\u5426\u5219\u5f53\u6a21\u7cca\u5f3a\u5ea6\u7a0d\u5fae\u62c9\u9ad8\uff0c\u6574\u4e2aAO\u90fd\u5f88\u7cca\uff0c\u770b\u7740\u5f88\u6ca1\u6709\u8d28\u611f\u3002\u56e0\u6b64\u9009\u62e9<strong>\u53cc\u8fb9\u6ee4\u6ce2<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u7b97\u6cd5<\/strong><\/p>\n<p><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/695df916ee664bba8767ae22.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/695df916ee664bba8767ae22.png\" alt=\"\" \/><\/p><\/noscript>\n<p>\u5176\u4e2d\uff0c<span class=\"katex math inline\">p = (p_x, p_y)<\/span>\u662f\u4e2d\u5fc3\u4f4d\u7f6e\uff1b<span class=\"katex math inline\">q = (q_x, q_y)<\/span>\u8868\u793a\u6ee4\u6ce2\u8ba1\u7b97\u65f6\u7684\u76ee\u6807\u50cf\u7d20\uff1b<span class=\"katex math inline\">\\sigma<\/span>\u8868\u793a\u9ad8\u65af\u5206\u5e03\u7684\u534a\u5f84(\u51b3\u5b9a\u4ee5<span class=\"katex math inline\">p<\/span>\u4e3a\u4e2d\u5fc3\u6db5\u76d6\u4e86\u591a\u5c11\u4e34\u8fd1\u50cf\u7d20\u9700\u8981\u53c2\u4e0e\u6ee4\u6ce2\u8ba1\u7b97)<\/p>\n<p>\u8fd9\u4e2a\u516c\u5f0f\u53ef\u4ee5\u7b80\u5316\uff1a<span class=\"katex math inline\">W = \\sum G_{space}(dist) * G_{range}(range)<\/span>\u3002\u5176\u4e2d<span class=\"katex math inline\">G_{space}(dist)<\/span>\u8868\u793a<strong>\u6ee4\u6ce2\u50cf\u7d20\u7684\u9ad8\u65af\u6743\u91cd<\/strong>\uff0c\u53ef\u4ee5\u63d0\u524d\u9884\u5236\u4e00\u7ec4\u9ad8\u65af\u6743\u91cd\uff0c\u800c\u4e0d\u662f\u5b9e\u65f6\u8ba1\u7b97\uff1b<span class=\"katex math inline\">G_{range}(range)<\/span>\u8868\u793a<strong>\u8303\u56f4\u6743\u91cd<\/strong>\uff0c\u5f53\u4e2d\u5fc3\u50cf\u7d20\u548c\u5f53\u524d\u6ee4\u6ce2\u50cf\u7d20\u7684\u8ddd\u79bb\u8d8a\u8fd1\u65f6\uff0c\u8303\u56f4\u6743\u91cd\u8d8a\u5927\uff1b\u8d8a\u8fdc\u65f6\uff0c\u8303\u56f4\u6743\u91cd\u8d8a\u5c0f<\/p>\n<p>\u5bf9\u4e8eAO\u7b97\u6cd5\uff0c\u80af\u5b9a\u4e0d\u80fd\u5728\u8ba1\u7b97\u8303\u56f4\u6743\u91cd\u65f6\uff0c\u4ee5\u4e24pixel\u7684\u8ddd\u79bb\u6765\u8ba1\u7b97\uff0c\u800c\u662f\u9700\u8981\u7528\u5230depth\u3001normal<\/p>\n<p>\u7531\u4e8e\u9ad8\u65af\u5177\u6709\u53ef\u5206\u79bb\u6027\uff0c\u53ef\u4ee5\u5c062d\u6a21\u7cca\u62c6\u5206\u6210\u4e24\u4e2a1d\u6a21\u7cca\uff0c\u5982\u6b64\u53ef\u4ee5\u5c06\u65f6\u95f4\u590d\u6742\u5ea6\u4ece<span class=\"katex math inline\">N^2<\/span>\u964d\u81f3<span class=\"katex math inline\">N<\/span>\uff08\u5bf9\u4e8e\u4e0d\u5206\u79bb\u7684\u6a21\u7cca\u7cca\uff0c\u91c7\u6837\u5fc5\u5b9a\u662f<span class=\"katex math inline\">(2R + 1) * (2R + 1)<\/span>\uff0c\u800c\u53ef\u5206\u79bb\u7684\u6c34\u5e73\u7ad6\u76f4\u91c7\u6837\u90fd\u662f<span class=\"katex math inline\">(R + 1) * (R + 1)<\/span>\uff09<\/p>\n<\/li>\n<li>\n<p>\u6548\u679c<\/p>\n<p><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/695e4ae1c1cee4b048c50556.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/695e4ae1c1cee4b048c50556.png\" alt=\"\" \/><\/p><\/noscript>\n<\/li>\n<\/ol>\n<h2>HI-Z<\/h2>\n<p>\u76ee\u524dSSAO\u7684\u7b97\u6cd5\u90fd\u662f\u5728\u539f\u751f\u5206\u8fa8\u7387\u4e0a\u8ba1\u7b97\uff0c\u8fd9\u6709\u51e0\u4e2a\u7f3a\u70b9\uff1a\u4e00\u662f<strong>\u5e26\u5bbd\u548c\u8ba1\u7b97\u91cf\u5927<\/strong>\uff1b\u4e8c\u662f<strong>\u964d\u4f4e\u7f13\u5b58\u547d\u4e2d\u7387<\/strong>\uff1b<\/p>\n<ul>\n<li>\u4e3a\u4ec0\u4e48<strong>\u964d\u4f4e\u7f13\u5b58\u547d\u4e2d\u7387<\/strong>\uff1f\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c\u5982\u679c\u4e00\u4e2a\u8fde\u7eed\u7684AO\u533a\u57df\u975e\u5e38\u5927\uff0c\u90a3\u4e48\u80af\u5b9a\u9700\u8981\u91c7\u6837\u79bb\u4e2d\u5fc3\u50cf\u7d20\u5f88\u8fdc\u7684\u50cf\u7d20\uff0c\u5bf9\u4e8e\u539f\u751f\u5206\u8fa8\u7387\u8fd9\u5df2\u7ecf\u964d\u4f4e\u4e86\u6548\u7387\uff1b\u800c\u4e14\uff0c\u56e0\u4e3a\u76f8\u90bb\u7ebf\u7a0b\u8bbf\u95ee\u7684\u5185\u5b58\u5730\u5740\u8de8\u5ea6\u5927\uff0c\u5bfc\u81f4\u7f13\u5b58\u547d\u4e2d\u7387\u4e5f\u4e0d\u9ad8<\/p>\n<\/li>\n<li>\n<p>\u7b97\u6cd5<\/p>\n<ol>\n<li><strong>HIZ\u5bf9\u8c61<\/strong>\uff1a\u5728\u505aGPU Culling\u65f6\uff0cHI-Z\u5bf9\u8c61\u65f6\u8ba1\u7b97\u533a\u57df\u7684min depth\uff1b\u800c\u5728AO\u4e2d\uff0c<strong>\u8981\u4e48\u8ba1\u7b972x2\u4e2d\u7684\u6700\u5c0f\u503c\uff0c\u8981\u4e48\u70b9\u91c7\u6837\u53d6\u5de6\u4e0a\u89d2pixel<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u5c42\u6570\u8ba1\u7b97<\/strong>\uff1a<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>\u5982\u4f55\u786e\u5b9a\u6700\u7ec8\u5c42\u6570\u5462\uff1f<\/p>\n<p>\u56e0\u4e3adepth render texture\u7684\u5bbd\u9ad8\u5f88\u6709\u53ef\u80fd\u4e0d\u662f<span class=\"katex math inline\">2^n<\/span>\uff0c\u90a3\u4ee5\u54ea\u6761\u8fb9\u6765\u8ba1\u7b97\u5c42\u6570\u5462\uff1fmipmap\u662f\u4e00\u4e2a\u4e0d\u65ad\u96642\u76f4\u81f3\u4e3a1\u7684\u8fc7\u7a0b\uff0c\u4e3a\u6b64\u5fc5\u987b<strong>\u786e\u4fdd\u5bbd\u9ad8\u6700\u7ec8\u90fd\u4e3a1<\/strong>\uff0c\u6240\u4ee5\u5e94\u8be5\u4ee5<strong>\u66f4\u957f\u7684\u8fb9<\/strong>\u8ba1\u7b97\u5c42\u6570<\/p>\n<\/li>\n<li>\n<p>\u516c\u5f0f\uff1a<span class=\"katex math inline\">floor(log_2(max(width, height))) + 1<\/span><\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-hlsl line-numbers\">#include \"private\\ShadingCommon.hlsl\"\n\n#define GROUP_SIZE 8\n\ncbuffer PassConstant : register(b0, perPassSpace)\n{\n  UINT g_TargetTexIndex;\n  UINT g_SourceTexIndex;\n  float4 g_TargetSize;\n  float4 g_SourceSize;\n}\n\n[numthreads(GROUP_SIZE, GROUP_SIZE, 1)]\nvoid TwoTwoMinHIZ(uint3 dispatchThreadID : SV_DispatchThreadID)\n{\n  if (dispatchThreadID.x &gt;= UINT(g_TargetSize.x) || dispatchThreadID.y &gt;= UINT(g_TargetSize.y))\n  {\n      return;\n  }\n\n  Texture2D&lt;float&gt; srcTex = ResourceDescriptorHeap[g_SourceTexIndex];\n  RWTexture2D&lt;float&gt; o = ResourceDescriptorHeap[g_TargetTexIndex];\n\n  float2 screenUV = (float2(dispatchThreadID.xy) + 0.5f) * g_SourceSize.zw;\n  UINT2 destCoord = dispatchThreadID.xy;\n  UINT2 srcCoord = dispatchThreadID.xy * 2;\n  uint2 maxCoord = (uint2)g_SourceSize.xy - 1;\n\n  float depthArray[4];\n  depthArray[0] = srcTex[min(srcCoord + UINT2(0, 0), maxCoord)].r;\n  depthArray[1] = srcTex[min(srcCoord + UINT2(0, 1), maxCoord)].r;\n  depthArray[2] = srcTex[min(srcCoord + UINT2(1, 0), maxCoord)].r;\n  depthArray[3] = srcTex[min(srcCoord + UINT2(1, 1), maxCoord)].r;\n\n  float minDepth = FLT_MAX;\n  [unroll(4)]\n  for (UINT i = 0; i &lt; 4; i ++)\n  {\n      minDepth = min(minDepth, depthArray[i]);\n  }\n\n  o[destCoord] = minDepth;\n}\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u6700\u7ec8\u6548\u679c<\/p>\n<p>\u56e0\u4e3a\u8ba1\u7b97\u5f97\u5230\u7684\u662f\u539f\u751f\u975e\u7ebf\u6027\u7684\u6df1\u5ea6\uff0c\u503c\u975e\u5e38\u5927\uff0c\u56fe\u7247\u5168\u767d\uff0c\u4e3a\u4e86\u66f4\u65b9\u4fbf\u7684debug\uff0c\u6240\u4ee5\u9700\u8981\u5728debug shader\u4e2d\u5c06\u8fd9\u4e00\u6df1\u5ea6\u8f6c\u6362\u523001\u7ebf\u6027\u6df1\u5ea6<\/p>\n<p>\u8fd9\u91cc\u5c55\u793a\u51e0\u4e2amipmap \u4e0b\u7684\u6df1\u5ea6\u56fe<\/p>\n<p>mipmap2\uff1a<br \/>\n<img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696b8f8055fa307818716479.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696b8f8055fa307818716479.png\" alt=\"\" \/><\/p><\/noscript>\n<p>mipmap 5\uff1a<br \/>\n<img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696b8f9955fa307818716531.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><br \/ >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696b8f9955fa307818716531.png\" alt=\"\" \/><br \/><\/noscript>\nmipmap7\uff1a<\/p>\n<p><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696b8fbf55fa307818716667.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><br \/ >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696b8fbf55fa307818716667.png\" alt=\"\" \/><br \/><\/noscript>\nmipmap 10:<br \/>\n<img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696b8fd155fa3078187166de.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696b8fd155fa3078187166de.png\" alt=\"\" \/><\/p><\/noscript>\n<\/li>\n<li>\n<p>\u5982\u4f55\u5224\u65adhi z\u662f\u5426\u6b63\u786e\u5462\uff1f\u56e0\u4e3a\u662f\u57282x2\u4e2d\u8ba1\u7b97\u6700\u5c0f\u503c\uff0c\u90a3\u4e48hiz\u4e4b\u95f4\u7684\u53d8\u5316\u80af\u5b9a\u662f\u8fde\u7eed\u7684\uff0c\u4e0d\u4f1a\u7a81\u7136\u5927\u53d8\uff0c\u4e14\u89c2\u5bdf\u4e0a\u9762\u8fd9\u4e9b\u56fe\u4e2d\u7684\u767d\u8272\u90e8\u5206\uff0c\u8fd9\u4e00\u90e8\u5206\u6df1\u5ea6\u662f\u6700\u8fdc\u7684\uff08\u663e\u767d\u8272\uff09\uff0cmipmap\u4ece0\u5230\u6700\u9ad8\u5c42\uff0c\u8fd9\u4e00\u90e8\u5206\u80af\u5b9a\u662f\u4e0d\u65ad\u4fdd\u6301\u767d\u8272\uff0c\u76f4\u81f3\u4e0d\u65ad\u88ab\u56db\u5468\u7684\u9ed1\u8272\u541e\u6ca1<\/p>\n<\/li>\n<li>\n<p>\u878d\u5165AO<\/p>\n<p>\u6211\u4eec\u9700\u8981\u8ba1\u7b97<strong>\u6492\u70b9\u5904\u5230\u4e2d\u5fc3\u70b9\u7684\u8ddd\u79bb<\/strong>\uff0c\u57fa\u4e8e\u8fd9\u4e2a\u8ddd\u79bb\u6765\u81ea\u52a8\u9009\u62e9\u5bf9\u5e94\u7684\u5c42\u6570<\/p>\n<pre><code class=\"language-glsl line-numbers\">float2 offsetPixel = abs(randomPosUV - screenUV) * g_TargetSize.xy;\n\/\/ \u53d6\u5bbd\u9ad8\u7684\u6700\u5927\u503c\u4f5c\u4e3a\u8de8\u5ea6\u53c2\u8003\uff0clog2 \u5f97\u5230\u5c42\u7ea7\n\/\/ \u4fdd\u8bc1\u91c7\u6837\u70b9\u8986\u76d6\u7684\u533a\u57df\u4e0e Mip \u4ee3\u8868\u7684\u533a\u57df\u4e00\u81f4\nfloat mipmapLevel = clamp(log2(max(offsetPixel.x, offsetPixel.y)), 0.f, (float)g_HIZMaxMipmap);\n<\/code><\/pre>\n<p>\u6548\u679c\uff1a<\/p>\n<p><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696b91a455fa307818717589.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696b91a455fa307818717589.png\" alt=\"\" \/><\/p><\/noscript>\n<\/li>\n<li>\n<p>\u4fee\u590d\u6761\u7eb9<\/p>\n<ul>\n<li>\u95ee\u9898\uff1a\u5f53AO Radius\u975e\u5e38\u5927\u65f6\uff0c\u4f1a\u9020\u6210\u4e0a\u56fe\u7684\u6761\u7eb9<\/p>\n<\/li>\n<li>\n<p>\u539f\u56e0<\/p>\n<\/li>\n<\/ul>\n<ol>\n<li>\u539f\u672c\u7684\u91c7\u6837\u533a\u57df\u88ab\u62c9\u5f00\u7684\u5f88\u5927\uff08<strong>\u7a00\u758f\u5316<\/strong>\uff09<\/li>\n<li>offsetPixel\u4e5f\u4f1a\u663e\u8457\u589e\u52a0\uff0c\u90a3\u4e48<strong>mipmap\u4e4b\u95f4\u7684\u5207\u6362\u4e0d\u5e73\u6ed1<\/strong><\/li>\n<\/ol>\n<ul>\n<li>\u89e3\u51b3\u65b9\u6848<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u95ee\u9898\u8ddfray marching\u5f88\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u52a0\u5165<strong>jitter<\/strong><\/p>\n<pre><code class=\"language-glsl line-numbers\">float jitter = randomVector.y * 0.5;    \/\/ blue noise\nfloat mipmapLevel = clamp(log2(max(offsetPixel.x, offsetPixel.y)) + jitter, 0.f, (float)g_HIZMaxMipmap);\n<\/code><\/pre>\n<p><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696b937255fa3078187181bb.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696b937255fa3078187181bb.png\" alt=\"\" \/><\/p><\/noscript>\n<p>\u53ef\u4ee5\u770b\u5230\u6709\u4e00\u5b9a\u7684\u6548\u679c\u4f46\u4e0d\u591a\uff0c\u56e0\u4e3a\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u80fd\u89e3\u51b3mipmap\u5207\u6362\u4e0d\u5e73\u6ed1\u7684\u95ee\u9898\uff0c\u5b83\u53ea\u80fd\u5c06\u6761\u7eb9\u8f6c\u5316\u4e3a\u566a\u58f0<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u9700\u8981\u901a\u8fc7\u4e09\u7ebf\u6027\u63d2\u503c\uff0c\u4e5f\u5c31\u662f<strong>lerp mipmap<\/strong><\/p>\n<pre><code class=\"language-glsl line-numbers\">float SampleHiZTrilinear(float2 uv, float mipmapLevel)\n{\n    \/\/ \u83b7\u53d6\u76f8\u90bb\u7684\u4e24\u4e2a\u6574\u6570\u5c42\u7ea7\n    uint mip0 = (uint)floor(mipmapLevel);\n    uint mip1 = min(mip0 + 1, g_HIZMaxMipmap);\n\n    \/\/ \u8ba1\u7b97\u4e24\u5c42\u4e4b\u95f4\u7684\u6df7\u5408\u56e0\u5b50\n    float t = frac(mipmapLevel);\n\n    \/\/ \u91c7\u6837\u4f4e\u5c42\u7ea7\uff08\u66f4\u7cbe\u7ec6\uff09\n    float depth0 = SampleTexture2D_LOD(g_HIZTextureIndex, uv, ClampLinearSampler, (float)mip0);\n\n    \/\/ \u91c7\u6837\u9ad8\u5c42\u7ea7\uff08\u66f4\u7c97\u7cd9\uff09\n    float depth1 = SampleTexture2D_LOD(g_HIZTextureIndex, uv, ClampLinearSampler, (float)mip1);\n\n    \/\/ \u5728\u4e24\u5c42\u6df1\u5ea6\u4e4b\u95f4\u8fdb\u884c\u7ebf\u6027\u63d2\u503c\n    return lerp(depth0, depth1, t);\n}\n\nfloat randomDepth = SampleHiZTrilinear(randomPosUV, mipmapLevel);\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u95ee\u9898\u89e3\u51b3\u4e86<br \/>\n<img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696b947855fa3078187188be.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696b947855fa3078187188be.png\" alt=\"\" \/><\/p><\/noscript>\n<\/li>\n<\/ul>\n<h2>Sobol Sequence<\/h2>\n<ul>\n<li>\n<p>\u95ee\u9898\uff1a\u4e4b\u95f4\u5728\u8ba1\u7b97\u968f\u673a\u5411\u91cf\u65f6\uff0c\u90fd\u662f\u7528c++\u76f4\u63a5\u5728\u751f\u6210\u968f\u673a\u6570\u518d\u4f20\u9012\u7ed9gpu\u7528\u4e8e\u751f\u6210\u968f\u673a\u7684\u5411\u91cf\uff0c\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\u8ba1\u7b97\u7684AO\u80af\u5b9a\u4f1a\u4ea7\u751f\u8bb8\u591a\u566a\u70b9\uff0c\u4f8b\u5982:<br \/>\n<img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696b965c55fa30781871c5d6.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696b965c55fa30781871c5d6.png\" alt=\"\" \/><\/p><\/noscript>\n<\/li>\n<li>\n<p>\u89e3\u51b3\uff1a\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u7528\u5230<strong>\u4f4e\u5dee\u5f02\u5e8f\u5217Sobol Sqeuence<\/strong><\/p>\n<\/li>\n<li>\n<p>\u7b97\u6cd5\uff1a<\/p>\n<pre><code class=\"language-glsl line-numbers\">std::vector&lt;Vector4&gt; AOPass::GenerateSSAOSampleKernel()\n{\n  std::vector&lt;Vector4&gt; o{};\n  UINT maxSampleCount = 16;\n  maxSampleCount = MathHelper::Min(UserData::GetInstance().aoParameter.SampleCount, maxSampleCount);\n  o.resize(maxSampleCount);\n\n  SobolSequenceGenerator sobol(2);\n  uint32_t* C = sobol.rightmostZeroBit(maxSampleCount);\n\n  for (UINT32 i = 0; i &lt; maxSampleCount; ++i)\n  {\n      auto point = sobol.nextPoint(C[i]);\n      float u1 = static_cast&lt;float&gt;(point[0]);\n      float u2 = static_cast&lt;float&gt;(point[1]);\n\n      \/\/ \u6838\u5fc3\uff1a\u4f7f\u7528\u4f59\u5f26\u52a0\u6743\u6620\u5c04\u5230\u534a\u7403 (Cosine-weighted Hemisphere)\n      float phi = 2.0f * 3.14159265f * u1;\n      float cosTheta = sqrt(1.0f - u2);\n      float sinTheta = sqrt(u2);\n\n      Vector4 v;\n      v.x = cos(phi) * sinTheta;\n      v.y = sin(phi) * sinTheta;\n      v.z = cosTheta; \/\/ Z\u8f74\u59cb\u7ec8\u4e3a\u6b63\uff0c\u4fdd\u8bc1\u5728\u534a\u7403\u5185\n      v.w = 0.0f;\n\n      \/\/ \u8ddd\u79bb\u7f29\u653e\uff08\u9760\u8fd1\u539f\u70b9\u7684\u70b9\u6743\u91cd\u66f4\u9ad8\uff0c\u589e\u5f3a\u63a5\u89e6\u9634\u5f71\uff09\n      float scale = (float)i \/ (float)maxSampleCount;\n      scale = 0.1f + 0.9f * (scale * scale); \/\/ Lerp(0.1, 1.0, scale^2)\n\n      o[i] = v * scale;\n  }\n\n  return o;\n}\n<\/code><\/pre>\n<\/li>\n<li>\u6548\u679c\n<p><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696b947855fa3078187188be.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696b947855fa3078187188be.png\" alt=\"\" \/><\/p><\/noscript>\n<\/li>\n<\/ul>\n<h2>\u81ea\u9002\u5e94\u534a\u5f84<\/h2>\n<ul>\n<li>\n<p>\u95ee\u9898<\/p>\n<p>\u76ee\u524d\u534a\u5f84\u662f\u4e00\u4e2a\u56fa\u5b9a\u503c\uff0c\u8fd9\u4f1a\u4ea7\u751f\u4e00\u4e2a\u95ee\u9898\u2014\u2014\u5982\u679c\u534a\u5f84\u5927\uff0c\u7eb9\u8def\u4f1a\u88ab\u62b9\u5e73\uff1b\u5982\u679c\u534a\u5f84\u5c0f\uff0c\u5927\u573a\u666f\u5c06\u6ca1\u6709\u9634\u5f71<\/p>\n<\/li>\n<li>\n<p>\u89e3\u51b3<\/p>\n<p>\u540c\u65f6\u8ba1\u7b97\u4e00\u4e2a\u5927\u534a\u5f84\u7684AO\u548c\u4e00\u4e2a\u5c0f\u534a\u5f84\u7684AO\uff0c\u5e76\u52a0\u6743\u5e73\u5747<\/p>\n<\/li>\n<li>\n<p>\u7b97\u6cd5<\/p>\n<p>\u5148\u8bbe\u5b9a\u4e00\u4e2a\u5927\u7684radius\uff1ag_AORadius\u548c\u4e00\u4e2a\u5c0f\u7684radius\uff1ag_AORadius * 0.2f\uff0c\u5b83\u4eec\u4f1a\u5f71\u54cdoffsetPixel\u7684\u5927\u5c0f<\/p>\n<p>\u5c0fradius\u7684offsetPixel\u8f83\u5c0f\uff0c\u9700\u8981\u7684mipmap level\u4f4e\uff0c\u4fdd\u8bc1AO\u9510\u5229\uff1b\u5927radius\u7684offsetPixel\u8f83\u5927\uff0c\u9700\u8981\u7684mipmap level\u9ad8\uff0c\u4fdd\u8bc1AO\u8f83\u4e3a\u6a21\u7cca<\/p>\n<p>\u540c\u65f6\u9700\u8981\u4fdd\u8bc1\uff0c\u906e\u6321\u5224\u5b9a\u548c\u534a\u5f84\u5927\u5c0f\u6709\u5173\uff0c\u8fd9\u610f\u5473\u7740rangeCheck\u9700\u8981\u52a0\u5165\u534a\u5f84\u7f29\u653e\u7cfb\u6570\uff08\u5373\u4e0a\u9762\u63d0\u5230\u76840.2f\uff09<\/p>\n<p>\u6700\u540e\uff0c\u56e0\u4e3a\u9634\u5f71\u5f80\u5f80\u662f\u7ec6\u8282\u5904\u66f4\u96be\u505a\uff0c\u6240\u4ee5\u52a0\u6743\u5e73\u5747\u65f6\uff0c\u5c0fradius\u7684\u6743\u91cd\u66f4\u5927<\/p>\n<pre><code class=\"language-glsl line-numbers\">float AO_Small = 0.0f;\nfloat AO_Large = 0.0f;\n[unroll(16)]\nfor (UINT sampleIndex = 0; sampleIndex &lt; g_AOSampleCount; ++sampleIndex)\n{\n  float3 randomVec = mul(g_AOSampleKernelArray[sampleIndex], TBN);\n\n  float3 vecLarge = randomVec * g_AORadius;\n  AO_Large += ComputeSingleAO(vecLarge, inputParam, normalVS, 1.0, randomVector * 0.5f);\n\n  float3 vecSmall = randomVec * (g_AORadius * 0.2f);\n  AO_Small += ComputeSingleAO(vecSmall, inputParam, normalVS, 0.2, randomVector * 0.5f);\n}\n\nAO_Large \/= (float)g_AOSampleCount;\nAO_Small \/= (float)g_AOSampleCount;\n\nfloat combinedAO = saturate(AO_Large * 0.4f + AO_Small * 0.6f);\n<\/code><\/pre>\n<p>\u6548\u679c<br \/>\n<img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696b9d3355fa30781871f41b.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696b9d3355fa30781871f41b.png\" alt=\"\" \/><\/p><\/noscript>\n<p>\u53ef\u4ee5\u770b\u5230\u8fdc\u5904\u7684\u9634\u5f71\u7ec6\u8282\u964d\u4f4e\u4e86\uff0c\u66f4\u5b8f\u5927\u6a21\u7cca<\/p>\n<\/li>\n<\/ul>\n<h2>HBAO<\/h2>\n<ul>\n<li>\n<p>\u95ee\u9898<\/p>\n<p>\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0cSSAO\u7684AO\u6548\u679c\u5176\u5b9e\u4e0d\u662f\u7279\u522b\u660e\u663e\uff0c\u8fd9\u662f\u56e0\u4e3aSSAO\u662f\u968f\u673a\u6492\u70b9\u518d\u8ba1\u7b97\u70b9\u662f\u5426\u906e\u6321\uff0c\u8fd9\u79cd\u65b9\u5f0f\u5e76\u4e0d\u7269\u7406\u2014\u2014\u4e0d\u80fd\u5b8c\u5168\u6b63\u786e\u5730\u8ba1\u7b97\u906e\u6321\uff0c\u4e5f\u5c31\u4e0d\u80fd\u505a\u5230\u8be5\u9ed1\u7684\u5730\u65b9\u5f88\u9ed1\u3002\u5b58\u5728\u7684\u95ee\u9898\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>SSAO<strong>\u5047\u8bbe\u6df1\u5ea6\u56fe\u4e2d\u6bcf\u4e2apixel\u5411\u540e\u65e0\u9650\u539a<\/strong>\uff1a\u8fd9\u5c31\u5bfc\u81f4\u4e00\u4e2a\u975e\u5e38\u8584\u7684\u8584\u7247\u9760\u8fd1\u5899\u4f53\uff0c\u5b83\u7684\u9634\u5f71\u8303\u56f4\u4f1a\u5f88\u5927<\/li>\n<li><strong>\u5149\u6655<\/strong>\uff1a\u5047\u8bbe\u4e00\u4e2a\u524d\u666f\u7269\u4f53\u79bb\u80cc\u666f\u5f88\u8fdc\uff0c\u8fd9\u79cd\u60c5\u51b5\u524d\u666f\u7269\u4f53\u4e0d\u5e94\u8be5\u4e0e\u80cc\u666f\u4ea7\u751f\u9634\u5f71\uff0c\u4f46SSAO\u4f1a\u5c06\u8fd9\u79cd\u60c5\u51b5\u7b97\u4e3a\u906e\u6321\uff08\u5373\u4f7f\u53ef\u4ee5\u7528\u8ddd\u79bb\u9608\u503c\u6765\u51cf\u8f7b\uff0c\u4f46\u4e0d\u80fd\u4ece\u6839\u672c\u4e0a\u89e3\u51b3\uff09<\/li>\n<\/ol>\n<\/li>\n<li>\u89e3\u51b3\n<p>\u4e3a\u4e86\u89e3\u51b3\u4ee5\u4e0a\u4e24\u4e2a\u95ee\u9898\uff0c\u4e0d\u80fd\u7b80\u5355\u5730\u6839\u636e\u6df1\u5ea6\u6765\u5224\u65ad\u906e\u6321\uff0c\u800c\u662f\u9700\u8981\u5f15\u5165ray marching\u4e00\u6b65\u4e00\u6b65\u5730\u5411\u67d0\u4e2a\u65b9\u5411\u6b65\u8fdb\uff0c\u5982\u6b64\u4fbf\u89e3\u51b3\u4e86SSAO\u4e0d\u9760\u8c31\u7684\u6df1\u5ea6\u5224\u65ad\u7684\u95ee\u9898<\/p>\n<p>HBAO\u4fbf\u662f\u8fd9\u4e00\u95ee\u9898\u7684\u89e3\u51b3\u8005<\/p>\n<\/li>\n<li>\n<p>\u7b97\u6cd5<\/p>\n<p>\u6b65\u8fdb\u5e76\u4e0d\u96be\uff0c\u96be\u7684\u662f\u5982\u4f55\u7cbe\u51c6\u5730\u8ba1\u7b97\u906e\u6321\uff0c\u8fd9\u4e5f\u6b63\u662fHBAO\u7684\u7b97\u6cd5\u7cbe\u9ad3<\/p>\n<ul>\n<li>\u6d41\u7a0b<\/li>\n<\/ul>\n<ol>\n<li><strong>\u968f\u673a\u751f\u6210\u5207\u7ebf\u89d2t<\/strong>\uff1a\u6839\u636epixel\u7684normal\u548c\u968f\u673a\u5411\u91cf\uff0c\u8ba1\u7b97\u5207\u7ebf\u89d2t<\/p>\n<\/li>\n<li>\n<p><strong>\u6b65\u8fdb<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u5bfb\u627e\u6700\u5927\u4ef0\u89d2<\/strong>\uff1a\u5bf9\u4e8e\u6b65\u8fdb\u5230\u7684\u6bcf\u4e00\u4e2a\u70b9 \uff0c\u5728<strong>\u6df1\u5ea6\u56fe<\/strong>\u4e0a\u8ba1\u7b97\u5b83\u4e0e\u8d77\u59cb\u70b9 <span class=\"katex math inline\">P<\/span> \u6784\u6210\u7684\u5411\u91cf\u7684\u4ef0\u89d2\u3002\u8bb0\u5f55\u5e76\u66f4\u65b0\u8be5\u65b9\u5411\u4e0a\u7684<strong>\u6700\u5927\u4ef0\u89d2<\/strong> <span class=\"katex math inline\">h<\/span>\uff08\u5373\u5730\u5e73\u7ebf\u89d2\u5ea6\uff09<\/p>\n<p>\u5177\u4f53\u6765\u8bf4\uff0c<strong>\u6bcf\u6b21\u6b65\u8fdb\u540e\u7684\u5750\u6807\u70b9\uff0c\u9700\u8981\u8f6c\u5316\u5230uv\uff0c\u5728\u6df1\u5ea6\u56fe\u4e0a\u91c7\u6837\u5bf9\u5e94uv\u7684\u6df1\u5ea6\uff0c\u5e76\u4f7f\u7528\u8be5\u6df1\u5ea6\u91cd\u5efaview\u7a7a\u95f4\u5750\u6807\uff0c\u8be5\u5750\u6807\u548c\u8d77\u59cb\u70b9\u76f8\u51cf\u5f97\u5230\u7684\u503c\u624d\u662f\u65b0\u5411\u91cf<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u8ba1\u7b97\u906e\u6321\u8d21\u732e<\/strong>\uff1a\u5c06\u6700\u5927\u4ef0\u89d2\u8f6c\u5316\u4e3a\u4e00\u4e2a 0 \u5230 1 \u7684<strong>\u906e\u6321\u503c<\/strong><\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p><strong>\u906e\u6321\u9879<\/strong><\/p>\n<ul>\n<li>\u516c\u5f0f\uff1a<span class=\"katex math inline\">W = sin(h) - sin(t)<\/span><\/li>\n<li>\u7269\u7406\u610f\u4e49\uff1a\u82e5\u4e0e\u5207\u7ebf\u5e73\u884c\uff0c\u5219\u6ca1\u6709\u906e\u6321\uff0c<span class=\"katex math inline\">W = 0<\/span>\uff1b\u82e5\u4e0e\u5207\u7ebf\u5782\u76f4\uff0c\u5219\u5b8c\u5168\u906e\u6321\uff0c<span class=\"katex math inline\">W = 1<\/span><\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8ddd\u79bb\u8870\u51cf<\/strong>\n<p>\u4e3a\u4e86\u66f4\u52a0\u7269\u7406\uff0c\u5373\u906e\u6321\u5e94\u968f<strong>\u5230\u906e\u6321\u7269\u8ddd\u79bb\u7684\u4e0d\u65ad\u4e0a\u5347\u800c\u4e0b\u964d<\/strong>\uff0c\u9700\u8981\u8ba1\u7b97\u8ddd\u79bb\u8870\u51cf<\/p>\n<ul>\n<li>\u516c\u5f0f\uff1a<span class=\"katex math inline\">f(d) = max(0, 1 - \\frac{d^2}{R^2})<\/span>\n<ul>\n<li>d\uff1a\u8d77\u59cb\u70b9\u5230\u6700\u5927\u4ef0\u89d2\u70b9\u7684\u8ddd\u79bb<\/li>\n<li>R\uff1a\u9884\u8bbe\u7684AO\u534a\u5f84<\/li>\n<\/ul>\n<\/li>\n<li>\u7269\u7406\u610f\u4e49\uff1a\u968f\u7740d\u7684\u589e\u5927\uff0c\u906e\u6321\u503c\u4f1a\u4e0d\u65ad\u964d\u4f4e\uff1b\u968f\u7740d\u7684\u964d\u4f4e\uff0c\u906e\u6321\u503c\u4f1a\u4e0d\u65ad\u589e\u5927<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u7d2f\u52a0\u5e73\u5747<\/strong>\n<p>\u5c06\u6bcf\u6b21\u6b65\u8fdb\u540e\u7684\u906e\u6321\u8d21\u732e\u76f8\u52a0\u5e76\u5e73\u5747<\/p>\n<ul>\n<li>\u5207\u7ebf\u89d2\u6709\u4ec0\u4e48\u7528\uff1f<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u907f\u514d\u628a\u50cf\u7d20\u201c\u81ea\u8eab\u7684\u8868\u9762\u201d\u8bef\u8ba4\u4e3a\u662f\u906e\u6321\u7269<\/strong>\uff1a\u6bd4\u5982\uff0c\u5728\u659c\u5761\u5411\u4e0a\u6b65\u8fdb\u80af\u5b9a\u4f1a\u5f97\u5230\u4e00\u4e2a\u5f88\u9ad8\u7684\u4ef0\u89d2\uff0c\u4fbf\u4f1a\u9020\u6210\u81ea\u906e\u6321<\/p>\n<ul>\n<li>\u4e3a\u4ec0\u4e48\u9700\u8981\u627e\u6700\u5927\u4ef0\u89d2\uff1f<\/li>\n<\/ul>\n<p><strong>\u8ba1\u7b97\u662f\u5426\u906e\u6321<\/strong>\uff1a\u627e\u5230\u6700\u5927\u4ef0\u89d2\uff0c\u548c\u5207\u7ebf\u89d2\u6bd4\u8f83\uff0c\u82e5\u5927\u4e8e\u5207\u7ebf\u89d2\uff0c\u90a3\u80af\u5b9a\u5b58\u5728\u906e\u6321<\/p>\n<p><strong>\u8ba1\u7b97\u906e\u6321\u8d21\u732e<\/strong><\/p>\n<\/li>\n<\/ul>\n<h3>\u900f\u89c6\u77eb\u6b63<\/h3>\n<ul>\n<li>\n<p>\u4e3a\u4ec0\u4e48\uff1f<\/p>\n<p>\u4e3a\u4ec0\u4e48HBAO\u9700\u8981\u900f\u89c6\u77eb\u6b63\uff0c\u800cSSAO\u4e0d\u7528\u5462\uff1f\u56e0\u4e3aSSAO\u751f\u6210\u968f\u673a\u53d8\u91cf\u540e\uff0c\u4f1a\u4e0d\u65ad\u8fdb\u884c\u77e9\u9635\u53d8\u5316\u76f4\u81f3uv\u7a7a\u95f4\uff0c\u77e9\u9635\u672c\u8eab\u5df2\u7ecf\u7b97\u900f\u89c6\u77eb\u6b63\u4e86\uff1b\u800cHBAO\u9700\u8981\u5728view space\u6b65\u8fdb\uff0c\u4eceuv space\u5230view space\uff0c\u672c\u8eab\u5c31\u4f1a\u53d7\u5230\u900f\u89c6\u7578\u53d8\u7684\u5f71\u54cd<\/p>\n<\/li>\n<li>\n<p>\u5982\u4f55\u77eb\u6b63<\/p>\n<p>\u9700\u8981\u8003\u8651<strong>fov \u548c \u5c4f\u5e55\u6bd4\u4f8b<\/strong>\u4e24\u79cd\u56e0\u7d20<\/p>\n<ul>\n<li>\u5982\u4f55\u77eb\u6b63uv space\u5230view space<\/li>\n<\/ul>\n<p>\u56e0\u4e3auv space\u6bcf\u4e2apixel\u90fd\u662f\u4e00\u4e2a\u5927\u5c0f\u76f8\u540c\u7684\u6b63\u65b9\u5f62\uff0c\u4f46\u5728view space \u53d7\u89c6\u9525\u4f53\u7684\u5f71\u54cd\uff0c\u4e0a\u4e0b\u5de6\u53f3\u79fb\u52a8pixel\u7684\u8ddd\u79bb\u662f\u4e0d\u7b49\uff0c\u6240\u4ee5\u9700\u8981\u77eb\u6b63\uff0c\u4f7f\u5f97<strong>view space\u4e2d\u4e0a\u4e0b\u5de6\u53f3\u79fb\u52a8pixel\u7684\u8ddd\u79bb\u662f\u76f8\u540c\u7684<\/strong><\/p>\n<p>\u4f17\u6240\u5468\u77e5\uff0cproject Matrix\u7684[0]&#91;0]\u4e0e[1]&#91;1]\u5206\u522b\u8868\u793a<span class=\"katex math inline\">\\frac{1}{tan(fovX\/2)}<\/span>\u4e0e<span class=\"katex math inline\">\\frac{1}{tan(fovY\/2)}<\/span>\uff0c\u518d\u6839\u636e<strong>\u5c4f\u5e55\u5bbd\u9ad8<\/strong>\uff0c\u4ee5\u53ca<strong>view space\u7684\u6df1\u5ea6<\/strong>\uff0c\u4e0d\u96be\u5b9e\u73b0\u4ee5\u4e0b\u77eb\u6b63<\/p>\n<pre><code class=\"language-glsl line-numbers\">float2 projScale = float2(projMatrix[0][0], projMatrix[1][1]);\nfloat ratio = g_TargetSize.x * g_TargetSize.w;\n\nfloat3 fovFix = float3(projScale.x, ratio * projScale.x, 1);\nfloat2 fovFixXY = fovFix.xy * (1.f \/ max(inputParam.PositionVS.z, 1e-4));   \/\/\u62b5\u6d88\u900f\u89c6\u6295\u5f71\u8fd1\u5927\u8fdc\u5c0f\u7684\u5f71\u54cd\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h3>\u91c7\u6837\u7a7a\u95f4<\/h3>\n<p>\u4e0eSSAO\u4e0d\u540c\u7684\u662f\uff0cHBAO\u7684\u968f\u673a\u5411\u91cf\u53ea\u9700\u8981xy\u5206\u91cf\uff0c\u4e0d\u9700\u8981xyz\u5206\u91cf\u3002\u8fd9\u662f\u56e0\u4e3aSSAO\u662f\u5728\u4e00\u4e2a3d\u7a7a\u95f4\u6492\u70b9\uff0c\u800cHBAO\u53ea\u9700\u8981\u786e\u5b9a2d\u7a7a\u95f4\u3002\u8fd9\u5c31\u597d\u50cf\uff0c\u6211\u4eec\u7ad9\u5728\u67d0\u4e2a\u4f4d\u7f6e\uff0c\u5411\u67d0\u4e2a\u65b9\u5411\u671b\u53bb\uff08\u5207\u7ebf\u89d2\uff09\uff0c\u6211\u4eec\u5e76\u4e0d\u5173\u5fc3x\u8f74\uff0c\u53ea\u5173\u5fc3yz\u8f74<\/p>\n<h3>\u968f\u673a\u6570\u9009\u62e9<\/h3>\n<p>SSAO\u53ef\u4ee5\u4f7f\u7528Sobol Sequence\uff0c\u4f46HBAO\u66f4\u504f\u5411<strong>Poisson Disk Distribution<\/strong><\/p>\n<p>\u8fd9\u662f\u56e0\u4e3aSobol Sequence\u5448\u73b0<strong>\u7f51\u683c\u72b6\u5f62\u72b6<\/strong>\uff0c\u800cPoisson Disk Distribution\u4e2d\u4efb\u610f\u4e24\u4e2a\u70b9\u7684\u8ddd\u79bb\u90fd\u5927\u4e8e\u67d0\u4e2a\u6700\u5c0f\u503c r\uff0c<strong>\u6ca1\u6709\u660e\u663e\u7684\u805a\u96c6<\/strong>\uff0c\u4e14\u662f<strong>\u5404\u5411\u540c\u6027<\/strong>\uff0c\u53e6\u5916Sobol Sequence\u5728\u6837\u672c\u8f83\u5c11\u7684\u65f6\u5019\uff0c\u6548\u679c\u5e76\u4e0d\u4f1a\u5f88\u597d<\/p>\n<h3>\u7b97\u6cd5\u5b9e\u73b0<\/h3>\n<ul>\n<li><strong>\u751f\u6210\u968f\u673a2d\u5411\u91cf\u5e76\u968f\u673a\u65cb\u8f6c<\/strong>\n<pre><code class=\"language-glsl line-numbers\">float3 randomVector = SampleTexture2D(BlueNoiseTexIndex, inputParam.ScreenUV * g_noiseScale, WarpPointSampler).xyz;\nfloat2 randomVec = randomVector.xy * 2.f - 1.f;\nfloat2x2 rotationMatrix = float2x2(\n      randomVec.x, randomVec.y,\n      -randomVec.y, randomVec.x\n      );\n\nfloat2 unrotatedRandomDir = g_AOSampleKernelArray[i].xy;\nfloat2 randomDirUV = mul(unrotatedRandomDir, rotationMatrix);\n<\/code><\/pre>\n<p>\u4e0eSSAO\u4e0d\u540c\uff0c\u8fd9\u91cc\u4e0d\u80fd\u4f7f\u7528sobol sequence\uff0c\u5426\u5219\u4f1a\u9020\u6210\u9700\u8981\u566a\u70b9<\/p>\n<\/li>\n<li>\n<p>\u8ba1\u7b97\u5207\u7ebf\u89d2<\/p>\n<pre><code class=\"language-glsl line-numbers\">float tanAngleSin = dot(tangentVS, normalVS) + sin(g_AOBias);\n<\/code><\/pre>\n<p>\u5207\u7ebf\u9762\u662fbit tangent\uff0c\u800c<span class=\"katex math inline\">dot(tangentVS, normalVS)<\/span>\u7b49\u540c\u4e8esin(\u5207\u7ebf\u9762)\uff0c\u7528\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u907f\u514d\u5750\u6807\u7cfb\u4e0d\u540c\u7684\u95ee\u9898<\/p>\n<\/li>\n<li>\n<p>\u6b65\u8fdb<\/p>\n<pre><code class=\"language-glsl line-numbers\">[unroll(_AO_MAX_SAMPLE_STEP_COUNT)]\nfor (UINT step = 0; step &lt; g_AOSampleStepCount; ++step) \n{\nfloat stepDistance = ((float)step + jitter) \/ (float)g_AOSampleStepCount; \/\/ \u6b65\u8fdb\u8ddd\u79bb\n\nfloat2 offsetUV = randomDirUV * stepDistance * actualAORadius * projScale.x * 0.5f \/ max(\n                                inputParam.PositionVS.z, 1.0f);\nfloat2 vSampleUV = inputParam.ScreenUV + offsetUV;\n\nif (any(vSampleUV &lt; 0) || any(vSampleUV &gt; 1))\n              continue;\n\n  float MipLevel = ComputeMipLevel(actualAORadius, inputParam.PositionVS.z, stepDistance, jitter);\n  float localRawDepth = SampleHiZTrilinear(vSampleUV, MipLevel);\n  float3 localPosVS = ComputeViewSpacePosition(vSampleUV, localRawDepth, projMatrix_I);\n}\n<\/code><\/pre>\n<p>\u6b65\u8fdb\u65f6\u4f7f\u7528jitter\u662f\u4e00\u4e2a\u7ecf\u5178\u505a\u6cd5\uff0c\u4f18\u5316\u91c7\u6837\u6b21\u6570\u4e0d\u8db3\u5e26\u6765\u7684\u566a\u70b9<\/p>\n<p><span class=\"katex math inline\">randomDirUV * stepDistance * actualAORadius * projScale.x * 0.5f \/ max(<br \/>\n                                inputParam.PositionVS.z, 1.0f)<\/span>\uff0c\u5c06<strong>radius\u4eceworld space\u8f6c\u5230uv space<\/strong><\/p>\n<\/li>\n<li>\n<p>\u8ba1\u7b97\u4ef0\u89d2<\/p>\n<pre><code class=\"language-glsl line-numbers\">\/\/ \u8ba1\u7b97\u4ef0\u89d2\u5411\u91cf\nfloat3 v = localPosVS - inputParam.PositionVS;\nfloat distSq = dot(v, v);\nfloat dist = sqrt(distSq);\n\n\/\/ \u8ddd\u79bb\u8870\u51cf\nfloat invRadiusSq = 1.0 \/ (actualAORadius * actualAORadius + 1e-5);\nfloat falloff = saturate(1.0 - distSq * invRadiusSq);\n\nfloat3 V_norm = v \/ (dist + 1e-6);\nfloat currentSinH = dot(V_norm, normalVS);\n\n\/\/ \u5982\u679c\u5f53\u524d\u9ad8\u5ea6\u89d2\u8d85\u8fc7\u5df2\u77e5\u6700\u5927\u89d2\uff0c\u66f4\u65b0\u906e\u6321\nif (currentSinH &gt; maxSinH)\n{\nmaxSinH = lerp(maxSinH, currentSinH, falloff);\n}\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u6700\u7ec8\u6548\u679c<\/p>\n<p><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/6970eda81404c8e205f04e10.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/6970eda81404c8e205f04e10.png\" alt=\"\" \/><\/p><\/noscript>\n<h3>\u4f18\u5316<\/h3>\n<p>\u7531\u4e8e\u9700\u8981\u63a7\u5236\u6b65\u8fdb\u6b21\u6570\uff0c\u6700\u591a6\u6b21\uff0c\u8fd9\u91cc\u8fd0\u7528\u81ea\u9002\u5e94\u534a\u5f84\u7684\u6536\u76ca\u5c31\u4e0d\u9ad8\u4e86\u3002\u6536\u76ca\u9ad8\u7684\u65b9\u6848\u6709\uff1a<\/p>\n<ul>\n<li>\u91c7\u7528UE\u7684\u601d\u8def\uff0c\u4f7f\u7528\u4e00\u5f20\u5168\u5206\u8fa8\u7387 AO + 1\/2\u5206\u8fa8\u7387 AO + 1\/4\u5206\u8fa8\u7387 AO\uff0c\u4ece\u4f4e\u5230\u9ad8\u6bcf\u6b21AO\u8ba1\u7b97\u540e\u4e0e\u4e0a\u4e00\u4e2aAO\u6df7\u5408<br \/>\n<img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/696e54d417fcb1e4ff524c6f.jpg\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/696e54d417fcb1e4ff524c6f.jpg\" alt=\"\" \/><\/p><\/noscript>\n<\/li>\n<li>\n<p>\u65e0\u9700\u989d\u5916pass\u76842x2 \u6a21\u7cca<\/p>\n<\/li>\n<li>\n<p>\u65f6\u95f4\u6ee4\u6ce2<\/p>\n<p>\u7531\u4e8eAO\u662f\u548c\u5411\u91cf\u6709\u5173\uff0c\u4e14\u5355\u5e27\u65e0\u6cd5\u652f\u6491\u591a\u592732\u6b21\u91c7\u6837\u7684\u6d88\u8017\uff0c\u90a3\u4e48\u4e0d\u5982\u6bcf\u5e27\u91c7\u68374\u6b21\uff0c\u5e76\u5728\u591a\u5e27\u4e2d\u65cb\u8f6c\u5411\u91cf\uff0c\u518d\u591a\u5e27\u6df7\u5408\uff0c\u8fbe\u5230\u4e00\u5e27\u62e5\u67094*n\u5e27\u7684\u6548\u679c<\/p>\n<\/li>\n<\/ul>\n<p>\u8017\u65f6\u548c\u6548\u679c\uff1a<\/p>\n<p><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/6974f5dbd0c7794503e316d0.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><br \/ >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/6974f5dbd0c7794503e316d0.png\" alt=\"\" \/><br \/><\/noscript>\npix gpu timer\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff0c\u5206\u522b\u662fhi normal depth + Calc AO + TAA<\/p>\n<p><img decoding=\"async\"  src=\"https:\/\/pic1.imgdb.cn\/item\/6974c2d412d4e117ead4bee7.png\" alt=\"\" \/><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/6974c28f12d4e117ead4bd9a.png\" alt=\"\" \/><img decoding=\"async\"  class=\"lazyload\" data-src=\"https:\/\/pic1.imgdb.cn\/item\/6974c2e912d4e117ead4bf62.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" \/><\/p >\n<noscript><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/6974c2d412d4e117ead4bee7.png\" alt=\"\" \/><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/6974c28f12d4e117ead4bd9a.png\" alt=\"\" \/><img decoding=\"async\" src=\"https:\/\/pic1.imgdb.cn\/item\/6974c2e912d4e117ead4bf62.png\" alt=\"\" \/><\/p><\/noscript>\n<p>Calc AO + TAA\u6ca1\u5565\u95ee\u9898\uff0c\u4f46hi normal depth\u7531\u4e8e\u91c7\u6837\u6b21\u6570\u6bd4\u8f83\u591a\uff0c\u9020\u6210\u9891\u7e41\u7684barrier\uff0c\u89e3\u51b3\u65b9\u6848\u6709\u4e24\u4e2a\uff1a<\/p>\n<ol>\n<li>\u5982\u679c\u4e0d\u60f3\u5927\u6539\uff0c\u7528pixel shader\u6027\u80fd\u4f1a\u597d\u4e00\u4e9b<\/li>\n<li>\u6709\u4e00\u79cd\u53ef\u4ee5\u4e00\u6b21dispatch\u5b8c\u6210\u6240\u6709hi normal depth\u7684\u8ba1\u7b97\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u7559\u5230\u540e\u7eed\u4ecb\u7ecd<\/li>\n<\/ol>\n<h1>Reference<\/h1>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/zhuanlan.zhihu.com\/p\/180497579\" target=\"_blank\"  rel=\"nofollow\" >\u53cc\u8fb9\u6ee4\u6ce2 - Bilateral Filter<\/a><\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.cnblogs.com\/KillerAery\/p\/15490834.html\" target=\"_blank\"  rel=\"nofollow\" >\u57fa\u4e8e\u5c4f\u5e55\u7a7a\u95f4\u7684\u5b9e\u65f6\u5168\u5c40\u5149\u7167\uff08Real-time Global Illumination Based On Screen Space\uff09<\/a><\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/zhuanlan.zhihu.com\/p\/473740101\" target=\"_blank\"  rel=\"nofollow\" >UE4 AO<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DX12 SSAO\u5165\u95e8\u5230HBAO\u5165\u575f \u524d\u8a00 \u4ec0\u4e48\u662fSSAO SSAO \u7684\u5168\u79f0\u662f Screen Space Ambient Occl &#8230;<\/p>","protected":false},"author":1,"featured_media":338,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"_links":{"self":[{"href":"http:\/\/chenglixue.top\/index.php?rest_route=\/wp\/v2\/posts\/337"}],"collection":[{"href":"http:\/\/chenglixue.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/chenglixue.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/chenglixue.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/chenglixue.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337"}],"version-history":[{"count":8,"href":"http:\/\/chenglixue.top\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":347,"href":"http:\/\/chenglixue.top\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions\/347"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/chenglixue.top\/index.php?rest_route=\/wp\/v2\/media\/338"}],"wp:attachment":[{"href":"http:\/\/chenglixue.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/chenglixue.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/chenglixue.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}