66#include "nbl/builtin/hlsl/bxdf/reflection.hlsl"
77#include "nbl/builtin/hlsl/bxdf/transmission.hlsl"
88
9- #include "render_common.hlsl"
10- #include "pathtracer.hlsl"
11-
129// add these defines (one at a time) using -D argument to dxc
1310// #define SPHERE_LIGHT
1411// #define TRIANGLE_LIGHT
1714#ifdef SPHERE_LIGHT
1815#define SPHERE_COUNT 9
1916#define LIGHT_TYPE ext::PST_SPHERE
20- #else
17+
18+ #define TRIANGLE_COUNT 0
19+ #define RECTANGLE_COUNT 0
20+ #endif
21+
22+ #ifdef TRIANGLE_LIGHT
23+ #define TRIANGLE_COUNT 1
24+ #define LIGHT_TYPE ext::PST_TRIANGLE
25+
26+ #define SPHERE_COUNT 8
27+ #define RECTANGLE_COUNT 0
28+ #endif
29+
30+ #ifdef RECTANGLE_LIGHT
31+ #define RECTANGLE_COUNT 1
32+ #define LIGHT_TYPE ext::PST_RECTANGLE
33+
2134#define SPHERE_COUNT 8
35+ #define TRIANGLE_COUNT 0
2236#endif
2337
38+ #define LIGHT_COUNT 1
39+ #define BXDF_COUNT 7
40+
41+ #include "render_common.hlsl"
42+ #include "pathtracer.hlsl"
43+
2444using namespace nbl::hlsl;
2545
2646NBL_CONSTEXPR uint32_t WorkgroupSize = 32 ;
@@ -80,22 +100,21 @@ static const ext::Shape<ext::PST_SPHERE> spheres[SPHERE_COUNT] = {
80100};
81101
82102#ifdef TRIANGLE_LIGHT
83- #define LIGHT_TYPE ext::PST_TRIANGLE
84- #define TRIANGLE_COUNT 1
85103static const ext::Shape<ext::PST_TRIANGLE> triangles[TRIANGLE_COUNT] = {
86104 ext::Shape<ext::PST_TRIANGLE>::create (float3 (-1.8 ,0.35 ,0.3 ) * 10.0 , float3 (-1.2 ,0.35 ,0.0 ) * 10.0 , float3 (-1.5 ,0.8 ,-0.3 ) * 10.0 , bxdfnode_type::INVALID_ID, 0u)
87105};
106+ #else
107+ static const ext::Shape<ext::PST_TRIANGLE> triangles[1 ];
88108#endif
89109
90110#ifdef RECTANGLE_LIGHT
91- #define LIGHT_TYPE ext::PST_RECTANGLE
92- #define RECTANGLE_COUNT 1
93111static const ext::Shape<ext::PST_RECTANGLE> rectangles[RECTANGLE_COUNT] = {
94112 ext::Shape<ext::PST_RECTANGLE>::create (float3 (-3.8 ,0.35 ,1.3 ), normalize (float3 (2 ,0 ,-1 ))*7.0 , normalize (float3 (2 ,-5 ,4 ))*0.1 , bxdfnode_type::INVALID_ID, 0u)
95113};
114+ #else
115+ static const ext::Shape<ext::PST_RECTANGLE> rectangles[1 ];
96116#endif
97117
98- #define LIGHT_COUNT 1
99118static const light_type lights[LIGHT_COUNT] = {
100119 light_type::create (spectral_t (30.0 ,25.0 ,15.0 ),
101120#ifdef SPHERE_LIGHT
@@ -106,7 +125,6 @@ static const light_type lights[LIGHT_COUNT] = {
106125 ext::IntersectMode::IM_PROCEDURAL, LIGHT_TYPE)
107126};
108127
109- #define BXDF_COUNT 7
110128static const bxdfnode_type bxdfs[BXDF_COUNT] = {
111129 bxdfnode_type::create (ext::MaterialSystem::MaterialType::DIFFUSE, false , float2 (0 ,0 ), spectral_t (0.8 ,0.8 ,0.8 )),
112130 bxdfnode_type::create (ext::MaterialSystem::MaterialType::DIFFUSE, false , float2 (0 ,0 ), spectral_t (0.8 ,0.4 ,0.4 )),
@@ -117,6 +135,12 @@ static const bxdfnode_type bxdfs[BXDF_COUNT] = {
117135 bxdfnode_type::create (ext::MaterialSystem::MaterialType::DIELECTRIC, false , float2 (0.0625 ,0.0625 ), spectral_t (1 ,1 ,1 ), spectral_t (0.71 ,0.69 ,0.67 ))
118136};
119137
138+ static const ext::Scene<light_type, bxdfnode_type> scene = ext::Scene<light_type, bxdfnode_type>::create (
139+ spheres, triangles, rectangles,
140+ SPHERE_COUNT, TRIANGLE_COUNT, RECTANGLE_COUNT,
141+ lights, LIGHT_COUNT, bxdfs, BXDF_COUNT
142+ );
143+
120144[numthreads (WorkgroupSize, WorkgroupSize, 1 )]
121145void main (uint32_t3 threadID : SV_DispatchThreadID )
122146{
@@ -164,32 +188,6 @@ void main(uint32_t3 threadID : SV_DispatchThreadID)
164188
165189 pathtracer_type pathtracer = pathtracer_type::create (ptCreateParams);
166190
167- // set up scene (can do as global var?)
168- ext::Scene<light_type, bxdfnode_type> scene;
169- scene.sphereCount = SPHERE_COUNT;
170- for (uint32_t i = 0 ; i < SPHERE_COUNT; i++)
171- scene.spheres[i] = spheres[i];
172- #ifdef TRIANGLE_LIGHT
173- scene.triangleCount = TRIANGLE_COUNT;
174- for (uint32_t i = 0 ; i < TRIANGLE_COUNT; i++)
175- scene.triangles[i] = triangles[i];
176- #else
177- scene.triangleCount = 0 ;
178- #endif
179- #ifdef RECTANGLE_LIGHT
180- scene.rectangleCount = RECTANGLE_COUNT;
181- for (uint32_t i = 0 ; i < RECTANGLE_COUNT; i++)
182- scene.rectangles[i] = rectangles[i];
183- #else
184- scene.rectangleCount = 0 ;
185- #endif
186- scene.lightCount = LIGHT_COUNT;
187- for (uint32_t i = 0 ; i < LIGHT_COUNT; i++)
188- scene.lights[i] = lights[i];
189- scene.bxdfCount = BXDF_COUNT;
190- for (uint32_t i = 0 ; i < BXDF_COUNT; i++)
191- scene.bxdfs[i] = bxdfs[i];
192-
193191 float32_t3 color = pathtracer.getMeasure (pc.sampleCount, pc.depth, scene);
194192 float32_t4 pixCol = float32_t4 (color, 1.0 );
195193 outImage[coords] = pixCol;
0 commit comments