Skip to content

Commit 046aa51

Browse files
committed
Add sun disk to sky model.
1 parent 964c5a9 commit 046aa51

File tree

9 files changed

+241
-10
lines changed

9 files changed

+241
-10
lines changed

src/appleseed/renderer/kernel/lighting/lightsamplerbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "renderer/kernel/intersection/intersector.h"
3535
#include "renderer/modeling/edf/edf.h"
3636
#include "renderer/modeling/light/light.h"
37+
#include "renderer/modeling/light/sunlight.h"
3738
#include "renderer/modeling/object/diskobject.h"
3839
#include "renderer/modeling/object/meshobject.h"
3940
#include "renderer/modeling/object/rectangleobject.h"

src/appleseed/renderer/kernel/lighting/lightsamplerbase.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class LightSamplerBase
7272
LightSample& light_sample,
7373
const float light_prob = 1.0f) const;
7474

75+
// Get non physical Space light vector.
76+
std::vector<NonPhysicalLightInfo> get_non_physical_light_vector() const;
77+
7578
protected:
7679
struct Parameters
7780
{
@@ -165,4 +168,9 @@ inline size_t LightSamplerBase::get_non_physical_light_count() const
165168
return m_non_physical_light_count;
166169
}
167170

171+
inline std::vector<NonPhysicalLightInfo> LightSamplerBase::get_non_physical_light_vector() const
172+
{
173+
return m_non_physical_lights;
174+
}
175+
168176
} // namespace renderer

