-
Notifications
You must be signed in to change notification settings - Fork 100
add light identity resolve to fix sparse reuse problem #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DQLin
wants to merge
3
commits into
NVIDIA-RTX:remix
Choose a base branch
from
DQLin:light-identity-fix
base: remix
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ bool RTXDI_StreamSample( | |
| reservoir.portalIdx = uint8_t(portalIndex); | ||
| reservoir.uv = uv; | ||
| reservoir.targetPdf = targetPdf; | ||
| reservoir.lightIdentity = RAB_UseLightIdentityResolution() ? RAB_GetLightIdentity(uint16_t(lightIndex)) : 0u; | ||
| } | ||
|
|
||
| return selectSample; | ||
|
|
@@ -87,6 +88,7 @@ bool RTXDI_CombineReservoirs( | |
| reservoir.portalIdx = newReservoir.portalIdx; | ||
| reservoir.uv = newReservoir.uv; | ||
| reservoir.targetPdf = targetPdf; | ||
| reservoir.lightIdentity = newReservoir.lightIdentity; | ||
| } | ||
|
|
||
| return selectSample; | ||
|
|
@@ -330,6 +332,7 @@ RTXDI_Reservoir RTXDI_SampleSingleLight( | |
| state.uv = lightUV; | ||
| state.targetPdf = targetPdf; | ||
| state.M = 1; | ||
| state.lightIdentity = (targetPdf > 0 && RAB_UseLightIdentityResolution()) ? RAB_GetLightIdentity(lightIdx) : 0u; | ||
|
|
||
| if (testVisibility) | ||
| { | ||
|
|
@@ -485,6 +488,8 @@ void RTXDI_TemporalResampling( | |
| // calculate targetPdf for the old sample | ||
| bool selectedPreviousSample = false; | ||
| uint previousM = 0; | ||
| bool useStoredTemporalTargetPdf = false; | ||
| float storedTemporalTargetPdf = 0.0f; | ||
| if (prevPixelID.x >= 0) | ||
| { | ||
| RTXDI_Reservoir prevReservoir = RAB_LoadReservoir(prevPixelID, tparams.sourceBufferIndex); | ||
|
|
@@ -493,17 +498,25 @@ void RTXDI_TemporalResampling( | |
|
|
||
| // Save the light index in the previous frame context | ||
| const uint16_t originalPrevLightIdx = prevReservoir.lightIdx; | ||
|
|
||
| uint16_t mappedLightID = RAB_TranslateLightIndex(prevReservoir.lightIdx, /* currentToPrevious = */ false); | ||
| if (mappedLightID == RTXDI_INVALID_LIGHT_INDEX) | ||
|
|
||
| // Map the previous reservoir's stored light index to the current frame. | ||
| bool prevReservoirValid; | ||
| if (RAB_UseLightIdentityResolution()) | ||
| { | ||
| // Kill the reservoir | ||
| prevReservoir.weightSum = 0; | ||
| prevReservoir.lightIdx = RTXDI_INVALID_LIGHT_INDEX; | ||
| prevReservoirValid = RAB_ResolveReservoirLightIndex(prevReservoir); | ||
| } | ||
| else | ||
| { | ||
| const uint16_t mappedLightID = RAB_TranslateLightIndex(prevReservoir.lightIdx, /* currentToPrevious = */ false); | ||
| prevReservoir.lightIdx = mappedLightID; | ||
| prevReservoirValid = (mappedLightID != RTXDI_INVALID_LIGHT_INDEX); | ||
| } | ||
|
|
||
| if (!prevReservoirValid) | ||
| { | ||
| // The light this reservoir referenced no longer exists: kill the reservoir. | ||
| prevReservoir.weightSum = 0; | ||
| prevReservoir.lightIdx = RTXDI_INVALID_LIGHT_INDEX; | ||
| } | ||
|
|
||
| float weightAtCurrent = 0; | ||
|
|
@@ -527,7 +540,17 @@ void RTXDI_TemporalResampling( | |
| selectedPreviousSample = RTXDI_CombineReservoirs(state, prevReservoir, RAB_GetNextRandom(rng), weightAtCurrent); | ||
| if (selectedPreviousSample) | ||
| { | ||
| selectedLightPrevIdx = originalPrevLightIdx; | ||
| if (!RAB_UseLightIdentityResolution()) | ||
| { | ||
| selectedLightPrevIdx = originalPrevLightIdx; | ||
| } | ||
| else | ||
| { | ||
| // Reuse the reservoir's stored targetPdf as the temporal MIS target | ||
| // This is more stable when reservoirs are not updated every frame | ||
| useStoredTemporalTargetPdf = true; | ||
| storedTemporalTargetPdf = prevReservoir.targetPdf; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -538,44 +561,54 @@ void RTXDI_TemporalResampling( | |
| float piSum = state.targetPdf * initialM; | ||
|
|
||
| if(RTXDI_IsValidReservoir(state) && | ||
| selectedLightPrevIdx != RTXDI_INVALID_LIGHT_INDEX && | ||
| (selectedLightPrevIdx != RTXDI_INVALID_LIGHT_INDEX || useStoredTemporalTargetPdf) && | ||
| previousM > 0) | ||
| { | ||
| float temporalP = 0; | ||
| RAB_Surface temporalSurface = RAB_GetSurfaceForTemporalBiasCorrection(surface, prevPixelID, prevNormal, tparams.virtualMotionVector); | ||
| float temporalP; | ||
|
|
||
| RAB_Surface virtualTemporalSurface = temporalSurface; | ||
| #if !RTXDI_NO_PORTALS | ||
| if (state.portalIdx != RTXDI_INVALID_PORTAL_INDEX) | ||
| if (useStoredTemporalTargetPdf) | ||
| { | ||
| RAB_TransformSurface(virtualTemporalSurface, RAB_GetPortalTransform(state.portalIdx)); | ||
| // the previous-frame light buffer can't be indexed with its stored index, | ||
| // so use the reservoir's stored target as the selected sample's target in the temporal domain. | ||
| temporalP = storedTemporalTargetPdf; | ||
| } | ||
| else | ||
| { | ||
| RAB_Surface temporalSurface = RAB_GetSurfaceForTemporalBiasCorrection(surface, prevPixelID, prevNormal, tparams.virtualMotionVector); | ||
|
|
||
| RAB_Surface virtualTemporalSurface = temporalSurface; | ||
| #if !RTXDI_NO_PORTALS | ||
| if (state.portalIdx != RTXDI_INVALID_PORTAL_INDEX) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The portal handling code should be independent from the multiple frame light ID match code. What it's doing here is to calculate the virtual surface with respect to portal space. It's still needed when you are matching light ID across multiple frames. |
||
| { | ||
| RAB_TransformSurface(virtualTemporalSurface, RAB_GetPortalTransform(state.portalIdx)); | ||
| } | ||
| #endif | ||
|
|
||
| RAB_LightSample selectedSampleAtTemporalSurface = RAB_GetLightSample(selectedLightPrevIdx, | ||
| state.uv, virtualTemporalSurface, /* usePreviousLights = */ true); | ||
| RAB_LightSample selectedSampleAtTemporalSurface = RAB_GetLightSample(selectedLightPrevIdx, | ||
| state.uv, virtualTemporalSurface, /* usePreviousLights = */ true); | ||
|
|
||
| temporalP = RAB_GetLightSampleTargetPdfForSurface(selectedSampleAtTemporalSurface, virtualTemporalSurface); | ||
| temporalP = RAB_GetLightSampleTargetPdfForSurface(selectedSampleAtTemporalSurface, virtualTemporalSurface); | ||
|
|
||
| // If we have selected the temporal sample and discard is enabled, we know that the sample was visible | ||
| // on the previous frame because otherwise it would've been discarded and we couldn't select it. | ||
| // In practice, temporal samples are selected way more often than new samples, which means this | ||
| // condition culls the vast majority of visibility rays here. | ||
| const bool selectedSampleKnownVisible = selectedPreviousSample && tparams.discardInvisibleSamples; | ||
| // If we have selected the temporal sample and discard is enabled, we know that the sample was visible | ||
| // on the previous frame because otherwise it would've been discarded and we couldn't select it. | ||
| // In practice, temporal samples are selected way more often than new samples, which means this | ||
| // condition culls the vast majority of visibility rays here. | ||
| const bool selectedSampleKnownVisible = selectedPreviousSample && tparams.discardInvisibleSamples; | ||
|
|
||
| if (temporalP > 0 && tparams.biasCorrectionMode >= RTXDI_BIAS_CORRECTION_RAY_TRACED && !selectedSampleKnownVisible) | ||
| { | ||
| float3 attenuation; | ||
| if (temporalP > 0 && tparams.biasCorrectionMode >= RTXDI_BIAS_CORRECTION_RAY_TRACED && !selectedSampleKnownVisible) | ||
| { | ||
| float3 attenuation; | ||
| #if RTXDI_NO_PORTALS | ||
| bool sampleVisible = RAB_TraceLightSampleVisibility(temporalSurface, selectedSampleAtTemporalSurface, | ||
| RTXDI_INVALID_PORTAL_INDEX, false, false, true, attenuation); | ||
| bool sampleVisible = RAB_TraceLightSampleVisibility(temporalSurface, selectedSampleAtTemporalSurface, | ||
| RTXDI_INVALID_PORTAL_INDEX, false, false, true, attenuation); | ||
| #else | ||
| bool sampleVisible = RAB_TraceLightSampleVisibility(temporalSurface, selectedSampleAtTemporalSurface, | ||
| state.portalIdx, false, false, true, attenuation); | ||
| bool sampleVisible = RAB_TraceLightSampleVisibility(temporalSurface, selectedSampleAtTemporalSurface, | ||
| state.portalIdx, false, false, true, attenuation); | ||
| #endif | ||
|
|
||
| if (!sampleVisible) | ||
| temporalP = 0; | ||
| if (!sampleVisible) | ||
| temporalP = 0; | ||
| } | ||
| } | ||
|
|
||
| pi = selectedPreviousSample ? temporalP : pi; | ||
|
|
@@ -684,6 +717,11 @@ RTXDI_Reservoir RTXDI_SpatialResampling( | |
|
|
||
| RTXDI_Reservoir neighborReservoir = RAB_LoadReservoir(neighborID, sparams.sourceBufferIndex); | ||
|
|
||
| if (RAB_UseLightIdentityResolution()) | ||
| { | ||
| RAB_ResolveReservoirLightIndex(neighborReservoir); | ||
| } | ||
|
|
||
| float targetPdf = 0; | ||
| if (RTXDI_IsValidReservoir(neighborReservoir)) | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the light identity match and light index translation cannot work at the same time? I see if else structure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. There is actually a light index translation inside RAB_ResolveReservoirLightIndex as a backup case for dynamic lights (because the hash is position-dependent). The main reason that a if-else is used here is that we don't know which reservoirs were active last frame. So we cannot guarantee that translate light index gives correct result.