Skip to content

Commit

Permalink
Merge branch 'master' of github.com:appleseedhq/appleseed
Browse files Browse the repository at this point in the history
  • Loading branch information
dictoon committed Aug 11, 2014
2 parents c1c510f + 4b0728e commit a568761
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 62 deletions.
2 changes: 2 additions & 0 deletions src/appleseed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,8 @@ source_group ("renderer\\modeling\\camera" FILES
set (renderer_modeling_color_sources
renderer/modeling/color/colorentity.cpp
renderer/modeling/color/colorentity.h
renderer/modeling/color/colorspace.cpp
renderer/modeling/color/colorspace.h
renderer/modeling/color/colortraits.h
renderer/modeling/color/wavelengths.cpp
renderer/modeling/color/wavelengths.h
Expand Down
1 change: 1 addition & 0 deletions src/appleseed/renderer/api/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

// API headers.
#include "renderer/modeling/color/colorentity.h"
#include "renderer/modeling/color/colorspace.h"
#include "renderer/modeling/color/colortraits.h"
#include "renderer/modeling/color/wavelengths.h"

Expand Down
1 change: 1 addition & 0 deletions src/appleseed/renderer/kernel/shading/closures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ void CompositeClosure::process_closure_tree(
values.m_sheen_tint = p->sheen_tint;
values.m_clearcoat = p->clearcoat;
values.m_clearcoat_gloss = p->clearcoat_gloss;
values.precompute_tint_color();

add_closure<DisneyBRDFInputValues>(
static_cast<ClosureID>(c->id),
Expand Down
94 changes: 38 additions & 56 deletions src/appleseed/renderer/modeling/bsdf/disneybrdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

// appleseed.renderer headers.
#include "renderer/modeling/bsdf/bsdfwrapper.h"
#include "renderer/modeling/color/colorspace.h"
#include "renderer/modeling/color/wavelengths.h"
#include "renderer/modeling/input/inputevaluator.h"

// appleseed.foundation headers.
Expand Down Expand Up @@ -86,12 +88,8 @@ namespace
: public BSDF
{
public:
DisneyDiffuseBRDF(
const LightingConditions& lighting_conditions,
const Spectrum& white_spectrum)
DisneyDiffuseBRDF()
: BSDF("disney_diffuse", Reflective, Diffuse, ParamArray())
, m_lighting_conditions(lighting_conditions)
, m_white_spectrum(white_spectrum)
{
}

Expand Down Expand Up @@ -195,9 +193,6 @@ namespace
}

private:
const LightingConditions& m_lighting_conditions;
const Spectrum& m_white_spectrum;

void evaluate_diffuse(
const DisneyBRDFInputValues* values,
const Basis3d& shading_basis,
Expand Down Expand Up @@ -236,7 +231,7 @@ namespace
{
Spectrum csheen;
mix_spectra(
m_white_spectrum,
g_white_spectrum,
values->m_tint_color,
static_cast<float>(values->m_sheen_tint),
csheen);
Expand All @@ -262,6 +257,8 @@ namespace
public:
typedef boost::mpl::bool_<false> IsAnisotropicType;

BerryMDF2() {}

private:
virtual Vector<T, 3> do_sample(
const Vector<T, 2>& s,
Expand Down Expand Up @@ -352,23 +349,7 @@ class DisneyBRDFImpl
m_inputs.declare("clearcoat", InputFormatScalar, "0.0");
m_inputs.declare("clearcoat_gloss", InputFormatScalar, "1.0");

m_lighting_conditions = LightingConditions(
IlluminantCIED65,
XYZCMFCIE196410Deg);

linear_rgb_reflectance_to_spectrum(
Color3f(1.0f, 1.0f, 1.0f),
m_white_spectrum);

m_diffuse_brdf.reset(new DisneyDiffuseBRDF(m_lighting_conditions, m_white_spectrum));
m_specular_mdf = new GGXMDF2<double>();
m_clearcoat_mdf = new BerryMDF2<double>();
}

~DisneyBRDFImpl()
{
delete m_specular_mdf;
delete m_clearcoat_mdf;
m_diffuse_brdf.reset(new DisneyDiffuseBRDF());
}

virtual void release() OVERRIDE
Expand Down Expand Up @@ -417,14 +398,7 @@ class DisneyBRDFImpl

char* ptr = reinterpret_cast<char*>(input_evaluator.data());
DisneyBRDFInputValues* values = reinterpret_cast<DisneyBRDFInputValues*>(ptr + offset);

// Precompute the tint color.
const Color3f tint_xyz =
spectrum_to_ciexyz<float>(m_lighting_conditions, values->m_base_color);
const float lum = tint_xyz[1];
if (lum > 0.0f)
ciexyz_reflectance_to_spectrum(tint_xyz / lum, values->m_tint_color);
else values->m_tint_color = m_white_spectrum;
values->precompute_tint_color();
}

virtual Mode sample(
Expand Down Expand Up @@ -471,17 +445,17 @@ class DisneyBRDFImpl
if (cos_on < 0.0)
return Absorption;

MDF<double>* mdf = 0;
const MDF<double>* mdf = 0;
double alpha_x, alpha_y, alpha_g;

if (s < weights[1])
{
mdf = m_specular_mdf;
mdf = &m_specular_mdf;
specular_roughness(values, alpha_x, alpha_y, alpha_g);
}
else
{
mdf = m_clearcoat_mdf;
mdf = &m_clearcoat_mdf;
alpha_x = alpha_y = clearcoat_roughness(values);
alpha_g = 0.25;
}
Expand Down Expand Up @@ -580,13 +554,13 @@ class DisneyBRDFImpl
specular_roughness(values, alpha_x, alpha_y, alpha_g);

const double D =
m_specular_mdf->D(
m_specular_mdf.D(
m,
alpha_x,
alpha_y);

const double G =
m_specular_mdf->G(
m_specular_mdf.G(
wo,
wi,
m,
Expand All @@ -598,21 +572,21 @@ class DisneyBRDFImpl
specular_value *= static_cast<float>(D * G / (4.0 * cos_on * cos_in));
value += specular_value;

pdf += m_specular_mdf->pdf(m, alpha_x, alpha_y) / (4.0 * cos_oh) * weights[1];
pdf += m_specular_mdf.pdf(m, alpha_x, alpha_y) / (4.0 * cos_oh) * weights[1];
}

if (weights[2] != 0.0)
{
const double alpha = clearcoat_roughness(values);

const double D =
m_clearcoat_mdf->D(
m_clearcoat_mdf.D(
m,
alpha,
alpha);

const double G =
m_clearcoat_mdf->G(
m_clearcoat_mdf.G(
wo,
wi,
m,
Expand All @@ -625,7 +599,7 @@ class DisneyBRDFImpl
clearcoat_value.set(static_cast<float>(D * G * F / (4.0 * cos_on * cos_in)));
value += clearcoat_value;

pdf += m_clearcoat_mdf->pdf(m, alpha, alpha) / (4.0 * cos_oh) * weights[2];
pdf += m_clearcoat_mdf.pdf(m, alpha, alpha) / (4.0 * cos_oh) * weights[2];
}

return pdf;
Expand Down Expand Up @@ -676,26 +650,24 @@ class DisneyBRDFImpl
{
double alpha_x, alpha_y, alpha_g;
specular_roughness(values, alpha_x, alpha_y, alpha_g);
pdf += m_specular_mdf->pdf(hl, alpha_x, alpha_y) / (4.0 * cos_oh) * weights[1];
pdf += m_specular_mdf.pdf(hl, alpha_x, alpha_y) / (4.0 * cos_oh) * weights[1];
}

if (weights[2] != 0.0)
{
const double alpha = clearcoat_roughness(values);
pdf += m_specular_mdf->pdf(hl, alpha, alpha) / (4.0 * cos_oh) * weights[2];
pdf += m_specular_mdf.pdf(hl, alpha, alpha) / (4.0 * cos_oh) * weights[2];
}

return pdf;
}

private:
typedef DisneyBRDFInputValues InputValues;

static foundation::LightingConditions m_lighting_conditions;
static Spectrum m_white_spectrum;
foundation::auto_release_ptr<BSDF> m_diffuse_brdf;
foundation::MDF<double>* m_specular_mdf;
foundation::MDF<double>* m_clearcoat_mdf;
auto_release_ptr<BSDF> m_diffuse_brdf;
const GGXMDF2<double> m_specular_mdf;
const BerryMDF2<double> m_clearcoat_mdf;

void compute_component_weights(
const DisneyBRDFInputValues* values,
Expand Down Expand Up @@ -728,10 +700,10 @@ class DisneyBRDFImpl
const double cos_oh,
Spectrum& f) const
{
mix_spectra(m_white_spectrum, values->m_tint_color, static_cast<float>(values->m_specular_tint), f);
mix_spectra(g_white_spectrum, values->m_tint_color, static_cast<float>(values->m_specular_tint), f);
f *= static_cast<float>(values->m_specular * 0.08);
mix_spectra(f, values->m_base_color, static_cast<float>(values->m_metallic), f);
mix_spectra(f, m_white_spectrum, static_cast<float>(schlick_fresnel(cos_oh)), f);
mix_spectra(f, g_white_spectrum, static_cast<float>(schlick_fresnel(cos_oh)), f);
}

double clearcoat_roughness(const DisneyBRDFInputValues* values) const
Expand All @@ -745,12 +717,22 @@ class DisneyBRDFImpl
}
};

LightingConditions DisneyBRDFImpl::m_lighting_conditions;
Spectrum DisneyBRDFImpl::m_white_spectrum;

typedef BSDFWrapper<DisneyBRDFImpl> DisneyBRDF;


void DisneyBRDFInputValues::precompute_tint_color()
{
// Precompute the tint color.
const Color3f tint_xyz =
spectrum_to_ciexyz<float>(
g_std_lighting_conditions, m_base_color);
const float lum = tint_xyz[1];
if (lum > 0.0f)
ciexyz_reflectance_to_spectrum(tint_xyz / lum, m_tint_color);
else m_tint_color = g_white_spectrum;
}


//
// DisneyBRDFFactory class implementation.
//
Expand Down
4 changes: 3 additions & 1 deletion src/appleseed/renderer/modeling/bsdf/disneybrdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ DECLARE_INPUT_VALUES(DisneyBRDFInputValues)
// This is not a real param of the BRDF.
// Instead, it's used to hold a temporary value.
Spectrum m_tint_color;

void precompute_tint_color();
};


Expand All @@ -79,7 +81,7 @@ DECLARE_INPUT_VALUES(DisneyBRDFInputValues)
class DLLSYMBOL DisneyBRDFFactory
: public IBSDFFactory
{
public:
public:
// Return a string identifying this BSDF model.
virtual const char* get_model() const OVERRIDE;

Expand Down
3 changes: 2 additions & 1 deletion src/appleseed/renderer/modeling/bsdf/disneylayeredbrdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void DisneyLayeredBRDF::evaluate_inputs(
DisneyBRDFInputValues* values = reinterpret_cast<DisneyBRDFInputValues*>(ptr + offset);
memset(values, 0, sizeof(DisneyBRDFInputValues));

Color3d base_color(0.0f);
Color3d base_color(0.0);

for (size_t i = 0, e = m_parent->get_layer_count(); i < e; ++i)
{
Expand All @@ -129,6 +129,7 @@ void DisneyLayeredBRDF::evaluate_inputs(

base_color = srgb_to_linear_rgb(base_color);
linear_rgb_reflectance_to_spectrum(Color3f(base_color), values->m_base_color);
values->precompute_tint_color();
}

BSDF::Mode DisneyLayeredBRDF::sample(
Expand Down
58 changes: 58 additions & 0 deletions src/appleseed/renderer/modeling/color/colorspace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

//
// This source file is part of appleseed.
// Visit http://appleseedhq.net/ for additional information and resources.
//
// This software is released under the MIT license.
//
// Copyright (c) 2014 Esteban Tovagliari, The appleseedhq Organization
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

// Interface header.
#include "colorspace.h"

using namespace foundation;

namespace renderer
{

//
// CIED65 XYZCMFCIE196410 Lighting Conditions.
//

foundation::LightingConditions g_std_lighting_conditions;

namespace
{
struct InitializeGlobalLightingConditions
{
InitializeGlobalLightingConditions()
{
g_std_lighting_conditions = LightingConditions(
IlluminantCIED65,
XYZCMFCIE196410Deg);
}
};

InitializeGlobalLightingConditions initialize_lighting_conditions;
}

} // namespace renderer
Loading

0 comments on commit a568761

Please sign in to comment.