@@ -58,6 +58,7 @@ float2 GetBlueNoise( uint2 pixelPos, bool isCheckerboard, uint seed = 0 )
5858 blue += ( dither.xyxy - 0.5 ) * ( 1.0 / 256.0 );
5959
6060 // Don't use blue noise in these cases
61+ [flatten]
6162 if ( gDenoiserType == DENOISER_REFERENCE || gRR )
6263 blue.xy = Rng::Hash::GetFloat2 ( );
6364
@@ -259,8 +260,8 @@ TraceOpaqueResult TraceOpaque( inout TraceOpaqueDesc desc )
259260 sharcState.voxelDataBuffer = gInOut_SharcVoxelDataBuffer;
260261
261262 bool isSharcAllowed = gSHARC && NRD_MODE < OCCLUSION; // trivial
262- isSharcAllowed &= geometryProps.hitT > voxelSize; // voxel angular size is acceptable
263263 isSharcAllowed &= Rng::Hash::GetFloat ( ) > Lpsr.w; // probabilistically estimate the need
264+ isSharcAllowed &= geometryProps.hitT > voxelSize; // voxel angular size is acceptable
264265 isSharcAllowed &= desc.bounceNum == 0 ; // allow only for the last bounce for PSR
265266
266267 float3 sharcRadiance;
@@ -358,7 +359,7 @@ TraceOpaqueResult TraceOpaque( inout TraceOpaqueDesc desc )
358359 // Diffuse or specular path?
359360 if ( gTracingMode == RESOLUTION_FULL_PROBABILISTIC || bounce > 1 )
360361 {
361- isDiffuse = rnd < diffuseProbability;
362+ isDiffuse = rnd < diffuseProbability; // TODO: if "diffuseProbability" is clamped, "pathThroughput" should be adjusted too
362363 pathThroughput /= abs ( float ( !isDiffuse ) - diffuseProbability );
363364
364365 if ( bounce == 1 )
@@ -437,7 +438,7 @@ TraceOpaqueResult TraceOpaque( inout TraceOpaqueDesc desc )
437438 // 1. If IS enabled, check the ray in LightBVH
438439 bool isMiss = false ;
439440 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 );
441442
442443 // 2. Count rays hitting emissive surfaces
443444 if ( !isMiss )
@@ -609,10 +610,10 @@ TraceOpaqueResult TraceOpaque( inout TraceOpaqueDesc desc )
609610 sharcState.hashMapData.hashEntriesBuffer = gInOut_SharcHashEntriesBuffer;
610611 sharcState.voxelDataBuffer = gInOut_SharcVoxelDataBuffer;
611612
613+ float footprint = geometryProps.hitT * ImportanceSampling::GetSpecularLobeTanHalfAngle ( ( isDiffuse || bounce == desc.bounceNum ) ? 1.0 : materialProps.roughness, 0.5 );
612614 bool isSharcAllowed = gSHARC && NRD_MODE < OCCLUSION; // trivial
613- isSharcAllowed &= geometryProps.hitT > voxelSize; // voxel angular size is acceptable
614615 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
616617
617618 float3 sharcRadiance;
618619 if ( isSharcAllowed && SharcGetCachedRadiance ( sharcState, sharcHitData, sharcRadiance, false ) )
@@ -698,26 +699,25 @@ TraceOpaqueResult TraceOpaque( inout TraceOpaqueDesc desc )
698699 }
699700 }
700701
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 );
704705
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 );
709708
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+ }
716715
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+ }
721721 }
722722
723723 // Radiance is already divided by sampling probability, we need to average across all paths
@@ -817,7 +817,7 @@ void main( uint2 pixelPos : SV_DispatchThreadId )
817817 float3 cameraRayDirection = ( float3 )0 ;
818818 GetCameraRay ( cameraRayOrigin, cameraRayDirection, sampleUv );
819819
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 );
821821 MaterialProps materialProps0 = GetMaterialProps ( geometryProps0 );
822822
823823 // ViewZ
@@ -909,8 +909,8 @@ void main( uint2 pixelPos : SV_DispatchThreadId )
909909 desc.pixelPos = pixelPos;
910910 desc.checkerboard = checkerboard;
911911 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 ;
914914 desc.rayFlags = 0 ;
915915
916916 TraceOpaqueResult result = TraceOpaque ( desc );
0 commit comments