Skip to content

Commit

Permalink
Add sun disk to sky model.
Browse files Browse the repository at this point in the history
  • Loading branch information
mororo250 committed Jun 29, 2020
1 parent 964c5a9 commit 046aa51
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "renderer/kernel/intersection/intersector.h"
#include "renderer/modeling/edf/edf.h"
#include "renderer/modeling/light/light.h"
#include "renderer/modeling/light/sunlight.h"
#include "renderer/modeling/object/diskobject.h"
#include "renderer/modeling/object/meshobject.h"
#include "renderer/modeling/object/rectangleobject.h"
Expand Down
8 changes: 8 additions & 0 deletions src/appleseed/renderer/kernel/lighting/lightsamplerbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class LightSamplerBase
LightSample& light_sample,
const float light_prob = 1.0f) const;

// Get non physical Space light vector.
std::vector<NonPhysicalLightInfo> get_non_physical_light_vector() const;

protected:
struct Parameters
{
Expand Down Expand Up @@ -165,4 +168,9 @@ inline size_t LightSamplerBase::get_non_physical_light_count() const
return m_non_physical_light_count;
}

inline std::vector<NonPhysicalLightInfo> LightSamplerBase::get_non_physical_light_vector() const
{
return m_non_physical_lights;
}

} // namespace renderer
53 changes: 53 additions & 0 deletions src/appleseed/renderer/kernel/lighting/pt/ptlightingengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "renderer/modeling/edf/edf.h"
#include "renderer/modeling/environment/environment.h"
#include "renderer/modeling/environmentedf/environmentedf.h"
#include "renderer/modeling/light/light.h"
#include "renderer/modeling/scene/scene.h"
#include "renderer/utility/spectrumclamp.h"
#include "renderer/utility/stochasticcast.h"
Expand Down Expand Up @@ -442,6 +443,29 @@ namespace
{
assert(vertex.m_prev_mode != ScatteringMode::None);

// Add contributions from all outter space light sources.
for (auto& light_info : m_light_sampler.get_non_physical_light_vector())
{
Spectrum value;
light_info.m_light->evaluate(
m_shading_context,
normalize(-Vector3d(vertex.m_outgoing.get_value())),
value);

// Apply path throughput.
value *= vertex.m_throughput;

// Optionally clamp secondary rays contribution.
if (m_params.m_has_max_ray_intensity && vertex.m_path_length > 1 && vertex.m_prev_mode != ScatteringMode::Specular)
clamp_contribution(value, m_params.m_max_ray_intensity);

// Update path radiance.
m_path_radiance.add_emission(
vertex.m_path_length,
vertex.m_aov_mode,
value);
}

// Can't look up the environment if there's no environment EDF.
if (m_env_edf == nullptr)
return;
Expand Down Expand Up @@ -548,6 +572,35 @@ namespace
{
assert(vertex.m_prev_mode != ScatteringMode::None);

// Add contributions from all Semi-physical light sources.
for (auto& light_info : m_light_sampler.get_non_physical_light_vector())
{
Spectrum value;
light_info.m_light->evaluate(
m_shading_context,
normalize(-Vector3d(vertex.m_outgoing.get_value())),
value);

// Multiple importance sampling.
if (vertex.m_prev_mode != ScatteringMode::Specular)
{
value.set(0.0f);
}

// Apply path throughput.
value *= vertex.m_throughput;

// Optionally clamp secondary rays contribution.
if (m_params.m_has_max_ray_intensity && vertex.m_path_length > 1 && vertex.m_prev_mode != ScatteringMode::Specular)
clamp_contribution(value, m_params.m_max_ray_intensity);

// Update path radiance.
m_path_radiance.add_emission(
vertex.m_path_length,
vertex.m_aov_mode,
value);
}

// Can't look up the environment if there's no environment EDF.
if (m_env_edf == nullptr)
return;
Expand Down
23 changes: 23 additions & 0 deletions src/appleseed/renderer/kernel/lighting/sppm/sppmlightingengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "renderer/modeling/edf/edf.h"
#include "renderer/modeling/environment/environment.h"
#include "renderer/modeling/environmentedf/environmentedf.h"
#include "renderer/modeling/light/light.h"
#include "renderer/modeling/scene/scene.h"
#include "renderer/utility/spectrumclamp.h"
#include "renderer/utility/stochasticcast.h"
Expand Down Expand Up @@ -291,6 +292,28 @@ namespace
// Don't compute lighting in the first pass if importons are enabled.
if (!m_params.m_enable_importons || m_pass_callback.get_pass_number() > 0)
{
for (auto& light_info : m_backward_light_sampler.get_non_physical_light_vector())
{
Spectrum value;
light_info.m_light->evaluate(
m_shading_context,
normalize(-Vector3d(vertex.m_outgoing.get_value())),
value);

// Apply path throughput.
value *= vertex.m_throughput;

// Optionally clamp secondary rays contribution.
if (m_params.m_path_tracing_has_max_ray_intensity && vertex.m_path_length > 1 && vertex.m_prev_mode != ScatteringMode::Specular)
clamp_contribution(value, m_params.m_path_tracing_has_max_ray_intensity);

// Update path radiance.
m_path_radiance.add_emission(
vertex.m_path_length,
vertex.m_aov_mode,
value);
}

// Can't look up the environment if there's no environment EDF.
if (m_env_edf == nullptr)
return;
Expand Down
31 changes: 31 additions & 0 deletions src/appleseed/renderer/kernel/shading/shadingengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@
// appleseed.renderer headers.
#include "renderer/kernel/aov/aovaccumulator.h"
#include "renderer/kernel/aov/aovcomponents.h"

#include "renderer/kernel/lighting/ilightingengine.h"
#include "renderer/kernel/shading/closures.h"
#include "renderer/kernel/shading/shadingcomponents.h"
#include "renderer/kernel/shading/shadingcontext.h"
#include "renderer/kernel/shading/shadingray.h"
#include "renderer/kernel/shading/shadingresult.h"
#include "renderer/modeling/color/colorspace.h"
#include "renderer/modeling/environment/environment.h"
#include "renderer/modeling/environmentshader/environmentshader.h"
#include "renderer/modeling/input/source.h"
#include "renderer/modeling/light/light.h"
#include "renderer/modeling/material/material.h"
#include "renderer/modeling/object/object.h"
#include "renderer/modeling/scene/assembly.h"
Expand Down Expand Up @@ -208,6 +212,33 @@ bool ShadingEngine::shade_hit_point(
return false;
}

void ShadingEngine::shade_light(
SamplingContext& sampling_context,
const PixelContext& pixel_context,
const ShadingContext& shading_context,
const ShadingPoint& shading_point,
AOVAccumulatorContainer& aov_accumulators,
ShadingResult& shading_result) const
{
ShadingComponents radiance;
AOVComponents aov_components;
Spectrum value;

for (Light& light : shading_point.get_scene().assembly_instances().begin()->get_assembly().lights())
{
Light* light_ptr = &light;
light_ptr->evaluate(
shading_context,
normalize(shading_point.get_ray().m_dir),
value);

radiance.m_emission = value;
}

Spectrum temp = radiance.m_emission;
shading_result.m_main.rgb() += temp.illuminance_to_rgb(g_std_lighting_conditions);
}

void ShadingEngine::shade_environment(
SamplingContext& sampling_context,
const PixelContext& pixel_context,
Expand Down
15 changes: 15 additions & 0 deletions src/appleseed/renderer/kernel/shading/shadingengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ class ShadingEngine
AOVAccumulatorContainer& aov_accumulators,
ShadingResult& shading_result) const;

void shade_light(
SamplingContext& sampling_context,
const PixelContext& pixel_context,
const ShadingContext& shading_context,
const ShadingPoint& shading_point,
AOVAccumulatorContainer& aov_accumulators,
ShadingResult& shading_result) const;

void shade_environment(
SamplingContext& sampling_context,
const PixelContext& pixel_context,
Expand Down Expand Up @@ -139,6 +147,13 @@ inline bool ShadingEngine::shade(
shading_point,
aov_accumulators,
shading_result);
shade_light(
sampling_context,
pixel_context,
shading_context,
shading_point,
aov_accumulators,
shading_result);
return true;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/appleseed/renderer/modeling/light/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,11 @@ void Light::sample(
probability);
}

void Light::evaluate(
const ShadingContext& shading_context,
const Vector3d& outgoing,
Spectrum& value) const
{
}

} // namespace renderer
6 changes: 6 additions & 0 deletions src/appleseed/renderer/modeling/light/light.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class APPLESEED_DLLSYMBOL Light
CastShadows = 1UL << 0, // does this light cast shadows?
CastIndirectLight = 1UL << 1, // does this light generate indirect lighting?
LightTreeCompatible = 1UL << 2, // can this light be used by the LightTree?
HasPhysicalShape = 1UL << 3, // can this light be used by the LightTree?
};

// Retrieve the flags.
Expand Down Expand Up @@ -130,6 +131,11 @@ class APPLESEED_DLLSYMBOL Light
Spectrum& value, // light value
float& probability) const; // PDF value

virtual void evaluate(
const ShadingContext& shading_context,
const foundation::Vector3d& outgoing,
Spectrum& value) const;

// Compute the distance attenuation of this light.
virtual float compute_distance_attenuation(
const foundation::Vector3d& target, // world space target point
Expand Down
Loading

0 comments on commit 046aa51

Please sign in to comment.