Skip to content

Commit 1a427e2

Browse files
committed
Add sun disc to preethan
1 parent 39b94c6 commit 1a427e2

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

sandbox/settings/appleseed.studio.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010
<parameter name="tile_ordering" value="spiral" />
1111
</parameters>
1212
<parameters name="ui">
13+
<parameters name="file_dialog">
14+
<parameters name="frames">
15+
<parameter name="last_directory" value="D:\appleseed-scenes" />
16+
<parameter name="selected_filter" value="JPEG Files (*.jpg *.jpe *.jpeg *.jif *.jfif *.jfi)" />
17+
</parameters>
18+
<parameters name="light_paths">
19+
<parameter name="selected_filter" value="" />
20+
</parameters>
21+
<parameters name="projects">
22+
<parameter name="last_directory" value="D:\appleseed\sandbox\tests\test scenes\light importance multipliers" />
23+
<parameter name="selected_filter" value="Project Files (*.appleseed *.appleseedz)" />
24+
</parameters>
25+
</parameters>
1326
<parameters name="render_region">
1427
<parameter name="triggers_rendering" value="true" />
1528
</parameters>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ namespace
135135
// Evaluate uniform values.
136136
m_inputs.evaluate_uniforms(&m_uniform_values);
137137

138-
// If there is a binded sun get it
138+
// If there is a bound sun get it.
139139
m_sun = dynamic_cast<SunLight*>(m_inputs.get_entity("sun_light"));
140140

141141
// Compute the sun direction.

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "renderer/modeling/input/inputarray.h"
4040
#include "renderer/modeling/input/source.h"
4141
#include "renderer/modeling/input/sourceinputs.h"
42+
#include "renderer/modeling/light/sunlight.h"
4243
#include "renderer/utility/transformsequence.h"
4344

4445
// appleseed.foundation headers.
@@ -102,6 +103,7 @@ namespace
102103
m_inputs.declare("luminance_gamma", InputFormat::Float, "1.0");
103104
m_inputs.declare("saturation_multiplier", InputFormat::Float, "1.0");
104105
m_inputs.declare("horizon_shift", InputFormat::Float, "0.0");
106+
m_inputs.declare("sun_light", InputFormat::Entity, "");
105107
}
106108

107109
void release() override
@@ -126,6 +128,9 @@ namespace
126128
// Evaluate uniform values.
127129
m_inputs.evaluate_uniforms(&m_uniform_values);
128130

131+
// If there is a bound sun get it.
132+
m_sun = dynamic_cast<SunLight*>(m_inputs.get_entity("sun_light"));
133+
129134
// Compute the sun direction.
130135
m_sun_theta = deg_to_rad(m_uniform_values.m_sun_theta);
131136
m_sun_phi = deg_to_rad(m_uniform_values.m_sun_phi);
@@ -185,6 +190,10 @@ namespace
185190
{
186191
assert(is_normalized(outgoing));
187192

193+
Spectrum sun_value(0.0f);
194+
if (m_sun)
195+
m_sun->evaluate(Vector3d(outgoing.x, outgoing.y, outgoing.z), sun_value);
196+
188197
Transformd scratch;
189198
const Transformd& transform = m_transform_sequence.evaluate(0.0f, scratch);
190199
const Vector3f local_outgoing = transform.vector_to_local(outgoing);
@@ -196,6 +205,7 @@ namespace
196205
else radiance.set(0.0f);
197206

198207
value.set(radiance, g_std_lighting_conditions, Spectrum::Illuminance);
208+
value += sun_value;
199209
}
200210

