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.
@@ -109,6 +110,7 @@ namespace
109110 m_inputs.declare (" luminance_gamma" , InputFormat::Float, " 1.0" );
110111 m_inputs.declare (" saturation_multiplier" , InputFormat::Float, " 1.0" );
111112 m_inputs.declare (" horizon_shift" , InputFormat::Float, " 0.0" );
113+ m_inputs.declare (" sun_light" , InputFormat::Entity, " " );
112114 }
113115
114116 void release () override
@@ -133,6 +135,9 @@ namespace
133135 // Evaluate uniform values.
134136 m_inputs.evaluate_uniforms (&m_uniform_values);
135137
138+ // If there is a binded sun get it
139+ m_sun = dynamic_cast <SunLight*>(m_inputs.get_entity (" sun_light" ));
140+
136141 // Compute the sun direction.
137142 m_sun_theta = deg_to_rad (m_uniform_values.m_sun_theta );
138143 m_sun_phi = deg_to_rad (m_uniform_values.m_sun_phi );
@@ -189,6 +194,10 @@ namespace
189194 {
190195 assert (is_normalized (outgoing));
191196
197+ Spectrum sun_value (0 .0f );
198+ if (m_sun)
199+ m_sun->evaluate (Vector3d (outgoing.x , outgoing.y , outgoing.z ), sun_value);
200+
192201 Transformd scratch;
193202 const Transformd& transform = m_transform_sequence.evaluate (0 .0f , scratch);
194203 const Vector3f local_outgoing = transform.vector_to_local (outgoing);
@@ -200,6 +209,7 @@ namespace
200209 else radiance.set (0 .0f );
201210
202211 value.set (radiance, g_std_lighting_conditions, Spectrum::Illuminance);
212+ value += sun_value;
203213 }
204214
205215 void evaluate (
@@ -210,6 +220,10 @@ namespace
210220 {
211221 assert (is_normalized (outgoing));
212222
223+ Spectrum sun_value (0 .0f );
224+ if (m_sun)
225+ m_sun->evaluate (Vector3d (outgoing.x , outgoing.y , outgoing.z ), sun_value);
226+
213227 Transformd scratch;
214228 const Transformd& transform = m_transform_sequence.evaluate (0 .0f , scratch);
215229 const Vector3f local_outgoing = transform.vector_to_local (outgoing);
@@ -221,6 +235,7 @@ namespace
221235 else radiance.set (0 .0f );
222236
223237 value.set (radiance, g_std_lighting_conditions, Spectrum::Illuminance);
238+ value += sun_value;
224239 probability = shifted_outgoing.y > 0 .0f ? shifted_outgoing.y * RcpPi<float >() : 0 .0f ;
225240 assert (probability >= 0 .0f );
226241 }
@@ -265,6 +280,8 @@ namespace
265280 float m_uniform_coeffs[3 * 9 ];
266281 float m_uniform_master_Y[3 ];
267282
283+ SunLight* m_sun;
284+
268285 // Compute the coefficients of the radiance distribution function and the master luminance value.
269286 static void compute_coefficients (
270287 const float turbidity,
0 commit comments