Skip to content

Commit 7daae39

Browse files
committed
Change spa algorithm used.
1 parent e9c9782 commit 7daae39

File tree

9 files changed

+383
-1376
lines changed

9 files changed

+383
-1376
lines changed

sandbox/settings/appleseed.studio.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
</parameters>
1212
<parameters name="ui">
1313
<parameters name="file_dialog">
14+
<parameters name="frames">
15+
<parameter name="last_directory" value="C:\Users\joao_\OneDrive\Desktop" />
16+
<parameter name="selected_filter" value="JPEG Files (*.jpg *.jpe *.jpeg *.jif *.jfif *.jfi)" />
17+
</parameters>
1418
<parameters name="projects">
1519
<parameter name="last_directory" value="C:\Users\joao_\OneDrive\Desktop\git\Appleaseed\appleseed\sandbox\tests\test scenes\sppm" />
1620
<parameter name="selected_filter" value="Project Files (*.appleseed *.appleseedz)" />

src/appleseed/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,8 @@ set (renderer_modeling_environmentedf_sources
18291829
renderer/modeling/environmentedf/oslenvironmentedf.h
18301830
renderer/modeling/environmentedf/preethamenvironmentedf.cpp
18311831
renderer/modeling/environmentedf/preethamenvironmentedf.h
1832+
renderer/modeling/environmentedf/skymodelenvironmentedf.cpp
1833+
renderer/modeling/environmentedf/skymodelenvironmentedf.h
18321834
renderer/modeling/environmentedf/sphericalcoordinates.h
18331835
)
18341836
list (APPEND appleseed_sources

src/appleseed/renderer/modeling/environmentedf/hosekenvironmentedf.cpp

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "renderer/global/globaltypes.h"
3535
#include "renderer/kernel/shading/shadingcontext.h"
3636
#include "renderer/modeling/color/colorspace.h"
37-
#include "renderer/modeling/environmentedf/environmentedf.h"
37+
#include "renderer/modeling/environmentedf/skymodelenvironmentedf.h"
3838
#include "renderer/modeling/environmentedf/sphericalcoordinates.h"
3939
#include "renderer/modeling/input/inputarray.h"
4040
#include "renderer/modeling/input/source.h"
@@ -93,13 +93,13 @@ namespace
9393
const float BaseTurbidity = 2.0f;
9494

9595
class HosekEnvironmentEDF
96-
: public EnvironmentEDF
96+
: public SkyModelEnvironmentEDF
9797
{
9898
public:
9999
HosekEnvironmentEDF(
100100
const char* name,
101101
const ParamArray& params)
102-
: EnvironmentEDF(name, params)
102+
: SkyModelEnvironmentEDF(name, params)
103103
{
104104
m_inputs.declare("sun_theta", InputFormat::InputFormatFloat);
105105
m_inputs.declare("sun_phi", InputFormat::InputFormatFloat);
@@ -128,39 +128,18 @@ namespace
128128
OnFrameBeginRecorder& recorder,
129129
IAbortSwitch* abort_switch) override
130130
{
131-
if (!EnvironmentEDF::on_frame_begin(project, parent, recorder, abort_switch))
131+
if (!SkyModelEnvironmentEDF::on_frame_begin(project, parent, recorder, abort_switch))
132132
return false;
133133

134134
// Evaluate uniform values.
135135
m_inputs.evaluate_uniforms(&m_uniform_values);
136-
137-
spa_data test;
138-
test.hour = m_params.get_optional<int>("hour", 12);
139-
test.minute = m_params.get_optional<int>("minute", 0);
140-
test.second = m_params.get_optional<int>("second", 0);
141-
142-
test.year = m_params.get_optional<int>("year", 2020);
143-
test.month = m_params.get_optional<int>("month", 1);
144-
test.day = m_params.get_optional<int>("day", 1);
145-
146-
test.timezone = 0;
147-
test.longitude = m_params.get_optional<float>("longitude", 0);
148-
test.latitude = m_params.get_optional<float>("latitude", 0);
149-
150-
test.azm_rotation = 0.0;
151-
test.elevation = 0.0;
152-
153-
test.function = SPA_ZA;
154-
155-
spa_calculate(&test);
156-
157-
m_uniform_values.m_sun_theta = static_cast<float>(test.zenith);
158-
m_uniform_values.m_sun_phi = static_cast<float>(test.azimuth);
159136

160137
// Compute the sun direction.
161-
m_sun_theta = deg_to_rad(m_uniform_values.m_sun_theta);
162-
m_sun_phi = deg_to_rad(m_uniform_values.m_sun_phi);
163-
m_sun_dir = Vector3f::make_unit_vector(m_sun_theta, m_sun_phi);
138+
m_sun_positioner.m_output_value.zenith = deg_to_rad(m_sun_positioner.m_output_value.zenith);
139+
m_sun_positioner.m_output_value.azimuth = deg_to_rad(m_sun_positioner.m_output_value.azimuth);
140+
m_sun_dir = Vector3f::make_unit_vector(static_cast<float>(m_sun_positioner.m_output_value.zenith)
141+
, static_cast<float>(m_sun_positioner.m_output_value.azimuth));
142+
m_horizon_shift = m_uniform_values.m_horizon_shift;
164143

165144
// Precompute the coefficients of the radiance distribution function and
166145
// the master luminance value if turbidity is uniform.
@@ -174,7 +153,7 @@ namespace
174153
compute_coefficients(
175154
m_uniform_values.m_turbidity,
176155
m_uniform_values.m_ground_albedo,
177-
m_sun_theta,
156+
static_cast<float>(m_sun_positioner.m_output_value.zenith),
178157
m_uniform_coeffs,
179158
m_uniform_master_Y);
180159
}
@@ -280,9 +259,6 @@ namespace
280259
};
281260

282261
InputValues m_uniform_values;
283-
284-
float m_sun_theta; // sun zenith angle in radians, 0=zenith
285-
float m_sun_phi; // radians
286262
Vector3f m_sun_dir;
287263

288264
bool m_uniform_turbidity;
@@ -447,7 +423,7 @@ namespace
447423
compute_coefficients(
448424
turbidity,
449425
m_uniform_values.m_ground_albedo,
450-
m_sun_theta,
426+
static_cast<float>(m_sun_positioner.m_output_value.zenith),
451427
coeffs,
452428
master_Y);
453429

@@ -492,7 +468,7 @@ namespace
492468

493469
Vector3f shift(Vector3f v) const
494470
{
495-
v.y -= m_uniform_values.m_horizon_shift;
471+
v.y -= m_horizon_shift;
496472
return normalize(v);
497473
}
498474
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
#include "skymodelenvironmentedf.h"
3+
4+
namespace renderer
5+
{
6+
SkyModelEnvironmentEDF::SkyModelEnvironmentEDF(
7+
const char* name,
8+
const ParamArray& params)
9+
: EnvironmentEDF(name, params),
10+
m_sun_positioner("Sun Positioner", params)
11+
{
12+
}
13+
14+
bool SkyModelEnvironmentEDF::on_frame_begin(const Project& project, const BaseGroup* parent, OnFrameBeginRecorder& recorder, foundation::IAbortSwitch* abort_switch)
15+
{
16+
if (!EnvironmentEDF::on_frame_begin(project, parent, recorder, abort_switch))
17+
return false;
18+
19+
if (!m_sun_positioner.on_frame_begin(project, parent, recorder, abort_switch))
20+
return false;
21+
22+
m_sun_positioner.compute_sun_position();
23+
24+
return true;
25+
}
26+
27+
} // namespace renderer
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#pragma once
2+
3+
// appleseed.renderer headers.
4+
#include "renderer/modeling/environmentedf/environmentedf.h"
5+
#include "renderer/utility/solarpositionalgorithm.h"
6+
7+
namespace renderer
8+
{
9+
10+
//
11+
// An Environment EDF Interface Class For Differents Sky Models implementation.
12+
//
13+
14+
class APPLESEED_DLLSYMBOL SkyModelEnvironmentEDF
15+
: public EnvironmentEDF
16+
{
17+
public:
18+
19+
// Constructor.
20+
SkyModelEnvironmentEDF(
21+
const char* name,
22+
const ParamArray& params);
23+
24+
bool on_frame_begin(
25+
const Project& project,
26+
const BaseGroup* parent,
27+
OnFrameBeginRecorder& recorder,
28+
foundation::IAbortSwitch* abort_switch = nullptr) override;
29+
30+
float get_sun_theta() const;
31+
32+
float get_sun_phi() const;
33+
34+
float get_shift() const;
35+
36+
protected:
37+
38+
SunPositioner m_sun_positioner;
39+
float m_horizon_shift;
40+
};
41+
42+
inline float SkyModelEnvironmentEDF::get_sun_theta() const
43+
{
44+
return static_cast<float>(m_sun_positioner.m_output_value.zenith);
45+
}
46+
47+
inline float SkyModelEnvironmentEDF::get_sun_phi() const
48+
{
49+
return static_cast<float>(m_sun_positioner.m_output_value.azimuth);
50+
}
51+
52+
inline float SkyModelEnvironmentEDF::get_shift() const
53+
{
54+
return m_horizon_shift;
55+
}
56+
57+
} // namespace renderer

src/appleseed/renderer/modeling/light/sunlight.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "renderer/global/globaltypes.h"
3535
#include "renderer/modeling/color/colorspace.h"
3636
#include "renderer/modeling/color/wavelengths.h"
37-
#include "renderer/modeling/environmentedf/environmentedf.h"
37+
#include "renderer/modeling/environmentedf/skymodelenvironmentedf.h"
3838
#include "renderer/modeling/input/inputarray.h"
3939
#include "renderer/modeling/input/source.h"
4040
#include "renderer/modeling/light/lighttarget.h"
@@ -157,7 +157,7 @@ namespace
157157
m_sun_solid_angle = TwoPi<float>() * (1.0f - std::cos(std::atan(SunRadius * m_values.m_size_multiplier / m_values.m_distance)));
158158

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

@@ -327,24 +327,13 @@ namespace
327327
RegularSpectrum31f m_k1;
328328
RegularSpectrum31f m_k2;
329329

330-
void apply_env_edf_overrides(const EnvironmentEDF* env_edf)
330+
void apply_env_edf_overrides(const SkyModelEnvironmentEDF* env_edf)
331331
{
332332
// Use the Sun direction from the EDF if it has one.
333-
const Source* sun_theta_src = env_edf->get_inputs().source("sun_theta");
334-
const Source* sun_phi_src = env_edf->get_inputs().source("sun_phi");
335-
const Source* sun_shift_src = env_edf-> get_inputs().source("horizon_shift");
336-
337-
if (sun_theta_src != nullptr &&
338-
sun_theta_src->is_uniform() &&
339-
sun_phi_src != nullptr &&
340-
sun_phi_src->is_uniform() &&
341-
sun_shift_src != nullptr &&
342-
sun_shift_src->is_uniform())
343333
{
344-
float sun_theta, sun_phi, sun_shift;
345-
sun_theta_src->evaluate_uniform(sun_theta);
346-
sun_phi_src->evaluate_uniform(sun_phi);
347-
sun_shift_src->evaluate_uniform(sun_shift);
334+
const float sun_theta = env_edf->get_sun_theta();
335+
const float sun_phi = env_edf->get_sun_phi();
336+
const float sun_shift = env_edf->get_shift();
348337

349338
Transformd scratch;
350339
const Transformd& env_edf_transform = env_edf->transform_sequence().evaluate(0.0f, scratch);
@@ -355,7 +344,7 @@ namespace
355344
Matrix4d::make_rotation(
356345
Quaterniond::make_rotation(
357346
Vector3d(0.0, 0.0, -1.0), // default emission direction of this light
358-
-Vector3d::make_unit_vector(deg_to_rad(sun_theta), deg_to_rad(sun_phi))))) *
347+
-Vector3d::make_unit_vector(sun_theta, sun_phi)))) *
359348
env_edf_transform);
360349
}
361350

