1- #include < mitsuba/render/texture.h>
2- #include < mitsuba/render/interaction.h>
31#include < mitsuba/core/properties.h>
2+ #include < mitsuba/render/interaction.h>
3+ #include < mitsuba/render/texture.h>
44
55NAMESPACE_BEGIN (mitsuba)
66
@@ -11,7 +11,8 @@ NAMESPACE_BEGIN(mitsuba)
1111Uniform spectrum (:monosp:`uniform`)
1212------------------------------------
1313
14- This spectrum returns a constant reflectance or emission value between 360 and 830nm.
14+ This spectrum returns a constant reflectance or emission value between 360 and
15+ 830nm.
1516
1617 */
1718
@@ -20,26 +21,40 @@ class UniformSpectrum final : public Texture<Float, Spectrum> {
2021public:
2122 MTS_IMPORT_TYPES (Texture)
2223
23- UniformSpectrum (const Properties &props) : Texture (props) {
24- m_value = props.float_ (" value" );
24+ UniformSpectrum (const Properties &props)
25+ : Texture (props), m_value (1 .f ), m_lambda_min (MTS_WAVELENGTH_MIN),
26+ m_lambda_max (MTS_WAVELENGTH_MAX) {
27+ if (props.has_property (" value" ))
28+ m_value = props.float_ (" value" );
29+
30+ if (props.has_property (" lambda_min" ))
31+ m_lambda_min = max (props.float_ (" lambda_min" ), MTS_WAVELENGTH_MIN);
32+
33+ if (props.has_property (" lambda_max" ))
34+ m_lambda_max = min (props.float_ (" lambda_max" ), MTS_WAVELENGTH_MAX);
35+
36+ if (!(m_lambda_min < m_lambda_max))
37+ Throw (
38+ " UniformSpectrum: 'lambda_min' must be less than 'lambda_max'" );
2539 }
2640
2741 UnpolarizedSpectrum eval (const SurfaceInteraction3f &si,
2842 Mask active) const override {
2943 MTS_MASKED_FUNCTION (ProfilerPhase::TextureEvaluate, active);
3044
3145 if constexpr (is_spectral_v<Spectrum>) {
32- auto active_w = (si.wavelengths >= MTS_WAVELENGTH_MIN ) &&
33- (si.wavelengths <= MTS_WAVELENGTH_MAX );
46+ auto active_w = (si.wavelengths >= m_lambda_min ) &&
47+ (si.wavelengths <= m_lambda_max );
3448
3549 return select (active_w, UnpolarizedSpectrum (m_value),
36- UnpolarizedSpectrum (0 .f ));
50+ UnpolarizedSpectrum (0 .f ));
3751 } else {
3852 return m_value;
3953 }
4054 }
4155
42- Float eval_1 (const SurfaceInteraction3f & /* it */ , Mask active) const override {
56+ Float eval_1 (const SurfaceInteraction3f & /* it */ ,
57+ Mask active) const override {
4358 MTS_MASKED_FUNCTION (ProfilerPhase::TextureEvaluate, active);
4459 return m_value;
4560 }
@@ -48,24 +63,25 @@ class UniformSpectrum final : public Texture<Float, Spectrum> {
4863 MTS_MASKED_FUNCTION (ProfilerPhase::TextureEvaluate, active);
4964
5065 if constexpr (is_spectral_v<Spectrum>) {
51- auto active_w = (si.wavelengths >= MTS_WAVELENGTH_MIN ) &&
52- (si.wavelengths <= MTS_WAVELENGTH_MAX );
66+ auto active_w = (si.wavelengths >= m_lambda_min ) &&
67+ (si.wavelengths <= m_lambda_max );
5368
5469 return select (active_w,
55- Wavelength (1 .f / (MTS_WAVELENGTH_MAX - MTS_WAVELENGTH_MIN)), Wavelength (0 .f ));
70+ Wavelength (1 .f / (m_lambda_max - m_lambda_min)),
71+ Wavelength (0 .f ));
5672 } else {
5773 NotImplementedError (" pdf" );
5874 }
5975 }
6076
61- std::pair<Wavelength, UnpolarizedSpectrum> sample ( const SurfaceInteraction3f & /* si */ ,
62- const Wavelength &sample,
63- Mask active) const override {
77+ std::pair<Wavelength, UnpolarizedSpectrum>
78+ sample ( const SurfaceInteraction3f & /* si */ , const Wavelength &sample,
79+ Mask active) const override {
6480 MTS_MASKED_FUNCTION (ProfilerPhase::TextureSample, active);
6581
6682 if constexpr (is_spectral_v<Spectrum>) {
67- return { MTS_WAVELENGTH_MIN + (MTS_WAVELENGTH_MAX - MTS_WAVELENGTH_MIN ) * sample,
68- m_value * (MTS_WAVELENGTH_MAX - MTS_WAVELENGTH_MIN ) };
83+ return { m_lambda_min + (m_lambda_max - m_lambda_min ) * sample,
84+ m_value * (m_lambda_max - m_lambda_min ) };
6985 } else {
7086 ENOKI_MARK_USED (sample);
7187 NotImplementedError (" sample" );
@@ -76,15 +92,25 @@ class UniformSpectrum final : public Texture<Float, Spectrum> {
7692
7793 void traverse (TraversalCallback *callback) override {
7894 callback->put_parameter (" value" , m_value);
95+ callback->put_parameter (" value" , m_lambda_min);
96+ callback->put_parameter (" value" , m_lambda_max);
7997 }
8098
8199 std::string to_string () const override {
82- return tfm::format (" UniformSpectrum[value=%f]" , m_value);
100+ std::ostringstream oss;
101+ oss << " UniformSpectrum[" << std::endl
102+ << " value = " << m_value << std::endl
103+ << " lambda_min = " << m_lambda_min << std::endl
104+ << " lambda_max = " << m_lambda_max << std::endl
105+ << " ]" ;
106+ return oss.str ();
83107 }
84108
85109 MTS_DECLARE_CLASS ()
86110private:
87111 Float m_value;
112+ ScalarFloat m_lambda_min;
113+ ScalarFloat m_lambda_max;
88114};
89115
90116MTS_IMPLEMENT_CLASS_VARIANT (UniformSpectrum, Texture)
0 commit comments