Skip to content

Commit

Permalink
added Gbuffer visualization (UI, cpp, etc.) + refactored Voxel Cone T…
Browse files Browse the repository at this point in the history
…racing visualization in CompositeIllumination.hlsl
  • Loading branch information
steaklive committed Nov 13, 2023
1 parent 2e056fc commit ddccef0
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 27 deletions.
36 changes: 26 additions & 10 deletions content/shaders/CompositeIllumination.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,49 @@ RWTexture2D<float4> outputTexture : register(u0);

cbuffer CompositeCB : register(b0)
{
float4 DebugVoxelAO_Disable; // r- voxel, g - ao, b - disable composite
uint CompositeFlags;
};

// Keep in sync with ER_Illumination!
#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_GBUFFER_ALBEDO 0x00000004
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_NORMALS 0x00000005
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_ROUGHNESS 0x00000006
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_METALNESS 0x00000007

[numthreads(8, 8, 1)]
void CSMain(uint3 Gid : SV_GroupID, uint3 GTid : SV_GroupThreadID, uint3 DTid : SV_DispatchThreadID)
{
uint width, height;
InputLocalIlluminationTexture.GetDimensions(width, height);
float2 texCooord = DTid.xy / float2(width, height);
float4 localIllumination = InputLocalIlluminationTexture.SampleLevel(LinearSampler, texCooord, 0);
if (DebugVoxelAO_Disable.b > 0.0f)

if (CompositeFlags > COMPOSITE_FLAGS_DEBUG_GI_INDIRECT)
{
outputTexture[DTid.xy] = float4(localIllumination.rgb, 1.0f);
if (CompositeFlags == COMPOSITE_FLAGS_DEBUG_GBUFFER_ALBEDO)
outputTexture[DTid.xy] = float4(pow(localIllumination.rgb, 2.2), 1.0f);
else if (CompositeFlags == COMPOSITE_FLAGS_DEBUG_GBUFFER_NORMALS)
outputTexture[DTid.xy] = float4(normalize(localIllumination.rgb), 1.0f);
else if (CompositeFlags == COMPOSITE_FLAGS_DEBUG_GBUFFER_ROUGHNESS)
outputTexture[DTid.xy] = float4(localIllumination.ggg, 1.0f);
else if (CompositeFlags == COMPOSITE_FLAGS_DEBUG_GBUFFER_METALNESS)
outputTexture[DTid.xy] = float4(localIllumination.bbb, 1.0f);
return;
}

float4 globalIllumination = InputGlobalIlluminationTexture.SampleLevel(LinearSampler, texCooord, 0);
float ao = 1.0f - globalIllumination.a;

if (DebugVoxelAO_Disable.g > 0.0f)
{
if (CompositeFlags == COMPOSITE_FLAGS_NO_GI)
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);
return;
}

