Skip to content

Commit

Permalink
Merge pull request #3 from yozhijk/master
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
yozhijk authored May 31, 2017
2 parents 54966c7 + 46c5f8e commit 74af1ba
Show file tree
Hide file tree
Showing 59 changed files with 1,978 additions and 1,052 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
*/
#pragma once

#include "SceneGraph/scene_controller.h"
#include "scene_controller.h"
#include "CLW.h"

#include "CLW/clwscene.h"
#include "SceneGraph/clwscene.h"

#include "radeon_rays_cl.h"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "SceneGraph/material.h"
#include "SceneGraph/texture.h"
#include "SceneGraph/Collector/collector.h"
#include "iterator.h"
#include "SceneGraph/iterator.h"

#include <chrono>
#include <memory>
Expand All @@ -23,7 +23,9 @@ namespace Baikal

template <typename CompiledScene>
inline
CompiledScene& SceneController<CompiledScene>::CompileScene(Scene1 const& scene, Collector& mat_collector, Collector& tex_collector) const
CompiledScene& SceneController<CompiledScene>::CompileScene(
Scene1 const& scene, Collector& mat_collector,
Collector& tex_collector) const
{
// The overall approach is:
// 1) Check if materials have changed, update collector if yes
Expand All @@ -40,15 +42,16 @@ namespace Baikal
tex_collector.Clear();

// Create shape and light iterators
std::unique_ptr<Iterator> shape_iter(scene.CreateShapeIterator());
std::unique_ptr<Iterator> light_iter(scene.CreateLightIterator());
auto shape_iter = scene.CreateShapeIterator();
auto light_iter = scene.CreateLightIterator();

auto default_material = GetDefaultMaterial();
// Collect materials from shapes first
mat_collector.Collect(shape_iter.get(),
mat_collector.Collect(*shape_iter,
// This function adds all materials to resulting map
// recursively via Material dependency API
[default_material](void const* item) -> std::set<void const*>
[default_material](void const* item) ->
std::set<void const*>
{
// Resulting material set
std::set<void const*> mats;
Expand Down Expand Up @@ -79,12 +82,14 @@ namespace Baikal
mats.emplace(m);

// Create dependency iterator
std::unique_ptr<Iterator> mat_iter(m->CreateMaterialIterator());
auto mat_iter = m->CreateMaterialIterator();

// Push all dependencies into the stack
for (; mat_iter->IsValid(); mat_iter->Next())
{
material_stack.push(mat_iter->ItemAs<Material const>());
material_stack.push(
mat_iter->ItemAs<Material const>()
);
}
}

Expand All @@ -97,10 +102,10 @@ namespace Baikal

// Now we need to collect textures from our materials
// Create material iterator
std::unique_ptr<Iterator> mat_iter(mat_collector.CreateIterator());
auto mat_iter = mat_collector.CreateIterator();

// Collect textures from materials
tex_collector.Collect(mat_iter.get(),
tex_collector.Collect(*mat_iter,
[](void const* item) -> std::set<void const*>
{
// Texture set
Expand All @@ -109,7 +114,7 @@ namespace Baikal
auto material = reinterpret_cast<Material const*>(item);

// Create texture dependency iterator
std::unique_ptr<Iterator> tex_iter(material->CreateTextureIterator());
auto tex_iter = material->CreateTextureIterator();

// Emplace all dependent textures
for (; tex_iter->IsValid(); tex_iter->Next())
Expand All @@ -123,7 +128,7 @@ namespace Baikal


// Collect textures from lights
tex_collector.Collect(light_iter.get(),
tex_collector.Collect(*light_iter,
[](void const* item) -> std::set<void const*>
{
// Resulting set
Expand All @@ -132,7 +137,7 @@ namespace Baikal
auto light = reinterpret_cast<Light const*>(item);

// Create texture dependency iterator
std::unique_ptr<Iterator> tex_iter(light->CreateTextureIterator());
auto tex_iter = light->CreateTextureIterator();

// Emplace all dependent textures
for (; tex_iter->IsValid(); tex_iter->Next())
Expand Down Expand Up @@ -199,7 +204,7 @@ namespace Baikal

{
// Check if we have lights in the scene
std::unique_ptr<Iterator> light_iter(scene.CreateLightIterator());
auto light_iter = scene.CreateLightIterator();

if (!light_iter->IsValid())
{
Expand Down Expand Up @@ -231,7 +236,7 @@ namespace Baikal

{
// Check if we have shapes in the scene
std::unique_ptr<Iterator> shape_iter(scene.CreateShapeIterator());
auto shape_iter = scene.CreateShapeIterator();

if (!shape_iter->IsValid())
{
Expand Down
28 changes: 21 additions & 7 deletions Baikal/CL/bxdf.cl → Baikal/Kernels/CL/bxdf.cl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ THE SOFTWARE.
#ifndef BXDF_CL
#define BXDF_CL

#include <../Baikal/CL/utils.cl>
#include <../Baikal/CL/texture.cl>
#include <../Baikal/CL/payload.cl>
#include <../Baikal/Kernels/CL/utils.cl>
#include <../Baikal/Kernels/CL/texture.cl>
#include <../Baikal/Kernels/CL/payload.cl>
#include <../Baikal/Kernels/CL/disney.cl>

#define DENOM_EPS 1e-8f
#define ROUGHNESS_EPS 0.0001f
Expand Down Expand Up @@ -452,7 +453,7 @@ float3 Lambert_Sample(

float F = dg->mat.fresnel;

*pdf = fabs(wo->y) / PI;
*pdf = fabs((*wo).y) / PI;

return F * kd / PI;
}
Expand Down Expand Up @@ -498,7 +499,7 @@ float3 Translucent_Sample(

*wo = normalize(Sample_MapToHemisphere(sample, n, 1.f));

*pdf = fabs(wo->y) / PI;
*pdf = fabs((*wo).y) / PI;

return kd / PI;
}
Expand Down Expand Up @@ -588,7 +589,7 @@ float3 IdealReflect_Sample(

float F = dg->mat.fresnel;

float coswo = fabs(wo->y);
float coswo = fabs((*wo).y);

// Return reflectance value
return coswo > DENOM_EPS ? (F * ks * (1.f / coswo)) : 0.f;
Expand Down Expand Up @@ -999,7 +1000,7 @@ float3 Passthrough_Sample(
{

*wo = -wi;
float coswo = fabs(wo->y);
float coswo = fabs((*wo).y);

// PDF is infinite at that point, but deltas are going to cancel out while evaluating
// so set it to 1.f
Expand Down Expand Up @@ -1046,6 +1047,10 @@ float3 Bxdf_Evaluate(
return MicrofacetRefractionGGX_Evaluate(dg, wi_t, wo_t, TEXTURE_ARGS);
case kMicrofacetRefractionBeckmann:
return MicrofacetRefractionBeckmann_Evaluate(dg, wi_t, wo_t, TEXTURE_ARGS);
#ifdef ENABLE_DISNEY
case kDisney:
return Disney_Evaluate(dg, wi_t, wo_t, TEXTURE_ARGS);
#endif
}

return 0.f;
Expand Down Expand Up @@ -1102,6 +1107,11 @@ float3 Bxdf_Sample(
case kMicrofacetRefractionBeckmann:
res = MicrofacetRefractionBeckmann_Sample(dg, wi_t, TEXTURE_ARGS, sample, &wo_t, pdf);
break;
#ifdef ENABLE_DISNEY
case kDisney:
res = Disney_Sample(dg, wi_t, TEXTURE_ARGS, sample, &wo_t, pdf);
break;
#endif
default:
*pdf = 0.f;
break;
Expand Down Expand Up @@ -1148,6 +1158,10 @@ float Bxdf_GetPdf(
return MicrofacetRefractionGGX_GetPdf(dg, wi_t, wo_t, TEXTURE_ARGS);
case kMicrofacetRefractionBeckmann:
return MicrofacetRefractionBeckmann_GetPdf(dg, wi_t, wo_t, TEXTURE_ARGS);
#ifdef ENABLE_DISNEY
case kDisney:
return Disney_GetPdf(dg, wi_t, wo_t, TEXTURE_ARGS);
#endif
}

return 0.f;
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions Baikal/CL/camera.cl → Baikal/Kernels/CL/camera.cl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ THE SOFTWARE.
#ifndef CAMERA_CL
#define CAMERA_CL

#include <../Baikal/CL/common.cl>
#include <../Baikal/CL/payload.cl>
#include <../Baikal/CL/sampling.cl>
#include <../Baikal/CL/utils.cl>
#include <../Baikal/CL/path.cl>
#include <../Baikal/CL/vertex.cl>
#include <../Baikal/Kernels/CL/common.cl>
#include <../Baikal/Kernels/CL/payload.cl>
#include <../Baikal/Kernels/CL/sampling.cl>
#include <../Baikal/Kernels/CL/utils.cl>
#include <../Baikal/Kernels/CL/path.cl>
#include <../Baikal/Kernels/CL/vertex.cl>

// Pinhole camera implementation.
// This kernel is being used if aperture value = 0.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Baikal/CL/denoise.cl → Baikal/Kernels/CL/denoise.cl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ THE SOFTWARE.
#ifndef DENOISE_CL
#define DENOISE_CL

#include <../Baikal/CL/common.cl>
#include <../Baikal/Kernels/CL/common.cl>

// Similarity function
inline float C(float3 x1, float3 x2, float sigma)
Expand Down
Loading

0 comments on commit 74af1ba

Please sign in to comment.