201211
void evaluate(
@@ -206,6 +216,10 @@ namespace
206216
{
207217
assert(is_normalized(outgoing));
208218

219+
Spectrum sun_value(0.0f);
220+
if (m_sun)
221+
m_sun->evaluate(Vector3d(outgoing.x, outgoing.y, outgoing.z), sun_value);
222+
209223
Transformd scratch;
210224
const Transformd& transform = m_transform_sequence.evaluate(0.0f, scratch);
211225
const Vector3f local_outgoing = transform.vector_to_local(outgoing);
@@ -217,6 +231,7 @@ namespace
217231
else radiance.set(0.0f);
218232

219233
value.set(radiance, g_std_lighting_conditions, Spectrum::Illuminance);
234+
value += sun_value;
220235
probability = shifted_outgoing.y > 0.0f ? shifted_outgoing.y * RcpPi<float>() : 0.0f;
221236
assert(probability >= 0.0f);
222237
}
@@ -265,6 +280,8 @@ namespace
265280
float m_uniform_y_zenith;
266281
float m_uniform_Y_zenith;
267282

283+
SunLight* m_sun;
284+
268285
// Compute the coefficients of the luminance distribution function.
269286
static void compute_Y_coefficients(
270287
const float turbidity,

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ bool SunLight::on_frame_begin(
150150
// Reference: https://en.wikipedia.org/wiki/Solid_angle#Sun_and_Moon
151151
m_sun_solid_angle = TwoPi<float>() * (1.0f - std::cos(std::atan(SunRadius * m_values.m_size_multiplier / m_values.m_distance)));
152152

153-
154153
// If the Sun light is bound to an environment EDF, let it override the Sun's direction and turbidity.
155154
EnvironmentEDF* env_edf = dynamic_cast<EnvironmentEDF*>(m_inputs.get_entity("environment_edf"));
156155
if (env_edf != nullptr)
@@ -274,39 +273,35 @@ void SunLight::evaluate(
274273
}
275274

276275
const Vector3d local_outgoing = normalize(get_transform().point_to_local(outgoing));
277-
const double cos_theta = dot(local_outgoing, Vector3d(0.0, 0.0, 1.0));
278-
const double sin_theta = std::sqrt(1.0 - cos_theta * cos_theta);
279-
280-
const double sin_theta_max = SunRadius * m_values.m_size_multiplier / m_values.m_distance;
281-
const double cos_theta_max = std::sqrt(1.0 - sin_theta_max * sin_theta_max);
276+
const double angle = std::acos(dot(local_outgoing, Vector3d(0.0, 0.0, 1.0)));
282277

278+
const double max_angle = SunRadius * m_values.m_size_multiplier / m_values.m_distance;
283279

284-
if (cos_theta < cos_theta_max)
280+
if (angle > std::atan(max_angle))
285281
{
286282
value.set(0.0f);
287283
return;
288284
}
289285

290-
const double distance_to_center = SunRadius * m_values.m_size_multiplier *
291-
((sin_theta / cos_theta) / (sin_theta_max / cos_theta_max));
286+
const double distance_to_center = std::tan(angle) * m_values.m_distance;
292287

293288
RegularSpectrum31f radiance;
294289
compute_sun_radiance(
295290
-outgoing,
296291
m_values.m_turbidity,
297292
m_values.m_radiance_multiplier,
298293
radiance,
299-
static_cast<float>(distance_to_center));
294+
square(static_cast<float>(distance_to_center)));
300295

301296
value.set(radiance, g_std_lighting_conditions, Spectrum::Illuminance);
302297
}
303298

304299
void SunLight::compute_sun_radiance(
305-
const Vector3d& outgoing,
306-
const float turbidity,
307-
const float radiance_multiplier,
308-
RegularSpectrum31f& radiance,
309-
const float distance_to_center) const
300+
const Vector3d& outgoing,
301+
const float turbidity,
302+
const float radiance_multiplier,
303+
RegularSpectrum31f& radiance,
304+
const float squared_distance_to_center) const
310305
{
311306
// Compute the relative optical mass.
312307
const float cos_theta = -static_cast<float>(outgoing.y);
@@ -411,11 +406,11 @@ void SunLight::compute_sun_radiance(
411406

412407
constexpr float LimbDarkeningCoeficent = 0.6f; // Limb darkening coefficient for the sun for visible sunlight.
413408
float limb_darkening = 1.0f;
414-
if (distance_to_center > 0.0f)
409+
if (squared_distance_to_center > 0.0f)
415410
{
416411
limb_darkening = (1.0f - LimbDarkeningCoeficent *
417-
(1.0f - std::sqrt(1.0f - std::pow(distance_to_center, 2.0f) /
418-
std::pow(SunRadius * m_values.m_size_multiplier, 2.0f))));
412+
(1.0f - std::sqrt(1.0f - squared_distance_to_center
413+
/ square(SunRadius * m_values.m_size_multiplier))));
419414
}
420415

421416
// Compute the attenuated radiance of the Sun.
@@ -570,7 +565,8 @@ void SunLight::sample_sun_surface(
570565
+ sun_radius * p[1] * basis.get_tangent_v();
571566

572567
outgoing = normalize(target_point - position);
573-
float distance_to_center = SunRadius * m_values.m_size_multiplier * float(std::sqrt(p[0] * p[0] + p[1] * p[1]));
568+
Vector2d test = static_cast<double>(SunRadius * m_values.m_size_multiplier) * p;
569+
float squared_distance_to_center = test[0] * test[0] + test[1] * test[1];
574570

575571

576572
RegularSpectrum31f radiance;
@@ -579,7 +575,7 @@ void SunLight::sample_sun_surface(
579575
m_values.m_turbidity,
580576
m_values.m_radiance_multiplier,
581577
radiance,
582-
distance_to_center);
578+
squared_distance_to_center);
583579

584580
value.set(radiance, g_std_lighting_conditions, Spectrum::Illuminance);
585581

0 commit comments

Comments
 (0)