Skip to content

Commit 4a713fd

Browse files
committed
Merge branch 'dev/adunn/exclude_alpha_shadows' into 'main'
Allow users to disable semi-transparent shadows for direction/indirect lighting to improve performance. See merge request lightspeedrtx/dxvk-remix-nv!1138
2 parents 32e26ff + a88a588 commit 4a713fd

15 files changed

+37
-18
lines changed

RtxOptions.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ Tables below enumerate all the options and their defaults set by RTX Remix. Note
207207
|rtx.enableCullingInSecondaryRays|bool|False|Enable front/backface culling for opaque objects\. Objects with alpha blend or alpha test are not culled\. Only applies in secondary rays, defaults to off\. Generally helps with light bleeding from objects that aren't watertight\.|
208208
|rtx.enableDLSSEnhancement|bool|True|Enhances lighting details when DLSS is on\.|
209209
|rtx.enableDecalMaterialBlending|bool|True|A flag to enable or disable material blending on decals\.<br>This should generally always be enabled when decals are in use as this allows decals to be blended down on to the surface they sit slightly above which results in more convincing decals rendering\.|
210+
|rtx.enableDirectAlphaBlendShadows|bool|True|Calculate shadows for semi\-transparent materials \(alpha blended\) in direct lighting\. In engineering terms: include OBJECT\_MASK\_ALPHA\_BLEND into primary visibility rays\.|
210211
|rtx.enableDirectLighting|bool|True|Enables direct lighting \(lighting directly from lights on to a surface\) on surfaces when set to true, otherwise disables it\.|
211-
|rtx.enableDirectTranslucentShadows|bool|False|Include OBJECT\_MASK\_TRANSLUCENT into primary visibility rays\.|
212+
|rtx.enableDirectTranslucentShadows|bool|False|Calculate coloured shadows for translucent materials \(i\.e\. glass, water\) in direct lighting\. In engineering terms: include OBJECT\_MASK\_TRANSLUCENT into primary visibility rays\.|
212213
|rtx.enableEmissiveBlendEmissiveOverride|bool|True|Override typical material emissive information on draw calls with any emissive blending modes to emulate their original look more accurately\.|
213214
|rtx.enableEmissiveBlendModeTranslation|bool|True|Treat incoming semi/additive D3D blend modes as emissive\.|
214215
|rtx.enableFallbackLightShaping|bool|False|Enables light shaping on the fallback light \(only used for non\-Distant light types\)\.|
@@ -219,7 +220,8 @@ Tables below enumerate all the options and their defaults set by RTX Remix. Note
219220
|rtx.enableFogMaxDistanceRemap|bool|True|A flag to enable or disable remapping fixed function fox's max distance\. Only takes effect when fog remapping in general is enabled\.<br>Enables or disables remapping functionality relating to the max distance parameter of fixed function fog\.<br>This allows dynamic changes to the game's fog max distance to be reflected somewhat in the volumetrics system\. Overrides the specified volumetric transmittance measurement distance\.|
220221
|rtx.enableFogRemap|bool|False|A flag to enable or disable fixed function fog remapping\. Only takes effect when volumetrics are enabled\.<br>Typically many old games used fixed function fog for various effects and while sometimes this fog can be replaced with proper volumetrics globally, other times require some amount of dynamic behavior controlled by the game\.<br>When enabled this option allows for remapping of fixed function fog parameters from the game to volumetric parameters to accomodate this dynamic need\.|
221222
|rtx.enableIndexBufferMemoization|bool|True|CPU performance optimization, should generally be enabled\. Will reduce main thread time by caching processIndexBuffer operations and reusing when possible, this will come at the expense of some CPU RAM\.|
222-
|rtx.enableIndirectTranslucentShadows|bool|False|Include OBJECT\_MASK\_TRANSLUCENT into secondary visibility rays\.|
223+
|rtx.enableIndirectAlphaBlendShadows|bool|True|Calculate shadows for semi\-transparent \(alpha blended\) objects in indirect lighting \(i\.e\. reflections and GI\)\. In engineering terms: include OBJECT\_MASK\_ALPHA\_BLEND into secondary visibility rays\.|
224+
|rtx.enableIndirectTranslucentShadows|bool|False|Calculate coloured shadows for translucent materials \(i\.e\. glass, water\) in indirect lighting \(i\.e\. reflections and GI\)\. In engineering terms: include OBJECT\_MASK\_TRANSLUCENT into secondary visibility rays\.|
223225
|rtx.enableInstanceDebuggingTools|bool|False|NOTE: This will disable temporal correllation for instances, but allow the use of instance developer debug tools|
224226
|rtx.enableMultiStageTextureFactorBlending|bool|True|Support texture factor blending in stage 1~7\. Currently only support 1 additional blending stage, more than 1 additional blending stages will be ignored\.|
225227
|rtx.enableNearPlaneOverride|bool|False|A flag to enable or disable the Camera's near plane override feature\.<br>Since the camera is not used directly for ray tracing the near plane the application uses typically does not matter, but for certain matrix\-based operations \(such as temporal reprojection or voxel grid projection\) it is still relevant\.<br>The issue arises when geometry is ray traced that is behind where the chosen Camera's near plane is located, typically common on viewmodels especially with how they are ray traced, causing graphical artifacts and other issues\.<br>This option helps correct this issue by overriding the near plane value to else \(usually smaller\) to sit behind the objects in question \(such as the view model\)\. As such this option should usually be enabled on games with viewmodels\.<br>Do note that when adjusting the near plane the larger the relative magnitude gap between the near and far plane the worse the precision of matrix operations will be, so the near plane should be set as high as possible even when overriding\.|

