Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Core/Shaders/SDFGIProbeUpdateCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Core/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#define ENABLE_DEPTH_PREPASS 0

// Enable SDF Ray-marching test
#define RAYMARCH_TEST 0
#define RAYMARCH_TEST 1

#include <Windows.h>
#include <wrl/client.h>
Expand Down
22 changes: 11 additions & 11 deletions Model/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions Model/Shaders/DefaultPS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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;
}

}
12 changes: 6 additions & 6 deletions Model/Shaders/SDFDebugRayMarchPS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 --
Expand Down
20 changes: 13 additions & 7 deletions ModelViewer/ModelViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
}
Expand Down