Skip to content

Commit 26a9527

Browse files
committed
Add sun disc to sky model
1 parent 33a0702 commit 26a9527

File tree

14 files changed

+289
-17
lines changed

14 files changed

+289
-17
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ BackwardLightSampler::BackwardLightSampler(
118118
importance *= light_info.m_light->get_uncached_importance_multiplier();
119119
m_non_physical_lights_cdf.insert(light_index, importance);
120120
}
121+
},
122+
[&](const OuterSpacePhysicalLightInfo& light_info)
123+
{
124+
m_outer_space_physical_lights.push_back(light_info);
121125
});
122126
m_non_physical_light_count = m_non_physical_lights.size();
123127

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class BackwardLightSampler
7272
// Return true if the scene contains at least one non-physical light or emitting shape.
7373
bool has_lights() const;
7474

75+
// Return true if the scene contains at leat one outter-space-physical light.
76+
bool has_outter_space_light() const;
77+
7578
// Return true if the scene contains at least one light that can be hit by a ray.
7679
bool has_hittable_lights() const;
7780

@@ -117,6 +120,11 @@ inline bool BackwardLightSampler::has_lights() const
117120
!m_light_tree_lights.empty();
118121
}
119122

123+
inline bool BackwardLightSampler::has_outter_space_light() const
124+
{
125+
return m_outer_space_physical_lights.empty();
126+
}
127+
120128
inline bool BackwardLightSampler::has_hittable_lights() const
121129
{
122130
return !m_emitting_shapes.empty();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ ForwardLightSampler::ForwardLightSampler(const Scene& scene, const ParamArray& p
7373
float importance = 1.0f;
7474
importance *= light_info.m_light->get_uncached_importance_multiplier();
7575
m_non_physical_lights_cdf.insert(light_index, importance);
76+
},
77+
[&](const OuterSpacePhysicalLightInfo& light_info)
78+
{
79+
m_outer_space_physical_lights.push_back(light_info);
7680
});
7781
m_non_physical_light_count = m_non_physical_lights.size();
7882

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

Lines changed: 15 additions & 4 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"
@@ -574,7 +575,8 @@ void LightSamplerBase::collect_emitting_shapes(
574575
void LightSamplerBase::collect_non_physical_lights(
575576
const AssemblyInstanceContainer& assembly_instances,
576577
const TransformSequence& parent_transform_seq,
577-
const LightHandlingFunction& light_handling)
578+
const LightHandlingFunction& light_handling,
579+
const OSLightHandlingFunction& light_handling_2)
578580
{
579581
for (const AssemblyInstance& assembly_instance : assembly_instances)
580582
{
@@ -590,27 +592,36 @@ void LightSamplerBase::collect_non_physical_lights(
590592
collect_non_physical_lights(
591593
assembly.assembly_instances(),
592594
cumulated_transform_seq,
593-
light_handling);
595+
light_handling,
596+
light_handling_2);
594597

595598
// Collect lights from this assembly.
596599
collect_non_physical_lights(
597600
assembly,
598601
cumulated_transform_seq,
599-
light_handling);
602+
light_handling,
603+
light_handling_2);
600604
}
601605
}
602606

603607
void LightSamplerBase::collect_non_physical_lights(
604608
const Assembly& assembly,
605609
const TransformSequence& transform_sequence,
606-
const LightHandlingFunction& light_handling)
610+
const LightHandlingFunction& light_handling,
611+
const OSLightHandlingFunction& light_handling_2)
607612
{
608613
for (const Light& light : assembly.lights())
609614
{
610615
NonPhysicalLightInfo light_info;
611616
light_info.m_transform_sequence = transform_sequence;
612617
light_info.m_light = &light;
613618
light_handling(light_info);
619+
if (light.get_flags() & Light::HasPhysicalShape)
620+
{
621+
OuterSpacePhysicalLightInfo light_info;
622+
light_info.m_light = &light;
623+
light_handling_2(light_info);
624+
}
614625
}
615626
}
616627

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

Lines changed: 15 additions & 2 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 Outer Space light vector.
76+
std::vector<OuterSpacePhysicalLightInfo> get_outer_space_physical_light_vector() const;
77+
7578
protected:
7679
struct Parameters
7780
{
@@ -81,15 +84,18 @@ class LightSamplerBase
8184
};
8285

