temp commit
[SARndbox.git] / SurfaceRenderer.h
blobf0038b37ec32139e343dd47ff557847798d0c158
1 /***********************************************************************
2 SurfaceRenderer - Class to render a surface defined by a regular grid in
3 depth image space.
4 Copyright (c) 2012-2018 Oliver Kreylos
6 This file is part of the Augmented Reality Sandbox (SARndbox).
8 The Augmented Reality Sandbox is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The Augmented Reality Sandbox is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with the Augmented Reality Sandbox; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ***********************************************************************/
23 #ifndef SURFACERENDERER_INCLUDED
24 #define SURFACERENDERER_INCLUDED
26 #include <IO/FileMonitor.h>
27 #include <Geometry/ProjectiveTransformation.h>
28 #include <Geometry/Plane.h>
29 #include <GL/gl.h>
30 #include <GL/Extensions/GLARBShaderObjects.h>
31 #include <GL/GLObject.h>
32 #include <Kinect/FrameBuffer.h>
34 #include "Types.h"
36 /* Forward declarations: */
37 class DepthImageRenderer;
38 class ElevationColorMap;
39 class GLLightTracker;
40 class DEM;
41 class WaterTable2;
43 class SurfaceRenderer: public GLObject {
44 /* Embedded classes: */
45 public:
46 typedef Geometry::Plane<GLfloat, 3> Plane; // Type for plane equations
48 private:
49 struct DataItem: public GLObject::DataItem {
50 /* Elements: */
51 public:
52 GLuint contourLineFramebufferSize[2]; // Current width and height of contour line rendering frame buffer
53 GLuint contourLineFramebufferObject; // Frame buffer object used to render topographic contour lines
54 GLuint contourLineDepthBufferObject; // Depth render buffer for topographic contour line frame buffer
55 GLuint contourLineColorTextureObject; // Color texture object for topographic contour line frame buffer
56 unsigned int contourLineVersion; // Version number of depth image used for contour line generation
57 GLhandleARB heightMapShader; // Shader program to render the surface using a height color map
58 GLint heightMapShaderUniforms[16]; // Locations of the height map shader's uniform variables
59 unsigned int
60 surfaceSettingsVersion; // Version number of surface settings for which the height map shader was built
61 unsigned int
62 lightTrackerVersion; // Version number of light tracker state for which the height map shader was built
63 GLhandleARB
64 globalAmbientHeightMapShader; // Shader program to render the global ambient component of the surface using a height color map
65 GLint globalAmbientHeightMapShaderUniforms[13]; // Locations of the global ambient height map shader's uniform variables
66 GLhandleARB
67 shadowedIlluminatedHeightMapShader; // Shader program to render the surface using illumination with shadows and a height color map
68 GLint shadowedIlluminatedHeightMapShaderUniforms[14]; // Locations of the shadowed illuminated height map shader's uniform variables
70 /* Constructors and destructors: */
71 DataItem(void);
72 virtual ~DataItem(void);
75 /* Elements: */
76 const DepthImageRenderer* depthImageRenderer; // Renderer for low-level surface rendering
77 unsigned int depthImageSize[2]; // Size of depth image texture
78 PTransform
79 tangentDepthProjection; // Transposed depth projection matrix for tangent planes, i.e., homogeneous normal vectors
80 IO::FileMonitor fileMonitor; // Monitor to watch the renderer's external shader source files
82 bool drawContourLines; // Flag if topographic contour lines are enabled
83 GLfloat contourLineFactor; // Inverse elevation distance between adjacent topographic contour lines
85 ElevationColorMap*
86 elevationColorMap; // Pointer to a color map for topographic elevation map coloring
88 bool drawDippingBed; // Flag to draw a potentially dipping bedding plane
89 bool dippingBedFolded; // Flag whether the dipping bed is folded or planar
90 Plane dippingBedPlane; // Plane equation of the planar dipping bed
91 GLfloat dippingBedCoeffs[5]; // Coefficients of folded dipping bed
92 GLfloat dippingBedThickness; // Thickness of dipping bed in camera-space units
94 DEM* dem; // Pointer to a pre-made digital elevation model to create a zero-surface for height color mapping
95 GLfloat demDistScale; // Maximum deviation from surface to DEM in camera-space units
97 bool illuminate; // Flag whether the surface shall be illuminated
99 WaterTable2* waterTable; // Pointer to the water table object; if NULL, water is ignored
100 bool advectWaterTexture; // Flag whether water texture coordinates are advected to visualize water flow
101 GLfloat waterOpacity; // Scaling factor for water opacity
103 unsigned int
104 surfaceSettingsVersion; // Version number of surface settings to invalidate surface rendering shader on changes
105 double animationTime; // Time value for water animation
107 /* Private methods: */
108 void shaderSourceFileChanged(const IO::FileMonitor::Event&
109 event); // Callback called when one of the external shader source files is changed
110 GLhandleARB createSinglePassSurfaceShader(const GLLightTracker& lt,
111 GLint* uniformLocations)
112 const; // Creates a single-pass surface rendering shader based on current renderer settings
113 void renderPixelCornerElevations(const int viewport[4], const PTransform& projectionModelview,
114 GLContextData& contextData, DataItem* dataItem)
115 const; // Creates texture containing pixel-corner elevations based on the current depth image
117 /* Constructors and destructors: */
118 public:
119 SurfaceRenderer(const DepthImageRenderer*
120 sDepthImageRenderer); // Creates a renderer for the given depth image renderer
122 /* Methods from GLObject: */
123 virtual void initContext(GLContextData& contextData) const;
125 /* New methods: */
126 void setDrawContourLines(bool
127 newDrawContourLines); // Enables or disables topographic contour lines
128 void setContourLineDistance(GLfloat
129 newContourLineDistance); // Sets the elevation distance between adjacent topographic contour lines
130 void setElevationColorMap(ElevationColorMap* newElevationColorMap); // Sets an elevation color map
131 void setDrawDippingBed(bool newDrawDippingBed); // Sets the dipping bed flag
132 void setDippingBedPlane(const Plane& newDippingBedPlane); // Sets the dipping bed plane equation
133 void setDippingBedCoeffs(const GLfloat
134 newDippingBedCoeffs[5]); // Sets folding dipping bed's coefficients
135 void setDippingBedThickness(GLfloat
136 newDippingBedThickness); // Sets the thickness of the dipping bed in camera-space units
137 void setDem(DEM*
138 newDem); // Sets a pre-made digital elevation model to create a zero surface for height color mapping
139 void setDemDistScale(GLfloat
140 newDemDistScale); // Sets the deviation from DEM to surface to saturate the deviation color map
141 void setIlluminate(bool newIlluminate); // Sets the illumination flag
142 void setWaterTable(WaterTable2*
143 newWaterTable); // Sets the pointer to the water table; NULL disables water handling
144 void setAdvectWaterTexture(bool
145 newAdvectWaterTexture); // Sets the water texture coordinate advection flag
146 void setWaterOpacity(GLfloat newWaterOpacity); // Sets the water opacity factor
147 void setAnimationTime(double newAnimationTime); // Sets the time for water animation in seconds
148 void renderSinglePass(const int viewport[4], const PTransform& projection,
149 const OGTransform& modelview, GLContextData& contextData)
150 const; // Renders the surface in a single pass using the current surface settings
151 #if 0
152 void renderGlobalAmbientHeightMap(GLuint heightColorMapTexture,
153 GLContextData& contextData)
154 const; // Renders the global ambient component of the surface as an illuminated height map in the current OpenGL context using the given pixel-corner elevation texture and 1D height color map
155 void renderShadowedIlluminatedHeightMap(GLuint heightColorMapTexture, GLuint shadowTexture,
156 const PTransform& shadowProjection,
157 GLContextData& contextData)
158 const; // Renders the surface as an illuminated height map in the current OpenGL context using the given pixel-corner elevation texture and 1D height color map
159 #endif
162 #endif