Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
basicshader.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_HW_BASICSHADER_H_)
21 #define __MITSUBA_HW_BASICSHADER_H_
22 
23 #include <mitsuba/render/texture.h>
24 #include <mitsuba/hw/gpuprogram.h>
25 
27 
28 /* ============================================================ */
29 /* Some vary basic texture and shader definitions */
30 /* These classes are in libhw instead of librender, since */
31 /* they link to some functions in libhw. */
32 /* ============================================================ */
33 
34 /**
35  * \brief Constant spectrum-valued texture
36  *
37  * Includes a \ref Shader implementation for hardware rendering
38  * \ingroup libhw
39  */
41 public:
42  inline ConstantSpectrumTexture(const Spectrum &value)
43  : Texture(Properties()), m_value(value) {
44  }
45 
47 
48  inline Spectrum eval(const Intersection &its, bool /* unused */) const {
49  return m_value;
50  }
51 
52  inline Spectrum getAverage() const {
53  return m_value;
54  }
55 
56  inline Spectrum getMaximum() const {
57  return m_value;
58  }
59 
60  inline Spectrum getMinimum() const {
61  return m_value;
62  }
63 
64  inline bool isConstant() const {
65  return true;
66  }
67 
68  inline std::string toString() const {
69  return m_value.toString();
70  }
71 
72  inline bool usesRayDifferentials() const {
73  return false;
74  }
75 
76  inline bool isMonochromatic() const {
77  return m_value == Spectrum(m_value[0]);
78  }
79 
80  Shader *createShader(Renderer *renderer) const;
81 
82  ref<Bitmap> getBitmap(const Vector2i &resolutionHint) const;
83 
84  void serialize(Stream *stream, InstanceManager *manager) const;
85 
87 protected:
88  Spectrum m_value;
89 };
90 
91 /**
92  * \brief Constant float-valued texture
93  *
94  * Includes a \ref Shader implementation for hardware rendering
95  * \ingroup libhw
96  */
98 public:
99  inline ConstantFloatTexture(const Float &value)
100  : Texture(Properties()), m_value(value) {
101  }
102 
103  ConstantFloatTexture(Stream *stream, InstanceManager *manager);
104 
105  inline Spectrum eval(const Intersection &its, bool /* unused */) const {
106  return Spectrum(m_value);
107  }
108 
109  inline Spectrum getAverage() const {
110  return Spectrum(m_value);
111  }
112 
113  inline Spectrum getMaximum() const {
114  return Spectrum(m_value);
115  }
116 
117  inline Spectrum getMinimum() const {
118  return Spectrum(m_value);
119  }
120 
121  inline bool isConstant() const {
122  return true;
123  }
124 
125  inline std::string toString() const {
126  std::ostringstream oss;
127  oss << m_value;
128  return oss.str();
129  }
130 
131  inline bool usesRayDifferentials() const {
132  return false;
133  }
134 
135  inline bool isMonochromatic() const {
136  return true;
137  }
138 
139  Shader *createShader(Renderer *renderer) const;
140 
141  ref<Bitmap> getBitmap(const Vector2i &resolutionHint) const;
142 
143  void serialize(Stream *stream, InstanceManager *manager) const;
144 
146 protected:
147  Float m_value;
148 };
149 
150 /**
151  * \brief Componentwise addition of two textures
152  *
153  * Includes a \ref Shader implementation for hardware rendering
154  * \ingroup libhw
155  */
156 class MTS_EXPORT_HW SpectrumAdditionTexture : public Texture {
157 public:
158  inline SpectrumAdditionTexture(const Texture *a, const Texture *b)
159  : Texture(Properties()), m_a(a), m_b(b) { }
160 
162 
163  inline Spectrum eval(const Intersection &its, bool /* unused */) const {
164  return m_a->eval(its) + m_b->eval(its);
165  }
166 
167  inline Spectrum getAverage() const {
168  return m_a->getAverage() + m_b->getAverage();
169  }
170 
171  inline Spectrum getMaximum() const {
172  // Return a conservative estimate
173  return m_a->getMaximum() + m_b->getMaximum();
174  }
175 
176  inline Spectrum getMinimum() const {
177  // Return a conservative estimate
178  return m_a->getMinimum() + m_b->getMinimum();
179  }
180 
181  inline bool isConstant() const {
182  return m_a->isConstant() && m_b->isConstant();
183  }
184 
185  inline std::string toString() const {
186  std::ostringstream oss;
187  oss << "SpectrumAdditionTexture[" << endl
188  << " a = " << indent(m_a->toString()) << "," << endl
189  << " b = " << indent(m_a->toString()) << endl
190  << "]";
191  return oss.str();
192  }
193 
194  inline bool usesRayDifferentials() const {
195  return m_a->usesRayDifferentials() || m_b->usesRayDifferentials();
196  }
197 
198  inline bool isMonochromatic() const {
199  return m_a->isMonochromatic() && m_b->isMonochromatic();
200  }
201 
202  Shader *createShader(Renderer *renderer) const;
203 
204  ref<Bitmap> getBitmap(const Vector2i &resolutionHint) const;
205 
206  void serialize(Stream *stream, InstanceManager *manager) const;
207 
209 protected:
210  ref<const Texture> m_a, m_b;
211 };
212 
213 /**
214  * \brief Componentwise subtraction of two textures
215  *
216  * Includes a \ref Shader implementation for hardware rendering
217  * \ingroup libhw
218  */
220 public:
221  inline SpectrumSubtractionTexture(const Texture *a, const Texture *b)
222  : Texture(Properties()), m_a(a), m_b(b) { }
223 
225 
226  inline Spectrum eval(const Intersection &its, bool /* unused */) const {
227  return m_a->eval(its) - m_b->eval(its);
228  }
229 
230  inline Spectrum getAverage() const {
231  return m_a->getAverage() - m_b->getAverage();
232  }
233 
234  inline Spectrum getMaximum() const {
235  // Return a conservative estimate
236  return m_a->getMaximum() - m_b->getMinimum();
237  }
238 
239  inline Spectrum getMinimum() const {
240  // Return a conservative estimate
241  return m_a->getMinimum() - m_b->getMaximum();
242  }
243 
244  inline bool isConstant() const {
245  return m_a->isConstant() && m_b->isConstant();
246  }
247 
248  inline std::string toString() const {
249  std::ostringstream oss;
250  oss << "SpectrumSubtractionTexture[" << endl
251  << " a = " << indent(m_a->toString()) << "," << endl
252  << " b = " << indent(m_b->toString()) << endl
253  << "]";
254  return oss.str();
255  }
256 
257  inline bool usesRayDifferentials() const {
258  return m_a->usesRayDifferentials() || m_b->usesRayDifferentials();
259  }
260 
261  inline bool isMonochromatic() const {
262  return m_a->isMonochromatic() && m_b->isMonochromatic();
263  }
264 
265  Shader *createShader(Renderer *renderer) const;
266 
267  ref<Bitmap> getBitmap(const Vector2i &resolutionHint) const;
268 
269  void serialize(Stream *stream, InstanceManager *manager) const;
270 
272 protected:
273  ref<const Texture> m_a, m_b;
274 };
275 
276 /**
277  * \brief Componentwise product of two textures
278  *
279  * Includes a \ref Shader implementation for hardware rendering
280  * \ingroup libhw
281  */
282 class MTS_EXPORT_HW SpectrumProductTexture : public Texture {
283 public:
284  inline SpectrumProductTexture(const Texture *a, const Texture *b)
285  : Texture(Properties()), m_a(a), m_b(b) { }
286 
287  SpectrumProductTexture(Stream *stream, InstanceManager *manager);
288 
289  inline Spectrum eval(const Intersection &its, bool /* unused */) const {
290  return m_a->eval(its) * m_b->eval(its);
291  }
292 
293  inline Spectrum getAverage() const {
294  SLog(EError, "SpectrumProductTexture::getAverage() -- information unavailable!");
295  return Spectrum(0.0f);
296  }
297 
298  inline Spectrum getMaximum() const {
299  // Return a conservative estimate
300  return m_a->getMaximum() * m_b->getMaximum();
301  }
302 
303  inline Spectrum getMinimum() const {
304  // Return a conservative estimate
305  return m_a->getMinimum() * m_b->getMinimum();
306  }
307 
308  inline bool isConstant() const {
309  return m_a->isConstant() && m_b->isConstant();
310  }
311 
312  inline std::string toString() const {
313  std::ostringstream oss;
314  oss << "SpectrumProductTexture[" << endl
315  << " a = " << indent(m_a->toString()) << "," << endl
316  << " b = " << indent(m_b->toString()) << endl
317  << "]";
318  return oss.str();
319  }
320 
321  inline bool usesRayDifferentials() const {
322  return m_a->usesRayDifferentials() || m_b->usesRayDifferentials();
323  }
324 
325  inline bool isMonochromatic() const {
326  return m_a->isMonochromatic() && m_b->isMonochromatic();
327  }
328 
329  Shader *createShader(Renderer *renderer) const;
330 
331  void serialize(Stream *stream, InstanceManager *manager) const;
332 
333  ref<Bitmap> getBitmap(const Vector2i &resolutionHint) const;
334 
336 protected:
337  ref<const Texture> m_a, m_b;
338 };
339 
341 
342 #endif /* __MITSUBA_HW_BASICSHADER_H_ */
Spectrum getAverage() const
Return the component-wise average value of the texture over its domain.
Definition: basicshader.h:293
bool isConstant() const
Return whether the texture takes on a constant value everywhere.
Definition: basicshader.h:308
Componentwise product of two textures.
Definition: basicshader.h:282
Componentwise addition of two textures.
Definition: basicshader.h:156
std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
Definition: basicshader.h:312
bool isMonochromatic() const
Return whether the texture is monochromatic / spectrally uniform.
Definition: basicshader.h:325
Shader base class for use with a VPL-style renderer.
Definition: shader.h:54
virtual void serialize(Stream *stream, InstanceManager *manager) const
Serialize to a binary data stream.
Spectrum getMinimum() const
Return the component-wise minimum of the texture over its domain.
Definition: basicshader.h:239
Constant float-valued texture.
Definition: basicshader.h:97
Spectrum getMinimum() const
Return the component-wise minimum of the texture over its domain.
Definition: basicshader.h:117
#define MTS_EXPORT_HW
Definition: platform.h:114
Spectrum getAverage() const
Return the component-wise average value of the texture over its domain.
Definition: basicshader.h:52
bool isConstant() const
Return whether the texture takes on a constant value everywhere.
Definition: basicshader.h:181
MTS_EXPORT_CORE std::string indent(const std::string &string, int amount=1)
Indent a string (Used for recursive toString() structure dumping)
Base class of all textures. Computes values for an arbitrary surface point. Texture2D is a specializa...
Definition: texture.h:34
SpectrumAdditionTexture(const Texture *a, const Texture *b)
Definition: basicshader.h:158
Componentwise subtraction of two textures.
Definition: basicshader.h:219
std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
Definition: basicshader.h:248
#define SLog(level, fmt,...)
Write a Log message to the console (static version - to be used outside of classes that derive from O...
Definition: logger.h:49
bool usesRayDifferentials() const
Does this texture perform any pre-filtering when ray differentials are available? ...
Definition: basicshader.h:321
virtual Shader * createShader(Renderer *renderer) const
virtual ref< Bitmap > getBitmap(const Vector2i &sizeHint=Vector2i(-1,-1)) const
Return a bitmap representation of the texture.
Spectrum getMaximum() const
Return the component-wise maximum of the texture over its domain.
Definition: basicshader.h:171
bool isMonochromatic() const
Return whether the texture is monochromatic / spectrally uniform.
Definition: basicshader.h:198
bool isConstant() const
Return whether the texture takes on a constant value everywhere.
Definition: basicshader.h:244
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Spectrum eval(const Intersection &its, bool) const
Return the texture value at its.
Definition: basicshader.h:105
ConstantFloatTexture(const Float &value)
Definition: basicshader.h:99
Float eval(Float lambda) const
Evaluate the SPD for the given wavelength in nanometers.
Spectrum getMaximum() const
Return the component-wise maximum of the texture over its domain.
Definition: basicshader.h:234
Spectrum getMinimum() const
Return the component-wise minimum of the texture over its domain.
Definition: basicshader.h:303
SpectrumProductTexture(const Texture *a, const Texture *b)
Definition: basicshader.h:284
bool usesRayDifferentials() const
Does this texture perform any pre-filtering when ray differentials are available? ...
Definition: basicshader.h:131
std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
Definition: basicshader.h:68
Spectrum eval(const Intersection &its, bool) const
Return the texture value at its.
Definition: basicshader.h:48
Spectrum getMaximum() const
Return the component-wise maximum of the texture over its domain.
Definition: basicshader.h:113
Spectrum getMinimum() const
Return the component-wise minimum of the texture over its domain.
Definition: basicshader.h:60
bool usesRayDifferentials() const
Does this texture perform any pre-filtering when ray differentials are available? ...
Definition: basicshader.h:194
Abstract seekable stream class.
Definition: stream.h:58
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Reference counting helper.
Definition: ref.h:40
bool isConstant() const
Return whether the texture takes on a constant value everywhere.
Definition: basicshader.h:121
std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
Definition: basicshader.h:185
ConstantSpectrumTexture(const Spectrum &value)
Definition: basicshader.h:42
Spectrum getMaximum() const
Return the component-wise maximum of the texture over its domain.
Definition: basicshader.h:298
Abstract renderer implementation.
Definition: renderer.h:79
Error message, causes an exception to be thrown.
Definition: formatter.h:33
SpectrumSubtractionTexture(const Texture *a, const Texture *b)
Definition: basicshader.h:221
bool isMonochromatic() const
Return whether the texture is monochromatic / spectrally uniform.
Definition: basicshader.h:261
bool usesRayDifferentials() const
Does this texture perform any pre-filtering when ray differentials are available? ...
Definition: basicshader.h:257
Spectrum getAverage() const
Return the component-wise average value of the texture over its domain.
Definition: basicshader.h:230
Associative parameter map for constructing subclasses of ConfigurableObject.
Definition: properties.h:46
Container for all information related to a surface intersection.
Definition: shape.h:36
Coordinates the serialization and unserialization of object graphs.
Definition: serialization.h:65
Spectrum eval(const Intersection &its, bool) const
Return the texture value at its.
Definition: basicshader.h:289
Discrete spectral power distribution based on a number of wavelength bins over the 360-830 nm range...
Definition: spectrum.h:663
bool isMonochromatic() const
Return whether the texture is monochromatic / spectrally uniform.
Definition: basicshader.h:135
Spectrum eval(const Intersection &its, bool) const
Return the texture value at its.
Definition: basicshader.h:163
std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
Definition: basicshader.h:125
Spectrum getMaximum() const
Return the component-wise maximum of the texture over its domain.
Definition: basicshader.h:56
bool isMonochromatic() const
Return whether the texture is monochromatic / spectrally uniform.
Definition: basicshader.h:76
Spectrum eval(const Intersection &its, bool) const
Return the texture value at its.
Definition: basicshader.h:226
Definition: fwd.h:95
bool isConstant() const
Return whether the texture takes on a constant value everywhere.
Definition: basicshader.h:64
Spectrum getAverage() const
Return the component-wise average value of the texture over its domain.
Definition: basicshader.h:167
#define MTS_NAMESPACE_END
Definition: platform.h:138
Spectrum getAverage() const
Return the component-wise average value of the texture over its domain.
Definition: basicshader.h:109
bool usesRayDifferentials() const
Does this texture perform any pre-filtering when ray differentials are available? ...
Definition: basicshader.h:72
Spectrum getMinimum() const
Return the component-wise minimum of the texture over its domain.
Definition: basicshader.h:176
Constant spectrum-valued texture.
Definition: basicshader.h:40