22
33#include "nbl/builtin/hlsl/jit/device_capabilities.hlsl"
44#include "nbl/builtin/hlsl/random/xoroshiro.hlsl"
5+ #include "nbl/builtin/hlsl/random/pcg.hlsl"
56
67#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
78#include "nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl"
@@ -15,13 +16,6 @@ static const float32_t3 s_clearColor = float32_t3(0.3, 0.3, 0.8);
1516
1617[[vk::binding (1 , 0 )]] RWTexture2D <float32_t4> colorImage;
1718
18- uint32_t pcgHash (uint32_t v)
19- {
20- const uint32_t state = v * 747796405u + 2891336453u;
21- const uint32_t word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
22- return (word >> 22u) ^ word;
23- }
24-
2519float32_t nextRandomUnorm (inout nbl::hlsl::Xoroshiro64StarStar rnd)
2620{
2721 return float32_t (rnd ()) / float32_t (0xFFFFFFFF );
@@ -34,8 +28,8 @@ void main()
3428 const uint32_t3 launchSize = DispatchRaysDimensions ();
3529 const uint32_t2 coords = launchID.xy;
3630
37- const uint32_t seed1 = pcgHash (pc.frameCounter);
38- const uint32_t seed2 = pcgHash (launchID.y * launchSize.x + launchID.x);
31+ const uint32_t seed1 = nbl::hlsl::Pcg:: construct (pc.frameCounter)( );
32+ const uint32_t seed2 = nbl::hlsl::Pcg:: construct (launchID.y * launchSize.x + launchID.x)( );
3933 nbl::hlsl::Xoroshiro64StarStar rnd = nbl::hlsl::Xoroshiro64StarStar::construct (uint32_t2 (seed1, seed2));
4034
4135 float32_t3 hitValues = float32_t3 (0 , 0 , 0 );
@@ -77,8 +71,6 @@ void main()
7771 cLight.inHitPosition = worldPosition;
7872 CallShader (pc.light.type, cLight);
7973
80- const float32_t3 diffuse = computeDiffuse (material, cLight.outLightDir, worldNormal);
81- float32_t3 specular = float32_t3 (0 , 0 , 0 );
8274 float32_t attenuation = 1 ;
8375
8476 if (dot (worldNormal, cLight.outLightDir) > 0 )
@@ -95,12 +87,14 @@ void main()
9587 TraceRay (topLevelAS, shadowRayFlags, 0xFF , ERT_OCCLUSION, 0 , EMT_OCCLUSION, rayDesc, occlusionPayload);
9688
9789 attenuation = occlusionPayload.attenuation;
98- if (occlusionPayload.attenuation > 0 )
90+ if (occlusionPayload.attenuation > 0.0001 )
9991 {
100- specular = computeSpecular (material, camDirection, cLight.outLightDir, worldNormal);
92+ const float32_t3 diffuse = computeDiffuse (material, cLight.outLightDir, worldNormal);
93+ const float32_t3 specular = computeSpecular (material, camDirection, cLight.outLightDir, worldNormal);
94+ hitValues += (cLight.outIntensity * attenuation * (diffuse + specular));
10195 }
10296 }
103- hitValues += ((cLight.outIntensity * attenuation * (diffuse + specular)) + material.ambient) ;
97+ hitValues += material.ambient;
10498 }
10599
106100 const float32_t3 hitValue = hitValues / s_sampleCount;
0 commit comments