src/appleseed/renderer/kernel/lighting/pt/ptlightingengine.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "renderer/modeling/edf/edf.h"
5050
#include "renderer/modeling/environment/environment.h"
5151
#include "renderer/modeling/environmentedf/environmentedf.h"
52+
#include "renderer/modeling/light/light.h"
5253
#include "renderer/modeling/scene/scene.h"
5354
#include "renderer/utility/spectrumclamp.h"
5455
#include "renderer/utility/stochasticcast.h"
@@ -442,6 +443,29 @@ namespace
442443
{
443444
assert(vertex.m_prev_mode != ScatteringMode::None);
444445

446+
// Add contributions from all outter space light sources.
447+
for (auto& light_info : m_light_sampler.get_non_physical_light_vector())
448+
{
449+
Spectrum value;
450+
light_info.m_light->evaluate(
451+
m_shading_context,
452+
normalize(-Vector3d(vertex.m_outgoing.get_value())),
453+
value);
454+
455+
// Apply path throughput.
456+
value *= vertex.m_throughput;
457+
458+
// Optionally clamp secondary rays contribution.
459+
if (m_params.m_has_max_ray_intensity && vertex.m_path_length > 1 && vertex.m_prev_mode != ScatteringMode::Specular)
460+
clamp_contribution(value, m_params.m_max_ray_intensity);
461+
462+
// Update path radiance.
463+
m_path_radiance.add_emission(
464+
vertex.m_path_length,
465+
vertex.m_aov_mode,
466+
value);
467+
}
468+
445469
// Can't look up the environment if there's no environment EDF.
446470
if (m_env_edf == nullptr)
447471
return;
@@ -548,6 +572,35 @@ namespace
548572
{
549573
assert(vertex.m_prev_mode != ScatteringMode::None);
550574

575+
// Add contributions from all Semi-physical light sources.
576+
for (auto& light_info : m_light_sampler.get_non_physical_light_vector())
577+
{
578+
Spectrum value;
579+
light_info.m_light->evaluate(
580+
m_shading_context,
581+
normalize(-Vector3d(vertex.m_outgoing.get_value())),
582+
value);
583+
584+
// Multiple importance sampling.
585+
if (vertex.m_prev_mode != ScatteringMode::Specular)
586+
{
587+
value.set(0.0f);
588+
}
589+
590+
// Apply path throughput.
591+
value *= vertex.m_throughput;
592+
593+
// Optionally clamp secondary rays contribution.
594+
if (m_params.m_has_max_ray_intensity && vertex.m_path_length > 1 && vertex.m_prev_mode != ScatteringMode::Specular)
595+
clamp_contribution(value, m_params.m_max_ray_intensity);
596+
597+
// Update path radiance.
598+
m_path_radiance.add_emission(
599+
vertex.m_path_length,
600+
vertex.m_aov_mode,
601+
value);
602+
}
603+
551604
// Can't look up the environment if there's no environment EDF.
552605
if (m_env_edf == nullptr)
553606
return;

src/appleseed/renderer/kernel/lighting/sppm/sppmlightingengine.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "renderer/modeling/edf/edf.h"
5050
#include "renderer/modeling/environment/environment.h"
5151
#include "renderer/modeling/environmentedf/environmentedf.h"
52+
#include "renderer/modeling/light/light.h"
5253
#include "renderer/modeling/scene/scene.h"
5354
#include "renderer/utility/spectrumclamp.h"
5455
#include "renderer/utility/stochasticcast.h"
@@ -291,6 +292,28 @@ namespace
291292
// Don't compute lighting in the first pass if importons are enabled.
292293
if (!m_params.m_enable_importons || m_pass_callback.get_pass_number() > 0)
293294
{
295+
for (auto& light_info : m_backward_light_sampler.get_non_physical_light_vector())
296+
{
297+
Spectrum value;
298+
light_info.m_light->evaluate(
299+
m_shading_context,
300+
normalize(-Vector3d(vertex.m_outgoing.get_value())),
301+
value);
302+
303+
// Apply path throughput.
304+
value *= vertex.m_throughput;
305+
306+
// Optionally clamp secondary rays contribution.
307+
if (m_params.m_path_tracing_has_max_ray_intensity && vertex.m_path_length > 1 && vertex.m_prev_mode != ScatteringMode::Specular)
308+
clamp_contribution(value, m_params.m_path_tracing_has_max_ray_intensity);
309+
310+
// Update path radiance.
311+
m_path_radiance.add_emission(
312+
vertex.m_path_length,
313+
vertex.m_aov_mode,
314+
value);
315+
}
316+
294317
// Can't look up the environment if there's no environment EDF.
295318
if (m_env_edf == nullptr)
296319
return;

src/appleseed/renderer/kernel/shading/shadingengine.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@
3333
// appleseed.renderer headers.
3434
#include "renderer/kernel/aov/aovaccumulator.h"
3535
#include "renderer/kernel/aov/aovcomponents.h"
36+
37+
#include "renderer/kernel/lighting/ilightingengine.h"
3638
#include "renderer/kernel/shading/closures.h"
3739
#include "renderer/kernel/shading/shadingcomponents.h"
3840
#include "renderer/kernel/shading/shadingcontext.h"
3941
#include "renderer/kernel/shading/shadingray.h"
4042
#include "renderer/kernel/shading/shadingresult.h"
43+
#include "renderer/modeling/color/colorspace.h"
4144
#include "renderer/modeling/environment/environment.h"
4245
#include "renderer/modeling/environmentshader/environmentshader.h"
4346
#include "renderer/modeling/input/source.h"
47+
#include "renderer/modeling/light/light.h"
4448
#include "renderer/modeling/material/material.h"
4549
#include "renderer/modeling/object/object.h"
4650
#include "renderer/modeling/scene/assembly.h"
@@ -208,6 +212,33 @@ bool ShadingEngine::shade_hit_point(
208212
return false;
209213
}
210214

215+
void ShadingEngine::shade_light(
216+
SamplingContext& sampling_context,
217+
const PixelContext& pixel_context,
218+
const ShadingContext& shading_context,
219+
const ShadingPoint& shading_point,
220+
AOVAccumulatorContainer& aov_accumulators,
221+
ShadingResult& shading_result) const
222+
{
223+
ShadingComponents radiance;
224+
AOVComponents aov_components;
225+
Spectrum value;
226+
227+
for (Light& light : shading_point.get_scene().assembly_instances().begin()->get_assembly().lights())
228+
{
229+
Light* light_ptr = &light;
230+
light_ptr->evaluate(
231+
shading_context,
232+
normalize(shading_point.get_ray().m_dir),
233+
value);
234+
235+
radiance.m_emission = value;
236+
}
237+
238+
Spectrum temp = radiance.m_emission;
239+
shading_result.m_main.rgb() += temp.illuminance_to_rgb(g_std_lighting_conditions);
240+
}
241+
211242
void ShadingEngine::shade_environment(
212243
SamplingContext& sampling_context,
213244
const PixelContext& pixel_context,

src/appleseed/renderer/kernel/shading/shadingengine.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ class ShadingEngine
9898
AOVAccumulatorContainer& aov_accumulators,
9999
ShadingResult& shading_result) const;
100100

101+
void shade_light(
102+
SamplingContext& sampling_context,
103+
const PixelContext& pixel_context,
104+
const ShadingContext& shading_context,
105+
const ShadingPoint& shading_point,
106+
AOVAccumulatorContainer& aov_accumulators,
107+
ShadingResult& shading_result) const;
108+
101109
void shade_environment(
102110
SamplingContext& sampling_context,
103111
const PixelContext& pixel_context,
@@ -139,6 +147,13 @@ inline bool ShadingEngine::shade(
139147
shading_point,
140148
aov_accumulators,
141149
shading_result);
150+
shade_light(
151+
sampling_context,
152+
pixel_context,
153+
shading_context,
154+
shading_point,
155+
aov_accumulators,
156+
shading_result);
142157
return true;
143158
}
144159
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,11 @@ void Light::sample(
150150
probability);
151151
}
152152

153+
void Light::evaluate(
154+
const ShadingContext& shading_context,
155+
const Vector3d& outgoing,
156+
Spectrum& value) const
157+
{
158+
}
159+
153160
} // namespace renderer

src/appleseed/renderer/modeling/light/light.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class APPLESEED_DLLSYMBOL Light
8181
CastShadows = 1UL << 0, // does this light cast shadows?
8282
CastIndirectLight = 1UL << 1, // does this light generate indirect lighting?
8383
LightTreeCompatible = 1UL << 2, // can this light be used by the LightTree?
84+
HasPhysicalShape = 1UL << 3, // can this light be used by the LightTree?
8485
};
8586

8687
// Retrieve the flags.
@@ -130,6 +131,11 @@ class APPLESEED_DLLSYMBOL Light
130131
Spectrum& value, // light value
131132
float& probability) const; // PDF value
132133

134+
virtual void evaluate(
135+
const ShadingContext& shading_context,
136+
const foundation::Vector3d& outgoing,
137+
Spectrum& value) const;
138+
133139
// Compute the distance attenuation of this light.
134140
virtual float compute_distance_attenuation(
135141
const foundation::Vector3d& target, // world space target point

0 commit comments

Comments
 (0)