Skip to content

Commit 2e5a177

Browse files
committed
Point light implementation
1 parent 188ef51 commit 2e5a177

File tree

8 files changed

+200
-38
lines changed

8 files changed

+200
-38
lines changed

App/CL/light.cl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,63 @@ float DirectionalLight_GetPdf(// Emissive object
392392
return 0.f;
393393
}
394394

395+
/*
396+
Point light
397+
*/
398+
// Get intensity for a given direction
399+
float3 PointLight_GetLe(// Emissive object
400+
Light const* light,
401+
// Scene
402+
Scene const* scene,
403+
// Geometry
404+
DifferentialGeometry const* dg,
405+
// Direction to light source
406+
float3* wo,
407+
// Textures
408+
TEXTURE_ARG_LIST
409+
)
410+
{
411+
return 0.f;
412+
}
413+
414+
/// Sample direction to the light
415+
float3 PointLight_Sample(// Emissive object
416+
Light const* light,
417+
// Scene
418+
Scene const* scene,
419+
// Geometry
420+
DifferentialGeometry const* dg,
421+
// Textures
422+
TEXTURE_ARG_LIST,
423+
// Sample
424+
float2 sample,
425+
// Direction to light source
426+
float3* wo,
427+
// PDF
428+
float* pdf)
429+
{
430+
*wo = light->p - dg->p;
431+
*pdf = 1.f;
432+
return light->intensity;
433+
}
434+
435+
/// Get PDF for a given direction
436+
float PointLight_GetPdf(// Emissive object
437+
Light const* light,
438+
// Scene
439+
Scene const* scene,
440+
// Geometry
441+
DifferentialGeometry const* dg,
442+
// Direction to light source
443+
float3 wo,
444+
// Textures
445+
TEXTURE_ARG_LIST
446+
)
447+
{
448+
return 0.f;
449+
}
450+
451+
395452

396453

397454
/*
@@ -421,6 +478,8 @@ float3 Light_GetLe(// Light index
421478
return AreaLight_GetLe(&light, scene, dg, wo, TEXTURE_ARGS);
422479
case kDirectional:
423480
return DirectionalLight_GetLe(&light, scene, dg, wo, TEXTURE_ARGS);
481+
case kPoint:
482+
return PointLight_GetLe(&light, scene, dg, wo, TEXTURE_ARGS);
424483
}
425484

426485
return make_float3(0.f, 0.f, 0.f);
@@ -452,6 +511,8 @@ float3 Light_Sample(// Light index
452511
return AreaLight_Sample(&light, scene, dg, TEXTURE_ARGS, sample, wo, pdf);
453512
case kDirectional:
454513
return DirectionalLight_Sample(&light, scene, dg, TEXTURE_ARGS, sample, wo, pdf);
514+
case kPoint:
515+
return PointLight_Sample(&light, scene, dg, TEXTURE_ARGS, sample, wo, pdf);
455516
}
456517

457518
*pdf = 0.f;
@@ -481,6 +542,8 @@ float Light_GetPdf(// Light index
481542
return AreaLight_GetPdf(&light, scene, dg, wo, TEXTURE_ARGS);
482543
case kDirectional:
483544
return DirectionalLight_GetPdf(&light, scene, dg, wo, TEXTURE_ARGS);
545+
case kPoint:
546+
return PointLight_GetPdf(&light, scene, dg, wo, TEXTURE_ARGS);
484547
}
485548

486549
return 0.f;

App/Core/output.h

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
/**********************************************************************
2+
Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
********************************************************************/
22+
23+
/**
24+
\file output.h
25+
\author Dmitry Kozlov
26+
\version 1.0
27+
\brief Contains declaration of Baikal::Output class, core interface representing renderer output surface.
28+
*/
29+
130
#pragma once
231

332
#include "math/float3.h"
@@ -6,9 +35,21 @@
635

736
namespace Baikal
837
{
38+
39+
/**
40+
\brief Interface for rendering output.
41+
42+
Represents discrete 2D surface with [0..w]x[0..h] coordinate ranges.
43+
*/
944
class Output
1045
{
1146
public:
47+
/**
48+
\brief Create output of a given size
49+
50+
\param w Output surface width
51+
\param h Output surface height
52+
*/
1253
Output(std::uint32_t w, std::uint32_t h)
1354
: m_width(w)
1455
, m_height(h)
@@ -17,13 +58,25 @@ namespace Baikal
1758

1859
virtual ~Output() = default;
1960

61+
/**
62+
\brief Interface for rendering output.
63+
64+
Represents discrete 2D surface with [0..w]x[0..h] coordinate ranges.
65+
*/
2066
virtual void GetData(RadeonRays::float3* data) const = 0;
2167

22-
std::uint32_t width() const { return m_width; }
23-
std::uint32_t height() const { return m_height; }
68+
// Get surface width
69+
std::uint32_t width() const;
70+
// Get surface height
71+
std::uint32_t height() const;
2472

2573
private:
74+
// Surface width
2675
std::uint32_t m_width;
76+
// Surface height
2777
std::uint32_t m_height;
2878
};
79+
80+
inline std::uint32_t Output::width() const { return m_width; }
81+
inline std::uint32_t Output::height() const { return m_height; }
2982
}

