Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "renderer/modeling/input/inputarray.h"
#include "renderer/modeling/input/source.h"
#include "renderer/modeling/input/sourceinputs.h"
#include "renderer/modeling/light/sunlight.h"
#include "renderer/utility/transformsequence.h"

// appleseed.foundation headers.
Expand Down Expand Up @@ -109,6 +110,7 @@ namespace
m_inputs.declare("luminance_gamma", InputFormat::Float, "1.0");
m_inputs.declare("saturation_multiplier", InputFormat::Float, "1.0");
m_inputs.declare("horizon_shift", InputFormat::Float, "0.0");
m_inputs.declare("sun_light", InputFormat::Entity, "");
}

void release() override
Expand All @@ -133,6 +135,9 @@ namespace
// Evaluate uniform values.
m_inputs.evaluate_uniforms(&m_uniform_values);

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

// 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);
Expand Down Expand Up @@ -189,6 +194,10 @@ namespace
{
assert(is_normalized(outgoing));

Spectrum sun_value(0.0f);
if (m_sun)
m_sun->evaluate(Vector3d(outgoing.x, outgoing.y, outgoing.z), sun_value);

Transformd scratch;
const Transformd& transform = m_transform_sequence.evaluate(0.0f, scratch);
const Vector3f local_outgoing = transform.vector_to_local(outgoing);
Expand All @@ -200,6 +209,7 @@ namespace
else radiance.set(0.0f);

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

void evaluate(
Expand All @@ -210,6 +220,10 @@ namespace
{
assert(is_normalized(outgoing));

Spectrum sun_value(0.0f);
if (m_sun)
m_sun->evaluate(Vector3d(outgoing.x, outgoing.y, outgoing.z), sun_value);

Transformd scratch;
const Transformd& transform = m_transform_sequence.evaluate(0.0f, scratch);
const Vector3f local_outgoing = transform.vector_to_local(outgoing);
Expand All @@ -221,6 +235,7 @@ namespace
else radiance.set(0.0f);

value.set(radiance, g_std_lighting_conditions, Spectrum::Illuminance);
value += sun_value;
probability = shifted_outgoing.y > 0.0f ? shifted_outgoing.y * RcpPi<float>() : 0.0f;
assert(probability >= 0.0f);
}
Expand Down Expand Up @@ -265,6 +280,8 @@ namespace
float m_uniform_coeffs[3 * 9];
float m_uniform_master_Y[3];

SunLight* m_sun;

// Compute the coefficients of the radiance distribution function and the master luminance value.
static void compute_coefficients(
const float turbidity,
Expand Down
Loading