Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Hineven committed May 22, 2024
1 parent 6857e81 commit 56187db
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 452 deletions.
166 changes: 100 additions & 66 deletions src/core/src/render_techniques/migi/migi.comp

Large diffs are not rendered by default.

47 changes: 26 additions & 21 deletions src/core/src/render_techniques/migi/migi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ void MIGI::render(CapsaicinInternal &capsaicin) noexcept

previous_constants_ = C;


GfxBuffer MI_constants = capsaicin.allocateConstantBuffer<MIGI_Constants>(1);
gfxBufferGetData<MIGI_Constants>(gfx_, MI_constants)[0] = C;
gfxProgramSetParameter(gfx_, kernels_.program, "MI", MI_constants);
Expand Down Expand Up @@ -355,6 +354,8 @@ void MIGI::render(CapsaicinInternal &capsaicin) noexcept

gfxProgramSetParameter(gfx_, kernels_.program, "g_RWDebugCursorWorldPosBuffer",
buf_.debug_cursor_world_pos);
gfxProgramSetParameter(gfx_, kernels_.program, "g_RWDebugProbeWorldPositionBuffer",
buf_.debug_probe_world_position);
gfxProgramSetParameter(gfx_, kernels_.program, "g_RWDebugVisualizeIncidentRadianceBuffer",
buf_.debug_visualize_incident_radiance);

