Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dictoon/appleseed
Browse files Browse the repository at this point in the history
  • Loading branch information
dictoon committed Jan 26, 2016
2 parents 7436415 + e1f51a7 commit 5ce191f
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/appleseed.studio/meta/tests/test_projectmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
// Standard headers.
#include <string>

using namespace appleseed::studio;
using namespace renderer;
using namespace std;

TEST_SUITE(Studio_ProjectManager)
{
using namespace appleseed::studio;
using namespace renderer;
using namespace std;

TEST_CASE(GetProject_GivenProjectManagerInDefaultState_ReturnsNull)
{
ProjectManager manager;
Expand Down
1 change: 1 addition & 0 deletions src/appleseed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ set (foundation_meta_benchmarks_sources
foundation/meta/benchmarks/benchmark_sampling.cpp
foundation/meta/benchmarks/benchmark_string.cpp
foundation/meta/benchmarks/benchmark_transform.cpp
foundation/meta/benchmarks/benchmark_vector.cpp
foundation/meta/benchmarks/benchmark_voxelgrid.cpp
)
list (APPEND appleseed_sources
Expand Down
9 changes: 9 additions & 0 deletions src/appleseed/foundation/math/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ template <typename T, size_t N> Vector<T, N> normalize(const Vector<T, N>& v);
template <typename T, size_t N> Vector<T, N> safe_normalize(const Vector<T, N>& v, const Vector<T, N>& fallback);
template <typename T, size_t N> Vector<T, N> safe_normalize(const Vector<T, N>& v);

// Bring the norm of a nearly-unit vector closer to 1.
template <typename T, size_t N> Vector<T, N> improve_normalization(const Vector<T, N>& v);

// Return true if a vector is normalized (unit-length), false otherwise.
template <typename T, size_t N> bool is_normalized(const Vector<T, N>& v);
template <typename T, size_t N> bool is_normalized(const Vector<T, N>& v, const T eps);
Expand Down Expand Up @@ -751,6 +754,12 @@ inline Vector<T, N> safe_normalize(const Vector<T, N>& v)
return result;
}

template <typename T, size_t N>
inline Vector<T, N> improve_normalization(const Vector<T, N>& v)
{
return v * (T(3.0) - square_norm(v)) * T(0.5);
}

template <typename T, size_t N>
inline bool is_normalized(const Vector<T, N>& v)
{
Expand Down
4 changes: 2 additions & 2 deletions src/appleseed/foundation/meta/benchmarks/benchmark_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
#include "foundation/math/vector.h"
#include "foundation/utility/benchmark.h"

using namespace foundation;

BENCHMARK_SUITE(Foundation_Math_Matrix44)
{
using namespace foundation;

template <typename T>
struct Fixture
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
#include <cstddef>
#include <memory>

using namespace foundation;
using namespace std;

BENCHMARK_SUITE(Foundation_Utility_PoolAllocator)
{
using namespace foundation;
using namespace std;

const size_t N = 100;

template <typename Allocator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#include "foundation/image/regularspectrum.h"
#include "foundation/utility/benchmark.h"

using namespace foundation;

BENCHMARK_SUITE(Foundation_Image_RegularSpectrum31f)
{
using namespace foundation;

struct Fixture
{
RegularSpectrum31f m_spectrum1;
Expand Down
69 changes: 69 additions & 0 deletions src/appleseed/foundation/meta/benchmarks/benchmark_vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

//
// 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) 2016 Francois Beaune, 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.
//

// appleseed.foundation headers.
#include "foundation/math/vector.h"
#include "foundation/utility/benchmark.h"

using namespace foundation;

BENCHMARK_SUITE(Foundation_Math_Vector)
{
template <typename T>
struct Fixture
{
Vector<T, 3> m_v;
Vector<T, 3> m_dummy;

Fixture()
: m_v(normalize(Vector<T, 3>(T(3.0), T(-5.0), T(7.0))))
, m_dummy(T(0.0))
{
}
};

BENCHMARK_CASE_F(Normalize_SinglePrecision, Fixture<float>)
{
m_dummy += normalize(m_v);
}

BENCHMARK_CASE_F(ImproveNormalization_SinglePrecision, Fixture<float>)
{
m_dummy += improve_normalization(m_v);
}

BENCHMARK_CASE_F(Normalize_DoublePrecision, Fixture<double>)
{
m_dummy += normalize(m_v);
}

BENCHMARK_CASE_F(ImproveNormalization_DoublePrecision, Fixture<double>)
{
m_dummy += improve_normalization(m_v);
}
}
4 changes: 2 additions & 2 deletions src/appleseed/foundation/meta/tests/test_aabb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ BEGIN_EXR_INCLUDES
END_EXR_INCLUDES
#endif

using namespace foundation;

TEST_SUITE(Foundation_Math_AABB)
{
using namespace foundation;

TEST_CASE(ConstructWithMinMax)
{
const AABB3d bbox(
Expand Down
4 changes: 2 additions & 2 deletions src/appleseed/foundation/meta/tests/test_attributeset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
// Standard headers.
#include <cstddef>

using namespace foundation;

TEST_SUITE(Foundation_Utility_AttributeSet)
{
using namespace foundation;

struct FixtureTestAttributeSet
{
AttributeSet attributes;
Expand Down
6 changes: 3 additions & 3 deletions src/appleseed/foundation/meta/tests/test_bufferedfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
#include <cstddef>
#include <string>

using namespace foundation;
using namespace std;

TEST_SUITE(Foundation_Utility_BufferedFile)
{
using namespace foundation;
using namespace std;

const char* Filename = "unit tests/outputs/test_bufferedfile.tmp";
const size_t BufferSize = 4;
const string DataString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Expand Down
4 changes: 2 additions & 2 deletions src/appleseed/foundation/meta/tests/test_casts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
#include "foundation/utility/casts.h"
#include "foundation/utility/test.h"

using namespace foundation;

TEST_SUITE(Foundation_Utility_Casts)
{
using namespace foundation;

const uint32 OnePattern = 0x3F800000UL;

TEST_CASE(TestBinaryCastFloatToUInt32)
Expand Down
4 changes: 2 additions & 2 deletions src/appleseed/foundation/meta/tests/test_otherwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#include "foundation/utility/otherwise.h"
#include "foundation/utility/test.h"

using namespace foundation;

TEST_SUITE(Foundation_Utility_Otherwise)
{
using namespace foundation;

TEST_CASE(TestThrowOtherwiseMacro)
{
EXPECT_EXCEPTION(SwitchException,
Expand Down
4 changes: 2 additions & 2 deletions src/appleseed/foundation/meta/tests/test_typetraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#include "foundation/utility/test.h"
#include "foundation/utility/typetraits.h"

using namespace foundation;

TEST_SUITE(Foundation_Core_TypeTraits)
{
using namespace foundation;

struct Base {};

struct NotDerived {};
Expand Down
4 changes: 2 additions & 2 deletions src/appleseed/foundation/meta/tests/test_utility_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#include "foundation/utility/filter.h"
#include "foundation/utility/test.h"

using namespace foundation;

TEST_SUITE(Foundation_Utility_Filter_RegExFilter)
{
using namespace foundation;

TEST_CASE(IsValid_GivenEmptyRegularExpression_ReturnsTrue)
{
const RegExFilter filter("");
Expand Down
10 changes: 10 additions & 0 deletions src/appleseed/foundation/meta/tests/test_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ TEST_SUITE(Foundation_Math_Vector)
EXPECT_FEQ(Vector3d(1.0, 0.0, 0.0), safe_normalize(Vector3d(0.0, 0.0, 0.0)));
}

TEST_CASE(TestImproveNormalization)
{
Vector3d v(-0.48859909517572381, 0.021669236596684682, -0.87223928390023286);
ASSERT_FALSE(is_normalized(v));

v = improve_normalization(v);

EXPECT_TRUE(is_normalized(v));
}

TEST_CASE(TestIsNormalized)
{
const Vector3d v(3.0, -5.0, 7.0);
Expand Down
4 changes: 1 addition & 3 deletions src/appleseed/renderer/modeling/bsdf/specularbtdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ namespace
cos_theta_i > 0.0
? (eta * cos_theta_i - cos_theta_t) * shading_normal - eta * sample.m_outgoing.get_value()
: (eta * cos_theta_i + cos_theta_t) * shading_normal - eta * sample.m_outgoing.get_value();

// Fix numerical inaccuracies.
incoming = normalize(incoming);
incoming = improve_normalization(incoming);

// Compute the refracted radiance.
sample.m_value = values->m_transmittance;
Expand Down

0 comments on commit 5ce191f

Please sign in to comment.