src/appleseed/renderer/modeling/scene/scene.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,6 @@ bool Scene::on_frame_begin(
395395
OnFrameBeginRecorder& recorder,
396396
IAbortSwitch* abort_switch)
397397
{
398-
if (!Entity::on_frame_begin(project, parent, recorder, abort_switch))
399-
return false;
400-
401-
if (!BaseGroup::on_frame_begin(project, parent, recorder, abort_switch))
402-
return false;
403-
404398
bool success = true;
405399
success = success && impl->m_default_surface_shader->on_frame_begin(project, this, recorder, abort_switch);
406400
success = success && invoke_on_frame_begin(environment_edfs(), project, this, recorder, abort_switch);
@@ -411,6 +405,12 @@ bool Scene::on_frame_begin(
411405
// Call on_frame_begin() on cameras last because some of them cast rays to sense depth in their autofocus mechanism.
412406
success = success && invoke_on_frame_begin(cameras(), project, this, recorder, abort_switch);
413407

408+
if (!Entity::on_frame_begin(project, parent, recorder, abort_switch))
409+
return false;
410+
411+
if (!BaseGroup::on_frame_begin(project, parent, recorder, abort_switch))
412+
return false;
413+
414414
return success;
415415
}
416416

0 commit comments

Comments
 (0)