VR-Forces 4.5 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtHdrDrawable.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2017 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 // This file is derived from the HDR NVIDIA gameworks SDK example
6 //----------------------------------------------------------------------------------
7 // Multiple Files in folder: es3aep-kepler\HDR/
8 // SDK Version: v2.11
9 // Email: gameworks@nvidia.com
10 // Site: http://developer.nvidia.com/
11 //
12 // Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
13 //
14 // Redistribution and use in source and binary forms, with or without
15 // modification, are permitted provided that the following conditions
16 // are met:
17 // * Redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 // * Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 // * Neither the name of NVIDIA CORPORATION nor the names of its
23 // contributors may be used to endorse or promote products derived
24 // from this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
34 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 //----------------------------------------------------------------------------------
39 
40 #pragma once
41 
46 
47 
48 // Get proper local export symbol
50 
51 #include <GL/glew.h>
52 
53 #include <osg/Drawable>
54 #include <osg/Program>
55 #include <osg/Texture>
56 #include <osg/Texture2D>
57 
58 namespace osg
59 {
60  class Object;
61  class State;
62  class RenderInfo;
63  class CopyOp;
64 }
65 
66 namespace makVrv {
67 
68  class DtDe;
69  class DtRenderTexture;
70 
72  class DT_DLL_VRVPOSTPROCESSOR DtHdrDrawable : public osg::Drawable
73  {
74  public:
75 
76  enum HDR_PASS { //Program ID enum
77  DOWNSAMPLE = 0,
95  PROGSIZE
96  };
97 
99  LEVEL_0 = 0,
105  LEVEL_TOTAL
106  };
107 
111  {
114  int hdrWidth;
117  float lumScaler;
119  float blendAmount;
120  float gamma;
122  float streakScale;
124  float streakDec;
126  float timeScale; //0.0 for instant
133  osg::Vec4f ghostScalar1;
134  osg::Vec4f ghostScalar2;
135  osg::Vec4f cameraMixCoeff;
136  osg::Vec4f gausCompCoeff;
137  osg::Vec4f blurScalar;
143  };
144 
146  DtHdrDrawable(DtDe &de, DtHdrOptions options);
147 
149  DtHdrDrawable(const DtHdrDrawable& orig, const osg::CopyOp& op);
150 
152  virtual ~DtHdrDrawable();
153 
155  virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new DtHdrDrawable(*this,copyop); }
156  virtual osg::Object* cloneType() const { return NULL; }
157 
158  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
159 
160 
162  virtual void setInputTexture(osg::Texture2D* inputTex);
163 
165  virtual void setEnabled( bool enabled );
166  virtual bool enabled();
167 
169  virtual DtHdrOptions& options();
170 
174  virtual void setLumOverride(bool lumOverride);
175 
177  // should just pass through without applying any effects
178  // used by SensorFX to turn off HDR on a per channel basis.
179  virtual void setHdrPassthrough(bool enable);
180  virtual bool hdrPassthrough();
181 
182  protected:
183 
185  virtual void initRenderTextures() const;
186 
188  virtual void drawTexturedQuad() const;
189 
191  virtual void downsample(DtRenderTexture *src, DtRenderTexture *dest, osg::State *state) const;
192 
195  virtual void downsample4x(DtRenderTexture *src, DtRenderTexture *dest, osg::State *state) const;
196 
198  virtual void extractHL(DtRenderTexture *src, DtRenderTexture *dest, osg::State *state) const;
199 
201  virtual void runPass(HDR_PASS prog, DtRenderTexture *src, DtRenderTexture *dest,
202  osg::State *state) const;
203 
205  virtual void blur(DtRenderTexture *src, DtRenderTexture *dest, DtRenderTexture *temp,
206  int blurWidth, osg::State *state) const;
207 
209  virtual void getBufferPyramidSize(BUFFER_PYRAMID level, int* w, int* h) const;
210 
212  virtual void genStarStreak(int streak, float dir, float length, osg::State *state) const;
213 
215  virtual void genGhostImage(const float* ghost_modulation1st,const float* ghost_modulation2nd, osg::State *state) const;
216 
218  virtual void composeEffect(osg::State *state) const;
219 
222  virtual void toneMappingPass(osg::State *state) const;
223 
225  virtual void calculateLuminance(osg::State *state) const;
226 
228  virtual void initBlurCode();
229 
231  virtual void initShaders();
232 
234  virtual osg::Program *createProgram(const std::string& name);
235 
236  //helper functions used for creating color constants
237  virtual void colorModulationRedShift(float* color, float r, float g, float b, int num);
238  virtual void colorModulation(float* color, float r, float g, float b, int num);
239  virtual void modulateColor();
240  protected:
241  bool myEnabled;
242  osg::ref_ptr<osg::Texture2D> myInputTex;
243 
244  //5 is the minimum required to avoid a draw time hit
245  static const int theNumLumCapturePbos = 5;
246 
247  static double theLastHdrFrameTime;
248 
250 
251  osg::ref_ptr<osg::Program> myShaders[PROGSIZE];
252 
253  osg::ref_ptr<osg::Texture> myLensMask;
254 
256 
260 
261  float myStarModulation1st[16];
262  float myStarModulation2nd[16];
263  float myStarModulation3rd[16];
264 
265  float myFilmicGhostModulation1st[16];
266  float myFilmicGhostModulation2nd[16];
267  float myCameraGhostModulation1st[16];
268  float myCameraGhostModulation2nd[16];
269 
270  float myHoriModulation1st[16];
271  float myHoriModulation2nd[16];
272  float myHoriModulation3rd[16];
273 
274  //mutables needed since osg drawable draw implementations are const functions.
275  // This allows us to keep track of a bit of state that is needed between frames
276  // Also these are protected instead of private because they may be needed by
277  // classes derived from this class
278 
279  //Render textures need to be initialized in draw implementation so
280  // they need to be mutable...
281  mutable DtRenderTexture* myMutableComposebuffer[LEVEL_TOTAL];
282  mutable DtRenderTexture* myMutableBlurbufferA[LEVEL_TOTAL];
283  mutable DtRenderTexture* myMutableBlurbufferB[LEVEL_TOTAL];
284 
285  mutable DtRenderTexture* myMutableStreakbufferA[8];
286  mutable DtRenderTexture* myMutableStreakbufferB[8];
288 
291 
293 
297 
299 
300  //PBO is initialized with the Render textures in draw implementation so it
301  // also has to be mutable. Also need to keep track of current PBO
302  // so that state is mutable as well.
303  mutable GLuint myMutableLumPbos[theNumLumCapturePbos];
306 
307  //need to keep track of the previous frame time in draw implementation
308  // so this needs to be mutable.
310 
311  };
312 }

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)