Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shadow.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_SHADOW_H_)
21 #define __MITSUBA_HW_SHADOW_H_
22 
23 #include <mitsuba/hw/gpuprogram.h>
24 
26 
27 /** \brief Utility class for creating different kinds of shadow maps (cube,
28  * directional, and paraboloid shadow maps) using hardware rasterization
29  *
30  * \ingroup libhw
31  */
33 public:
35  /// Directional (orthographic) shadow map
36  EDirectional = 0,
37 
38  /// Nonlinear paraboloid shadow map (captures one hemisphere)
40 
41  /// Omnidirectional shadow map, 6 passes
43 
44  /// Omnidirectional shadow map, 1 pass with geometry shader
46 
47  /// Hemispherical cube shadow map, 5 passes
49 
50  /// Hemispherical cube shadow map, 1 pass with geometry shader
52 
53  /// Unused
54  ETypeCount
55  };
56 
57  /// Create a new shadow map generator
58  ShadowMapGenerator(Renderer *renderer);
59 
60  /// Register the associated GPU programs
61  void init();
62 
63  /**
64  * \brief Allocate a texture that is suitable for storing
65  * the requested type of shadow map and return it
66  */
67  ref<GPUTexture> allocate(Renderer *renderer,
68  EShadowMapType type, int resolution);
69 
70  /**
71  * \brief Render a shadow map using the desired technique
72  *
73  * \param renderer
74  * Underlying \ref Renderer instance
75  * \param shadowMap
76  * Target texture, which was previously created using \ref allocate()
77  * \param type
78  * Desired shadow map type
79  * \param trafo
80  * View transformation of the source
81  */
82  void render(Renderer *renderer, GPUTexture *shadowMap, EShadowMapType type,
83  const Transform &trafo, Float minDepth, Float maxDepth,
84  const std::vector<Renderer::TransformedGPUGeometry> &geo);
85 
86  /**
87  * \brief Convenience function for computing a transformation that
88  * is suitable for creating a directional shadow map
89  *
90  * \param aabb
91  * Axis-aligned bounding box of the world-space content that
92  * should be covered
93  *
94  * \param d
95  * Viewing direction of the shadow map
96  */
97  Transform directionalFindGoodFrame(const AABB &aabb, const Vector &d) const;
98 
99  /// Release allocated resources
100  void cleanup();
101 
102  /// Return the number of resident shaders
103  size_t getShaderCount() const;
104 
106 protected:
107  /// Virtual destructor
108  virtual ~ShadowMapGenerator() { }
109 protected:
110  ref<GPUProgram> m_program[ETypeCount];
112 
113  /* Cached parameter indices (ECube) */
116 
117  /* Cached parameter indices (ECubeSinglePass) */
118  int m_cubeSinglePassTransform[6];
119  int m_cubeSinglePassProjDir[6];
120 
121  /* Cached parameter indices (EHemicubeSinglePass) */
122  int m_hemicubeSinglePassTransform[5];
123  int m_hemicubeSinglePassProjDir[5];
124 
125  /* Cached parameter indices (EParaboloid) */
128 };
129 
131 
132 #endif /* __MITSUBA_HW_SHADOW_H_ */
Utility class for creating different kinds of shadow maps (cube, directional, and paraboloid shadow m...
Definition: shadow.h:32
#define MTS_EXPORT_HW
Definition: platform.h:114
int m_cubeProjDir
Definition: shadow.h:115
Omnidirectional shadow map, 1 pass with geometry shader.
Definition: shadow.h:45
int m_paraboloidMinDepth
Definition: shadow.h:126
Hemispherical cube shadow map, 5 passes.
Definition: shadow.h:48
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Hemispherical cube shadow map, 1 pass with geometry shader.
Definition: shadow.h:51
Axis-aligned bounding box data structure in three dimensions.
Definition: aabb.h:437
bool m_cubeDepthMapsSupported
Definition: shadow.h:111
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
int m_paraboloidInvDepthRange
Definition: shadow.h:127
Reference counting helper.
Definition: ref.h:40
Omnidirectional shadow map, 6 passes.
Definition: shadow.h:42
Encapsulates a 4x4 linear transformation and its inverse.
Definition: transform.h:33
Abstract renderer implementation.
Definition: renderer.h:79
A data structure for 1/2/3D and cube texture mapping. Also has optional render-to-texture functionali...
Definition: gputexture.h:32
Definition: fwd.h:96
Nonlinear paraboloid shadow map (captures one hemisphere)
Definition: shadow.h:39
Parent of all Mitsuba classes.
Definition: object.h:38
EShadowMapType
Definition: shadow.h:34
int m_cubeTransform
Definition: shadow.h:114
#define MTS_NAMESPACE_END
Definition: platform.h:138