Skip to content

Commit d35ec4e

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

File tree

16 files changed

+298
-20
lines changed

16 files changed

+298
-20
lines changed

sandbox/tests/test scenes/sun and sky/05 - hosek - theta 0 - ptne.appleseed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,4 @@
161161
</parameters>
162162
</configuration>
163163
</configurations>
164-
</project>
164+
</project>

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 fake_physical_light_info& light_info)
123+
{
124+
m_semi_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+
// Check if there is a semi_physical_light
76+
bool has_sp_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_sp_light() const
124+
{
125+
return m_semi_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 fake_physical_light_info& light_info)
78+
{
79+
m_semi_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: 16 additions & 5 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 SPLightHandlingFunction& 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 SPLightHandlingFunction& light_handling_2)
607612
{
608-
for (const Light& light : assembly.lights())
613+
for (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+
fake_physical_light_info 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 Semi physical light vector.
76+
std::vector<fake_physical_light_info> get_semi_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<fake_physical_light_info> SemiPhysicalLightVector;
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 fake_physical_light_info&)> SPLightHandlingFunction;
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+
SemiPhysicalLightVector m_semi_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 SPLightHandlingFunction& 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 SPLightHandlingFunction& 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<fake_physical_light_info> LightSamplerBase::get_semi_physical_light_vector() const
177+
{
178+
return m_semi_physical_lights;
179+
}
180+
168181
} // namespace renderer

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

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

73+
// Testing code for disc sun ...
74+
75+
class fake_physical_light_info
76+
{
77+
public:
78+
const Light* m_light;
79+
};
80+
7381

7482
//
7583
// A light-emitting shape.

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

Lines changed: 55 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,30 @@ namespace
442443
{
443444
assert(vertex.m_prev_mode != ScatteringMode::None);
444445

446+
// Add contributions from all Semi-physical light sources.
447+
for (auto& light_info : m_light_sampler.get_semi_physical_light_vector())
448+
{
449+
Spectrum value;
450+
float light_prob = 1.0f;
451+
light_info.m_light->evaluate(
452+
m_shading_context,
453+
normalize(-Vector3d(vertex.m_outgoing.get_value())),
454+
value);
455+
456+
// Apply path throughput.
457+
value *= vertex.m_throughput;
458+
459+
// Optionally clamp secondary rays contribution.
460+
if (m_params.m_has_max_ray_intensity && vertex.m_path_length > 1 && vertex.m_prev_mode != ScatteringMode::Specular)
461+
clamp_contribution(value, m_params.m_max_ray_intensity);
462+
463+
// Update path radiance.
464+
m_path_radiance.add_emission(
465+
vertex.m_path_length,
466+
vertex.m_aov_mode,
467+
value);
468+
}
469+
445470
// Can't look up the environment if there's no environment EDF.
446471
if (m_env_edf == nullptr)
447472
return;
@@ -548,6 +573,36 @@ namespace
548573
{
549574
assert(vertex.m_prev_mode != ScatteringMode::None);
550575

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

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

Lines changed: 24 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,29 @@ 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_semi_physical_light_vector())
296+
{
297+
Spectrum value;
298+
float light_prob = 1.0f;
299+
light_info.m_light->evaluate(
300+
m_shading_context,
301+
normalize(-Vector3d(vertex.m_outgoing.get_value())),
302+
value);
303+
304+
// Apply path throughput.
305+
value *= vertex.m_throughput;
306+
307+
// Optionally clamp secondary rays contribution.
308+
if (m_params.m_path_tracing_has_max_ray_intensity && vertex.m_path_length > 1 && vertex.m_prev_mode != ScatteringMode::Specular)
309+
clamp_contribution(value, m_params.m_path_tracing_has_max_ray_intensity);
310+
311+
// Update path radiance.
312+
m_path_radiance.add_emission(
313+
vertex.m_path_length,
314+
vertex.m_aov_mode,
315+
value);
316+
}
317+
294318
// Can't look up the environment if there's no environment EDF.
295319
if (m_env_edf == nullptr)
296320
return;

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
// appleseed.renderer headers.
3434
#include "renderer/kernel/aov/aovaccumulator.h"
3535
#include "renderer/kernel/aov/aovcomponents.h"
36+
#include "renderer/kernel/lighting/ilightingengine.h"
3637
#include "renderer/kernel/shading/closures.h"
3738
#include "renderer/kernel/shading/shadingcomponents.h"
3839
#include "renderer/kernel/shading/shadingcontext.h"
@@ -55,6 +56,8 @@
5556
#include "foundation/containers/dictionary.h"
5657
#include "foundation/math/vector.h"
5758

59+
#include "renderer/modeling/light/light.h"
60+
5861
using namespace foundation;
5962

6063
namespace renderer
@@ -208,6 +211,35 @@ 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+
ILightingEngine* light_engine = shading_context.get_lighting_engine();
225+
226+
Spectrum value;
227+
228+
for (Light& light : shading_point.get_scene().assembly_instances().begin()->get_assembly().lights())
229+
{
230+
Light* light_ptr = &light;
231+
light_ptr->evaluate(
232+
shading_context,
233+
normalize(shading_point.get_ray().m_dir),
234+
value);
235+
236+
radiance.m_emission = value;
237+
}
238+
239+
Spectrum temp = radiance.m_emission;
240+
shading_result.m_main.rgb() = temp.illuminance_to_rgb();
241+
}
242+
211243
void ShadingEngine::shade_environment(
212244
SamplingContext& sampling_context,
213245
const PixelContext& pixel_context,

0 commit comments

Comments
 (0)