From 3ba558be702ee862c0e0ba791d2dc0c33ef4cd7c Mon Sep 17 00:00:00 2001 From: Michael Mason Date: Sat, 23 Nov 2024 14:58:58 -0500 Subject: [PATCH 1/2] 512 voxel resoution --- Core/Shaders/SDFGIProbeUpdateCS.hlsl | 8 ++++---- Core/pch.h | 2 +- Model/Renderer.cpp | 22 +++++++++++----------- Model/Shaders/DefaultPS.hlsl | 2 +- Model/Shaders/SDFDebugRayMarchPS.hlsl | 12 ++++++------ ModelViewer/ModelViewer.cpp | 20 +++++++++++++------- 6 files changed, 36 insertions(+), 30 deletions(-) diff --git a/Core/Shaders/SDFGIProbeUpdateCS.hlsl b/Core/Shaders/SDFGIProbeUpdateCS.hlsl index 201e4725a..a64e3b251 100644 --- a/Core/Shaders/SDFGIProbeUpdateCS.hlsl +++ b/Core/Shaders/SDFGIProbeUpdateCS.hlsl @@ -58,7 +58,7 @@ float3 WorldSpaceToTextureSpace(float3 worldPos) { // assuming a 128 * 128 * 128 texture, but we could make this dynamic // u' = u * (tmax - tmin) + tmin // where tmax == 127 and tmin == 0 - return texCoord * 127.0; + return texCoord * 511; } float4 SampleSDFAlbedo(float3 worldPos, float3 marchingDirection) { @@ -69,11 +69,11 @@ float4 SampleSDFAlbedo(float3 worldPos, float3 marchingDirection) { float depth = start; for (int i = 0; i < MAX_MARCHING_STEPS; i++) { int3 hit = (eye + depth * marchingDirection); - if (any(hit > int3(127, 127, 127)) || any(hit < int3(0, 0, 0))) { + if (any(hit > int3(511, 511, 511)) || any(hit < int3(0, 0, 0))) { return float4(0., 0., 0., 1.); } - hit.y = 127 - hit.y; - hit.z = 127 - hit.z; + hit.y = 511 - hit.y; + hit.z = 511 - hit.z; float dist = SDFTex[hit]; if (dist == 0.f) { return AlbedoTex[hit]; diff --git a/Core/pch.h b/Core/pch.h index e780f9d7a..30ae61436 100644 --- a/Core/pch.h +++ b/Core/pch.h @@ -52,7 +52,7 @@ #define ENABLE_DEPTH_PREPASS 0 // Enable SDF Ray-marching test -#define RAYMARCH_TEST 0 +#define RAYMARCH_TEST 1 #include #include diff --git a/Model/Renderer.cpp b/Model/Renderer.cpp index 1ff650d96..b5875540b 100644 --- a/Model/Renderer.cpp +++ b/Model/Renderer.cpp @@ -345,14 +345,14 @@ void Renderer::InitializeVoxel(void) m_DefaultVoxelPSO.SetRenderTargetFormats(1, &g_SceneColorBuffer.GetFormat(), DXGI_FORMAT_UNKNOWN); // SDFGI: Create Voxel UAV Textures - constexpr size_t size = 128 * 128 * 128; + constexpr size_t size = 512 * 512 * 512; uint32_t* init = new uint32_t[size]; std::fill(init, init + size, 0x0); m_VoxelAlbedo.Create3D( - 4, 128, 128, 128, DXGI_FORMAT_R8G8B8A8_UNORM, init, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"Voxel Albedo" + 4, 512, 512, 512, DXGI_FORMAT_R8G8B8A8_UNORM, init, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"Voxel Albedo" ); m_VoxelVoronoiInput.Create3D( - 4, 128, 128, 128, DXGI_FORMAT_R8G8B8A8_UINT, init, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"Voxel Voronoi Input" + 4, 512, 512, 512, DXGI_FORMAT_R16G16B16A16_UINT, init, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"Voxel Voronoi Input" ); delete[] init; @@ -398,14 +398,14 @@ void Renderer::InitializeJFA(void) } //Resource Initialization { - constexpr size_t size = 128 * 128 * 128; + constexpr size_t size = 512 * 512 * 512; uint32_t* init = new uint32_t[size]; std::fill(init, init + size, 0x0); m_FinalSDFOutput.Create3D( - 4, 128, 128, 128, DXGI_FORMAT_R32_FLOAT, init, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"SDF Output" + 4, 512, 512, 512, DXGI_FORMAT_R32_FLOAT, init, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"SDF Output" ); m_IntermediateSDFOutput.Create3D( - 4, 128, 128, 128, DXGI_FORMAT_R8G8B8A8_UINT, init, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"Intermediate JFA Output" + 4, 512, 512, 512, DXGI_FORMAT_R16G16B16A16_UINT, init, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, L"Intermediate JFA Output" ); delete[] init; } @@ -447,9 +447,9 @@ void Renderer::InitializeJFA(void) } //JFA3D Initialization - m_jfaGlobals.gridResolution[0] = 128.f; - m_jfaGlobals.gridResolution[1] = 128.f; - m_jfaGlobals.gridResolution[2] = 128.f; + m_jfaGlobals.gridResolution[0] = 512; + m_jfaGlobals.gridResolution[1] = 512; + m_jfaGlobals.gridResolution[2] = 512; } void Renderer::InitializeRayMarchDebug() { @@ -839,7 +839,7 @@ void Renderer::ComputeSDF(ComputeContext& context) context.FlushResourceBarriers(); bool swap = false; - for (uint32_t i = 64; i >= 1; i /= 2) { + for (uint32_t i = 256; i >= 1; i /= 2) { //0. Globals CBV { m_jfaGlobals.stepSize = i; @@ -855,7 +855,7 @@ void Renderer::ComputeSDF(ComputeContext& context) } } //2. Dispatch - context.Dispatch(16, 16, 16); + context.Dispatch(64, 64, 64); //3. Update swap bool swap = !swap; } diff --git a/Model/Shaders/DefaultPS.hlsl b/Model/Shaders/DefaultPS.hlsl index a371ca2eb..a4adff4a7 100644 --- a/Model/Shaders/DefaultPS.hlsl +++ b/Model/Shaders/DefaultPS.hlsl @@ -441,7 +441,7 @@ float4 main(VSOutput vsOutput) : SV_Target0 // 512 * 512, and that the 3D texture is 128 * 128 * 128. We could // make these CBV's if we want. float screenResolution = 512.0; - float textureResolution = 128.0; + float textureResolution = 512.0; float2 uv = vsOutput.position.xy / screenResolution; // normalized UV coords uint3 voxelCoords = GetVoxelCoords(vsOutput.position.xyz, uv, textureResolution, axis); diff --git a/Model/Shaders/SDFDebugRayMarchPS.hlsl b/Model/Shaders/SDFDebugRayMarchPS.hlsl index dd774222c..6340fe3e4 100644 --- a/Model/Shaders/SDFDebugRayMarchPS.hlsl +++ b/Model/Shaders/SDFDebugRayMarchPS.hlsl @@ -61,14 +61,14 @@ float3 worldToTex(float3 worldPos) { // assuming a 128 * 128 * 128 texture, but this can be changed // u' = u * (tmax - tmin) + tmin // where tmax == 127 and tmin == 0 - return texCoord * 127.0; + return texCoord * 511.0; } // hm I'm not actually sure if I need texToWorld float3 texToWorld(uint3 texPos) { // normalize texPos uint tmin = 0; - uint tmax = 127; + uint tmax = 511; float3 range = tmax - tmin; float3 uvw = float3(0, 0, 0); uvw.x = (texPos.x - tmin) / range; @@ -154,11 +154,11 @@ int3 shortestDistanceToSurfaceTexSpace(float3 eye, float3 marchingDirection, out depth = start; for (int i = 0; i < MAX_MARCHING_STEPS; i++) { int3 hit = (eye + depth * marchingDirection); - if (any(hit > int3(127, 127, 127)) || any(hit < int3(0, 0, 0))) { + if (any(hit > int3(511, 511, 511)) || any(hit < int3(0, 0, 0))) { return int3(-1, -1, -1); } - hit.y = 127 - hit.y; - hit.z = 127 - hit.z; + hit.y = 511 - hit.y; + hit.z = 511 - hit.z; float dist = SDFTex[hit]; if (dist == 0.f) { return hit; @@ -182,7 +182,7 @@ float4 main(VSOutput input) : SV_TARGET{ if (hit.x == -1) { // Didn't hit anything - return float4(0.0, 0.0, 0.0, 0.0); + return float4(0.0, 0.0, 0.0, 1.0); } // -- test that we're getting UAV's -- diff --git a/ModelViewer/ModelViewer.cpp b/ModelViewer/ModelViewer.cpp index 81521a11b..c8ca9b4b7 100644 --- a/ModelViewer/ModelViewer.cpp +++ b/ModelViewer/ModelViewer.cpp @@ -101,8 +101,8 @@ class ModelViewer : public GameCore::IGameApp CREATE_APPLICATION( ModelViewer ) ExpVar g_SunLightIntensity("Viewer/Lighting/Sun Light Intensity", 4.0f, 0.0f, 16.0f, 0.1f); -NumVar g_SunOrientation("Viewer/Lighting/Sun Orientation", -0.0f, -0.0f, 0.0f, 0.1f ); -NumVar g_SunInclination("Viewer/Lighting/Sun Inclination", 0.0f, 0.0f, 1.0f, 0.01f ); +NumVar g_SunOrientation("Viewer/Lighting/Sun Orientation", -0.5f, -100.0f, 100.0f, 0.1f); +NumVar g_SunInclination("Viewer/Lighting/Sun Inclination", 0.75f, 0.0f, 1.0f, 0.01f); void ChangeIBLSet(EngineVar::ActionType); void ChangeIBLBias(EngineVar::ActionType); @@ -203,9 +203,9 @@ void ModelViewer::Startup( void ) Sponza::Startup(m_Camera); #else scaleModel = 100.0f; - //m_ModelInst = Renderer::LoadModel(L"Sponza/PBR/sponza2.gltf", forceRebuild); + m_ModelInst = Renderer::LoadModel(L"Sponza/PBR/sponza2.gltf", forceRebuild); // m_ModelInst = Renderer::LoadModel(L"Models/BoxAndPlane/BoxAndPlane.gltf", forceRebuild); - m_ModelInst = Renderer::LoadModel(L"Models/CornellWithSonicThickWalls/CornellWithSonicThickWalls.gltf", forceRebuild); + //m_ModelInst = Renderer::LoadModel(L"Models/CornellWithSonicThickWalls/CornellWithSonicThickWalls.gltf", forceRebuild); // m_ModelInst = Renderer::LoadModel(L"Models/CubemapTest/CubemapTest.gltf", forceRebuild); // m_ModelInst = Renderer::LoadModel(L"Models/2PlaneBall/2PlaneBall.gltf", forceRebuild); m_ModelInst.Resize(scaleModel * m_ModelInst.GetRadius()); @@ -632,9 +632,11 @@ void ModelViewer::RenderScene( void ) const D3D12_VIEWPORT& viewport = m_MainViewport; const D3D12_RECT& scissor = m_MainScissor; + static bool runOnce = true; + ParticleEffectManager::Update(gfxContext.GetComputeContext(), Graphics::GetFrameTime()); #if RAYMARCH_TEST - static bool runOnce = true; + //static bool runOnce = true; static bool rayMarchDebug = true; if (runOnce) { NonLegacyRenderShadowMap(gfxContext, m_Camera, viewport, scissor); @@ -650,7 +652,7 @@ void ModelViewer::RenderScene( void ) } else { NonLegacyRenderShadowMap(gfxContext, m_Camera, viewport, scissor); - NonLegacyRenderSDF(gfxContext); + // NonLegacyRenderSDF(gfxContext); NonLegacyRenderScene(gfxContext, m_Camera, viewport, scissor, /*renderShadows=*/true, /*useSDFGI=*/false); } #else @@ -664,7 +666,11 @@ void ModelViewer::RenderScene( void ) else { NonLegacyRenderShadowMap(gfxContext, m_Camera, viewport, scissor); - NonLegacyRenderSDF(gfxContext); + if (runOnce) { + NonLegacyRenderSDF(gfxContext); + runOnce = false; + } + mp_SDFGIManager->Update(gfxContext, m_Camera, viewport, scissor); NonLegacyRenderScene(gfxContext, m_Camera, viewport, scissor, /*renderShadows=*/true, /*useSDFGI=*/true); } From d9784677c719cedb49069f28ab3e05466b86e024 Mon Sep 17 00:00:00 2001 From: Michael Mason Date: Sun, 24 Nov 2024 16:55:33 -0500 Subject: [PATCH 2/2] use base color for albedo for the milestone 2 demo --- Model/Shaders/DefaultPS.hlsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/Shaders/DefaultPS.hlsl b/Model/Shaders/DefaultPS.hlsl index a4adff4a7..c465d551a 100644 --- a/Model/Shaders/DefaultPS.hlsl +++ b/Model/Shaders/DefaultPS.hlsl @@ -452,7 +452,7 @@ float4 main(VSOutput vsOutput) : SV_Target0 } // TODO: using baseColor for debug purposes - SDFGIVoxelAlbedo[voxelCoords] = float4(colorAccum.xyz, 1.0); + SDFGIVoxelAlbedo[voxelCoords] = float4(baseColor.xyz, 1.0); //SDFGIVoxelAlbedo[voxelCoords] = float4(baseColor.xyz, 1.0); SDFGIVoxelVoronoi[voxelCoords] = uint4(voxelCoords, 255); @@ -463,7 +463,7 @@ float4 main(VSOutput vsOutput) : SV_Target0 if (UseAtlas) { return float4(GammaCorrection(ACESToneMapping(SampleIrradiance(vsOutput.worldPos, normalize(vsOutput.normal))), 2.2f), 1.0f); } else { - return float4(GammaCorrection(ACESToneMapping(colorAccum), 2.2f), baseColor.a); + return baseColor; } }