Skip to content

Commit

Permalink
Merge branch 'dev/adunn/test_displacement_fix' into 'release/v0.6'
Browse files Browse the repository at this point in the history
Introduce more safety checks around POM

See merge request lightspeedrtx/dxvk-remix-nv!1001
  • Loading branch information
AlexDunn committed Sep 26, 2024
2 parents 70c832a + e599e45 commit f33aba1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/dxvk/shaders/rtx/algorithm/integrator_direct.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,18 @@ void evalNEEPrimary(
uint8_t rayMask = OBJECT_MASK_OPAQUE | (geometryFlags.objectMask & OBJECT_MASK_ALL_DYNAMIC);
if (cb.enableDirectTranslucentShadows) rayMask |= OBJECT_MASK_TRANSLUCENT;

const bool enablePOM = cb.pomEnableDirectLighting && opaqueSurfaceMaterialInteractionHasHeightTexture(opaqueSurfaceMaterialInteraction);
const uint16_t primarySurfaceIndex = enablePOM ? uint16_t(SharedSurfaceIndex[pixelCoordinate]) : BINDING_INDEX_INVALID;
// We can encounter a POM surface during resolving (as it's a shared function) but if direct lighting for POM
// is disabled, we must also handle that user choice gracefully.
const bool pomOpaqueSurfaceEncountered = geometryFlags.pomOpaqueSurfaceEncountered && cb.pomEnableDirectLighting;

const uint16_t primarySurfaceIndex = pomOpaqueSurfaceEncountered ? uint16_t(SharedSurfaceIndex[pixelCoordinate]) : BINDING_INDEX_INVALID;

const bool isSubsurface = isSubsurfaceMaterial(opaqueSurfaceMaterialInteraction);

const VisibilityResult visibility = traceVisibilityRay<visibilityModeEnablePom | visibilityModeAccurateHitDistance | visibilityModeEnableTranslucentMaterials | visibilityModeEnableSubsurfaceMaterials>(
minimalSurfaceInteraction,
lightSample.position, rayMask,
sampledTransportPortalIndex, geometryFlags.portalSpace, geometryFlags.pomOpaqueSurfaceEncountered,
sampledTransportPortalIndex, geometryFlags.portalSpace, pomOpaqueSurfaceEncountered,
minimalRayInteraction.coneRadius, viewRay.spreadAngle, 1.0, geometryFlags.isViewModel, false,
primarySurfaceIndex, SharedTextureCoord[pixelCoordinate],
isSubsurface, opaqueSurfaceMaterialInteraction.shadingNormal);
Expand Down
6 changes: 5 additions & 1 deletion src/dxvk/shaders/rtx/algorithm/integrator_indirect.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ void integratePathVertex(
pomOpaqueSurfaceEncountered,
isRaytracedRenderTarget);

// We can encounter a POM surface during resolving (as it's a shared function). But if POM is disabled in indirect cases
// we must also handle that case and ensure nothing tries to use POM elsewhere.
pomOpaqueSurfaceEncountered = pomOpaqueSurfaceEncountered && cb.pomEnableIndirectLighting;

// Output ReSTIR GI geometry information

if (cb.enableReSTIRGI && !pathState.restirGiHasHitGeometry)
Expand Down Expand Up @@ -627,7 +631,7 @@ void integratePathVertex(
{
const bool isViewModel = pathState.rayMask & OBJECT_MASK_ALL_VIEWMODEL;

uint16_t surfaceIndex = (cb.pomEnableIndirectLighting && pomOpaqueSurfaceEncountered) ? uint(rayInteraction.surfaceIndex) : BINDING_INDEX_INVALID;
uint16_t surfaceIndex = pomOpaqueSurfaceEncountered ? uint(rayInteraction.surfaceIndex) : BINDING_INDEX_INVALID;

// Todo: Ray Portal transport sampling in the future.
evalNEESecondary(
Expand Down
2 changes: 1 addition & 1 deletion src/dxvk/shaders/rtx/algorithm/visibility.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ VisibilityResult traceVisibilityRay<let VisibilityMode : uint>(
{
const MemoryPolymorphicSurfaceMaterial memoryPolymorphicSurfaceMaterial = surfaceMaterials[primarySurfaceIndex];
OpaqueSurfaceMaterial opaqueSurfaceMaterial = opaqueSurfaceMaterialCreate(primarySurfaceIndex, memoryPolymorphicSurfaceMaterial);

pomAttenuation = opaqueSurfaceMaterialInteractionCalcHeightThroughput(
minimalSurfaceInteraction, visibilityRay.direction, opaqueSurfaceMaterial.heightTextureIndex,
opaqueSurfaceMaterial.samplerIndex, texCoords, opaqueSurfaceMaterial.displaceIn
Expand Down

0 comments on commit f33aba1

Please sign in to comment.