Expand Down Expand Up @@ -790,26 +791,30 @@ void MIGI::render(CapsaicinInternal &capsaicin) noexcept
// uint dispatch_size[] = {divideAndRoundUp(options_.width, threads[0]), divideAndRoundUp(options_.height, threads[1])};
// gfxCommandDispatch(gfx_, dispatch_size[0], dispatch_size[1], 1);
} else if(options_.active_debug_view == "SSRC_IncidentRadiance") {
// const TimedSection timed_section(*this, "SSRC_IncidentRadiance");
// if(options_.cursor_dragging)
// {
// gfxCommandBindKernel(gfx_, kernels_.DebugSSRC_fetch_cursor_pos);
// gfxCommandDispatch(gfx_, 1, 1, 1);
// }
// gfxCommandBindKernel(gfx_, kernels_.DebugSSRC_precompute_incident_radiance);
// auto threads = gfxKernelGetNumThreads(gfx_, kernels_.DebugSSRC_precompute_incident_radiance);
// gfxCommandDispatch(gfx_, divideAndRoundUp(options_.debug_visualize_incident_radiance_num_points, threads[0]), 1, 1);
// // Copy the depth buffer to the depth buffer for debug visualization
// gfxCommandCopyTexture(gfx_, tex_.depth, capsaicin.getAOVBuffer("VisibilityDepth"));
// debug_buffer_copied = true;
// __override_primitive_topology = true;
// __override_primitive_topology_draw = D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
// gfxCommandBindKernel(gfx_, kernels_.DebugSSRC_incident_radiance);
// gfxCommandDraw(gfx_, options_.debug_visualize_incident_radiance_num_points);
// __override_primitive_topology = false;
// __override_primitive_topology_draw = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
// // Additionally accumulate the radiance buffer to compute the numerical integral of incoming radiance
// gfxCommandReduceSum(gfx_, GfxDataType::kGfxDataType_Float, buf_.debug_visualize_incident_radiance_sum, buf_.debug_visualize_incident_radiance, &buf_.reduce_count);
const TimedSection timed_section(*this, "SSRC_IncidentRadiance");
if(options_.cursor_dragging)
{
gfxCommandBindKernel(gfx_, kernels_.DebugSSRC_FetchCursorPos);
gfxCommandDispatch(gfx_, 1, 1, 1);
}
gfxCommandBindKernel(gfx_, kernels_.DebugSSRC_PrepareProbeIncidentRadiance);
auto threads = gfxKernelGetNumThreads(gfx_, kernels_.DebugSSRC_PrepareProbeIncidentRadiance);
gfxCommandDispatch(gfx_, divideAndRoundUp(options_.debug_visualize_incident_radiance_num_points, threads[0]), 1, 1);
// Copy the depth buffer to the depth buffer for debug visualization
if(!debug_buffer_copied)
{
gfxCommandCopyTexture(gfx_, tex_.depth, capsaicin.getAOVBuffer("VisibilityDepth"));
gfxCommandCopyTexture(gfx_, capsaicin.getAOVBuffer("Debug"), gi_output_aov);
debug_buffer_copied = true;
}
__override_primitive_topology = true;
__override_primitive_topology_draw = D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
gfxCommandBindKernel(gfx_, kernels_.DebugSSRC_VisualizeIncidentRadiance);
gfxCommandDraw(gfx_, options_.debug_visualize_incident_radiance_num_points);
__override_primitive_topology = false;
__override_primitive_topology_draw = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
// Additionally accumulate the radiance buffer to compute the numerical integral of incoming radiance
gfxCommandReduceSum(gfx_, GfxDataType::kGfxDataType_Float, buf_.debug_visualize_incident_radiance_sum, buf_.debug_visualize_incident_radiance, &buf_.reduce_count);
} else if(options_.active_debug_view == "SSRC_UpdateRays") {
// const TimedSection timed_section(*this, "SSRC_UpdateRays");
// gfxCommandBindKernel(gfx_, kernels_.DebugSSRC_prepare_update_rays);
Expand Down
151 changes: 22 additions & 129 deletions src/core/src/render_techniques/migi/migi.frag
Original file line number Diff line number Diff line change
Expand Up @@ -8,142 +8,35 @@
#include "migi_lib.hlsl"


struct InjectReprojectedBasis_Input {
float4 Position : SV_Position;
nointerpolation float4 PARAMS : TEXCOORD0;
float4 PARAMS1 : TEXCOORD1;
};

void SSRC_InjectReprojectedBasis (
in InjectReprojectedBasis_Input Input
) {
uint BasisIndex = asuint(Input.PARAMS.x);
if(BasisIndex == kGI10_InvalidId) {
// Degenerate the disk
return;
}
int2 TileCoords = uint2(Input.Position.xy);

float HiZ_Min = g_TileHiZ_Min.Load(int3(TileCoords, 0)).x;
float HiZ_Max = g_TileHiZ_Max.Load(int3(TileCoords, 0)).x;
// Fully empty tile, no injection
if(HiZ_Min == 1.f) return ;

// Intersect the sphere with the tile's truncated pyramid (rough approximation)
float PyramidMin = GetLinearDepth(HiZ_Min);
float PyramidMax = GetLinearDepth(HiZ_Max);
float2 MinTileFilm = TileCoords * SSRC_TILE_SIZE;
float2 MaxTileFilm = MinTileFilm + SSRC_TILE_SIZE.xx;
float EffectiveRadius = g_RWBasisEffectiveRadiusBuffer[BasisIndex];
float EffectiveRadiusFilm = g_RWBasisEffectiveRadiusFilmBuffer[BasisIndex];

float2 BasisNDC2 = Input.PARAMS.yz;
float2 BasisFilm = NDC22UV(BasisNDC2) * g_OutputDimensions.xy;
float BasisLinearDistance = Input.PARAMS.w;

bool Inject = true;
// Clip condition 1
if(BasisLinearDistance < PyramidMin || BasisLinearDistance > PyramidMax) {
float MinDistance = min(abs(BasisLinearDistance - PyramidMin), abs(BasisLinearDistance - PyramidMax));
if(MinDistance > EffectiveRadius) {
Inject = false;
}
}
// Clip condition 2
float MinNDCDistX = 0.f;
float MinNDCDistY = 0.f;
if(BasisFilm.x < MinTileFilm.x || BasisFilm.x > MaxTileFilm.x) {
MinNDCDistX = min(abs(BasisFilm.x - MinTileFilm.x), abs(BasisFilm.x - MaxTileFilm.x));
}
if(BasisFilm.y < MinTileFilm.y || BasisFilm.y > MaxTileFilm.y) {
MinNDCDistY = min(abs(BasisFilm.y - MinTileFilm.y), abs(BasisFilm.y - MaxTileFilm.y));
}
if(MinNDCDistX*MinNDCDistX + MinNDCDistY*MinNDCDistY > EffectiveRadiusFilm*EffectiveRadiusFilm) {
Inject = false;
}

// Insert the basis index into the tile
if(Inject) ScreenCache_InjectBasisIndexToTile(TileCoords, BasisIndex);
}


struct DebugBasis_Input {
float4 Position : SV_Position;
nointerpolation float4 BasisIndex : TEXCOORD0;
};

float4 DebugSSRC_Basis (
in DebugBasis_Input Input
) : SV_Target {
uint BasisIndex = asuint(Input.BasisIndex.x);
if(BasisIndex == kGI10_InvalidId) {
// Degenerate the disk
discard;
}
if(g_DebugVisualizeMode == 3) {
SGData SG;
WData W;
FetchBasisData_W(BasisIndex, SG, W);
return float4((SG.Direction + 1.f) * 0.5f, 1.f);
}
return float4(BasisIndexToColor(BasisIndex), 1.f);
}

struct DebugBasis3D_Input {
float4 Position : SV_Position;
float4 Color : COLOR;
nointerpolation float4 BasisIndex : TEXCOORD0;
};

float4 DebugSSRC_Basis3D (
in DebugBasis3D_Input Input
) : SV_Target {
uint BasisIndex = asuint(Input.BasisIndex.x);
if(BasisIndex == kGI10_InvalidId) {
// Degenerate the disk
discard;
}
SGData SG;
WData W;
FetchBasisData_W(BasisIndex, SG, W);
float Pos = Input.Color.x;
if(Pos < 0.004f) return float4(0.f, 0.f, 0.f, 1.f);
if(g_DebugVisualizeMode == 0) {
return float4((SG.Direction + 1.f) * 0.5f, 1.f);
} else {
return float4((SG.Direction + 1.f) * 0.5f, 1.f);
}
}

struct DebugIncidentRadiance_Input {
float4 Position : SV_Position;
float4 Color : COLOR;
};

float4 DebugSSRC_IncidentRadiance (
float4 DebugSSRC_VisualizeIncidentRadiance (
in DebugIncidentRadiance_Input Input
) : SV_Target {
return Input.Color;
}

struct DebugUpdateRays_Input {
float4 Position : SV_Position;
float4 Color : COLOR;
};

float4 DebugSSRC_UpdateRays (
in DebugUpdateRays_Input Input
) : SV_Target {
return Input.Color;
}

struct DebugLight_Input {
float4 Position : SV_Position;
float4 Color : COLOR;
};

float4 DebugSSRC_Light (
in DebugLight_Input Input
) : SV_Target {
return Input.Color;
}
// struct DebugUpdateRays_Input {
// float4 Position : SV_Position;
// float4 Color : COLOR;
// };

// float4 DebugSSRC_UpdateRays (
// in DebugUpdateRays_Input Input
// ) : SV_Target {
// return Input.Color;
// }

// struct DebugLight_Input {
// float4 Position : SV_Position;
// float4 Color : COLOR;
// };

// float4 DebugSSRC_Light (
// in DebugLight_Input Input
// ) : SV_Target {
// return Input.Color;
// }
3 changes: 3 additions & 0 deletions src/core/src/render_techniques/migi/migi.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class MIGI : public RenderTechnique
GfxBuffer probe_update_error {};

GfxBuffer debug_cursor_world_pos {};
GfxBuffer debug_probe_world_position {};
GfxBuffer debug_visualize_incident_radiance {};
GfxBuffer debug_visualize_incident_radiance_sum {};

Expand Down Expand Up @@ -158,6 +159,8 @@ class MIGI : public RenderTechnique
GfxKernel SSRC_IntegrateASG {};
GfxKernel DebugSSRC_FetchCursorPos {};
GfxKernel DebugSSRC_VisualizeProbePlacement {};
GfxKernel DebugSSRC_PrepareProbeIncidentRadiance {};
GfxKernel DebugSSRC_VisualizeIncidentRadiance {};
GfxKernel DebugSSRC_PrepareUpdateRays {};

GfxKernel GenerateDispatch {};
Expand Down
Loading

0 comments on commit 56187db

Please sign in to comment.