if (DebugVoxelAO_Disable.r > 0.0f)
outputTexture[DTid.xy] = float4(globalIllumination.rgb, 1.0f);
else if (CompositeFlags == COMPOSITE_FLAGS_DEBUG_GI_INDIRECT)
outputTexture[DTid.xy] = float4(globalIllumination.rgb, 1.0f);
else
outputTexture[DTid.xy] = localIllumination + float4(globalIllumination.rgb * ao, 1.0f);
}
11 changes: 11 additions & 0 deletions source/EveryRay_Core/ER_GBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ namespace EveryRay_Core {
static std::string psoNameNonInstancedWireframe = "ER_RHI_GPUPipelineStateObject: GBufferMaterial (Wireframe)";
static std::string psoNameInstancedWireframe = "ER_RHI_GPUPipelineStateObject: GBufferMaterial w/ Instancing (Wireframe)";

static const char* debugModeNames[GBufferDebugMode::GBUFFER_DEBUG_COUNT] =
{
"None",
"Albedo",
"Normals",
"Roughness",
"Metalness"
};

ER_GBuffer::ER_GBuffer(ER_Core& game, ER_Camera& camera, int width, int height):
ER_CoreComponent(game), mWidth(width), mHeight(height)
{
Expand Down Expand Up @@ -148,6 +157,8 @@ namespace EveryRay_Core {

ImGui::Begin("GBuffer");
ImGui::Checkbox("Enabled", &mIsEnabled);

ImGui::ListBox("Debug Mode", &(int)mCurrentDebugMode, debugModeNames, (int)GBufferDebugMode::GBUFFER_DEBUG_COUNT, (int)GBufferDebugMode::GBUFFER_DEBUG_COUNT);
ImGui::End();
}

Expand Down
15 changes: 15 additions & 0 deletions source/EveryRay_Core/ER_GBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ namespace EveryRay_Core
class ER_Scene;
class ER_Camera;

enum GBufferDebugMode
{
GBUFFER_DEBUG_NONE = 0,
GBUFFER_DEBUG_ALBEDO,
GBUFFER_DEBUG_NORMALS,
GBUFFER_DEBUG_ROUGHNESS,
GBUFFER_DEBUG_METALNESS,

GBUFFER_DEBUG_COUNT
};

class ER_GBuffer: public ER_CoreComponent
{
public:
Expand All @@ -31,6 +42,8 @@ namespace EveryRay_Core
ER_RHI_GPUTexture* GetExtra2Buffer() { return mExtra2Buffer; } // [1 channel: "RenderingObjectFlags" bitmasks]
ER_RHI_GPUTexture* GetDepth() { return mDepthBuffer; }

GBufferDebugMode GetCurrentDebugMode() { return mCurrentDebugMode; }

private:
void UpdateImGui();

Expand All @@ -47,5 +60,7 @@ namespace EveryRay_Core
int mHeight;
bool mIsEnabled = true;
bool mShowDebug = false;

GBufferDebugMode mCurrentDebugMode = GBUFFER_DEBUG_NONE;
};
}
58 changes: 48 additions & 10 deletions source/EveryRay_Core/ER_Illumination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ namespace EveryRay_Core {

//voxelization debug
//TODO: for some reason not working on DX12
if (mShowVCTVoxelizationOnly)
if (mVCTDebugMode == VCT_DEBUG_VOXELS)
{
rhi->SetRootSignature(mVoxelizationDebugRS);
rhi->SetTopologyType(ER_RHI_PRIMITIVE_TYPE::ER_PRIMITIVE_TOPOLOGY_POINTLIST);
Expand Down Expand Up @@ -628,13 +628,52 @@ namespace EveryRay_Core {
}

// Combine GI output (Voxel Cone Tracing) with local illumination output
void ER_Illumination::CompositeTotalIllumination()
void ER_Illumination::CompositeTotalIllumination(ER_GBuffer* gbuffer)
{
auto rhi = GetCore()->GetRHI();

mCompositeTotalIlluminationConstantBuffer.Data.DebugVoxelAO_Disable = XMFLOAT4(
mShowVCTVoxelizationOnly ? 1.0f : -1.0f,
mShowVCTAmbientOcclusionOnly ? 1.0f : -1.0f, mCurrentGIQuality == GIQuality::GI_LOW ? 1.0f : 0.0f, 0.0f);
ER_RHI_GPUTexture* currentCustomLocalIllumination = mLocalIlluminationRT;

mCompositeTotalIlluminationConstantBuffer.Data.CompositeFlags = COMPOSITE_FLAGS_NONE;
GBufferDebugMode currentDebugMode = gbuffer->GetCurrentDebugMode();
if (currentDebugMode == GBUFFER_DEBUG_NONE)
{
if (mCurrentGIQuality == GIQuality::GI_LOW)
mCompositeTotalIlluminationConstantBuffer.Data.CompositeFlags = COMPOSITE_FLAGS_NO_GI;
else
{
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
{
mVCTDebugMode = VCT_DEBUG_NONE;

switch (currentDebugMode)
{
case GBUFFER_DEBUG_ALBEDO:
mCompositeTotalIlluminationConstantBuffer.Data.CompositeFlags = COMPOSITE_FLAGS_DEBUG_GBUFFER_ALBEDO;
currentCustomLocalIllumination = gbuffer->GetAlbedo();
break;
case GBUFFER_DEBUG_NORMALS:
mCompositeTotalIlluminationConstantBuffer.Data.CompositeFlags = COMPOSITE_FLAGS_DEBUG_GBUFFER_NORMALS;
currentCustomLocalIllumination = gbuffer->GetNormals();
break;
case GBUFFER_DEBUG_ROUGHNESS:
mCompositeTotalIlluminationConstantBuffer.Data.CompositeFlags = COMPOSITE_FLAGS_DEBUG_GBUFFER_ROUGHNESS;
currentCustomLocalIllumination = gbuffer->GetExtraBuffer();
break;
case GBUFFER_DEBUG_METALNESS:
mCompositeTotalIlluminationConstantBuffer.Data.CompositeFlags = COMPOSITE_FLAGS_DEBUG_GBUFFER_METALNESS;
currentCustomLocalIllumination = gbuffer->GetExtraBuffer();
break;
default:
mCompositeTotalIlluminationConstantBuffer.Data.CompositeFlags = COMPOSITE_FLAGS_NONE;
}
}
mCompositeTotalIlluminationConstantBuffer.ApplyChanges(rhi);

// mLocalIllumination might be bound as RTV before this pass
Expand All @@ -651,12 +690,12 @@ namespace EveryRay_Core {
rhi->SetSamplers(ER_COMPUTE, { ER_RHI_SAMPLER_STATE::ER_TRILINEAR_WRAP });
if (mCurrentGIQuality == GIQuality::GI_LOW)
{
rhi->SetShaderResources(ER_COMPUTE, { nullptr, mLocalIlluminationRT }, 0,
rhi->SetShaderResources(ER_COMPUTE, { nullptr, currentCustomLocalIllumination }, 0,
mCompositeIlluminationRS, COMPOSITE_PASS_ROOT_DESCRIPTOR_TABLE_SRV_INDEX, true);
}
else
{
rhi->SetShaderResources(ER_COMPUTE, { mShowVCTVoxelizationOnly ? mVCTVoxelizationDebugRT : mVCTUpsampleAndBlurRT, mLocalIlluminationRT }, 0,
rhi->SetShaderResources(ER_COMPUTE, { mVCTDebugMode == VCT_DEBUG_VOXELS ? mVCTVoxelizationDebugRT : mVCTUpsampleAndBlurRT, currentCustomLocalIllumination }, 0,
mCompositeIlluminationRS, COMPOSITE_PASS_ROOT_DESCRIPTOR_TABLE_SRV_INDEX, true);
}
rhi->SetUnorderedAccessResources(ER_COMPUTE, { mFinalIlluminationRT }, 0, mCompositeIlluminationRS, COMPOSITE_PASS_ROOT_DESCRIPTOR_TABLE_UAV_INDEX, true);
Expand Down Expand Up @@ -750,7 +789,7 @@ namespace EveryRay_Core {

void ER_Illumination::UpdateImGui()
{
if (!mShowDebug)
if (!mShowDebugWindow)
return;

ImGui::Begin("Illumination System");
Expand All @@ -772,8 +811,7 @@ namespace EveryRay_Core {
ImGui::SliderFloat(name.c_str(), &mWorldVoxelScales[cascade], 0.1f, 10.0f);
}
ImGui::Separator();
ImGui::Checkbox("DEBUG - Ambient Occlusion", &mShowVCTAmbientOcclusionOnly);
ImGui::Checkbox("DEBUG - Voxel Texture", &mShowVCTVoxelizationOnly);
ImGui::SliderInt("DEBUG - None, AO, Voxels, Indirect", &(int)mVCTDebugMode, 0, VCT_DEBUG_COUNT - 1);
ImGui::Checkbox("DEBUG - Voxel Cascades Gizmos (Editor)", &mDrawVCTVoxelZonesGizmos);
}
if (ImGui::CollapsingHeader("Static - Light Probes"))
Expand Down
32 changes: 26 additions & 6 deletions source/EveryRay_Core/ER_Illumination.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
// ...
#define LIGHTING_SRV_INDEX_MAX 22 // nothing > is allowed in Deferred/Forward shaders; increase if needed

// Keep in sync with CompositeIllumination.hlsl!
#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_GBUFFER_ALBEDO 0x00000004
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_NORMALS 0x00000005
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_ROUGHNESS 0x00000006
#define COMPOSITE_FLAGS_DEBUG_GBUFFER_METALNESS 0x00000007

namespace EveryRay_Core
{
class ER_CoreTime;
Expand All @@ -56,6 +66,16 @@ namespace EveryRay_Core
GI_HIGH
};

enum VCTDebugMode
{
VCT_DEBUG_NONE = 0,
VCT_DEBUG_AO,
VCT_DEBUG_VOXELS,
VCT_DEBUG_INDIRECT, // final indirect GI result

VCT_DEBUG_COUNT
};

struct PointLightData
{
XMFLOAT4 PositionRadius;
Expand Down Expand Up @@ -85,7 +105,7 @@ namespace EveryRay_Core
};
struct ER_ALIGN_GPU_BUFFER CompositeTotalIlluminationCB
{
XMFLOAT4 DebugVoxelAO_Disable;
UINT CompositeFlags;
};
struct ER_ALIGN_GPU_BUFFER UpsampleBlurCB
{
Expand Down Expand Up @@ -137,13 +157,13 @@ namespace EveryRay_Core

void DrawLocalIllumination(ER_GBuffer* gbuffer, ER_Skybox* skybox);
void DrawDynamicGlobalIllumination(ER_GBuffer* gbuffer, const ER_CoreTime& gameTime);
void CompositeTotalIllumination();
void CompositeTotalIllumination(ER_GBuffer* gbuffer);

void DrawDebugGizmos(ER_RHI_GPUTexture* aRenderTarget, ER_RHI_GPUTexture* aDepth, ER_RHI_GPURootSignature* rs);
void DrawDebugProbes(ER_RHI_GPUTexture* aRenderTarget, ER_RHI_GPUTexture* aDepth);

void Update(const ER_CoreTime& gameTime, const ER_Scene* scene);
void Config() { mShowDebug = !mShowDebug; }
void Config() { mShowDebugWindow = !mShowDebugWindow; }

void SetShadowMap(ER_RHI_GPUTexture* tex) { mShadowMap = tex; }
void SetFoliageSystemForGI(ER_FoliageManager* foliageSystem);
Expand Down Expand Up @@ -287,8 +307,8 @@ namespace EveryRay_Core
float mVCTGIPower = 1.0f;
float mVCTDownscaleFactor = 0.5f; // % from full-res RT
bool mIsVCTVoxelCameraPositionsUpdated = true;
bool mShowVCTVoxelizationOnly = false;
bool mShowVCTAmbientOcclusionOnly = false;

VCTDebugMode mVCTDebugMode = VCTDebugMode::VCT_DEBUG_NONE;
bool mDrawVCTVoxelZonesGizmos = false;
bool mIsVCTEnabled = false;

Expand All @@ -305,7 +325,7 @@ namespace EveryRay_Core
float mSSSStrength = 1.35f;
float mSSSDirectionalLightPlaneScale = 0.15f;

bool mShowDebug = false;
bool mShowDebugWindow = false;
bool mDebugShadowCascades = false; // only works in deferred mode

RenderingObjectInfo mForwardPassObjects;
Expand Down
2 changes: 1 addition & 1 deletion source/EveryRay_Core/ER_Sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ namespace EveryRay_Core {
// combine the results of local and global illumination
rhi->BeginEventTag("EveryRay: Composite Illumination");
{
mIllumination->CompositeTotalIllumination();
mIllumination->CompositeTotalIllumination(mGBuffer);
}
rhi->EndEventTag();

Expand Down

0 comments on commit ddccef0

Please sign in to comment.