Skip to content

Commit

Permalink
Add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
yozhijk committed May 31, 2017
1 parent e3b4b4b commit 46c5f8e
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 172 deletions.
2 changes: 1 addition & 1 deletion Baikal/Controllers/clw_scene_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Baikal
m_api = CreateFromOpenClContext(m_context, id, queue);

m_api->SetOption("acc.type", "fatbvh");
m_api->SetOption("bvh.forceflat", 1.f);
//m_api->SetOption("bvh.forceflat", 1.f);
m_api->SetOption("bvh.builder", "sah");
m_api->SetOption("bvh.sah.num_bins", 64.f);
}
Expand Down
2 changes: 1 addition & 1 deletion Baikal/Controllers/scene_controller.inl
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 Down
14 changes: 10 additions & 4 deletions Baikal/Kernels/CL/bxdf.cl
Original file line number Diff line number Diff line change
Expand Up @@ -453,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 @@ -499,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 @@ -589,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 @@ -1000,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 @@ -1047,8 +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 @@ -1105,9 +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 @@ -1154,8 +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
2 changes: 1 addition & 1 deletion Baikal/Kernels/CL/common.cl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ THE SOFTWARE.
#define INVALID_IDX -1

#define CRAZY_LOW_THROUGHPUT 0.0f
#define CRAZY_HIGH_RADIANCE 5.f
#define CRAZY_HIGH_RADIANCE 3.f
#define CRAZY_HIGH_DISTANCE 1000000.f
#define CRAZY_LOW_DISTANCE 0.001f
#define REASONABLE_RADIANCE(x) (clamp((x), 0.f, CRAZY_HIGH_RADIANCE))
Expand Down
38 changes: 27 additions & 11 deletions Baikal/Kernels/CL/disney.cl
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ INLINE float Disney_GetPdf(
// Normalize lum. to isolate hue+sat
float3 c_tint = cd_lum > 0.f ? (cd_lin / cd_lum) : WHITE;

float3 c_spec0 = mix(specular * 0.08f * mix(WHITE,
float3 c_spec0 = mix(specular * 0.1f * mix(WHITE,
c_tint, specular_tint),
cd_lin, metallic);

float cs_lum = dot(c_spec0, make_float3(0.3f, 0.6f, 0.1f));

float cs_w = cs_lum / (cs_lum + cd_lum);
float cs_w = cs_lum / (cs_lum + (1.f - metallic) * cd_lum);

return c_pdf * clearcoat * 0.25f + (1.f - clearcoat * 0.25f) * (cs_w * r_pdf + (1.f - cs_w) * d_pdf);
return c_pdf * clearcoat + (1.f - clearcoat) * (cs_w * r_pdf + (1.f - cs_w) * d_pdf);
}


Expand Down Expand Up @@ -151,7 +151,7 @@ INLINE float3 Disney_Evaluate(
// Normalize lum. to isolate hue+sat
float3 c_tint = cd_lum > 0.f ? (cd_lin / cd_lum) : WHITE;

float3 c_spec0 = mix(specular * 0.08f * mix(WHITE,
float3 c_spec0 = mix(specular * 0.1f * mix(WHITE,
c_tint, specular_tint),
cd_lin, metallic);

Expand Down Expand Up @@ -192,7 +192,7 @@ INLINE float3 Disney_Evaluate(
float gr = SmithGGX_G(ndotwo, 0.25f) * SmithGGX_G(ndotwi, 0.25f);

return ((1.f / PI) * mix(fd, ss, subsurface) * cd_lin + f_sheen) *
(1.f - metallic) + gs * fs * ds + 0.25f * clearcoat * gr * fr * dr;
(1.f - metallic) + gs * fs * ds + clearcoat * gr * fr * dr;
}

INLINE float3 Disney_Sample(
Expand All @@ -210,6 +210,7 @@ INLINE float3 Disney_Sample(
float* pdf
)
{
float3 base_color = Texture_GetValue3f(dg->mat.base_color.xyz, dg->uv, TEXTURE_ARGS_IDX(dg->mat.base_color_map_idx));
float metallic = Texture_GetValue1f(dg->mat.metallic, dg->uv, TEXTURE_ARGS_IDX(dg->mat.metallic_map_idx));
float specular = Texture_GetValue1f(dg->mat.specular, dg->uv, TEXTURE_ARGS_IDX(dg->mat.specular_map_idx));
float anisotropy = Texture_GetValue1f(dg->mat.anisotropy, dg->uv, TEXTURE_ARGS_IDX(dg->mat.anisotropy_map_idx));
Expand All @@ -230,7 +231,7 @@ INLINE float3 Disney_Sample(

if (sample.x < clearcoat)
{
sample.x /= clearcoat;
sample.x /= (clearcoat);

float a = mix(0.1f,0.001f, clearcoat_gloss);
float ndotwh = native_sqrt((1.f - native_powr(a*a, 1.f - sample.y)) / (1.f - a*a));
Expand All @@ -244,12 +245,27 @@ INLINE float3 Disney_Sample(
}
else
{
sample.x -= clearcoat;
sample.x -= (clearcoat);
sample.x /= (1.f - clearcoat);

float3 cd_lin = native_powr(base_color, 2.2f);
// Luminance approximmation
float cd_lum = dot(cd_lin, make_float3(0.3f, 0.6f, 0.1f));

// Normalize lum. to isolate hue+sat
float3 c_tint = cd_lum > 0.f ? (cd_lin / cd_lum) : WHITE;

float3 c_spec0 = mix(specular * 0.3f * mix(WHITE,
c_tint, specular_tint),
cd_lin, metallic);

float cs_lum = dot(c_spec0, make_float3(0.3f, 0.6f, 0.1f));

float cs_w = cs_lum / (cs_lum + (1.f - metallic) * cd_lum);

if (sample.y < metallic)
if (sample.y < cs_w)
{
sample.y /= metallic;
sample.y /= cs_w;

float t = native_sqrt(sample.y / (1.f - sample.y));
wh = normalize(make_float3(t * ax * native_cos(2.f * PI * sample.x),
Expand All @@ -260,8 +276,8 @@ INLINE float3 Disney_Sample(
}
else
{
sample.y -= metallic;
sample.y /= (1.f - metallic);
sample.y -= cs_w;
sample.y /= (1.f - cs_w);

*wo = Sample_MapToHemisphere(sample, make_float3(0.f, 1.f, 0.f) , 1.f);

Expand Down
4 changes: 2 additions & 2 deletions Baikal/Renderers/ptrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ namespace Baikal
//
GetContext().Flush(0);

//samples statisticks
//samples statistics
output->Clear(0.f);
start = std::chrono::high_resolution_clock::now();
for (auto i = 0U; i < num_passes; ++i)
Expand All @@ -840,6 +840,6 @@ namespace Baikal
}
delta = std::chrono::high_resolution_clock::now() - start;

stats.samples_pes_sec = output->width() * output->height() / ((float)std::chrono::duration_cast<std::chrono::milliseconds>(delta).count() / num_passes) / 1000.f;
stats.samples_pes_sec = num_passes * output->width() * output->height() / ((float)(std::chrono::duration_cast<std::chrono::milliseconds>(delta).count() / 1000.f)) / 10000000.f;
}
}
1 change: 1 addition & 0 deletions Baikal/SceneGraph/IO/image_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#pragma once

#include <string>
#include <memory>

namespace Baikal
{
Expand Down
1 change: 1 addition & 0 deletions Baikal/SceneGraph/IO/material_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <string>
#include <map>
#include <memory>

namespace Baikal
{
Expand Down
10 changes: 5 additions & 5 deletions Baikal/SceneGraph/IO/scene_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,27 +241,27 @@ namespace Baikal
}

// TODO: temporary code, add IBL
Texture* ibl_texture = image_io->LoadImage("../Resources/Textures/studio015.hdr");
Texture* ibl_texture = image_io->LoadImage("../Resources/Textures/sky.hdr");
scene->AttachAutoreleaseObject(ibl_texture);

ImageBasedLight* ibl = new ImageBasedLight();
ibl->SetTexture(ibl_texture);
ibl->SetMultiplier(1.f);
ibl->SetMultiplier(10.f);
scene->AttachAutoreleaseObject(ibl);

// TODO: temporary code to add directional light
DirectionalLight* light = new DirectionalLight();
light->SetDirection(RadeonRays::normalize(RadeonRays::float3(-1.1f, -0.6f, -0.2f)));
light->SetEmittedRadiance(3.5f * RadeonRays::float3(1.f, 1.f, 1.f));
light->SetEmittedRadiance(35.f * RadeonRays::float3(1.f, 0.95f, 0.92f));
scene->AttachAutoreleaseObject(light);

DirectionalLight* light1 = new DirectionalLight();
light1->SetDirection(RadeonRays::float3(0.3f, -1.f, -0.5f));
light1->SetEmittedRadiance(RadeonRays::float3(1.f, 0.8f, 0.65f));
scene->AttachAutoreleaseObject(light1);

//scene->AttachLight(light);
scene->AttachLight(light1);
scene->AttachLight(light);
//scene->AttachLight(light1);
scene->AttachLight(ibl);

return std::unique_ptr<Scene1>(scene);
Expand Down
20 changes: 5 additions & 15 deletions Baikal/SceneGraph/IO/scene_test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,6 @@ namespace Baikal
scene->AttachShape(mesh);
scene->AttachAutoreleaseObject(mesh);

DisneyBxdf* disney = new DisneyBxdf();
disney->SetInputValue("albedo", float4(0.7f, 0.f, 0.f, 0.0f));
// disney->SetInputValue("metallic", float4(0.5f, 0.5f, 0.5f, 0.5f));
// disney->SetInputValue("roughness", float4(0.f, 0.f, 0.f, 0.f));
// disney->SetInputValue("specular", float4(1.f, 1.f, 1.f, 1.f));
// disney->SetInputValue("specular_tint", float4(1.f, 1.f, 1.f, 1.f));

scene->AttachAutoreleaseObject(disney);

mesh->SetMaterial(disney);

Mesh* floor = CreateQuad(
{
RadeonRays::float3(-8, 0, -8),
Expand All @@ -306,11 +295,11 @@ namespace Baikal

ImageBasedLight* ibl = new ImageBasedLight();
ibl->SetTexture(ibl_texture);
ibl->SetMultiplier(5.f);
ibl->SetMultiplier(3.f);
scene->AttachLight(ibl);
scene->AttachAutoreleaseObject(ibl);
}
else if (filename == "10spheres+plane+ibl")
else if (filename == "100spheres+plane+ibl+disney")
{
auto mesh = CreateSphere(64, 32, 0.9f, float3(0.f, 1.0f, 0.f));
scene->AttachShape(mesh);
Expand Down Expand Up @@ -347,7 +336,7 @@ namespace Baikal

if (params[i] == "anisotropy")
{
disney->SetInputValue("roughness", float4(0.2f));
disney->SetInputValue("roughness", float4(0.4f));
disney->SetInputValue("metallic", float4(0.75f));
disney->SetInputValue("specular", float4(0.f));
disney->SetInputValue("clearcoat", float4(0.f));
Expand All @@ -367,6 +356,7 @@ namespace Baikal
disney->SetInputValue("metallic", float4(0.0f));
disney->SetInputValue("clearcoat", float4(1.0f));
disney->SetInputValue("clearcoat_gloss", float4(0.5f));
disney->SetInputValue("specular", float4(0.f));
}

if (params[i] == "specular" || params[i] == "specular_tint")
Expand All @@ -382,7 +372,7 @@ namespace Baikal
disney->SetInputValue("roughness", float4(0.f));
disney->SetInputValue("metallic", float4(0.0f));
disney->SetInputValue("clearcoat", float4(0.f));
disney->SetInputValue("specular", float4(1.f));
disney->SetInputValue("specular", float4(0.f));
}

float3 value = float3( j / 10.f, j / 10.f, j / 10.f);
Expand Down
Loading

0 comments on commit 46c5f8e

Please sign in to comment.