Skip to content

Commit

Permalink
Change code used.
Browse files Browse the repository at this point in the history
  • Loading branch information
mororo250 committed Jun 4, 2020
1 parent e9c9782 commit 9701d54
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 1,376 deletions.
4 changes: 4 additions & 0 deletions sandbox/settings/appleseed.studio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
</parameters>
<parameters name="ui">
<parameters name="file_dialog">
<parameters name="frames">
<parameter name="last_directory" value="C:\Users\joao_\OneDrive\Desktop" />
<parameter name="selected_filter" value="JPEG Files (*.jpg *.jpe *.jpeg *.jif *.jfif *.jfi)" />
</parameters>
<parameters name="projects">
<parameter name="last_directory" value="C:\Users\joao_\OneDrive\Desktop\git\Appleaseed\appleseed\sandbox\tests\test scenes\sppm" />
<parameter name="selected_filter" value="Project Files (*.appleseed *.appleseedz)" />
Expand Down
2 changes: 2 additions & 0 deletions src/appleseed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,8 @@ set (renderer_modeling_environmentedf_sources
renderer/modeling/environmentedf/oslenvironmentedf.h
renderer/modeling/environmentedf/preethamenvironmentedf.cpp
renderer/modeling/environmentedf/preethamenvironmentedf.h
renderer/modeling/environmentedf/skymodelenvironmentedf.cpp
renderer/modeling/environmentedf/skymodelenvironmentedf.h
renderer/modeling/environmentedf/sphericalcoordinates.h
)
list (APPEND appleseed_sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "renderer/global/globaltypes.h"
#include "renderer/kernel/shading/shadingcontext.h"
#include "renderer/modeling/color/colorspace.h"
#include "renderer/modeling/environmentedf/environmentedf.h"
#include "renderer/modeling/environmentedf/skymodelenvironmentedf.h"
#include "renderer/modeling/environmentedf/sphericalcoordinates.h"
#include "renderer/modeling/input/inputarray.h"
#include "renderer/modeling/input/source.h"
Expand Down Expand Up @@ -93,13 +93,13 @@ namespace
const float BaseTurbidity = 2.0f;

class HosekEnvironmentEDF
: public EnvironmentEDF
: public SkyModelEnvironmentEDF
{
public:
HosekEnvironmentEDF(
const char* name,
const ParamArray& params)
: EnvironmentEDF(name, params)
: SkyModelEnvironmentEDF(name, params)
{
m_inputs.declare("sun_theta", InputFormat::InputFormatFloat);
m_inputs.declare("sun_phi", InputFormat::InputFormatFloat);
Expand Down Expand Up @@ -128,39 +128,18 @@ namespace
OnFrameBeginRecorder& recorder,
IAbortSwitch* abort_switch) override
{
if (!EnvironmentEDF::on_frame_begin(project, parent, recorder, abort_switch))
if (!SkyModelEnvironmentEDF::on_frame_begin(project, parent, recorder, abort_switch))
return false;

// Evaluate uniform values.
m_inputs.evaluate_uniforms(&m_uniform_values);

spa_data test;
test.hour = m_params.get_optional<int>("hour", 12);
test.minute = m_params.get_optional<int>("minute", 0);
test.second = m_params.get_optional<int>("second", 0);

test.year = m_params.get_optional<int>("year", 2020);
test.month = m_params.get_optional<int>("month", 1);
test.day = m_params.get_optional<int>("day", 1);

test.timezone = 0;
test.longitude = m_params.get_optional<float>("longitude", 0);
test.latitude = m_params.get_optional<float>("latitude", 0);

test.azm_rotation = 0.0;
test.elevation = 0.0;

test.function = SPA_ZA;

spa_calculate(&test);

m_uniform_values.m_sun_theta = static_cast<float>(test.zenith);
m_uniform_values.m_sun_phi = static_cast<float>(test.azimuth);

// Compute the sun direction.
m_sun_theta = deg_to_rad(m_uniform_values.m_sun_theta);
m_sun_phi = deg_to_rad(m_uniform_values.m_sun_phi);
m_sun_dir = Vector3f::make_unit_vector(m_sun_theta, m_sun_phi);
m_sun_positioner.m_output_value.zenith = deg_to_rad(m_sun_positioner.m_output_value.zenith);
m_sun_positioner.m_output_value.azimuth = deg_to_rad(m_sun_positioner.m_output_value.azimuth);
m_sun_dir = Vector3f::make_unit_vector(static_cast<float>(m_sun_positioner.m_output_value.zenith)
, static_cast<float>(m_sun_positioner.m_output_value.azimuth));
m_horizon_shift = m_uniform_values.m_horizon_shift;

// Precompute the coefficients of the radiance distribution function and
// the master luminance value if turbidity is uniform.
Expand All @@ -174,7 +153,7 @@ namespace
compute_coefficients(
m_uniform_values.m_turbidity,
m_uniform_values.m_ground_albedo,
m_sun_theta,
static_cast<float>(m_sun_positioner.m_output_value.zenith),
m_uniform_coeffs,
m_uniform_master_Y);
}
Expand Down Expand Up @@ -280,9 +259,6 @@ namespace
};

InputValues m_uniform_values;

float m_sun_theta; // sun zenith angle in radians, 0=zenith
float m_sun_phi; // radians
Vector3f m_sun_dir;

bool m_uniform_turbidity;
Expand Down Expand Up @@ -447,7 +423,7 @@ namespace
compute_coefficients(
turbidity,
m_uniform_values.m_ground_albedo,
m_sun_theta,
static_cast<float>(m_sun_positioner.m_output_value.zenith),
coeffs,
master_Y);

Expand Down Expand Up @@ -492,7 +468,7 @@ namespace

Vector3f shift(Vector3f v) const
{
v.y -= m_uniform_values.m_horizon_shift;
v.y -= m_horizon_shift;
return normalize(v);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#include "skymodelenvironmentedf.h"

namespace renderer
{
SkyModelEnvironmentEDF::SkyModelEnvironmentEDF(
const char* name,
const ParamArray& params)
: EnvironmentEDF(name, params),
m_sun_positioner("Sun Positioner", params)
{
}

bool SkyModelEnvironmentEDF::on_frame_begin(const Project& project, const BaseGroup* parent, OnFrameBeginRecorder& recorder, foundation::IAbortSwitch* abort_switch)
{
if (!EnvironmentEDF::on_frame_begin(project, parent, recorder, abort_switch))
return false;

if (!m_sun_positioner.on_frame_begin(project, parent, recorder, abort_switch))
return false;

m_sun_positioner.compute_sun_position();

return true;
}

} // namespace renderer
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once

// appleseed.renderer headers.
#include "renderer/modeling/environmentedf/environmentedf.h"
#include "renderer/utility/solarpositionalgorithm.h"

namespace renderer
{

//
// An Environment EDF Interface Class For Differents Sky Models implementation.
//

class APPLESEED_DLLSYMBOL SkyModelEnvironmentEDF
: public EnvironmentEDF
{
public:

// Constructor.
SkyModelEnvironmentEDF(
const char* name,
const ParamArray& params);

bool on_frame_begin(
const Project& project,
const BaseGroup* parent,
OnFrameBeginRecorder& recorder,
foundation::IAbortSwitch* abort_switch = nullptr) override;

float get_sun_theta() const;

float get_sun_phi() const;

float get_shift() const;

protected:

SunPositioner m_sun_positioner;
float m_horizon_shift;
};

inline float SkyModelEnvironmentEDF::get_sun_theta() const
{
return static_cast<float>(m_sun_positioner.m_output_value.zenith);
}

inline float SkyModelEnvironmentEDF::get_sun_phi() const
{
return static_cast<float>(m_sun_positioner.m_output_value.azimuth);
}

inline float SkyModelEnvironmentEDF::get_shift() const
{
return m_horizon_shift;
}

} // namespace renderer
25 changes: 7 additions & 18 deletions src/appleseed/renderer/modeling/light/sunlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "renderer/global/globaltypes.h"
#include "renderer/modeling/color/colorspace.h"
#include "renderer/modeling/color/wavelengths.h"
#include "renderer/modeling/environmentedf/environmentedf.h"
#include "renderer/modeling/environmentedf/skymodelenvironmentedf.h"
#include "renderer/modeling/input/inputarray.h"
#include "renderer/modeling/input/source.h"
#include "renderer/modeling/light/lighttarget.h"
Expand Down Expand Up @@ -157,7 +157,7 @@ namespace
m_sun_solid_angle = TwoPi<float>() * (1.0f - std::cos(std::atan(SunRadius * m_values.m_size_multiplier / m_values.m_distance)));

// If the Sun light is bound to an environment EDF, let it override the Sun's direction and turbidity.
const EnvironmentEDF* env_edf = dynamic_cast<EnvironmentEDF*>(m_inputs.get_entity("environment_edf"));
const SkyModelEnvironmentEDF* env_edf = dynamic_cast<SkyModelEnvironmentEDF*>(m_inputs.get_entity("environment_edf"));
if (env_edf != nullptr)
apply_env_edf_overrides(env_edf);

Expand Down Expand Up @@ -327,24 +327,13 @@ namespace
RegularSpectrum31f m_k1;
RegularSpectrum31f m_k2;

void apply_env_edf_overrides(const EnvironmentEDF* env_edf)
void apply_env_edf_overrides(const SkyModelEnvironmentEDF* env_edf)
{
// Use the Sun direction from the EDF if it has one.
const Source* sun_theta_src = env_edf->get_inputs().source("sun_theta");
const Source* sun_phi_src = env_edf->get_inputs().source("sun_phi");
const Source* sun_shift_src = env_edf-> get_inputs().source("horizon_shift");

if (sun_theta_src != nullptr &&
sun_theta_src->is_uniform() &&
sun_phi_src != nullptr &&
sun_phi_src->is_uniform() &&
sun_shift_src != nullptr &&
sun_shift_src->is_uniform())
{
float sun_theta, sun_phi, sun_shift;
sun_theta_src->evaluate_uniform(sun_theta);
sun_phi_src->evaluate_uniform(sun_phi);
sun_shift_src->evaluate_uniform(sun_shift);
const float sun_theta = env_edf->get_sun_theta();
const float sun_phi = env_edf->get_sun_phi();
const float sun_shift = env_edf->get_shift();

Transformd scratch;
const Transformd& env_edf_transform = env_edf->transform_sequence().evaluate(0.0f, scratch);
Expand All @@ -355,7 +344,7 @@ namespace
Matrix4d::make_rotation(
Quaterniond::make_rotation(
Vector3d(0.0, 0.0, -1.0), // default emission direction of this light
-Vector3d::make_unit_vector(deg_to_rad(sun_theta), deg_to_rad(sun_phi))))) *
-Vector3d::make_unit_vector(sun_theta, sun_phi)))) *
env_edf_transform);
}

Expand Down
12 changes: 6 additions & 6 deletions src/appleseed/renderer/modeling/scene/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,6 @@ bool Scene::on_frame_begin(
OnFrameBeginRecorder& recorder,
IAbortSwitch* abort_switch)
{
if (!Entity::on_frame_begin(project, parent, recorder, abort_switch))
return false;

if (!BaseGroup::on_frame_begin(project, parent, recorder, abort_switch))
return false;

bool success = true;
success = success && impl->m_default_surface_shader->on_frame_begin(project, this, recorder, abort_switch);
success = success && invoke_on_frame_begin(environment_edfs(), project, this, recorder, abort_switch);
Expand All @@ -411,6 +405,12 @@ bool Scene::on_frame_begin(
// Call on_frame_begin() on cameras last because some of them cast rays to sense depth in their autofocus mechanism.
success = success && invoke_on_frame_begin(cameras(), project, this, recorder, abort_switch);

if (!Entity::on_frame_begin(project, parent, recorder, abort_switch))
return false;

if (!BaseGroup::on_frame_begin(project, parent, recorder, abort_switch))
return false;

return success;
}

Expand Down
Loading

0 comments on commit 9701d54

Please sign in to comment.