Skip to content

Commit

Permalink
Added SRF to radiancemeter
Browse files Browse the repository at this point in the history
  • Loading branch information
leroyvn committed Jul 14, 2020
1 parent 3e3eddf commit 878b46d
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 105 deletions.
69 changes: 54 additions & 15 deletions src/sensors/radiancemeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <mitsuba/core/transform.h>
#include <mitsuba/render/fwd.h>
#include <mitsuba/render/sensor.h>
#include <mitsuba/render/texture.h>

NAMESPACE_BEGIN(mitsuba)

Expand Down Expand Up @@ -46,13 +47,23 @@ priority.
*/

MTS_VARIANT class RadianceMeter final : public Sensor<Float, Spectrum> {
template <typename Float, typename Spectrum>
class RadianceMeter final : public Sensor<Float, Spectrum> {
public:
MTS_IMPORT_BASE(Sensor, m_film, m_world_transform, m_needs_sample_2,
m_needs_sample_3)
MTS_IMPORT_TYPES()
MTS_IMPORT_TYPES(Texture)

RadianceMeter(const Properties &props) : Base(props), m_srf(nullptr) {
if (props.has_property("srf")) {
if constexpr(is_spectral_v<Spectrum>) {
m_srf = props.texture<Texture>("srf");
} else {
Log(Warn, "Ignoring spectral response function "
"(not supported for non-spectral variants)");
}
}

RadianceMeter(const Properties &props) : Base(props) {
if (props.has_property("to_world")) {
// if direction and origin are present but overridden by
// to_world, they must still be marked as queried
Expand Down Expand Up @@ -93,22 +104,34 @@ MTS_VARIANT class RadianceMeter final : public Sensor<Float, Spectrum> {
const Point2f & /*aperture_sample*/,
Mask active) const override {
MTS_MASKED_FUNCTION(ProfilerPhase::EndpointSampleRay, active);

// 1. Sample spectrum
Wavelength wavelengths;
Spectrum wav_weight;

if (m_srf == nullptr) {
std::tie(wavelengths, wav_weight) =
sample_wavelength<Float, Spectrum>(wavelength_sample);
} else {
std::tie(wavelengths, wav_weight) =
m_srf->sample_spectrum(
zero<SurfaceInteraction3f>(),
math::sample_shifted<Wavelength>(wavelength_sample)
);
}

// 2. Set ray origin and direction
Ray3f ray;
ray.time = time;

// 1. Sample spectrum
auto [wavelengths, wav_weight] =
sample_wavelength<Float, Spectrum>(wavelength_sample);
ray.wavelengths = wavelengths;

// 2. Set ray origin and direction
auto trafo = m_world_transform->eval(time, active);
ray.o = trafo.transform_affine(Point3f{ 0.f, 0.f, 0.f });
ray.d = trafo.transform_affine(Vector3f{ 0.f, 0.f, 1.f });

ray.update();

return std::make_pair(ray, wav_weight);
return { ray, wav_weight };
}

std::pair<RayDifferential3f, Spectrum>
Expand All @@ -117,15 +140,26 @@ MTS_VARIANT class RadianceMeter final : public Sensor<Float, Spectrum> {
const Point2f & /*aperture_sample*/,
Mask active) const override {
MTS_MASKED_FUNCTION(ProfilerPhase::EndpointSampleRay, active);
// 1. Sample spectrum
Wavelength wavelengths;
Spectrum wav_weight;

if (m_srf == nullptr) {
std::tie(wavelengths, wav_weight) =
sample_wavelength<Float, Spectrum>(wavelength_sample);
} else {
std::tie(wavelengths, wav_weight) =
m_srf->sample_spectrum(
zero<SurfaceInteraction3f>(),
math::sample_shifted<Wavelength>(wavelength_sample)
);
}

// 2. Set ray origin and direction
RayDifferential3f ray;
ray.time = time;

// 1. Sample spectrum
auto [wavelengths, wav_weight] =
sample_wavelength<Float, Spectrum>(wavelength_sample);
ray.wavelengths = wavelengths;

// 2. Set ray origin and direction
auto trafo = m_world_transform->eval(time, active);
ray.o = trafo.transform_affine(Point3f{ 0.f, 0.f, 0.f });
ray.d = trafo.transform_affine(Vector3f{ 0.f, 0.f, 1.f });
Expand All @@ -136,7 +170,7 @@ MTS_VARIANT class RadianceMeter final : public Sensor<Float, Spectrum> {

ray.update();

return std::make_pair(ray, wav_weight);
return { ray, wav_weight };
}

ScalarBoundingBox3f bbox() const override {
Expand All @@ -145,15 +179,20 @@ MTS_VARIANT class RadianceMeter final : public Sensor<Float, Spectrum> {
}

std::string to_string() const override {
using string::indent;

std::ostringstream oss;
oss << "RadianceMeter[" << std::endl
<< " world_transform = " << m_world_transform << "," << std::endl
<< " film = " << m_film << "," << std::endl
<< " srf = " << indent(m_srf) << std::endl
<< "]";
return oss.str();
}

MTS_DECLARE_CLASS()
private:
ref<Texture> m_srf;
};

MTS_IMPLEMENT_CLASS_VARIANT(RadianceMeter, Sensor)
Expand Down
Loading

0 comments on commit 878b46d

Please sign in to comment.