src/dxvk/imgui/dxvk_imgui.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2665,7 +2665,9 @@ namespace dxvk {
26652665
ImGui::DragInt("Max Secondary Interactions", &RtxOptions::Get()->secondaryRayMaxInteractionsObject(), 1.0f, 1, 255, "%d", sliderFlags);
26662666
ImGui::Checkbox("Separate Unordered Approximations", &RtxOptions::Get()->enableSeparateUnorderedApproximationsObject());
26672667
ImGui::Checkbox("Direct Translucent Shadows", &RtxOptions::Get()->enableDirectTranslucentShadowsObject());
2668+
ImGui::Checkbox("Direct Alpha Blended Shadows", &RtxOptions::Get()->enableDirectAlphaBlendShadowsObject());
26682669
ImGui::Checkbox("Indirect Translucent Shadows", &RtxOptions::Get()->enableIndirectTranslucentShadowsObject());
2670+
ImGui::Checkbox("Indirect Alpha Blended Shadows", &RtxOptions::Get()->enableIndirectAlphaBlendShadowsObject());
26692671
ImGui::Checkbox("Decal Material Blending", &RtxOptions::Get()->enableDecalMaterialBlendingObject());
26702672
ImGui::Checkbox("Billboard Orientation Correction", &RtxOptions::Get()->enableBillboardOrientationCorrectionObject());
26712673
if (RtxOptions::Get()->enableBillboardOrientationCorrection()) {

src/dxvk/rtx_render/rtx_context.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,10 @@ namespace dxvk {
942942
constants.enableDirectLighting = RtxOptions::Get()->isDirectLightingEnabled();
943943
constants.enableStochasticAlphaBlend = m_common->metaComposite().enableStochasticAlphaBlend();
944944
constants.enableSeparateUnorderedApproximations = RtxOptions::Get()->enableSeparateUnorderedApproximations() && getResourceManager().getTLAS(Tlas::Unordered).accelStructure != nullptr;
945-
constants.enableDirectTranslucentShadows = RtxOptions::Get()->areDirectTranslucentShadowsEnabled();
946-
constants.enableIndirectTranslucentShadows = RtxOptions::Get()->areIndirectTranslucentShadowsEnabled();
945+
constants.enableDirectTranslucentShadows = RtxOptions::enableDirectTranslucentShadows();
946+
constants.enableDirectAlphaBlendShadows = RtxOptions::enableDirectAlphaBlendShadows();
947+
constants.enableIndirectTranslucentShadows = RtxOptions::enableIndirectTranslucentShadows();
948+
constants.enableIndirectAlphaBlendShadows = RtxOptions::enableIndirectAlphaBlendShadows();
947949
constants.enableRussianRoulette = RtxOptions::Get()->isRussianRouletteEnabled();
948950
constants.enableDemodulateRoughness = m_common->metaDemodulate().demodulateRoughness();
949951
constants.enableReplaceDirectSpecularHitTWithIndirectSpecularHitT = RtxOptions::Get()->isReplaceDirectSpecularHitTWithIndirectSpecularHitTEnabled();

src/dxvk/rtx_render/rtx_instance_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ namespace dxvk {
11221122
// Portal
11231123
mask |= OBJECT_MASK_PORTAL;
11241124
} else {
1125-
mask |= OBJECT_MASK_OPAQUE;
1125+
mask |= currentInstance.surface.alphaState.isBlendingDisabled ? OBJECT_MASK_OPAQUE : OBJECT_MASK_ALPHA_BLEND;
11261126
}
11271127
}
11281128
}

src/dxvk/rtx_render/rtx_options.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,10 @@ namespace dxvk {
490490
"Do note however the unordered nature of this resolving method may result in visual artifacts with large numbers of stacked particles due to difficulty in determining the intended order.\n"
491491
"Additionally, unordered approximations will only be done on the first indirect ray bounce (as particles matter less in higher bounces), and only if enabled by its corresponding setting.");
492492
RTX_OPTION("rtx", bool, trackParticleObjects, true, "Track last frame's corresponding particle object.");
493-
RTX_OPTION("rtx", bool, enableDirectTranslucentShadows, false, "Include OBJECT_MASK_TRANSLUCENT into primary visibility rays.");
494-
RTX_OPTION("rtx", bool, enableIndirectTranslucentShadows, false, "Include OBJECT_MASK_TRANSLUCENT into secondary visibility rays.");
493+
RTX_OPTION_ENV("rtx", bool, enableDirectTranslucentShadows, false, "RTX_ENABLE_DIRECT_TRANSLUCENT_SHADOWS", "Calculate coloured shadows for translucent materials (i.e. glass, water) in direct lighting. In engineering terms: include OBJECT_MASK_TRANSLUCENT into primary visibility rays.");
494+
RTX_OPTION_ENV("rtx", bool, enableDirectAlphaBlendShadows, true, "RTX_ENABLE_DIRECT_ALPHABLEND_SHADOWS", "Calculate shadows for semi-transparent materials (alpha blended) in direct lighting. In engineering terms: include OBJECT_MASK_ALPHA_BLEND into primary visibility rays.");
495+
RTX_OPTION_ENV("rtx", bool, enableIndirectTranslucentShadows, false, "RTX_ENABLE_INDIRECT_TRANSLUCENT_SHADOWS", "Calculate coloured shadows for translucent materials (i.e. glass, water) in indirect lighting (i.e. reflections and GI). In engineering terms: include OBJECT_MASK_TRANSLUCENT into secondary visibility rays.");
496+
RTX_OPTION_ENV("rtx", bool, enableIndirectAlphaBlendShadows, true, "RTX_ENABLE_INDIRECT_ALPHABLEND_SHADOWS", "Calculate shadows for semi-transparent (alpha blended) objects in indirect lighting (i.e. reflections and GI). In engineering terms: include OBJECT_MASK_ALPHA_BLEND into secondary visibility rays.");
495497

496498
RTX_OPTION("rtx", float, resolveTransparencyThreshold, 1.0f / 255.0f, "A threshold for which any opacity value below is considered totally transparent and may be safely skipped without as significant of a performance cost.");
497499
RTX_OPTION("rtx", float, resolveOpaquenessThreshold, 254.0f / 255.0f, "A threshold for which any opacity value above is considered totally opaque.");
@@ -1325,8 +1327,6 @@ namespace dxvk {
13251327
uint8_t getPrimaryRayMaxInteractions() const { return primaryRayMaxInteractions(); }
13261328
uint8_t getPSRRayMaxInteractions() const { return psrRayMaxInteractions(); }
13271329
uint8_t getSecondaryRayMaxInteractions() const { return secondaryRayMaxInteractions(); }
1328-
bool areDirectTranslucentShadowsEnabled() const { return enableDirectTranslucentShadows(); }
1329-
bool areIndirectTranslucentShadowsEnabled() const { return enableIndirectTranslucentShadows(); }
13301330
float getResolveTransparencyThreshold() const { return resolveTransparencyThreshold(); }
13311331
float getResolveOpaquenessThreshold() const { return resolveOpaquenessThreshold(); }
13321332

src/dxvk/shaders/rtx/algorithm/integrator.slangh

+2-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ bool evalNEESecondary(
231231
// Setup and trace the visibility ray
232232

233233
uint8_t rayMask = OBJECT_MASK_OPAQUE | (objectMask & OBJECT_MASK_ALL_DYNAMIC);
234-
if (cb.enableIndirectTranslucentShadows) rayMask |= OBJECT_MASK_TRANSLUCENT;
234+
rayMask |= (cb.enableIndirectTranslucentShadows) ? OBJECT_MASK_TRANSLUCENT : 0;
235+
rayMask |= (cb.enableIndirectAlphaBlendShadows) ? OBJECT_MASK_ALPHA_BLEND : 0;
235236

236237
const bool isSubsurface = isSubsurfaceMaterial(opaqueSurfaceMaterialInteraction);
237238

src/dxvk/shaders/rtx/algorithm/integrator_direct.slangh

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ void evalNEEPrimary(
5858
// Setup and trace the visibility ray
5959

6060
uint8_t rayMask = OBJECT_MASK_OPAQUE | (geometryFlags.objectMask & OBJECT_MASK_ALL_DYNAMIC);
61-
if (cb.enableDirectTranslucentShadows) rayMask |= OBJECT_MASK_TRANSLUCENT;
61+
rayMask |= (cb.enableDirectTranslucentShadows) ? OBJECT_MASK_TRANSLUCENT : 0;
62+
rayMask |= (cb.enableDirectAlphaBlendShadows) ? OBJECT_MASK_ALPHA_BLEND : 0;
6263

6364
// We can encounter a POM surface during resolving (as it's a shared function) but if direct lighting for POM
6465
// is disabled, we must also handle that user choice gracefully.

src/dxvk/shaders/rtx/algorithm/rtxdi/RtxdiApplicationBridge.slangh

+4-2
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@ bool RAB_TraceLightSampleVisibility(RAB_Surface surface, RAB_LightSample lightSa
711711
}
712712

713713
uint8_t rayMask = OBJECT_MASK_OPAQUE | (surface.objectMask & OBJECT_MASK_ALL_DYNAMIC);
714-
if (cb.enableDirectTranslucentShadows) rayMask |= OBJECT_MASK_TRANSLUCENT;
714+
rayMask |= (cb.enableDirectTranslucentShadows) ? OBJECT_MASK_TRANSLUCENT : 0;
715+
rayMask |= (cb.enableDirectAlphaBlendShadows) ? OBJECT_MASK_ALPHA_BLEND : 0;
715716

716717
const bool isSubsurface = isSubsurfaceMaterial(surface.opaqueSurfaceMaterialInteraction);
717718

@@ -734,7 +735,8 @@ bool RAB_TraceGISampleVisibility(RAB_Surface surface, RAB_Surface neighborSurfac
734735
uint8_t portalID = ReSTIRGI_PortalID2BitTo8Bit(reservoir.getPortalID());
735736
if (portalID == RTXDI_INVALID_PORTAL_INDEX || portalID < numPortals)
736737
{
737-
const uint8_t rayMask = OBJECT_MASK_OPAQUE | (surface.objectMask & OBJECT_MASK_ALL_DYNAMIC);
738+
uint8_t rayMask = OBJECT_MASK_OPAQUE | (surface.objectMask & OBJECT_MASK_ALL_DYNAMIC);
739+
rayMask |= (cb.enableIndirectAlphaBlendShadows) ? OBJECT_MASK_ALPHA_BLEND : 0;
738740

739741
const float3 dstPosition = reservoir.getVisibilityPoint(neighborSurface.minimalSurfaceInteraction.position);
740742

src/dxvk/shaders/rtx/algorithm/volume_integrator_helpers.slangh

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ VisibilityResult evalVolumeNEEVisibility(
2929
// to cast rays through them (as this would be expensive). We may want to add a bit more nuance here in the future to allow
3030
// approximations of glass as large glass objects should ideally cast tinted shadows into particles, but we currently do not
3131
// have a way to discriminate between translucency and opacity (and have no more bits available at least for now for this).
32-
uint8_t rayMask = OBJECT_MASK_OPAQUE;
32+
uint8_t rayMask = OBJECT_MASK_OPAQUE | OBJECT_MASK_ALPHA_BLEND;
3333

3434
// Note: Culling disabled via visibilityModeDisableCulling to avoid light leaking through geometry as this is especially
3535
// bad in volumetrics due to how the voxels leak through walls to begin with. Other NEE does not disable culling like this

src/dxvk/shaders/rtx/pass/instance_definitions.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070

7171
#define OBJECT_MASK_TRANSLUCENT (1 << 0)
7272
#define OBJECT_MASK_PORTAL (1 << 1)
73+
#define OBJECT_MASK_ALPHA_BLEND (1 << 2)
7374
#define OBJECT_MASK_OPAQUE (1 << 3)
7475

7576
// Instances to be drawn and visible in ViewModel pass only
@@ -91,7 +92,7 @@
9192

9293
// Note: Sky excluded as often it should not be traced against when calculating visibility.
9394
// ViewModel is excluded
94-
#define OBJECT_MASK_ALL_STANDARD (OBJECT_MASK_TRANSLUCENT | OBJECT_MASK_PORTAL | OBJECT_MASK_OPAQUE)
95+
#define OBJECT_MASK_ALL_STANDARD (OBJECT_MASK_TRANSLUCENT | OBJECT_MASK_PORTAL | OBJECT_MASK_OPAQUE | OBJECT_MASK_ALPHA_BLEND)
9596
#define OBJECT_MASK_ALL (OBJECT_MASK_ALL_STANDARD)
9697

9798
/****************************** ~Instance Mask - Ordered TLAS ************************************************/

src/dxvk/shaders/rtx/pass/integrate/integrate_nee.comp.slang

+2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ void main(uint2 threadIndex : SV_DispatchThreadID, uint2 LocalIndex : SV_GroupTh
152152
evaluateUnshadowedLight(lightSample, opaqueSurfaceMaterialInteraction, minimalRayInteraction, inputDirection, diffuseLight, specularLight);
153153

154154
uint8_t rayMask = OBJECT_MASK_OPAQUE | (geometryFlags.objectMask & OBJECT_MASK_ALL_DYNAMIC);
155+
rayMask |= (cb.enableIndirectAlphaBlendShadows) ? OBJECT_MASK_ALPHA_BLEND : 0;
156+
155157
bool pomOpaqueSurfaceEncountered = cb.pomEnableNEECache && opaqueSurfaceMaterialInteractionHasHeightTexture(opaqueSurfaceMaterialInteraction);
156158
isVisible = evalNEESecondary(
157159
lightSample, invalidRayPortalIndex, surface.portalSpace, rayMask, pomOpaqueSurfaceEncountered,

src/dxvk/shaders/rtx/pass/raytrace_args.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,10 @@ struct RaytraceArgs {
225225
uint enableSecondaryBounces;
226226
uint enableSeparateUnorderedApproximations;
227227
uint enableStochasticAlphaBlend;
228-
uint enableDirectTranslucentShadows;
229-
uint enableIndirectTranslucentShadows;
228+
uint16_t enableDirectTranslucentShadows;
229+
uint16_t enableDirectAlphaBlendShadows;
230+
uint16_t enableIndirectTranslucentShadows;
231+
uint16_t enableIndirectAlphaBlendShadows;
230232
uint enableFirstBounceLobeProbabilityDithering;
231233
uint enableUnorderedResolveInIndirectRays;
232234
uint enableProbabilisticUnorderedResolveInIndirectRays;

src/dxvk/shaders/rtx/pass/rtxdi/restir_gi_final_shading.comp.slang

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ void main(uint2 threadIndex : SV_DispatchThreadID, uint2 LocalIndex : SV_GroupTh
173173
if (portalID == invalidRayPortalIndex || portalID < cb.numActiveRayPortals)
174174
{
175175
uint8_t rayMask = OBJECT_MASK_OPAQUE | (geometryFlags.objectMask & OBJECT_MASK_ALL_DYNAMIC);
176+
rayMask |= (cb.enableIndirectAlphaBlendShadows) ? OBJECT_MASK_ALPHA_BLEND : 0;
176177

177178
// Use non-zero cone spread angle to reduce noise if there are alpha tested objects, like the fences in the portal game.
178179
// The value is based on experiment. If incorrect shadows are observed, a smaller value should be used.

src/dxvk/shaders/rtx/pass/rtxdi/restir_gi_temporal_reuse.comp.slang

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ void main(int2 thread_id : SV_DispatchThreadID)
234234
// Calculate reflection hit T
235235
uint8_t backupPortalID = RTXDI_INVALID_PORTAL_INDEX;
236236
uint8_t rayMask = OBJECT_MASK_OPAQUE | (surface.objectMask & OBJECT_MASK_ALL_DYNAMIC);
237+
rayMask |= (cb.enableIndirectAlphaBlendShadows) ? OBJECT_MASK_ALPHA_BLEND : 0;
238+
237239
const float infiniteHitT = 1e5;
238240
float3 dstPosition = worldPos + reflectionVector * infiniteHitT;
239241
VisibilityResult visibility = traceVisibilityRay<visibilityModeAccurateHitDistance>(surface.minimalSurfaceInteraction,

src/dxvk/shaders/rtx/pass/rtxdi/rtxdi_compute_gradients.comp.slang

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ float getSurfaceIlluminance(
3636
// Setup and trace the visibility ray
3737

3838
uint8_t rayMask = OBJECT_MASK_OPAQUE | (objectMask & OBJECT_MASK_ALL_DYNAMIC);
39-
if (cb.enableDirectTranslucentShadows) rayMask |= OBJECT_MASK_TRANSLUCENT;
39+
rayMask |= (cb.enableDirectTranslucentShadows) ? OBJECT_MASK_TRANSLUCENT : 0;
40+
rayMask |= (cb.enableDirectAlphaBlendShadows) ? OBJECT_MASK_ALPHA_BLEND : 0;
4041

4142
VisibilityResult visibility = traceVisibilityRay<visibilityModeEnableTranslucentMaterials | visibilityModeEnableSubsurfaceMaterials>(minimalSurfaceInteraction,
4243
lightSample.position, rayMask,

0 commit comments

Comments
 (0)