VR-Forces 4.6.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtHdrDrawable.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2018 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
51 
52 #include <GL/glew.h>
53 
54 #include <osg/Drawable>
55 #include <osg/Program>
56 #include <osg/Texture>
57 #include <osg/Texture2D>
58 
59 namespace osg
60 {
61  class Object;
62  class State;
63  class RenderInfo;
64  class CopyOp;
65 }
66 
67 namespace makVrv {
68 
69  class DtDe;
70  class DtGlRenderTexture;
71 
74  {
75  public:
76 
77  enum HDR_PASS { //Program ID enum
78  DOWNSAMPLE = 0,
96  PROGSIZE
97  };
98 
100  LEVEL_0 = 0,
106  LEVEL_TOTAL
107  };
108 
112  {
115  int hdrWidth;
118  float lumScaler;
120  float blendAmount;
121  float gamma;
123  float streakScale;
125  float streakDec;
127  float timeScale; //0.0 for instant
134  osg::Vec4f ghostScalar1;
135  osg::Vec4f ghostScalar2;
136  osg::Vec4f cameraMixCoeff;
137  osg::Vec4f gausCompCoeff;
138  osg::Vec4f blurScalar;
144  };
145 
147  DtHdrDrawable(DtDe &de, DtHdrOptions options, osg::Texture *lensFlareTexture);
148 
150  DtHdrDrawable(const DtHdrDrawable& orig, const osg::CopyOp& op);
151 
153  virtual ~DtHdrDrawable();
154 
156  virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new DtHdrDrawable(*this,copyop); }
157  virtual osg::Object* cloneType() const { return NULL; }
158 
159  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
160 
161 
163  virtual void setInputTexture(osg::Texture2D* inputTex);
164 
166  virtual void setEnabled( bool enabled );
167  virtual bool enabled();
168 
170  virtual DtHdrOptions& options();
171 
175  virtual void setLumOverride(bool lumOverride);
176 
178  // should just pass through without applying any effects
179  // used by SensorFX to turn off HDR on a per channel basis.
180  virtual void setHdrPassthrough(bool enable);
181  virtual bool hdrPassthrough();
182 
184  virtual void cleanupGpuMemory();
185  protected:
186 
188  virtual void initRenderTextures() const;
189 
191  virtual void downsample(DtGlRenderTexture *src, DtGlRenderTexture *dest, osg::State *state) const;
192 
195  virtual void downsample4x(DtGlRenderTexture *src, DtGlRenderTexture *dest, osg::State *state) const;
196 
198  virtual void extractHL(DtGlRenderTexture *src, DtGlRenderTexture *dest, osg::State *state) const;
199 
201  virtual void runPass(HDR_PASS prog, DtGlRenderTexture *src, DtGlRenderTexture *dest,
202  osg::State *state) const;
203 
205  virtual void blur(DtGlRenderTexture *src, DtGlRenderTexture *dest, DtGlRenderTexture *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 
233  //helper functions used for creating color constants
234  virtual void colorModulationRedShift(float* color, float r, float g, float b, int num);
235  virtual void colorModulation(float* color, float r, float g, float b, int num);
236  virtual void modulateColor();
237  protected:
238  bool myEnabled;
239 
240  osg::ref_ptr<osg::Texture2D> myInputTex;
241 
242  //5 is the minimum required to avoid a draw time hit
243  static const int theNumLumCapturePbos = 5;
244 
245  static double theLastHdrFrameTime;
246 
248 
249  osg::ref_ptr<osg::Program> myShaders[PROGSIZE];
250 
251  osg::ref_ptr<osg::Texture> myLensMask;
252 
254 
258 
259  float myStarModulation1st[16];
260  float myStarModulation2nd[16];
261  float myStarModulation3rd[16];
262 
263  float myFilmicGhostModulation1st[16];
264  float myFilmicGhostModulation2nd[16];
265  float myCameraGhostModulation1st[16];
266  float myCameraGhostModulation2nd[16];
267 
268  float myHoriModulation1st[16];
269  float myHoriModulation2nd[16];
270  float myHoriModulation3rd[16];
271 
272  //mutables needed since osg drawable draw implementations are const functions.
273  // This allows us to keep track of a bit of state that is needed between frames
274  // Also these are protected instead of private because they may be needed by
275  // classes derived from this class
276 
277  //Render textures need to be initialized in draw implementation so
278  // they need to be mutable...
279  mutable DtGlRenderTexture* myMutableComposebuffer[LEVEL_TOTAL];
280  mutable DtGlRenderTexture* myMutableBlurbufferA[LEVEL_TOTAL];
281  mutable DtGlRenderTexture* myMutableBlurbufferB[LEVEL_TOTAL];
282 
283  mutable DtGlRenderTexture* myMutableStreakbufferA[8];
284  mutable DtGlRenderTexture* myMutableStreakbufferB[8];
286 
289 
291 
295 
297 
298  //PBO is initialized with the Render textures in draw implementation so it
299  // also has to be mutable. Also need to keep track of current PBO
300  // so that state is mutable as well.
301  mutable GLuint myMutableLumPbos[theNumLumCapturePbos];
304 
305  //need to keep track of the previous frame time in draw implementation
306  // so this needs to be mutable.
308 
309  };
310 }

Document ID: Generated on Wed Jul 25 16:57:45 EDT 2018 from SVN revision 190790
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)