Skip to content

Commit 50b5fed

Browse files
committed
PT: improved SHARC usage (better IQ for single bounce reflections and glass)
1 parent 6566c00 commit 50b5fed

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

Shaders/TraceOpaque.cs.hlsl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ TraceOpaqueResult TraceOpaque( GeometryProps geometryProps0, MaterialProps mater
172172
sharcParams.resolvedBuffer = gInOut_SharcResolved;
173173

174174
#if( USE_SHARC_DEBUG == 2 )
175-
result.diffRadiance = HashGridDebugColoredHash( sharcHitData.positionWorld, hashGridParams );
175+
result.diffRadiance = HashGridDebugColoredHash( sharcHitData.positionWorld, sharcHitData.normalWorld, hashGridParams );
176176
#else
177177
bool isValid = SharcGetCachedRadiance( sharcParams, sharcHitData, result.diffRadiance, true );
178178

@@ -349,10 +349,9 @@ TraceOpaqueResult TraceOpaque( GeometryProps geometryProps0, MaterialProps mater
349349
rndScaled *= USE_SHARC_DITHERING;
350350

351351
float3x3 mBasis = Geometry::GetBasis( geometryProps.N );
352-
Xglobal += mBasis[ 0 ] * rndScaled.x + mBasis[ 1 ] * rndScaled.y;
352+
float3 jitter = mBasis[ 0 ] * rndScaled.x + mBasis[ 1 ] * rndScaled.y;
353353

354354
SharcHitData sharcHitData;
355-
sharcHitData.positionWorld = Xglobal;
356355
sharcHitData.materialDemodulation = GetMaterialDemodulation( geometryProps, materialProps );
357356
sharcHitData.normalWorld = geometryProps.N;
358357
sharcHitData.emissive = materialProps.Lemi;
@@ -374,9 +373,24 @@ TraceOpaqueResult TraceOpaque( GeometryProps geometryProps0, MaterialProps mater
374373
isSharcAllowed &= Rng::Hash::GetFloat( ) < ( bounce == gBounceNum ? 1.0 : footprintNorm ); // is voxel size acceptable?
375374
isSharcAllowed &= gSHARC && NRD_MODE < OCCLUSION; // trivial
376375

377-
float3 sharcRadiance;
378-
if( isSharcAllowed && SharcGetCachedRadiance( sharcParams, sharcHitData, sharcRadiance, false ) )
379-
Lcached = float4( sharcRadiance, 1.0 );
376+
if( isSharcAllowed )
377+
{
378+
// Try jittered position
379+
float3 sharcRadiance;
380+
381+
sharcHitData.positionWorld = Xglobal + jitter;
382+
bool isFound = SharcGetCachedRadiance( sharcParams, sharcHitData, sharcRadiance, false );
383+
384+
if( !isFound )
385+
{
386+
// Slipped out of the surface or mismatched normals, try non-jittered position
387+
sharcHitData.positionWorld = Xglobal;
388+
isFound = SharcGetCachedRadiance( sharcParams, sharcHitData, sharcRadiance, false );
389+
}
390+
391+
if( isFound )
392+
Lcached = float4( sharcRadiance, 1.0 );
393+
}
380394

381395
// Cache miss - compute lighting, if not found in caches
382396
if( Rng::Hash::GetFloat( ) > Lcached.w )

Shaders/TraceTransparent.cs.hlsl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,9 @@ float3 TraceTransparent( TraceTransparentDesc desc )
118118
rndScaled *= USE_SHARC_DITHERING * float( USE_SHARC_DEBUG == 0 );
119119

120120
float3x3 mBasis = Geometry::GetBasis( geometryProps.N );
121-
Xglobal += mBasis[ 0 ] * rndScaled.x + mBasis[ 1 ] * rndScaled.y;
121+
float3 jitter = mBasis[ 0 ] * rndScaled.x + mBasis[ 1 ] * rndScaled.y;
122122

123123
SharcHitData sharcHitData;
124-
sharcHitData.positionWorld = Xglobal;
125124
sharcHitData.materialDemodulation = GetMaterialDemodulation( geometryProps, materialProps );
126125
sharcHitData.normalWorld = geometryProps.N;
127126
sharcHitData.emissive = materialProps.Lemi;
@@ -141,9 +140,24 @@ float3 TraceTransparent( TraceTransparentDesc desc )
141140
bool isSharcAllowed = Rng::Hash::GetFloat( ) > Lcached.w; // is needed?
142141
isSharcAllowed &= gSHARC && NRD_MODE < OCCLUSION; // trivial
143142

144-
float3 sharcRadiance;
145-
if (isSharcAllowed && SharcGetCachedRadiance( sharcParams, sharcHitData, sharcRadiance, false))
146-
Lcached = float4( sharcRadiance, 1.0 );
143+
if( isSharcAllowed )
144+
{
145+
// Try jittered position
146+
float3 sharcRadiance;
147+
148+
sharcHitData.positionWorld = Xglobal + jitter;
149+
bool isFound = SharcGetCachedRadiance( sharcParams, sharcHitData, sharcRadiance, false );
150+
151+
if( !isFound )
152+
{
153+
// Slipped out of the surface or mismatched normals, try non-jittered position
154+
sharcHitData.positionWorld = Xglobal;
155+
isFound = SharcGetCachedRadiance( sharcParams, sharcHitData, sharcRadiance, false );
156+
}
157+
158+
if( isFound )
159+
Lcached = float4( sharcRadiance, 1.0 );
160+
}
147161

148162
// Cache miss - compute lighting, if not found in caches
149163
if( Rng::Hash::GetFloat( ) > Lcached.w )

0 commit comments

Comments
 (0)