Skip to content

Commit 8414922

Browse files
committed
Fix SunPositioner Factory bug
1 parent db1ac46 commit 8414922

File tree

12 files changed

+942
-855
lines changed

12 files changed

+942
-855
lines changed

sandbox/settings/appleseed.studio.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<parameter name="selected_filter" value="JPEG Files (*.jpg *.jpe *.jpeg *.jif *.jfif *.jfi)" />
1717
</parameters>
1818
<parameters name="projects">
19-
<parameter name="last_directory" value="C:\Users\joao_\OneDrive\Desktop\git\Appleaseed\appleseed\sandbox\tests\test scenes\sppm" />
19+
<parameter name="last_directory" value="D:\appleseed-scenes\house" />
2020
<parameter name="selected_filter" value="Project Files (*.appleseed *.appleseedz)" />
2121
</parameters>
2222
</parameters>

src/appleseed.python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ set (sources
106106
bindshadercompiler.cpp
107107
bindshadergroup.cpp
108108
bindshaderquery.cpp
109+
bindsunpositioner.cpp
109110
bindsurfaceshader.cpp
110111
bindtexture.cpp
111112
bindtilecallback.cpp
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
//
3+
// This source file is part of appleseed.
4+
// Visit https://appleseedhq.net/ for additional information and resources.
5+
//
6+
// This software is released under the MIT license.
7+
//
8+
// Copyright (c) 2020 Joao Marcos Costa, The appleseedhq Organization
9+
//
10+
// Permission is hereby granted, free of charge, to any person obtaining a copy
11+
// of this software and associated documentation files (the "Software"), to deal
12+
// in the Software without restriction, including without limitation the rights
13+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
// copies of the Software, and to permit persons to whom the Software is
15+
// furnished to do so, subject to the following conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be included in
18+
// all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
// THE SOFTWARE.
27+
//
28+
29+
#pragma once
30+
31+
// appleseed.python headers.
32+
#include "bindentitycontainers.h"
33+
#include "dict2dict.h"
34+
#include "metadata.h"
35+
36+
// appleseed.renderer header.
37+
#include "renderer/utility/solarpositionalgorithm.h"
38+
39+
// appleseed.foundation headers.
40+
#include "foundation/platform/python.h"
41+
42+
namespace bpy = boost::python;
43+
using namespace foundation;
44+
using namespace renderer;
45+
46+
namespace
47+
{
48+
auto_release_ptr<SunPositioner> create_sun_positioner(const bpy::dict& params)
49+
{
50+
return SunPositionerFactory::create("Sun Positioner", bpy_dict_to_param_array(params));
51+
}
52+
53+
void compute_sun_position(SunPositioner* sun_position)
54+
{
55+
sun_position->fetch_data();
56+
sun_position->compute_sun_position();
57+
}
58+
59+
bpy::list get_input_metadata()
60+
{
61+
return dictionary_array_to_bpy_list(SunPositionerFactory::get_input_metadata());
62+
}
63+
}
64+
65+
void bind_sun_position()
66+
{
67+
bpy::class_<SunPositioner, auto_release_ptr<SunPositioner>, bpy::bases<Entity>, boost::noncopyable>("SunPositioner", bpy::no_init)
68+
.def("get_input_metadata", get_input_metadata).staticmethod("get_input_metadata")
69+
.def("__init__", bpy::make_constructor(create_sun_positioner))
70+
.def("compute_sun_position", compute_sun_position)
71+
72+
.def("get_zenith", &SunPositioner::get_zenith)
73+
.def("get_azimuth", &SunPositioner::get_azimuth)
74+
.def("get_solar_noon", &SunPositioner::get_solar_noon)
75+
.def("get_sunrise", &SunPositioner::get_sunrise)
76+
.def("get_sunset", &SunPositioner::get_sunset);
77+
}

src/appleseed.python/module.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void bind_scene();
6666
void bind_shader_compiler();
6767
void bind_shader_group();
6868
void bind_shader_query();
69+
void bind_sun_position();
6970
void bind_surface_shader();
7071
void bind_texture();
7172
void bind_tile_callback();
@@ -132,6 +133,7 @@ extern "C" void bind_appleseed_python_classes()
132133
bind_fresnel();
133134
bind_display();
134135
bind_project();
136+
bind_sun_position();
135137

136138
bind_renderer_controller();
137139
bind_tile_callback();

src/appleseed/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,8 +1829,6 @@ 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
18341832
renderer/modeling/environmentedf/sphericalcoordinates.h
18351833
)
18361834
list (APPEND appleseed_sources

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

Lines changed: 13 additions & 13 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/skymodelenvironmentedf.h"
37+
#include "renderer/modeling/environmentedf/environmentedf.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 SkyModelEnvironmentEDF
96+
: public EnvironmentEDF
9797
{
9898
public:
9999
HosekEnvironmentEDF(
100100
const char* name,
101101
const ParamArray& params)
102-
: SkyModelEnvironmentEDF(name, params)
102+
: EnvironmentEDF(name, params)
103103
{
104104
m_inputs.declare("sun_theta", InputFormat::InputFormatFloat);
105105
m_inputs.declare("sun_phi", InputFormat::InputFormatFloat);
@@ -128,18 +128,15 @@ namespace
128128
OnFrameBeginRecorder& recorder,
129129
IAbortSwitch* abort_switch) override
130130
{
131-
if (!SkyModelEnvironmentEDF::on_frame_begin(project, parent, recorder, abort_switch))
131+
if (!EnvironmentEDF::on_frame_begin(project, parent, recorder, abort_switch))
132132
return false;
133-
134133
// Evaluate uniform values.
135134
m_inputs.evaluate_uniforms(&m_uniform_values);
136135

137136
// Compute the sun direction.
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;
137+
m_sun_theta = deg_to_rad(m_uniform_values.m_sun_theta);
138+
m_sun_phi = deg_to_rad(m_uniform_values.m_sun_phi);
139+
m_sun_dir = Vector3f::make_unit_vector(m_sun_theta, m_sun_phi);
143140

144141
// Precompute the coefficients of the radiance distribution function and
145142
// the master luminance value if turbidity is uniform.
@@ -153,7 +150,7 @@ namespace
153150
compute_coefficients(
154151
m_uniform_values.m_turbidity,
155152
m_uniform_values.m_ground_albedo,
156-
static_cast<float>(m_sun_positioner.m_output_value.zenith),
153+
m_sun_theta,
157154
m_uniform_coeffs,
158155
m_uniform_master_Y);
159156
}
@@ -259,6 +256,9 @@ namespace
259256
};
260257

261258
InputValues m_uniform_values;
259+
260+
float m_sun_theta; // sun zenith angle in radians, 0=zenith
261+
float m_sun_phi; // radians
262262
Vector3f m_sun_dir;
263263

264264
bool m_uniform_turbidity;
@@ -423,7 +423,7 @@ namespace
423423
compute_coefficients(
424424
turbidity,
425425
m_uniform_values.m_ground_albedo,
426-
static_cast<float>(m_sun_positioner.m_output_value.zenith),
426+
m_sun_theta,
427427
coeffs,
428428
master_Y);
429429

@@ -468,7 +468,7 @@ namespace
468468

469469
Vector3f shift(Vector3f v) const
470470
{
471-
v.y -= m_horizon_shift;
471+
v.y -= m_uniform_values.m_horizon_shift;;
472472
return normalize(v);
473473
}
474474
};

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

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -173,142 +173,6 @@ void IEnvironmentEDFFactory::add_common_sky_input_metadata(DictionaryArray& meta
173173
.insert("use", "optional")
174174
.insert("default", "0.0")
175175
.insert("help", "Shift the horizon vertically"));
176-
177-
metadata.push_back(
178-
Dictionary()
179-
.insert("name", "hour")
180-
.insert("label", "hour")
181-
.insert("type", "integer")
182-
.insert("min",
183-
Dictionary()
184-
.insert("value", "0")
185-
.insert("type", "hard"))
186-
.insert("max",
187-
Dictionary()
188-
.insert("value", "24")
189-
.insert("type", "hard"))
190-
.insert("use", "optional")
191-
.insert("default", "12")
192-
.insert("help", "..."));
193-
194-
metadata.push_back(
195-
Dictionary()
196-
.insert("name", "minute")
197-
.insert("label", "minute")
198-
.insert("type", "integer")
199-
.insert("min",
200-
Dictionary()
201-
.insert("value", "0")
202-
.insert("type", "hard"))
203-
.insert("max",
204-
Dictionary()
205-
.insert("value", "60")
206-
.insert("type", "hard"))
207-
.insert("use", "optional")
208-
.insert("default", "0")
209-
.insert("help", "..."));
210-
211-
metadata.push_back(
212-
Dictionary()
213-
.insert("name", "second")
214-
.insert("label", "second")
215-
.insert("type", "integer")
216-
.insert("min",
217-
Dictionary()
218-
.insert("value", "0")
219-
.insert("type", "hard"))
220-
.insert("max",
221-
Dictionary()
222-
.insert("value", "60")
223-
.insert("type", "hard"))
224-
.insert("use", "optional")
225-
.insert("default", "0")
226-
.insert("help", "..."));
227-
228-
metadata.push_back(
229-
Dictionary()
230-
.insert("name", "year")
231-
.insert("label", "year")
232-
.insert("type", "integer")
233-
.insert("min",
234-
Dictionary()
235-
.insert("value", "-2000")
236-
.insert("type", "soft"))
237-
.insert("max",
238-
Dictionary()
239-
.insert("value", "6000")
240-
.insert("type", "soft"))
241-
.insert("use", "optional")
242-
.insert("default", "2020")
243-
.insert("help", "..."));
244-
245-
metadata.push_back(
246-
Dictionary()
247-
.insert("name", "month")
248-
.insert("label", "month ")
249-
.insert("type", "integer")
250-
.insert("min",
251-
Dictionary()
252-
.insert("value", "1")
253-
.insert("type", "hard"))
254-
.insert("max",
255-
Dictionary()
256-
.insert("value", "12")
257-
.insert("type", "hard"))
258-
.insert("use", "optional")
259-
.insert("default", "1")
260-
.insert("help", "..."));
261-
262-
metadata.push_back(
263-
Dictionary()
264-
.insert("name", "day")
265-
.insert("label", "day")
266-
.insert("type", "integer")
267-
.insert("min",
268-
Dictionary()
269-
.insert("value", "1")
270-
.insert("type", "hard"))
271-
.insert("max",
272-
Dictionary()
273-
.insert("value", "31")
274-
.insert("type", "hard"))
275-
.insert("use", "optional")
276-
.insert("default", "1")
277-
.insert("help", "..."));
278-
279-
metadata.push_back(
280-
Dictionary()
281-
.insert("name", "longitude")
282-
.insert("label", "longitude")
283-
.insert("type", "numeric")
284-
.insert("min",
285-
Dictionary()
286-
.insert("value", "-180.0")
287-
.insert("type", "hard"))
288-
.insert("max",
289-
Dictionary()
290-
.insert("value", "180.0")
291-
.insert("type", "hard"))
292-
.insert("use", "optional")
293-
.insert("default", "0.0")
294-
.insert("help", "..."));
295-
296-
metadata.push_back(
297-
Dictionary()
298-
.insert("name", "latitude")
299-
.insert("label", "latitude")
300-
.insert("type", "numeric")
301-
.insert("min",
302-
Dictionary()
303-
.insert("value", "-90.0")
304-
.insert("type", "hard"))
305-
.insert("max",
306-
Dictionary()
307-
.insert("value", "90.0")
308-
.insert("type", "hard"))
309-
.insert("use", "optional")
310-
.insert("default", "0")
311-
.insert("help", "..."));
312176
}
313177

314178
} // namespace renderer

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)