3535#define LIGHT_COUNT 1
3636#define BXDF_COUNT 7
3737
38- #include "render_common.hlsl"
38+ #include <render_common.hlsl>
39+ #include <rwmc_global_settings_common.hlsl>
40+
41+ #ifdef RWMC_ENABLED
42+ #include <nbl/builtin/hlsl/rwmc/CascadeAccumulator.hlsl>
43+ #include <render_rwmc_common.hlsl>
44+ #endif
45+
46+ #ifdef RWMC_ENABLED
47+ [[vk::push_constant]] RenderRWMCPushConstants pc;
48+ #else
49+ [[vk::push_constant]] RenderPushConstants pc;
50+ #endif
51+
52+ [[vk::combinedImageSampler]] [[vk::binding (0 , 2 )]] Texture2D <float3 > envMap; // unused
53+ [[vk::combinedImageSampler]] [[vk::binding (0 , 2 )]] SamplerState envSampler;
54+
55+ [[vk::binding (1 , 2 )]] Buffer <uint3 > sampleSequence;
56+
57+ [[vk::combinedImageSampler]] [[vk::binding (2 , 2 )]] Texture2D <uint2 > scramblebuf; // unused
58+ [[vk::combinedImageSampler]] [[vk::binding (2 , 2 )]] SamplerState scrambleSampler;
59+
60+ [[vk::image_format ("rgba16f" )]] [[vk::binding (0 )]] RWTexture2DArray <float32_t4> outImage;
61+ [[vk::image_format ("rgba16f" )]] [[vk::binding (1 )]] RWTexture2DArray <float32_t4> cascade;
62+
3963#include "pathtracer.hlsl"
4064
4165using namespace nbl;
@@ -59,15 +83,15 @@ NBL_CONSTEXPR ext::PTPolygonMethod POLYGON_METHOD = ext::PPM_SOLID_ANGLE;
5983
6084int32_t2 getCoordinates ()
6185{
62- uint32_t width, height;
63- outImage.GetDimensions (width, height);
86+ uint32_t width, height, imageArraySize ;
87+ outImage.GetDimensions (width, height, imageArraySize );
6488 return int32_t2 (glsl::gl_GlobalInvocationID ().x % width, glsl::gl_GlobalInvocationID ().x / width);
6589}
6690
6791float32_t2 getTexCoords ()
6892{
69- uint32_t width, height;
70- outImage.GetDimensions (width, height);
93+ uint32_t width, height, imageArraySize ;
94+ outImage.GetDimensions (width, height, imageArraySize );
7195 int32_t2 iCoords = getCoordinates ();
7296 return float32_t2 (float (iCoords.x) / width, 1.0 - float (iCoords.y) / height);
7397}
@@ -97,7 +121,14 @@ using raygen_type = ext::RayGen::Basic<ray_type>;
97121using intersector_type = ext::Intersector::Comprehensive<ray_type, light_type, bxdfnode_type>;
98122using material_system_type = ext::MaterialSystem::System<diffuse_bxdf_type, conductor_bxdf_type, dielectric_bxdf_type>;
99123using nee_type = ext::NextEventEstimator::Estimator<scene_type, ray_type, sample_t, aniso_interaction, ext::IntersectMode::IM_PROCEDURAL, LIGHT_TYPE, POLYGON_METHOD>;
100- using pathtracer_type = ext::PathTracer::Unidirectional<randgen_type, raygen_type, intersector_type, material_system_type, nee_type>;
124+
125+ #ifdef RWMC_ENABLED
126+ using accumulator_type = rwmc::CascadeAccumulator<float32_t3, CascadeCount>;
127+ #else
128+ using accumulator_type = ext::PathTracer::DefaultAccumulator<float32_t3>;
129+ #endif
130+
131+ using pathtracer_type = ext::PathTracer::Unidirectional<randgen_type, raygen_type, intersector_type, material_system_type, nee_type, accumulator_type>;
101132
102133static const ext::Shape<ext::PST_SPHERE> spheres[SPHERE_COUNT] = {
103134 ext::Shape<ext::PST_SPHERE>::create (float3 (0.0 , -100.5 , -1.0 ), 100.0 , 0u, light_type::INVALID_ID),
@@ -130,7 +161,7 @@ static const ext::Shape<ext::PST_RECTANGLE> rectangles[1];
130161#endif
131162
132163static const light_type lights[LIGHT_COUNT] = {
133- light_type::create (spectral_t ( 30.0 , 25.0 , 15.0 ) ,
164+ light_type::create (LightEminence ,
134165#ifdef SPHERE_LIGHT
135166 8u,
136167#else
@@ -155,11 +186,22 @@ static const ext::Scene<light_type, bxdfnode_type> scene = ext::Scene<light_type
155186 lights, LIGHT_COUNT, bxdfs, BXDF_COUNT
156187);
157188
158- [numthreads (WorkgroupSize, 1 , 1 )]
189+ RenderPushConstants retireveRenderPushConstants ()
190+ {
191+ #ifdef RWMC_ENABLED
192+ return pc.renderPushConstants;
193+ #else
194+ return pc;
195+ #endif
196+ }
197+
198+ [numthreads (RenderWorkgroupSize, 1 , 1 )]
159199void main (uint32_t3 threadID : SV_DispatchThreadID )
160200{
161- uint32_t width, height;
162- outImage.GetDimensions (width, height);
201+ const RenderPushConstants renderPushConstants = retireveRenderPushConstants ();
202+
203+ uint32_t width, height, imageArraySize;
204+ outImage.GetDimensions (width, height, imageArraySize);
163205#ifdef PERSISTENT_WORKGROUPS
164206 uint32_t virtualThreadIndex;
165207 [loop]
@@ -181,10 +223,10 @@ void main(uint32_t3 threadID : SV_DispatchThreadID)
181223#endif
182224 }
183225
184- if (((pc .depth - 1 ) >> MAX_DEPTH_LOG2) > 0 || ((pc .sampleCount - 1 ) >> MAX_SAMPLES_LOG2) > 0 )
226+ if (((renderPushConstants .depth - 1 ) >> MAX_DEPTH_LOG2) > 0 || ((renderPushConstants .sampleCount - 1 ) >> MAX_SAMPLES_LOG2) > 0 )
185227 {
186228 float32_t4 pixelCol = float32_t4 (1.0 ,0.0 ,0.0 ,1.0 );
187- outImage[coords] = pixelCol;
229+ outImage[uint3 ( coords.x, coords.y, 0 ) ] = pixelCol;
188230#ifdef PERSISTENT_WORKGROUPS
189231 continue ;
190232#else
@@ -204,19 +246,33 @@ void main(uint32_t3 threadID : SV_DispatchThreadID)
204246
205247 float4 NDC = float4 (texCoord * float2 (2.0 , -2.0 ) + float2 (-1.0 , 1.0 ), 0.0 , 1.0 );
206248 {
207- float4 tmp = mul (pc .invMVP, NDC);
249+ float4 tmp = mul (renderPushConstants .invMVP, NDC);
208250 ptCreateParams.camPos = tmp.xyz / tmp.w;
209251 NDC.z = 1.0 ;
210252 }
211253
212254 ptCreateParams.NDC = NDC;
213- ptCreateParams.invMVP = pc .invMVP;
255+ ptCreateParams.invMVP = renderPushConstants .invMVP;
214256
215257 pathtracer_type pathtracer = pathtracer_type::create (ptCreateParams);
216258
217- float32_t3 color = pathtracer.getMeasure (pc.sampleCount, pc.depth, scene);
218- float32_t4 pixCol = float32_t4 (color, 1.0 );
219- outImage[coords] = pixCol;
259+ #ifdef RWMC_ENABLED
260+ accumulator_type accumulator = accumulator_type::create (pc.splattingParameters);
261+ #else
262+ accumulator_type accumulator = accumulator_type::create ();
263+ #endif
264+ // path tracing loop
265+ for (int i = 0 ; i < renderPushConstants.sampleCount; ++i)
266+ pathtracer.sampleMeasure (i, renderPushConstants.depth, scene, accumulator);
267+
268+ #ifdef RWMC_ENABLED
269+ for (uint32_t i = 0 ; i < CascadeCount; ++i)
270+ cascade[uint3 (coords.x, coords.y, i)] = float32_t4 (accumulator.accumulation.data[i], 1.0f );
271+ #else
272+ outImage[uint3 (coords.x, coords.y, 0 )] = float32_t4 (accumulator.accumulation, 1.0 );
273+ #endif
274+
275+
220276
221277#ifdef PERSISTENT_WORKGROUPS
222278 }
0 commit comments