App/Core/renderer.h

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1919
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
THE SOFTWARE.
2121
********************************************************************/
22+
23+
/**
24+
\file renderer.h
25+
\author Dmitry Kozlov
26+
\version 1.0
27+
\brief Contains declaration of Baikal::Renderer class, core interface representing representing the renderer.
28+
*/
2229
#pragma once
2330

2431
#include "math/float3.h"
@@ -30,43 +37,80 @@ namespace Baikal
3037
class Output;
3138
class Scene;
3239

33-
///< Renderer interface
40+
/**
41+
\brief Interface for the renderer.
42+
43+
Renderer implemenation is taking the scene and producing its image into an output surface.
44+
*/
3445
class Renderer
3546
{
3647
public:
3748
Renderer() = default;
38-
// Destructor
3949
virtual ~Renderer() = default;
40-
// Create output
50+
51+
/**
52+
\brief Create output of a given size.
53+
54+
\param w Output surface width
55+
\param h Output surface height
56+
*/
4157
virtual Output* CreateOutput(std::uint32_t w, std::uint32_t h) const = 0;
42-
// Delete output
58+
59+
/**
60+
\brief Delete given output.
61+
62+
\param output The output to delete
63+
*/
4364
virtual void DeleteOutput(Output* output) const = 0;
44-
// Clear output
65+
66+
/**
67+
\brief Clear output surface using given value.
68+
69+
\param val Value to clear to
70+
\param output Output to clear
71+
*/
4572
virtual void Clear(RadeonRays::float3 const& val, Output& output) const = 0;
46-
// Do necessary precalculation and initialization
47-
// TODO: is it really necessary? can be async? progress reporting?
73+
74+
/**
75+
\brief Do necessary scene dependent computations and caching.
76+
77+
\param scene The scene to process
78+
*/
4879
virtual void Preprocess(Scene const& scene) = 0;
49-
// Render single iteration
80+
81+
/**
82+
\brief Render single iteration.
83+
84+
\param scene Scene to render
85+
*/
5086
virtual void Render(Scene const& scene) = 0;
51-
// Set output
87+
88+
/**
89+
\brief Set the output for rendering.
90+
91+
\param output The output to render into.
92+
*/
5293
virtual void SetOutput(Output* output) = 0;
5394

54-
95+
96+
/**
97+
Forbidden stuff.
98+
*/
99+
Renderer(Renderer const&) = delete;
100+
Renderer& operator = (Renderer const&) = delete;
101+
102+
103+
// Temporary functionality
55104
struct BenchmarkStats
56105
{
57106
std::uint32_t num_passes;
58-
107+
59108
RadeonRays::int2 resolution;
60109
float primary_rays_time_in_ms;
61110
float secondary_rays_time_in_ms;
62111
float shadow_rays_time_in_ms;
63112
};
64-
65-
// Run render benchmark
113+
66114
virtual void RunBenchmark(Scene const& scene, std::uint32_t num_passes, BenchmarkStats& stats) {}
67-
68-
// Does not make sense to copy it
69-
Renderer(Renderer const&) = delete;
70-
Renderer& operator = (Renderer const&) = delete;
71115
};
72116
}

App/PT/ptrenderer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ namespace Baikal
272272
m_render_data->intersections = m_context.CreateBuffer<Intersection>(output.width() * output.height(), CL_MEM_READ_WRITE);
273273
m_vidmemws += output.width() * output.height() * sizeof(Intersection);
274274

275-
m_render_data->shadowrays = m_context.CreateBuffer<ray>(2 * output.width() * output.height() * kMaxLightSamples, CL_MEM_READ_WRITE);
275+
m_render_data->shadowrays = m_context.CreateBuffer<ray>(output.width() * output.height() * kMaxLightSamples, CL_MEM_READ_WRITE);
276276
m_vidmemws += output.width() * output.height() * sizeof(ray)* kMaxLightSamples;
277277