8386
typedef std::vector<NonPhysicalLightInfo> NonPhysicalLightVector;
87+
typedef std::vector<OuterSpacePhysicalLightInfo> OuterSpacePhysicalLightVector;
8488
typedef std::vector<EmittingShape> EmittingShapeVector;
8589
typedef foundation::CDF<size_t, float> EmitterCDF;
8690

8791
typedef std::function<void (const NonPhysicalLightInfo&)> LightHandlingFunction;
92+
typedef std::function<void (const OuterSpacePhysicalLightInfo&)> OSLightHandlingFunction;
8893
typedef std::function<bool (const Material*, const float, const size_t)> ShapeHandlingFunction;
8994

9095
const Parameters m_params;
9196

9297
NonPhysicalLightVector m_non_physical_lights;
98+
OuterSpacePhysicalLightVector m_outer_space_physical_lights;
9399
EmittingShapeVector m_emitting_shapes;
94100

95101
size_t m_non_physical_light_count;
@@ -126,13 +132,15 @@ class LightSamplerBase
126132
void collect_non_physical_lights(
127133
const AssemblyInstanceContainer& assembly_instances,
128134
const TransformSequence& parent_transform_seq,
129-
const LightHandlingFunction& light_handling);
135+
const LightHandlingFunction& light_handling,
136+
const OSLightHandlingFunction& light_handling_2);
130137

131138
// Collect non-physical lights from a given assembly.
132139
void collect_non_physical_lights(
133140
const Assembly& assembly,
134141
const TransformSequence& transform_sequence,
135-
const LightHandlingFunction& light_handling);
142+
const LightHandlingFunction& light_handling,
143+
const OSLightHandlingFunction& light_handling_2);
136144

137145
void store_object_area_in_shadergroups(
138146
const AssemblyInstance* assembly_instance,
@@ -165,4 +173,9 @@ inline size_t LightSamplerBase::get_non_physical_light_count() const
165173
return m_non_physical_light_count;
166174
}
167175

176+
inline std::vector<OuterSpacePhysicalLightInfo> LightSamplerBase::get_outer_space_physical_light_vector() const
177+
{
178+
return m_outer_space_physical_lights;
179+
}
180+
168181
} // namespace renderer

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ class NonPhysicalLightInfo
7070
const Light* m_light;
7171
};
7272

73+
//
74+
// A outer space light source.
75+
//
76+
77+
class OuterSpacePhysicalLightInfo
78+
{
79+
public:
80+
const Light* m_light;
81+
};
82+
7383

7484
//
7585
// A light-emitting shape.

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_outer_space_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_outer_space_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_outer_space_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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
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"
@@ -41,6 +43,7 @@
4143
#include "renderer/modeling/environment/environment.h"
4244
#include "renderer/modeling/environmentshader/environmentshader.h"
4345
#include "renderer/modeling/input/source.h"
46+
#include "renderer/modeling/light/light.h"
4447
#include "renderer/modeling/material/material.h"
4548
#include "renderer/modeling/object/object.h"
4649
#include "renderer/modeling/scene/assembly.h"
@@ -208,6 +211,33 @@ bool ShadingEngine::shade_hit_point(
208211
return false;
209212
}
210213

214+
void ShadingEngine::shade_light(
215+
SamplingContext& sampling_context,
216+
const PixelContext& pixel_context,
217+
const ShadingContext& shading_context,
218+
const ShadingPoint& shading_point,
219+
AOVAccumulatorContainer& aov_accumulators,
220+
ShadingResult& shading_result) const
221+
{
222+
ShadingComponents radiance;
223+
AOVComponents aov_components;
224+
Spectrum value;
225+
226+
for (Light& light : shading_point.get_scene().assembly_instances().begin()->get_assembly().lights())
227+
{
228+
Light* light_ptr = &light;
229+
light_ptr->evaluate(
230+
shading_context,
231+
normalize(shading_point.get_ray().m_dir),
232+
value);
233+
234+
radiance.m_emission = value;
235+
}
236+
237+
Spectrum temp = radiance.m_emission;
238+
shading_result.m_main.rgb() = temp.illuminance_to_rgb();
239+
}
240+
211241
void ShadingEngine::shade_environment(
212242
SamplingContext& sampling_context,
213243
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,
@@ -132,6 +140,13 @@ inline bool ShadingEngine::shade(
132140
}
133141
else
134142
{
143+
shade_light(
144+
sampling_context,
145+
pixel_context,
146+
shading_context,
147+
shading_point,
148+
aov_accumulators,
149+
shading_result);
135150
shade_environment(
136151
sampling_context,
137152
pixel_context,

0 commit comments

Comments
 (0)