forked from mitsuba-renderer/mitsuba
-
Notifications
You must be signed in to change notification settings - Fork 5
/
integrator2.h
188 lines (157 loc) · 6.76 KB
/
integrator2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
This file is part of Mitsuba, a physically based rendering system.
Copyright (c) 2007-2014 by Wenzel Jakob and others.
Mitsuba is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License Version 3
as published by the Free Software Foundation.
Mitsuba is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#if !defined(__MITSUBA_RENDER_INTEGRATOR2_H_)
#define __MITSUBA_RENDER_INTEGRATOR2_H_
#include <mitsuba/core/object.h>
#include <mitsuba/core/properties.h>
#include <mitsuba/render/shape.h>
MTS_NAMESPACE_BEGIN
/**
* \brief Abstract integrator base-class; does not make any assumptions on
* how radiance is computed.
*
* In Mitsuba, the different rendering techniques are collectively referred to as
* \a integrators, since they perform integration over a high-dimensional
* space. Each integrator represents a specific approach for solving
* the light transport equation---usually favored in certain scenarios, but
* at the same time affected by its own set of intrinsic limitations.
* Therefore, it is important to carefully select an integrator based on
* user-specified accuracy requirements and properties of the scene to be
* rendered.
*
* This is the base class of all integrators; it does not make any assumptions on
* how radiance is computed, which allows for many different kinds of implementations
* ranging from software-based path tracing and Markov-Chain based techniques such
* as Metropolis Light Transport up to hardware-accelerated rasterization.
*
* \ingroup librender
*/
class MTS_EXPORT_RENDER ResponsiveIntegrator : public ConfigurableObject {
public:
class Interrupt;
struct Controls {
int volatile const* continu;
int volatile const* abort;
Interrupt* interrupt;
};
class Interrupt {
public:
virtual int progress(ResponsiveIntegrator* integrator, const Scene &scene, const Sensor &sensor, Sampler &sampler, ImageBlock& target, double spp
, Controls controls, int threadIdx, int threadCount) = 0;
};
/**
* \brief Possibly perform a pre-process task.
*
* This function is called automatically before the main rendering process;
* the default implementation does nothing.
*/
virtual bool preprocess(const Scene *scene, const Sensor* sensor, const Sampler* sampler);
/**
* \brief This function is called automatically before the first rendering process;
* the default implementation does nothing.
*/
virtual bool allocate(const Scene &scene, Sampler *const *samplers, ImageBlock *const *targets, int threadCount);
/**
* \brief Render the scene as seen by the given sensor (or default sensor, for some path-space algorithms).
*/
virtual int render(const Scene &scene, const Sensor &sensor, Sampler &sampler, ImageBlock& target
, Controls controls, int threadIdx, int threadCount) = 0;
/**
* \brief Lower bound for the amount of undersampling within one pixel (1 is default, as for independent samplers).
* Correlated samplers might set this to 0 when they generate meaningful information at lower rates than 1 spp.
*/
virtual Float getLowerSampleBound() const;
/**
* \brief Real-time statistics, nullptr by default.
*/
virtual char const* getRealtimeStatistics();
MTS_DECLARE_CLASS()
/// Create a integrator
ResponsiveIntegrator(const Properties &props);
/// Virtual destructor
virtual ~ResponsiveIntegrator();
};
/** \brief Abstract base class, which describes integrators scheduled per pixel.
* \ingroup librender
*/
class MTS_EXPORT_RENDER ImageOrderIntegrator : public ResponsiveIntegrator {
public:
/**
* \brief Render the scene as seen by the given sensor (or default sensor, for some path-space algorithms).
*/
virtual int render(const Scene &scene, const Sensor &sensor, Sampler &sampler
, ImageBlock& target, Point2i pixel, int threadIdx, int threadCount, void* userData) = 0;
// prepare px permutation
bool allocate(const Scene &scene, Sampler *const *samplers, ImageBlock *const *targets, int threadCount) override;
// redirect through px permutation
int render(const Scene &scene, const Sensor &sensor, Sampler &sampler, ImageBlock& target
, Controls controls, int threadIdx, int threadCount) override;
MTS_DECLARE_CLASS()
/// Create a integrator
ImageOrderIntegrator(const Properties &props);
/// Virtual destructor
virtual ~ImageOrderIntegrator();
protected:
/**
* \brief Actual render loop, for derived classes to call with additional data.
*/
int render(const Scene &scene, const Sensor &sensor, Sampler &sampler, ImageBlock& target
, Controls controls, int threadIdx, int threadCount, void* userData);
std::vector<int> m_pxPermutation;
};
struct PixelSample {
RayDifferential ray;
Point2 point;
Float time;
};
struct PixelDifferential {
Float scale;
MTS_EXPORT_RENDER PixelDifferential(int sampleCount);
MTS_EXPORT_RENDER Spectrum sample(PixelSample& sample, Sensor const& sensor, Point2i px, Sampler& sampler);
};
/*
* \brief Wrapper class of all recursive Monte Carlo integrators implemented in classic
* mitsuba, which compute unbiased solutions to the rendering equation (and optionally
* the radiative transfer equation).
* \ingroup librender
*/
class MTS_EXPORT_RENDER ClassicSamplingIntegrator : public ImageOrderIntegrator {
public:
struct MTS_EXPORT_RENDER SchedulerResourceContext {
int sceneID;
int sensorID;
int samplerID;
ref<Scheduler> scheduler;
SchedulerResourceContext(const Scene *scene, const Sensor* sensor, const Sampler* sampler);
~SchedulerResourceContext();
};
bool allocate(const Scene &scene, Sampler *const *samplers, ImageBlock *const *targets, int threadCount) override;
bool preprocess(const Scene *scene, const Sensor* sensor, const Sampler* sampler) override;
using ImageOrderIntegrator::render;
int render(const Scene &scene, const Sensor &sensor, Sampler &sampler
, ImageBlock& target, Point2i pixel, int threadIdx, int threadCount, void* userData) override;
// utility function for derived classes using mutable classic integrators
int render(SamplingIntegrator& threadLocalIntegrator, const Scene &scene, const Sensor &sensor, Sampler &sampler
, ImageBlock& target, Point2i pixel, int threadIdx, int threadCount);
MTS_DECLARE_CLASS()
/// Create a integrator
ClassicSamplingIntegrator(SamplingIntegrator* classic, const Properties &props);
/// Virtual destructor
virtual ~ClassicSamplingIntegrator();
ref<SamplingIntegrator> classicIntegrator;
PixelDifferential pixelDifferential;
};
MTS_NAMESPACE_END
#endif /* __MITSUBA_RENDER_INTEGRATOR_H_ */