Skip to content

Commit

Permalink
fixed voxelization debug of bigger cascades; added event tags for VCT…
Browse files Browse the repository at this point in the history
… in ER_Illumination::DrawDynamicGlobalIllumination()
  • Loading branch information
steaklive committed Dec 17, 2023
1 parent 4fc7317 commit 8dfcb14
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
6 changes: 3 additions & 3 deletions content/shaders/CompositeIllumination.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cbuffer CompositeCB : register(b0)
#define COMPOSITE_FLAGS_NONE 0x00000000
#define COMPOSITE_FLAGS_NO_GI 0x00000001
#define COMPOSITE_FLAGS_DEBUG_GI_AO 0x00000002
#define COMPOSITE_FLAGS_DEBUG_GI_INDIRECT 0x00000003
#define COMPOSITE_FLAGS_DEBUG_GI_IRRADIANCE 0x00000003
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_ALBEDO 0x00000004
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_NORMALS 0x00000005
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_ROUGHNESS 0x00000006
Expand All @@ -28,7 +28,7 @@ void CSMain(uint3 Gid : SV_GroupID, uint3 GTid : SV_GroupThreadID, uint3 DTid :
float2 texCooord = DTid.xy / float2(width, height);
float4 localIllumination = InputLocalIlluminationTexture.SampleLevel(LinearSampler, texCooord, 0);

if (CompositeFlags > COMPOSITE_FLAGS_DEBUG_GI_INDIRECT)
if (CompositeFlags > COMPOSITE_FLAGS_DEBUG_GI_IRRADIANCE)
{
if (CompositeFlags == COMPOSITE_FLAGS_DEBUG_GBUFFER_ALBEDO)
outputTexture[DTid.xy] = float4(pow(localIllumination.rgb, 2.2), 1.0f);
Expand All @@ -48,7 +48,7 @@ void CSMain(uint3 Gid : SV_GroupID, uint3 GTid : SV_GroupThreadID, uint3 DTid :
outputTexture[DTid.xy] = float4(localIllumination.rgb, 1.0f);
else if (CompositeFlags == COMPOSITE_FLAGS_DEBUG_GI_AO)
outputTexture[DTid.xy] = float4(ao, ao, ao, 1.0f);
else if (CompositeFlags == COMPOSITE_FLAGS_DEBUG_GI_INDIRECT)
else if (CompositeFlags == COMPOSITE_FLAGS_DEBUG_GI_IRRADIANCE)
outputTexture[DTid.xy] = float4(globalIllumination.rgb, 1.0f);
else
outputTexture[DTid.xy] = localIllumination + float4(globalIllumination.rgb * ao, 1.0f);
Expand Down
31 changes: 22 additions & 9 deletions source/EveryRay_Core/ER_Illumination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ namespace EveryRay_Core {

rhi->SetTopologyType(ER_RHI_PRIMITIVE_TYPE::ER_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

//voxelization
rhi->BeginEventTag("EveryRay: Voxel Cone Tracing - Voxelization");
{
rhi->SetRootSignature(mVoxelizationRS);
for (int cascade = 0; cascade < NUM_VOXEL_GI_CASCADES; cascade++)
Expand Down Expand Up @@ -501,18 +501,24 @@ namespace EveryRay_Core {
rhi->SetRasterizerState(ER_RHI_RASTERIZER_STATE::ER_BACK_CULLING);
}
}
rhi->EndEventTag();

//voxelization debug
//TODO: for some reason not working on DX12
if (mVCTDebugMode == VCT_DEBUG_VOXELS)
{
if (rhi->GetAPI() == DX12)
throw ER_CoreException("'Voxel Cone Tracing - Debug Voxels' is not yet supported on DX12!");

rhi->BeginEventTag("EveryRay: Voxel Cone Tracing - Debug Voxels");
rhi->SetRootSignature(mVoxelizationDebugRS);
rhi->SetTopologyType(ER_RHI_PRIMITIVE_TYPE::ER_PRIMITIVE_TOPOLOGY_POINTLIST);

int cascade = 0; //TODO fix for other cascades
assert(mVCTVoxelsDebugSelectedCascade < NUM_VOXEL_GI_CASCADES);
int cascade = mVCTVoxelsDebugSelectedCascade;
{
float scale = 1.0f / (mWorldVoxelScales[cascade] * 0.5f);
float sizeTranslateShift = -voxelCascadesSizes[cascade] / mWorldVoxelScales[cascade] * 0.5f;
mVoxelizationDebugConstantBuffer.Data.WorldVoxelCube =
XMMatrixScaling(scale, scale, scale) *
XMMatrixTranslation(
sizeTranslateShift + mVoxelCameraPositions[cascade].x,
sizeTranslateShift - mVoxelCameraPositions[cascade].y,
Expand All @@ -539,7 +545,7 @@ namespace EveryRay_Core {
rhi->FinalizePSO(mVoxelizationDebugPSOName);
}
rhi->SetPSO(mVoxelizationDebugPSOName);
rhi->SetShaderResources(ER_VERTEX, { mVCTVoxelCascades3DRTs[cascade] }, 0, mVoxelizationDebugRS, VCT_DEBUG_PASS_ROOT_DESCRIPTOR_TABLE_SRV_INDEX);
rhi->SetShaderResources(ER_VERTEX, { mVCTVoxelCascades3DRTs[cascade] }, 0, mVoxelizationDebugRS, VCT_DEBUG_PASS_ROOT_DESCRIPTOR_TABLE_SRV_INDEX);
rhi->SetConstantBuffers(ER_VERTEX, { mVoxelizationDebugConstantBuffer.Buffer() }, 0, mVoxelizationDebugRS, VCT_DEBUG_PASS_ROOT_DESCRIPTOR_TABLE_CBV_INDEX);
rhi->SetConstantBuffers(ER_GEOMETRY, { mVoxelizationDebugConstantBuffer.Buffer() }, 0, mVoxelizationDebugRS, VCT_DEBUG_PASS_ROOT_DESCRIPTOR_TABLE_CBV_INDEX);
rhi->SetConstantBuffers(ER_PIXEL, { mVoxelizationDebugConstantBuffer.Buffer() }, 0, mVoxelizationDebugRS, VCT_DEBUG_PASS_ROOT_DESCRIPTOR_TABLE_CBV_INDEX);
Expand All @@ -552,9 +558,11 @@ namespace EveryRay_Core {
rhi->UnbindResourcesFromShader(ER_PIXEL);
rhi->SetDepthStencilState(ER_DEPTH_ONLY_WRITE_COMPARISON_LESS_EQUAL);
}
rhi->EndEventTag();
}
else // main pass
{
rhi->BeginEventTag("EveryRay: Voxel Cone Tracing - Main");
rhi->UnbindRenderTargets();

for (int i = 0; i < NUM_VOXEL_GI_CASCADES; i++)
Expand Down Expand Up @@ -600,9 +608,11 @@ namespace EveryRay_Core {
rhi->Dispatch(ER_DivideByMultiple(static_cast<UINT>(mVCTMainRT->GetWidth()), 8u), ER_DivideByMultiple(static_cast<UINT>(mVCTMainRT->GetHeight()), 8u), 1u);
rhi->UnsetPSO();
rhi->UnbindResourcesFromShader(ER_COMPUTE);

rhi->EndEventTag();
}

//upsample & blur
rhi->BeginEventTag("EveryRay: Voxel Cone Tracing - Upsample/Blur");
{
mUpsampleBlurConstantBuffer.Data.Upsample = true;
mUpsampleBlurConstantBuffer.ApplyChanges(rhi);
Expand All @@ -624,6 +634,7 @@ namespace EveryRay_Core {
rhi->UnsetPSO();
rhi->UnbindResourcesFromShader(ER_COMPUTE);
}
rhi->EndEventTag();
}

// Combine GI output (Voxel Cone Tracing) with local illumination output
Expand All @@ -643,8 +654,8 @@ namespace EveryRay_Core {
{
if (mVCTDebugMode == VCT_DEBUG_AO)
mCompositeTotalIlluminationConstantBuffer.Data.CompositeFlags = COMPOSITE_FLAGS_DEBUG_GI_AO;
else if (mVCTDebugMode == VCT_DEBUG_VOXELS || mVCTDebugMode == VCT_DEBUG_INDIRECT)
mCompositeTotalIlluminationConstantBuffer.Data.CompositeFlags = COMPOSITE_FLAGS_DEBUG_GI_INDIRECT;
else if (mVCTDebugMode == VCT_DEBUG_VOXELS || mVCTDebugMode == VCT_DEBUG_IRRADIANCE)
mCompositeTotalIlluminationConstantBuffer.Data.CompositeFlags = COMPOSITE_FLAGS_DEBUG_GI_IRRADIANCE;
}
}
else
Expand Down Expand Up @@ -827,7 +838,9 @@ namespace EveryRay_Core {
}
ImGui::Checkbox("DEBUG - Voxel Cascades Update Always", &mIsVCTAlwaysUpdated);
}
ImGui::SliderInt("DEBUG - None, AO, Voxels, Indirect", &(int)mVCTDebugMode, 0, VCT_DEBUG_COUNT - 1);
ImGui::SliderInt("DEBUG - None, AO, Irradiance, Voxels", &(int)mVCTDebugMode, 0, VCT_DEBUG_COUNT - 1);
if (mVCTDebugMode == VCT_DEBUG_VOXELS)
ImGui::SliderInt("DEBUG - Cascade Index", &mVCTVoxelsDebugSelectedCascade, 0, NUM_VOXEL_GI_CASCADES - 1);
}
if (ImGui::CollapsingHeader("Static - Light Probes"))
{
Expand Down
14 changes: 9 additions & 5 deletions source/EveryRay_Core/ER_Illumination.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define COMPOSITE_FLAGS_NONE 0x00000000
#define COMPOSITE_FLAGS_NO_GI 0x00000001
#define COMPOSITE_FLAGS_DEBUG_GI_AO 0x00000002
#define COMPOSITE_FLAGS_DEBUG_GI_INDIRECT 0x00000003
#define COMPOSITE_FLAGS_DEBUG_GI_IRRADIANCE 0x00000003
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_ALBEDO 0x00000004
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_NORMALS 0x00000005
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_ROUGHNESS 0x00000006
Expand All @@ -55,9 +55,12 @@ namespace EveryRay_Core
class ER_Skybox;
class ER_VolumetricFog;

// TODO: At the moment our GIQuality config only affects VCT and it's resolution (off, 0.5, 0.75), we should also add:
// - voxel resolution for vct per config (currently its hardcoded in voxelCascadesSizes)
// - light probes settings (i.e., limit the amount of reflection probes per config)
// TODO: At the moment our GIQuality config only affects VCT and it's final output RT resolution (off, 0.5, 0.75), we can also add:
// - dynamic gi:
// - - voxel resolution for vct per config (currently its hardcoded in 'voxelCascadesSizes')
// - - cone amounts per voxel trace (currently everything is hardcoded with 6 cones)
// - static gi:
// - - limit the amount of reflection probes per config
// - maybe something else...
enum GIQuality
{
Expand All @@ -70,8 +73,8 @@ namespace EveryRay_Core
{
VCT_DEBUG_NONE = 0,
VCT_DEBUG_AO,
VCT_DEBUG_IRRADIANCE, // final indirect GI result
VCT_DEBUG_VOXELS,
VCT_DEBUG_INDIRECT, // final indirect GI result

VCT_DEBUG_COUNT
};
Expand Down Expand Up @@ -312,6 +315,7 @@ namespace EveryRay_Core
bool mIsVCTAlwaysUpdated = false; // update volumes every frame (only for debugging)

VCTDebugMode mVCTDebugMode = VCTDebugMode::VCT_DEBUG_NONE;
int mVCTVoxelsDebugSelectedCascade = 0; // cascade for VCTDebugMode::VCT_DEBUG_VOXELS
bool mShowVCTVoxelZonesGizmos[NUM_VOXEL_GI_CASCADES] = { false, false };
bool mIsVCTEnabled = false;

Expand Down

0 comments on commit 8dfcb14

Please sign in to comment.