@@ -58,6 +58,7 @@ float2 GetBlueNoise( uint2 pixelPos, bool isCheckerboard, uint seed = 0 )
58
58
blue += ( dither.xyxy - 0.5 ) * ( 1.0 / 256.0 );
59
59
60
60
// Don't use blue noise in these cases
61
+ [flatten]
61
62
if ( gDenoiserType == DENOISER_REFERENCE || gRR )
62
63
blue.xy = Rng::Hash::GetFloat2 ( );
63
64
@@ -259,8 +260,8 @@ TraceOpaqueResult TraceOpaque( inout TraceOpaqueDesc desc )
259
260
sharcState.voxelDataBuffer = gInOut_SharcVoxelDataBuffer;
260
261
261
262
bool isSharcAllowed = gSHARC && NRD_MODE < OCCLUSION; // trivial
262
- isSharcAllowed &= geometryProps.hitT > voxelSize; // voxel angular size is acceptable
263
263
isSharcAllowed &= Rng::Hash::GetFloat ( ) > Lpsr.w; // probabilistically estimate the need
264
+ isSharcAllowed &= geometryProps.hitT > voxelSize; // voxel angular size is acceptable
264
265
isSharcAllowed &= desc.bounceNum == 0 ; // allow only for the last bounce for PSR
265
266
266
267
float3 sharcRadiance;
@@ -358,7 +359,7 @@ TraceOpaqueResult TraceOpaque( inout TraceOpaqueDesc desc )
358
359
// Diffuse or specular path?
359
360
if ( gTracingMode == RESOLUTION_FULL_PROBABILISTIC || bounce > 1 )
360
361
{
361
- isDiffuse = rnd < diffuseProbability;
362
+ isDiffuse = rnd < diffuseProbability; // TODO: if "diffuseProbability" is clamped, "pathThroughput" should be adjusted too
362
363
pathThroughput /= abs ( float ( !isDiffuse ) - diffuseProbability );
363
364
364
365
if ( bounce == 1 )
@@ -437,7 +438,7 @@ TraceOpaqueResult TraceOpaque( inout TraceOpaqueDesc desc )
437
438
// 1. If IS enabled, check the ray in LightBVH
438
439
bool isMiss = false ;
439
440
if ( gDisableShadowsAndEnableImportanceSampling && maxSamplesNum != 1 )
440
- isMiss = CastVisibilityRay_AnyHit ( geometryProps.GetXoffset ( geometryProps.N ), r, 0.0 , INF, mipAndCone, gLightTlas, GEOMETRY_ALL , desc.rayFlags );
441
+ isMiss = CastVisibilityRay_AnyHit ( geometryProps.GetXoffset ( geometryProps.N ), r, 0.0 , INF, mipAndCone, gLightTlas, FLAG_NON_TRANSPARENT , desc.rayFlags );
441
442
442
443
// 2. Count rays hitting emissive surfaces
443
444
if ( !isMiss )
@@ -609,10 +610,10 @@ TraceOpaqueResult TraceOpaque( inout TraceOpaqueDesc desc )
609
610
sharcState.hashMapData.hashEntriesBuffer = gInOut_SharcHashEntriesBuffer;
610
611
sharcState.voxelDataBuffer = gInOut_SharcVoxelDataBuffer;
611
612
613
+ float footprint = geometryProps.hitT * ImportanceSampling::GetSpecularLobeTanHalfAngle ( ( isDiffuse || bounce == desc.bounceNum ) ? 1.0 : materialProps.roughness, 0.5 );
612
614
bool isSharcAllowed = gSHARC && NRD_MODE < OCCLUSION; // trivial
613
- isSharcAllowed &= geometryProps.hitT > voxelSize; // voxel angular size is acceptable
614
615
isSharcAllowed &= Rng::Hash::GetFloat ( ) > Lcached.w; // probabilistically estimate the need
615
- isSharcAllowed &= isDiffuse || Rng::Hash:: GetFloat ( ) < smc || bounce == desc.bounceNum ; // allowed for diffuse-like events or last bounce
616
+ isSharcAllowed &= footprint > voxelSize ; // voxel angular size is acceptable
616
617
617
618
float3 sharcRadiance;
618
619
if ( isSharcAllowed && SharcGetCachedRadiance ( sharcState, sharcHitData, sharcRadiance, false ) )
@@ -698,26 +699,25 @@ TraceOpaqueResult TraceOpaque( inout TraceOpaqueDesc desc )
698
699
}
699
700
}
700
701
701
- // Material de-modulation ( convert irradiance into radiance )
702
- float3 albedo, Rf0;
703
- BRDF::ConvertBaseColorMetalnessToAlbedoRf0 ( desc.materialProps.baseColor, desc.materialProps.metalness, albedo, Rf0 );
702
+ { // Material de-modulation ( convert irradiance into radiance )
703
+ float3 albedo, Rf0;
704
+ BRDF::ConvertBaseColorMetalnessToAlbedoRf0 ( desc.materialProps.baseColor, desc.materialProps.metalness, albedo, Rf0 );
704
705
705
- float NoV = abs ( dot ( desc.materialProps.N, desc.geometryProps.V ) );
706
- float3 Fenv = BRDF::EnvironmentTerm_Rtg ( Rf0, NoV, desc.materialProps.roughness );
707
- float3 diffDemod = ( 1.0 - Fenv ) * albedo * 0.99 + 0.01 ;
708
- float3 specDemod = Fenv * 0.99 + 0.01 ;
706
+ float3 diffFactor, specFactor;
707
+ NRD_MaterialFactors ( desc.materialProps.N, desc.geometryProps.V, albedo, Rf0, desc.materialProps.roughness, diffFactor, specFactor );
709
708
710
- // We can combine radiance ( for everything ) and irradiance ( for hair ) in denoising if material ID test is enabled
711
- if ( desc.geometryProps.Has ( FLAG_HAIR ) && NRD_NORMAL_ENCODING == NRD_NORMAL_ENCODING_R10G10B10A2_UNORM )
712
- {
713
- diffDemod = 1.0 ;
714
- specDemod = 1.0 ;
715
- }
709
+ // We can combine radiance ( for everything ) and irradiance ( for hair ) in denoising if material ID test is enabled
710
+ if ( desc.geometryProps.Has ( FLAG_HAIR ) && NRD_NORMAL_ENCODING == NRD_NORMAL_ENCODING_R10G10B10A2_UNORM )
711
+ {
712
+ diffFactor = 1.0 ;
713
+ specFactor = 1.0 ;
714
+ }
716
715
717
- if ( gOnScreen != SHOW_MIP_SPECULAR )
718
- {
719
- result.diffRadiance /= diffDemod;
720
- result.specRadiance /= specDemod;
716
+ if ( gOnScreen != SHOW_MIP_SPECULAR )
717
+ {
718
+ result.diffRadiance /= diffFactor;
719
+ result.specRadiance /= specFactor;
720
+ }
721
721
}
722
722
723
723
// Radiance is already divided by sampling probability, we need to average across all paths
@@ -817,7 +817,7 @@ void main( uint2 pixelPos : SV_DispatchThreadId )
817
817
float3 cameraRayDirection = ( float3 )0 ;
818
818
GetCameraRay ( cameraRayOrigin, cameraRayDirection, sampleUv );
819
819
820
- GeometryProps geometryProps0 = CastRay ( cameraRayOrigin, cameraRayDirection, 0.0 , INF, GetConeAngleFromRoughness ( 0.0 , 0.0 ), gWorldTlas, ( gOnScreen == SHOW_INSTANCE_INDEX || gOnScreen == SHOW_NORMAL ) ? GEOMETRY_ALL : GEOMETRY_IGNORE_TRANSPARENT , 0 );
820
+ GeometryProps geometryProps0 = CastRay ( cameraRayOrigin, cameraRayDirection, 0.0 , INF, GetConeAngleFromRoughness ( 0.0 , 0.0 ), gWorldTlas, ( gOnScreen == SHOW_INSTANCE_INDEX || gOnScreen == SHOW_NORMAL ) ? GEOMETRY_ALL : FLAG_NON_TRANSPARENT , 0 );
821
821
MaterialProps materialProps0 = GetMaterialProps ( geometryProps0 );
822
822
823
823
// ViewZ
@@ -909,8 +909,8 @@ void main( uint2 pixelPos : SV_DispatchThreadId )
909
909
desc.pixelPos = pixelPos;
910
910
desc.checkerboard = checkerboard;
911
911
desc.pathNum = gSampleNum;
912
- desc.bounceNum = gBounceNum; // TODO: adjust by roughness?
913
- desc.instanceInclusionMask = GEOMETRY_IGNORE_TRANSPARENT ;
912
+ desc.bounceNum = gBounceNum;
913
+ desc.instanceInclusionMask = FLAG_NON_TRANSPARENT ;
914
914
desc.rayFlags = 0 ;
915
915
916
916
TraceOpaqueResult result = TraceOpaque ( desc );
0 commit comments