1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkShadowMapPass.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME vtkShadowMapPass - Implement a shadow mapping render pass.
16 // .SECTION Description
17 // Render the opaque polygonal geometry of a scene with shadow maps (a
18 // technique to render hard shadows in hardware).
19 //
20 // This pass expects an initialized depth buffer and color buffer.
21 // Initialized buffers means they have been cleared with farest z-value and
22 // background color/gradient/transparent color.
23 // An opaque pass may have been performed right after the initialization.
24 //
25 //
26 //
27 // Its delegate is usually set to a vtkOpaquePass.
28 //
29 // .SECTION Implementation
30 // The first pass of the algorithm is to generate a shadow map per light
31 // (depth map from the light point of view) by rendering the opaque objects
32 // with the OCCLUDER property keys.
33 // The second pass is to render the opaque objects with the RECEIVER keys.
34 //
35 // .SECTION See Also
36 // vtkRenderPass, vtkOpaquePass
37 
38 #ifndef vtkShadowMapPass_h
39 #define vtkShadowMapPass_h
40 
41 #include "vtkRenderingOpenGLModule.h" // For export macro
42 #include "vtkRenderPass.h"
43 
44 class vtkOpenGLRenderWindow;
45 class vtkInformationIntegerKey;
46 class vtkCamera;
47 class vtkLight;
48 class vtkFrameBufferObject;
49 class vtkShadowMapPassTextures; // internal
50 class vtkShadowMapPassLightCameras; // internal
51 class vtkShaderProgram2;
52 class vtkImageExport;
53 class vtkTextureObject;
54 class vtkImplicitHalo;
55 class vtkSampleFunction;
56 class vtkShadowMapBakerPass;
57 
58 class VTKRENDERINGOPENGL_EXPORT vtkShadowMapPass : public vtkRenderPass
59 {
60 public:
61   static vtkShadowMapPass *New();
62   vtkTypeMacro(vtkShadowMapPass,vtkRenderPass);
63   void PrintSelf(ostream& os, vtkIndent indent);
64 
65   //BTX
66   // Description:
67   // Perform rendering according to a render state \p s.
68   // \pre s_exists: s!=0
69   virtual void Render(const vtkRenderState *s);
70   //ETX
71 
72   // Description:
73   // Release graphics resources and ask components to release their own
74   // resources.
75   // \pre w_exists: w!=0
76   void ReleaseGraphicsResources(vtkWindow *w);
77 
78   // Description:
79   // Pass that generates the shadow maps.
80   // the vtkShadowMapPass will use the Resolution ivar of
81   // this pass.
82   // Initial value is a NULL pointer.
83   vtkGetObjectMacro(ShadowMapBakerPass,vtkShadowMapBakerPass);
84   virtual void SetShadowMapBakerPass(
85     vtkShadowMapBakerPass *shadowMapBakerPass);
86 
87   // Description:
88   // Pass that render the opaque geometry, with no camera pass (otherwise
89   // it does not work with Ice-T).
90   // Initial value is a NULL pointer.
91   // Typically a sequence pass with a light pass and opaque pass.
92   // This should be the Opaque pass of the vtkShadowMapBakerPass without the
93   // vtkCameraPass.
94   vtkGetObjectMacro(OpaquePass,vtkRenderPass);
95   virtual void SetOpaquePass(vtkRenderPass *opaquePass);
96 
97  protected:
98   // Description:
99   // Default constructor. DelegatetPass is set to NULL.
100   vtkShadowMapPass();
101 
102   // Description:
103   // Destructor.
104   virtual ~vtkShadowMapPass();
105 
106   // Description:
107   // Build the intensity map.
108   void BuildSpotLightIntensityMap();
109 
110   // Description:
111   // Check if shadow mapping is supported by the current OpenGL context.
112   // \pre w_exists: w!=0
113   void CheckSupport(vtkOpenGLRenderWindow *w);
114 
115   vtkShadowMapBakerPass *ShadowMapBakerPass;
116   vtkRenderPass *CompositeRGBAPass;
117 
118   vtkRenderPass *OpaquePass;
119 
120   // Description:
121   // Graphics resources.
122   vtkFrameBufferObject *FrameBufferObject;
123 
124   vtkShadowMapPassTextures *ShadowMaps;
125   vtkShadowMapPassLightCameras *LightCameras;
126   vtkShaderProgram2 *Program;
127 
128   vtkTextureObject *IntensityMap;
129 
130   vtkSampleFunction *IntensitySource;
131   vtkImageExport *IntensityExporter;
132   vtkImplicitHalo *Halo;
133 
134   vtkTimeStamp LastRenderTime;
135 
136 private:
137   vtkShadowMapPass(const vtkShadowMapPass&);  // Not implemented.
138   void operator=(const vtkShadowMapPass&);  // Not implemented.
139 };
140 
141 #endif
142