278-
m_render_data->shadowhits = m_context.CreateBuffer<int>(2 * output.width() * output.height() * kMaxLightSamples, CL_MEM_READ_WRITE);
278+
m_render_data->shadowhits = m_context.CreateBuffer<int>(output.width() * output.height() * kMaxLightSamples, CL_MEM_READ_WRITE);
279279
m_vidmemws += output.width() * output.height() * sizeof(int)* kMaxLightSamples;
280280

281-
m_render_data->lightsamples = m_context.CreateBuffer<float3>(2 * output.width() * output.height() * kMaxLightSamples, CL_MEM_READ_WRITE);
281+
m_render_data->lightsamples = m_context.CreateBuffer<float3>(output.width() * output.height() * kMaxLightSamples, CL_MEM_READ_WRITE);
282282
m_vidmemws += output.width() * output.height() * sizeof(float3)* kMaxLightSamples;
283283

284284
m_render_data->paths = m_context.CreateBuffer<PathState>(output.width() * output.height(), CL_MEM_READ_WRITE);

App/Scene/scene.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,16 @@ void Scene::AddDirectionalLight(RadeonRays::float3 const& d, RadeonRays::float3
12651265
light.intensity = e;
12661266
lights_.push_back(light);
12671267
}
1268-
1268+
1269+
void Scene::AddPointLight(RadeonRays::float3 const& p, RadeonRays::float3 const& e)
1270+
{
1271+
Light light;
1272+
light.type = kPoint;
1273+
light.p = p;
1274+
light.intensity = e;
1275+
lights_.push_back(light);
1276+
}
1277+
12691278
void Scene::SetEnvironment(std::string const& filename, std::string const& basepath, float envmapmul)
12701279
{
12711280
// Save multiplier

App/Scene/scene.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ namespace Baikal
4444
void SetBackground(std::string const& filename, std::string const& basepath = "");
4545

4646
void AddDirectionalLight(RadeonRays::float3 const& d, RadeonRays::float3 const& e);
47+
48+
void AddPointLight(RadeonRays::float3 const& p, RadeonRays::float3 const& e);
4749

4850
enum DirtyFlags
4951
{

App/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ GLuint g_vertex_buffer;
8787
GLuint g_index_buffer;
8888
GLuint g_texture;
8989

90-
int g_window_width = 800;
91-
int g_window_height = 600;
90+
int g_window_width = 512;
91+
int g_window_height = 512;
9292
int g_num_shadow_rays = 1;
9393
int g_num_ao_rays = 1;
9494
int g_ao_enabled = false;
9595
int g_progressive = false;
9696
int g_num_bounces = 5;
97-
int g_num_samples = -1;
97+
int g_num_samples = 256;
9898
int g_samplecount = 0;
9999
float g_ao_radius = 1.f;
100100
float g_envmapmul = 1.f;
@@ -365,6 +365,7 @@ void InitData()
365365

366366
//g_scene->SetEnvironment(g_envmapname, "", g_envmapmul);
367367
g_scene->AddDirectionalLight(RadeonRays::float3(-0.3f, -1.f, -0.4f), RadeonRays::float3(1.f, 1.f, 1.f));
368+
g_scene->AddPointLight(RadeonRays::float3(0.5f, 1.5f, 0.0f), RadeonRays::float3(1.f, 0.6f, 1.f));
368369

369370
#pragma omp parallel for
370371
for (int i = 0; i < g_cfgs.size(); ++i)

CLW/CLWProgram.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,7 @@ CLWProgram CLWProgram::CreateFromSource(char const* sourcecode, size_t sourcesiz
7070
deviceIds[i] = context.GetDevice(i);
7171
}
7272

73-
char const* buildopts1 =
74-
#if defined(__APPLE__)
75-
"-D APPLE -cl-mad-enable -cl-fast-relaxed-math -cl-std=CL1.2 -I ."
76-
#elif defined(_WIN32) || defined (WIN32)
77-
"-D WIN32 -cl-mad-enable -cl-std=CL1.2 -I."
78-
#elif defined(__linux__)
79-
"-D __linux__ -I."
80-
#else
81-
nullptr
82-
#endif
83-
;
73+
8474

8575
status = clBuildProgram(program, context.GetDeviceCount(), &deviceIds[0], buildopts, nullptr, nullptr);
8676

@@ -267,4 +257,4 @@ CLWKernel CLWProgram::GetKernel(std::string const& funcName) const
267257
ThrowIf(iter == kernels_.end(), CL_INVALID_KERNEL_NAME, "No such kernel in program");
268258

269259
return iter->second;
270-
}
260+
}

0 commit comments

Comments
 (0)