changed: gcc8 base update
[opensg.git] / Examples / Simple / tonemapping.cpp
blob63fa1b549b090ca37c229f4eb4baab49529af24e
1 // OpenSG Tutorial Example: tonemapping
2 //
3 // This example shows the usage of the HDR2Stage for tonemapping and blooming.
4 //
5 // The example uses the Antweak bar for gui rendering on top of OpenSG.
6 //
8 #define USE_MIRROR_SPHERE
10 #include <cstddef>
11 #include <boost/foreach.hpp>
12 #include <boost/filesystem.hpp>
13 #include <boost/algorithm/string.hpp>
14 #include <boost/assign/std/vector.hpp>
16 #ifdef OSG_WITH_ANTTWEAKBAR
17 #include <AntTweakBar.h>
18 #endif
20 #ifdef OSG_BUILD_ACTIVE
21 // Headers
22 #include <OSGGLUT.h>
23 #include <OSGConfig.h>
24 #include <OSGSimpleGeometry.h>
25 #include <OSGGLUTWindow.h>
26 #include <OSGSimpleSceneManager.h>
27 #include <OSGBaseFunctions.h>
28 #include <OSGTransform.h>
29 #include <OSGGroup.h>
31 // new headers:
32 #include <OSGGLEXT.h>
33 #include <OSGSkyBackground.h>
34 #include <OSGSolidBackground.h>
35 #include <OSGShaderVariableOSG.h>
36 #include <OSGChunkMaterial.h>
37 #include <OSGMaterialGroup.h>
38 #include <OSGMaterialChunkOverrideGroup.h>
39 #include <OSGUniformBufferObjStd140Chunk.h>
40 #include <OSGPolygonChunk.h>
41 #include <OSGDepthChunk.h>
42 #include <OSGShaderProgramVariableChunk.h>
43 #include <OSGSimpleSHLChunk.h>
44 #include <OSGHDR2Stage.h>
45 #include <OSGCallbackAlgorithm.h>
46 #include <OSGCallbackAlgorithmForeground.h>
47 #include <OSGCubeMapGenerator.h>
48 #include <OSGVisitSubTree.h>
49 #include <OSGImageFileHandler.h>
50 #include <OSGTextureObjChunk.h>
51 #include <OSGRandomPoolManager.h>
53 #else
54 // Headers
55 #include <OpenSG/OSGGLUT.h>
56 #include <OpenSG/OSGConfig.h>
57 #include <OpenSG/OSGSimpleGeometry.h>
58 #include <OpenSG/OSGGLUTWindow.h>
59 #include <OpenSG/OSGSimpleSceneManager.h>
60 #include <OpenSG/OSGBaseFunctions.h>
61 #include <OpenSG/OSGTransform.h>
62 #include <OpenSG/OSGGroup.h>
64 // new headers:
65 #include <OpenSG/OSGGLEXT.h>
66 #include <OpenSG/OSGSkyBackground.h>
67 #include <OpenSG/OSGSolidBackground.h>
68 #include <OpenSG/OSGShaderVariableOSG.h>
69 #include <OpenSG/OSGChunkMaterial.h>
70 #include <OpenSG/OSGMaterialGroup.h>
71 #include <OpenSG/OSGMaterialChunkOverrideGroup.h>
72 #include <OpenSG/OSGUniformBufferObjStd140Chunk.h>
73 #include <OpenSG/OSGPolygonChunk.h>
74 #include <OpenSG/OSGDepthChunk.h>
75 #include <OpenSG/OSGShaderProgramVariableChunk.h>
76 #include <OpenSG/OSGSimpleSHLChunk.h>
77 #include <OpenSG/OSGHDR2Stage.h>
78 #include <OpenSG/OSGCallbackAlgorithm.h>
79 #include <OpenSG/OSGCallbackAlgorithmForeground.h>
80 #include <OpenSG/OSGCubeMapGenerator.h>
81 #include <OpenSG/OSGVisitSubTree.h>
82 #include <OpenSG/OSGImageFileHandler.h>
83 #include <OpenSG/OSGTextureObjChunk.h>
84 #include <OpenSG/OSGRandomPoolManager.h>
85 #endif
87 /*---- Light --------------------------------------------------------------*/
89 struct Light
91 enum Type
93 directional_light = 0,
94 point_light,
95 spot_light,
96 no_light
99 Light();
101 static Light create_light(Type e);
103 OSG::Pnt3f position; // in object space
104 OSG::Vec3f spot_direction; // in object space, also used for dir of directional lights (see shader code)
105 OSG::Color3f Ia; // ambient max. Intensity
106 OSG::Color3f Id; // diffuse max. Intensity
107 OSG::Color3f Is; // specular max. Intensity
109 OSG::Vec3f attenuation; // (constant, linear, quadratic) with constant >= 1 and linear,quadratic >= 0
110 OSG::Real32 spot_cos_cutoff; // cosine cut of angle
111 OSG::Real32 spot_exponent; // [0-128]
112 OSG::Int32 type; // directional_light, point_light, spot_light, no_light
115 typedef std::vector<Light> VecLightsT; // multiple lights
117 const std::size_t num_lights = 1; // simple example with just one light
119 VecLightsT initialize_lights() // helper to create lights
121 VecLightsT lights;
123 lights.push_back(Light::create_light(Light::directional_light));
125 assert(lights.size() == num_lights);
127 return lights;
130 VecLightsT lights = initialize_lights(); // the lights
132 /*---- Material -----------------------------------------------------------*/
134 struct Material
136 Material();
138 OSG::Color3f ambient;
139 OSG::Color3f diffuse;
140 OSG::Color3f specular;
141 OSG::Color3f emissive;
143 OSG::Real32 opacity;
144 OSG::Real32 shininess;
147 typedef std::vector<Material> VecMaterialsT; // multiple materials
149 VecMaterialsT initialize_materials(std::size_t num); // helper to create materials
151 const std::size_t num_materials = 100; // any number of materials
153 /*---- GeomState ----------------------------------------------------------*/
155 struct GeomState
157 GeomState();
159 OSG::UInt32 material_index;
162 const std::size_t num_geometries = 10; // number of colored geometry: cyl + torus mirror_sphere + colored spheres
163 const float circle_radius = 5.f;
165 /*---- HDRShaderData ------------------------------------------------------*/
167 struct HDRShaderData
169 HDRShaderData();
170 HDRShaderData(const HDRShaderData& rhs);
172 HDRShaderData& operator= (const HDRShaderData& rhs);
174 static HDRShaderData create_min_shader_data();
175 static HDRShaderData create_max_shader_data();
177 float bloomThreshold;
178 float bloomMagnitude;
179 int toneMapTechnique;
180 float exposure;
181 float keyValue;
182 int autoExposure;
183 float whiteLevel;
184 float shoulderStrength;
185 float linearStrength;
186 float linearAngle;
187 float toeStrength;
188 float toeNumerator;
189 float toeDenominator;
190 float linearWhite;
191 float lumSaturation;
192 float bias;
193 float tau;
194 int nTaps;
195 float sigma;
196 bool useLinChromInterp;
199 /*---- Example ------------------------------------------------------------*/
201 class Example
203 public:
204 static void displayCB () { if (_pExample) _pExample->display(); }
205 static void reshapeCB (int w, int h) { if (_pExample) _pExample->reshape(w, h); }
206 static void mouseCB (int button, int state, int x, int y) { if (_pExample) _pExample->mouse(button, state, x, y); }
207 static void motionCB (int x, int y) { if (_pExample) _pExample->motion(x, y); }
208 static void keyboardCB (unsigned char k, int x, int y) { if (_pExample) _pExample->keyboard(k, x, y); }
209 static void specialCB (int k, int x, int y) { if (_pExample) _pExample->special(k, x, y); }
211 public:
212 Example(int argc, char *argv[]);
213 ~Example();
215 private:
216 void initialize (int argc, char *argv[]);
217 int setupGLUT (int *argc, char *argv[]);
218 void initialize_skybackgrounds ();
220 void display ();
221 void reshape (int w, int h);
222 void mouse (int button, int state, int x, int y);
223 void motion (int x, int y);
224 void keyboard (unsigned char k, int x, int y);
225 void special (int key, int x, int y);
226 void tweakbar (OSG::DrawEnv* drawEnv);
228 void setupScene ();
230 std::string get_vp_program ();
231 std::string get_fp_program ();
233 // Light
234 OSG::Pnt3f transform_to_eye_space (const OSG::Pnt3f& p, OSG::SimpleSceneManager* pSSM);
235 OSG::Vec3f transform_to_eye_space (const OSG::Vec3f& v, OSG::SimpleSceneManager* pSSM);
237 std::size_t calc_light_buffer_size (const VecLightsT& lights);
238 std::vector<OSG::UInt8> create_light_buffer (const VecLightsT& lights);
240 OSG::UniformBufferObjStd140ChunkTransitPtr
241 create_light_state (const VecLightsT& lights);
242 void update_light_state (OSG::UniformBufferObjStd140Chunk* ubo, const VecLightsT& lights);
244 // Material
245 std::size_t calc_material_database_buffer_size (const VecMaterialsT& materials);
246 std::vector<OSG::UInt8> create_material_database_buffer (const VecMaterialsT& materials);
248 OSG::UniformBufferObjStd140ChunkTransitPtr
249 create_material_database_state (const VecMaterialsT& materials);
250 void update_material_database_state (OSG::UniformBufferObjStd140Chunk* ubo, const VecMaterialsT& materials);
252 // Geom state
253 std::size_t calc_geometry_material_buffer_size ();
254 std::vector<OSG::UInt8> create_geometry_material_buffer (const GeomState& geom_state);
256 OSG::UniformBufferObjStd140ChunkTransitPtr
257 create_geometry_material_state (const GeomState& geom_state);
258 void update_geometry_material_state (OSG::UniformBufferObjStd140Chunk* ubo, const GeomState& geom_state);
260 // HDR stage
261 void create_hdr_stage ();
262 void setup_hdr_stage ();
264 #ifdef OSG_WITH_ANTTWEAKBAR
265 private:
266 void setupTweakBar ();
268 public:
269 void ResetParameters ();
270 void SetSampleNumber (int value); int GetSampleNumber () const;
271 void SetClearColor (const OSG::Color3f& value); const OSG::Color3f& GetClearColor () const;
272 void SetForceBgnd (bool value); bool GetForceBgnd () const;
273 void SetAjustLuminance (bool value); bool GetAjustLuminance () const;
274 void SetSkyBgndIndex (int value); int GetSkyBgndIndex () const;
275 void SetPerformBloom (bool value); bool GetPerformBloom () const;
276 void SetBloomBackground (bool value); bool GetBloomBackground () const;
277 void SetCarryDepth (bool value); bool GetCarryDepth () const;
278 void SetResultIndex (int value); int GetResultIndex () const;
279 void SetRenderEmissive (bool value); bool GetRenderEmissive () const;
280 void SetRenderAmbient (bool value); bool GetRenderAmbient () const;
281 void SetRenderDiffuse (bool value); bool GetRenderDiffuse () const;
282 void SetRenderSpecular (bool value); bool GetRenderSpecular () const;
283 void SetAccurateGamma (bool value); bool GetAccurateGamma () const;
284 void SetGamma (bool value); bool GetGamma () const;
285 void SetUseITURBT709 (bool value); bool GetUseITURBT709 () const;
286 void SetMipmapLevel (int value); int GetMipmapLevel () const;
287 void SetBloomThreshold (float value); float GetBloomThreshold () const;
288 void SetBloomMagnitude (float value); float GetBloomMagnitude () const;
289 void SetToneMapTechnique (int value); int GetToneMapTechnique () const;
290 void SetExposure (float value); float GetExposure () const;
291 void SetKeyValue (float value); float GetKeyValue () const;
292 void SetAutoExposure (int value); int GetAutoExposure () const;
293 void SetWhiteLevel (float value); float GetWhiteLevel () const;
294 void SetShoulderStrength (float value); float GetShoulderStrength () const;
295 void SetLinearStrength (float value); float GetLinearStrength () const;
296 void SetLinearAngle (float value); float GetLinearAngle () const;
297 void SetToeStrength (float value); float GetToeStrength () const;
298 void SetToeNumerator (float value); float GetToeNumerator () const;
299 void SetToeDenominator (float value); float GetToeDenominator () const;
300 void SetLinearWhite (float value); float GetLinearWhite () const;
301 void SetLumSaturation (float value); float GetLumSaturation () const;
302 void SetBias (float value); float GetBias () const;
303 void SetTau (float value); float GetTau () const;
304 void SetNTaps (int value); int GetNTaps () const;
305 void SetSigma (float value); float GetSigma () const;
306 void SetUseLinChromInterp(bool value); bool GetUseLinChromInterp() const;
307 #endif
309 private:
310 static Example* _pExample; // Hack
312 OSG::SimpleSceneManagerRefPtr _mgr;
314 VecLightsT _lights;
315 VecMaterialsT _materials;
317 OSG::NodeRefPtr _hdrRoot;
318 OSG::HDR2StageRefPtr _hdrStage;
320 OSG::TransformRefPtr _geom_trans[num_geometries];
322 OSG::SimpleSHLChunkRefPtr _prog_chunk;
324 OSG::UniformBufferObjStd140ChunkRefPtr _ubo_light_state;
325 OSG::UniformBufferObjStd140ChunkRefPtr _ubo_geom_state[num_geometries];
327 HDRShaderData _hdrShaderData;
328 HDRShaderData _hdrShaderDataDefault;
329 HDRShaderData _hdrShaderDataMin;
330 HDRShaderData _hdrShaderDataMax;
332 bool _gamma;
333 bool _accurate_gamma;
334 bool _use_ITU_R_BT_709;
335 int _mipmap_level;
336 int _num_samples;
338 OSG::Color3f _clear_color;
339 bool _force_bgnd;
340 bool _adjust_luminance;
342 OSG::SolidBackgroundRefPtr _solidBgnd;
343 typedef std::vector<std::pair<std::string, OSG::SkyBackgroundRefPtr> > VecSkyBgndT;
344 VecSkyBgndT _vecSkyBgnd;
345 int _skyBgnd_index;
347 int _result_index;
349 bool _render_ambient;
350 bool _render_diffuse;
351 bool _render_specular;
352 bool _render_emissive;
354 bool _perform_bloom;
355 bool _bloom_background;
356 bool _carry_depth;
358 bool _pause;
360 #ifdef OSG_WITH_ANTTWEAKBAR
361 TwBar* _tweakbar;
362 #endif
365 /*---- helper -------------------------------------------------------------*/
367 std::size_t align_offset(std::size_t base_alignment, std::size_t base_offset)
369 return base_alignment * ((base_alignment + base_offset - 1) / base_alignment);
372 /*---- Example ------------------------------------------------------------*/
374 Example* Example::_pExample = NULL;
376 Example::Example(int argc, char *argv[])
377 : _mgr(NULL)
378 , _lights(initialize_lights())
379 , _materials(initialize_materials(num_materials))
380 , _hdrRoot(NULL)
381 , _hdrStage(NULL)
382 , _prog_chunk(NULL)
383 , _ubo_light_state(NULL)
384 , _hdrShaderData()
385 , _hdrShaderDataDefault()
386 , _hdrShaderDataMin(HDRShaderData::create_min_shader_data())
387 , _hdrShaderDataMax(HDRShaderData::create_max_shader_data())
388 , _gamma(true)
389 , _accurate_gamma(true)
390 , _use_ITU_R_BT_709(true)
391 , _mipmap_level(-1)
392 , _num_samples(4)
393 , _clear_color(0.0f, 0.0f, 0.4f)
394 , _force_bgnd(false)
395 , _adjust_luminance(true)
396 , _solidBgnd(NULL)
397 , _vecSkyBgnd()
398 , _skyBgnd_index(-1)
399 , _result_index(OSG::HDR2Stage::COMPOSITE_TEXTURE)
400 , _render_ambient(true)
401 , _render_diffuse(true)
402 , _render_specular(true)
403 , _render_emissive(false)
404 , _perform_bloom(true)
405 , _bloom_background(true)
406 , _carry_depth(true)
407 , _pause(true)
408 #ifdef OSG_WITH_ANTTWEAKBAR
409 , _tweakbar(NULL)
410 #endif
412 for (std::size_t i = 0; i < num_geometries; ++i)
414 _geom_trans[i] = NULL;
415 _ubo_geom_state[i] = NULL;
418 initialize(argc, argv);
421 Example::~Example()
423 _pExample = NULL;
426 void Example::initialize(int argc, char *argv[])
428 _pExample = this;
431 // This might be necessary depending on the
432 // used platform to ensure that the corresponding
433 // libraries get loaded.
435 OSG::preloadSharedObject("OSGFileIO");
436 OSG::preloadSharedObject("OSGImageFileIO");
437 OSG::preloadSharedObject("OSGContribPLY");
439 // OSG init
440 OSG::osgInit(argc,argv);
442 // GLUT init
443 int winid = setupGLUT(&argc, argv);
445 #ifdef OSG_WITH_ANTTWEAKBAR
446 TwInit(TW_OPENGL_CORE, NULL);
447 #endif
449 // the connection between GLUT and OpenSG
450 OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
451 gwin->setGlutId(winid);
452 gwin->init();
454 // create a callback for AntTweakBar drawing
455 OSG::RenderFunctor functor = boost::bind(&Example::tweakbar, this, _1);
457 OSG::CallbackAlgorithmRefPtr cbAlgorithm = OSG::CallbackAlgorithm::create();
458 cbAlgorithm->setCallback(functor, "");
460 // create a callback foreground for the AntTweackBar drawing callback
461 OSG::CallbackAlgorithmForegroundRefPtr cbForeground = OSG::CallbackAlgorithmForeground::create();
462 cbForeground->setCallbackAlgorithm(cbAlgorithm);
465 // create the SimpleSceneManager helper
466 _mgr = OSG::SimpleSceneManager::create();
467 _mgr->setWindow(gwin);
469 _mgr->addForeground(cbForeground);
471 initialize_skybackgrounds();
472 setupScene();
474 _solidBgnd = OSG::SolidBackground::create();
475 _solidBgnd->setColor(_clear_color);
477 if (_skyBgnd_index >= 0 && _skyBgnd_index < int(_vecSkyBgnd.size()))
478 _mgr->setBackground(_vecSkyBgnd[_skyBgnd_index].second);
479 else
480 _mgr->setBackground(_solidBgnd);
482 // show the whole scene
483 _mgr->showAll();
485 #ifdef OSG_WITH_ANTTWEAKBAR
486 setupTweakBar();
487 #endif
490 void Example::initialize_skybackgrounds()
492 namespace fs = boost::filesystem;
494 using namespace boost::assign;
496 std::vector<fs::path> names;
497 names += "+x", "negx";
499 std::vector<fs::path> extensions;
500 extensions += ".jpg", ".jpeg", ".png";
502 fs::path skybox_path("data/skybox");
505 // default hdr cross cube map
506 fs::path file("data/grace_cross.chdr");
507 if (fs::exists(file) && fs::is_regular_file(file))
509 std::string skybox_name = file.filename().stem().string();
511 OSG::SkyBackgroundRefPtr skyBgnd = OSG::SkyBackground::create();
512 OSG::ImageUnrecPtr image = OSG::ImageFileHandler::the()->read(file.string().c_str());
513 OSG::TextureObjChunkUnrecPtr texObj = OSG::TextureObjChunk::create();
515 texObj->setImage(image);
516 texObj->setInternalFormat(GL_RGB32F);
517 texObj->setWrapS(GL_CLAMP_TO_EDGE);
518 texObj->setWrapT(GL_CLAMP_TO_EDGE);
520 skyBgnd->setFrontTexture (texObj);
521 skyBgnd->setBackTexture (texObj);
522 skyBgnd->setLeftTexture (texObj);
523 skyBgnd->setRightTexture (texObj);
524 skyBgnd->setTopTexture (texObj);
525 skyBgnd->setBottomTexture(texObj);
527 _vecSkyBgnd.push_back(std::make_pair(skybox_name, skyBgnd));
530 // try to lookup more cube maps for the sky background
531 if (exists(skybox_path) && fs::is_directory(skybox_path))
533 fs::directory_iterator iter(skybox_path);
534 fs::directory_iterator end;
536 for (; iter != end; ++iter)
538 if (fs::is_directory(iter->status()))
540 const fs::path dir = *iter;
542 std::string skybox_name = dir.filename().string();
544 BOOST_FOREACH(fs::path name, names)
546 BOOST_FOREACH(fs::path ext, extensions)
548 fs::path p = dir / name; p.replace_extension(ext);
549 if (fs::exists(p))
551 fs::path pth_negx, pth_negy, pth_negz, pth_posx, pth_posy, pth_posz;
553 if (name == "+x")
555 pth_negx = dir / "-x"; pth_negx.replace_extension(ext);
556 pth_negy = dir / "-y"; pth_negy.replace_extension(ext);
557 pth_negz = dir / "-z"; pth_negz.replace_extension(ext);
558 pth_posx = dir / "+x"; pth_posx.replace_extension(ext);
559 pth_posy = dir / "+y"; pth_posy.replace_extension(ext);
560 pth_posz = dir / "+z"; pth_posz.replace_extension(ext);
562 else
564 pth_negx = dir / "negx"; pth_negx.replace_extension(ext);
565 pth_negy = dir / "negy"; pth_negy.replace_extension(ext);
566 pth_negz = dir / "negz"; pth_negz.replace_extension(ext);
567 pth_posx = dir / "posx"; pth_posx.replace_extension(ext);
568 pth_posy = dir / "posy"; pth_posy.replace_extension(ext);
569 pth_posz = dir / "posz"; pth_posz.replace_extension(ext);
572 if (fs::exists(pth_negx) && fs::exists(pth_negy) && fs::exists(pth_negz) &&
573 fs::exists(pth_posx) && fs::exists(pth_posy) && fs::exists(pth_posz))
575 OSG::SkyBackgroundRefPtr skyBgnd = OSG::SkyBackground::create();
577 OSG::ImageUnrecPtr imgNegX = OSG::ImageFileHandler::the()->read(pth_negx.string().c_str());
578 OSG::ImageUnrecPtr imgNegY = OSG::ImageFileHandler::the()->read(pth_negy.string().c_str());
579 OSG::ImageUnrecPtr imgNegZ = OSG::ImageFileHandler::the()->read(pth_negz.string().c_str());
580 OSG::ImageUnrecPtr imgPosX = OSG::ImageFileHandler::the()->read(pth_posx.string().c_str());
581 OSG::ImageUnrecPtr imgPosY = OSG::ImageFileHandler::the()->read(pth_posy.string().c_str());
582 OSG::ImageUnrecPtr imgPosZ = OSG::ImageFileHandler::the()->read(pth_posz.string().c_str());
584 OSG::TextureObjChunkUnrecPtr texObjNegX = OSG::TextureObjChunk::create();
585 OSG::TextureObjChunkUnrecPtr texObjNegY = OSG::TextureObjChunk::create();
586 OSG::TextureObjChunkUnrecPtr texObjNegZ = OSG::TextureObjChunk::create();
587 OSG::TextureObjChunkUnrecPtr texObjPosX = OSG::TextureObjChunk::create();
588 OSG::TextureObjChunkUnrecPtr texObjPosY = OSG::TextureObjChunk::create();
589 OSG::TextureObjChunkUnrecPtr texObjPosZ = OSG::TextureObjChunk::create();
591 texObjNegX->setImage(imgNegX);
592 texObjNegY->setImage(imgNegY);
593 texObjNegZ->setImage(imgNegZ);
594 texObjPosX->setImage(imgPosX);
595 texObjPosY->setImage(imgPosY);
596 texObjPosZ->setImage(imgPosZ);
598 texObjNegX->setInternalFormat(GL_RGB32F);
599 texObjNegY->setInternalFormat(GL_RGB32F);
600 texObjNegZ->setInternalFormat(GL_RGB32F);
601 texObjPosX->setInternalFormat(GL_RGB32F);
602 texObjPosY->setInternalFormat(GL_RGB32F);
603 texObjPosZ->setInternalFormat(GL_RGB32F);
605 texObjNegX->setWrapS(GL_CLAMP_TO_EDGE);
606 texObjNegY->setWrapS(GL_CLAMP_TO_EDGE);
607 texObjNegZ->setWrapS(GL_CLAMP_TO_EDGE);
608 texObjPosX->setWrapS(GL_CLAMP_TO_EDGE);
609 texObjPosY->setWrapS(GL_CLAMP_TO_EDGE);
610 texObjPosZ->setWrapS(GL_CLAMP_TO_EDGE);
612 texObjNegX->setWrapT(GL_CLAMP_TO_EDGE);
613 texObjNegY->setWrapT(GL_CLAMP_TO_EDGE);
614 texObjNegZ->setWrapT(GL_CLAMP_TO_EDGE);
615 texObjPosX->setWrapT(GL_CLAMP_TO_EDGE);
616 texObjPosY->setWrapT(GL_CLAMP_TO_EDGE);
617 texObjPosZ->setWrapT(GL_CLAMP_TO_EDGE);
619 skyBgnd->setBackTexture (texObjNegZ);
620 skyBgnd->setFrontTexture (texObjPosZ);
621 skyBgnd->setLeftTexture (texObjNegX);
622 skyBgnd->setRightTexture (texObjPosX);
623 skyBgnd->setBottomTexture(texObjNegY);
624 skyBgnd->setTopTexture (texObjPosY);
626 _vecSkyBgnd.push_back(std::make_pair(skybox_name, skyBgnd));
632 else if (fs::is_regular_file(iter->status()))
634 const fs::path filePath = *iter;
635 std::string ext = filePath.extension().string();
636 boost::to_lower(ext);
637 if (ext == ".chdr")
639 std::string skybox_name = filePath.filename().stem().string();
641 OSG::SkyBackgroundRefPtr skyBgnd = OSG::SkyBackground::create();
642 OSG::ImageUnrecPtr image = OSG::ImageFileHandler::the()->read(filePath.string().c_str());
643 OSG::TextureObjChunkUnrecPtr texObj = OSG::TextureObjChunk::create();
645 texObj->setImage(image);
646 texObj->setInternalFormat(GL_RGB32F);
647 texObj->setWrapS(GL_CLAMP_TO_EDGE);
648 texObj->setWrapT(GL_CLAMP_TO_EDGE);
650 skyBgnd->setFrontTexture (texObj);
651 skyBgnd->setBackTexture (texObj);
652 skyBgnd->setLeftTexture (texObj);
653 skyBgnd->setRightTexture (texObj);
654 skyBgnd->setTopTexture (texObj);
655 skyBgnd->setBottomTexture(texObj);
657 _vecSkyBgnd.push_back(std::make_pair(skybox_name, skyBgnd));
662 } catch (const fs::filesystem_error&) {}
664 // load the first sky background if available
665 if (!_vecSkyBgnd.empty())
666 _skyBgnd_index = 0;
669 void Example::setupScene()
671 // create a pretty simple graph: a Group with two Transforms as children,
672 // each of which carries a single Geometry.
674 // The hdr root node
675 _hdrRoot = OSG::Node::create();
676 _hdrRoot->setCore(OSG::Group::create());
678 create_hdr_stage();
680 OSG::NodeRefPtr root = OSG::Node::create();
681 root->setCore(OSG::Group::create());
683 _hdrRoot->addChild(root);
685 // The scene
686 OSG::NodeRefPtr scene = OSG::Node::create();
688 // The geometry transformations: cylinder, torus and spheres
689 for (std::size_t i = 0; i < num_geometries; ++i)
690 _geom_trans[i] = OSG::Transform::create();
692 // The cylinder
693 OSG::NodeRefPtr cyl = OSG::Node::create();
694 OSG::GeometryRefPtr cylGeo = OSG::makeCylinderGeo( 1.4f, .3f, 24, true, true, true );
696 cyl->setCore(cylGeo);
698 OSG::NodeRefPtr cylTransNode = OSG::Node::create();
699 cylTransNode->setCore(_geom_trans[0]);
700 cylTransNode->addChild(cyl);
702 scene->addChild(cylTransNode);
704 // The torus
705 OSG::NodeRefPtr torus = OSG::Node::create();
706 OSG::GeometryRefPtr torusGeo = OSG::makeTorusGeo( .2f, 1, 24, 36 );
708 torus->setCore(torusGeo);
710 OSG::NodeRefPtr torTransNode = OSG::Node::create();
711 torTransNode->setCore(_geom_trans[1]);
712 torTransNode->addChild(torus);
714 scene->addChild(torTransNode);
716 OSG::Matrix m;
718 #ifdef USE_MIRROR_SPHERE
719 // The mirror sphere
720 OSG::NodeRefPtr mirrorSceneRoot = OSG::Node::create();
721 OSG::VisitSubTreeRefPtr visitSubTree = OSG::VisitSubTree::create();
723 mirrorSceneRoot->setCore(visitSubTree);
724 visitSubTree->setSubTreeRoot(root);
726 OSG::NodeRefPtr mirrorRoot = OSG::Node::create();
727 OSG::CubeMapGeneratorRefPtr cubeMapGen = OSG::CubeMapGenerator::create();
729 cubeMapGen->setBackground(_solidBgnd);
730 cubeMapGen->setRoot(mirrorSceneRoot);
731 cubeMapGen->setTexUnit(3);
732 cubeMapGen->setSize(512, 512);
733 cubeMapGen->setTextureFormat(GL_RGB32F);
735 mirrorRoot->setCore(cubeMapGen);
737 OSG::NodeRefPtr mirrorSphere = OSG::Node::create();
738 OSG::GeometryRefPtr mirrorSphereGeo = OSG::makeSphereGeo(3, 1.f);
740 mirrorSphere->setCore(mirrorSphereGeo);
742 m.setIdentity();
743 m.setTranslate(OSG::Vec3f(0.3f*circle_radius, 0.3f*circle_radius, 0.3f*circle_radius));
744 _geom_trans[2]->setMatrix(m);
746 OSG::NodeRefPtr mirrorSphereTransNode = OSG::Node::create();
747 mirrorSphereTransNode->setCore(_geom_trans[2]);
748 mirrorSphereTransNode->addChild(mirrorRoot);
750 mirrorRoot->addChild(mirrorSphere);
751 #endif // USE_MIRROR_SPHERE
753 // The spheres
754 OSG::GeometryRefPtr sphereGeo[num_geometries];
755 for (std::size_t i = 3; i < num_geometries; ++i)
757 OSG::NodeRefPtr sphere = OSG::Node::create();
759 sphereGeo[i] = OSG::makeSphereGeo(3, 0.7f);
761 sphere->setCore(sphereGeo[i]);
763 OSG::Real32 theta = (i-3) * 2.f * OSG::Pi / (num_geometries - 3);
765 m.setIdentity();
766 m.setTranslate(OSG::Vec3f(circle_radius * OSG::osgCos(theta), 0.5f, circle_radius * OSG::osgSin(theta)));
768 _geom_trans[i]->setMatrix(m);
770 OSG::NodeRefPtr sphereTransNode = OSG::Node::create();
771 sphereTransNode->setCore (_geom_trans[i]);
772 sphereTransNode->addChild(sphere);
774 // add it to the scene
775 scene->addChild(sphereTransNode);
779 // create the shader program
781 _prog_chunk = OSG::SimpleSHLChunk::create();
783 _prog_chunk->setVertexProgram (get_vp_program());
784 _prog_chunk->setFragmentProgram (get_fp_program());
786 _prog_chunk->addUniformBlock("Materials", 1); // block binding point
787 _prog_chunk->addUniformBlock("Lights", 2); // block binding point
789 _prog_chunk->addUniformVariable("uRenderEmissive", _render_emissive);
790 _prog_chunk->addUniformVariable("uRenderAmbient", _render_ambient);
791 _prog_chunk->addUniformVariable("uRenderDiffuse", _render_diffuse);
792 _prog_chunk->addUniformVariable("uRenderSpecular", _render_specular);
795 // create uniform buffer objects and corresponding materials
797 OSG::UniformBufferObjStd140ChunkRefPtr ubo_material_database = create_material_database_state(_materials);
798 _ubo_light_state = create_light_state(_lights);
800 OSG::PolygonChunkRefPtr polygon_chunk = OSG::PolygonChunk::create();
801 polygon_chunk->setFrontMode(GL_FILL);
802 polygon_chunk->setBackMode(GL_FILL);
803 polygon_chunk->setCullFace(GL_NONE);
805 OSG::DepthChunkRefPtr depth_chunk = OSG::DepthChunk::create();
806 depth_chunk->setEnable(true);
808 OSG::ChunkMaterialRefPtr prog_state = OSG::ChunkMaterial::create();
809 prog_state->addChunk( ubo_material_database, 1); // buffer binding point 1
810 prog_state->addChunk(_ubo_light_state, 2); // buffer binding point 2
811 prog_state->addChunk(_prog_chunk);
812 prog_state->addChunk(polygon_chunk);
813 prog_state->addChunk(depth_chunk);
816 OSG::ShaderProgramVariableChunkRefPtr shader_var_chunk = OSG::ShaderProgramVariableChunk::create();
817 shader_var_chunk->addUniformBlock("GeomState", 3);
819 OSG::ChunkMaterialRefPtr geom_state[num_geometries];
821 for (std::size_t i = 0; i < num_geometries; ++i)
823 if (i == 2) continue; // do not do this for the mirror sphere
824 GeomState geom;
825 geom.material_index = OSG::RandomPoolManager::the()->getRandomInt32(0, num_materials-1);
827 geom_state[i] = OSG::ChunkMaterial::create();
829 _ubo_geom_state[i] = create_geometry_material_state(geom);
831 geom_state[i]->addChunk(_ubo_geom_state[i], 3); // buffer binding point 3
832 geom_state[i]->addChunk(shader_var_chunk); // block binding point
835 cylGeo ->setMaterial(geom_state[0]);
836 torusGeo->setMaterial(geom_state[1]);
838 for (std::size_t i = 3; i < num_geometries; ++i)
839 sphereGeo[i]->setMaterial(geom_state[i]);
841 OSG::MaterialChunkOverrideGroupRefPtr mgrp = OSG::MaterialChunkOverrideGroup::create();
842 mgrp->setMaterial(prog_state);
843 scene->setCore(mgrp);
845 root->addChild(scene);
846 #ifdef USE_MIRROR_SPHERE
847 root->addChild(mirrorSphereTransNode);
848 #endif // USE_MIRROR_SPHERE
850 OSG::commitChanges();
852 _mgr->setRoot(_hdrRoot);
855 int Example::setupGLUT(int *argc, char *argv[])
857 glutInit(argc, argv);
858 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
859 glutInitWindowSize(1000, 800);
861 int winid = glutCreateWindow("OpenSG");
863 glutReshapeFunc(reshapeCB);
864 glutDisplayFunc(displayCB);
866 glutMouseFunc(mouseCB);
867 glutMotionFunc(motionCB);
868 glutPassiveMotionFunc(motionCB);
869 glutKeyboardFunc(keyboardCB);
870 glutSpecialFunc(specialCB);
872 #ifdef OSG_WITH_ANTTWEAKBAR
873 TwGLUTModifiersFunc(glutGetModifiers);
874 #endif
876 // call the redraw function whenever there's nothing else to do
877 glutIdleFunc(displayCB);
879 return winid;
882 void Example::display()
884 // light spot direction and light position must be provided in eye space
885 update_light_state(_ubo_light_state, _lights);
887 if (!_pause)
890 // create the matrix
891 OSG::Matrix m;
892 OSG::Real32 t = glutGet(GLUT_ELAPSED_TIME );
894 // set the transforms' matrices
895 m.setTransform(OSG::Vec3f(0, 0, OSG::osgSin(t / 1000.f) * 1.5),
896 OSG::Quaternion( OSG::Vec3f (1, 0, 0), t / 500.f));
898 _geom_trans[0]->setMatrix(m);
900 m.setTransform(OSG::Vec3f(OSG::osgSin(t / 1000.f), 0, 0),
901 OSG::Quaternion( OSG::Vec3f (0, 0, 1), t / 1000.f));
903 _geom_trans[1]->setMatrix(m);
905 for (std::size_t i = 3; i < num_geometries; ++i)
907 OSG::Real32 theta = (i-3) * 2.f * OSG::Pi / (num_geometries - 3);
909 OSG::Real32 rad = circle_radius + 0.3 * circle_radius * OSG::osgSin(t / 2000.f);
911 m.setIdentity();
912 m.setTranslate(OSG::Vec3f(rad * OSG::osgCos(theta), 0.5f, rad * OSG::osgSin(theta)));
913 _geom_trans[i]->setMatrix(m);
917 OSG::commitChanges();
919 _mgr->redraw();
922 void Example::reshape(int w, int h)
924 _mgr->resize(w, h);
926 #ifdef OSG_WITH_ANTTWEAKBAR
927 TwWindowSize(w, h);
928 #endif
930 glutPostRedisplay();
934 // react to mouse button presses
936 void Example::mouse(int button, int state, int x, int y)
938 #ifdef OSG_WITH_ANTTWEAKBAR
939 if(TwEventMouseButtonGLUT(button, state, x, y))
941 glutPostRedisplay();
942 return;
944 #endif
946 if (state)
947 _mgr->mouseButtonRelease(button, x, y);
948 else
949 _mgr->mouseButtonPress(button, x, y);
951 glutPostRedisplay();
955 // react to mouse motions with pressed buttons
957 void Example::motion(int x, int y)
959 #ifdef OSG_WITH_ANTTWEAKBAR
960 if(TwEventMouseMotionGLUT(x, y))
962 glutPostRedisplay();
963 return;
965 #endif
967 _mgr->mouseMove(x, y);
969 glutPostRedisplay();
973 // react to keys
975 void Example::keyboard(unsigned char k, int x, int y)
977 #ifdef OSG_WITH_ANTTWEAKBAR
978 if(TwEventKeyboardGLUT(k, x, y))
980 glutPostRedisplay();
981 return;
983 #endif
985 switch(k)
987 case 27:
989 // clean up global variables
990 _mgr = NULL;
992 _ubo_light_state = NULL;
994 for (std::size_t i = 0; i < num_geometries; ++i)
996 _geom_trans[i] = NULL;
997 _ubo_geom_state[i] = NULL;
1000 OSG::osgExit();
1001 exit(0);
1003 break;
1005 case 'm':
1007 for (std::size_t i = 0; i < num_geometries; ++i)
1009 GeomState geom;
1010 geom.material_index = OSG::RandomPoolManager::the()->getRandomInt32(0, num_materials-1);
1012 update_geometry_material_state(_ubo_geom_state[i], geom);
1015 glutPostRedisplay();
1017 break;
1019 case 's':
1021 _mgr->setStatistics(!_mgr->getStatistics());
1023 break;
1027 void Example::special(int key, int x, int y)
1029 #ifdef OSG_WITH_ANTTWEAKBAR
1030 if(TwEventSpecialGLUT(key, x, y))
1032 glutPostRedisplay();
1033 return;
1035 #endif
1038 void Example::tweakbar(OSG::DrawEnv* drawEnv)
1040 #ifdef OSG_WITH_ANTTWEAKBAR
1042 // Save the current state
1044 glMatrixMode(GL_PROJECTION);
1045 glPushMatrix();
1047 glMatrixMode(GL_MODELVIEW);
1048 glPushMatrix();
1050 glPushAttrib(GL_ALL_ATTRIB_BITS);
1053 // execute the actual callback wrapped by this class
1055 TwDraw();
1058 // Restore the state
1060 glPopAttrib();
1062 glMatrixMode(GL_PROJECTION);
1063 glPopMatrix();
1065 glMatrixMode(GL_MODELVIEW);
1066 glPopMatrix();
1067 #endif
1071 // transform point from world space to eye space
1073 OSG::Pnt3f Example::transform_to_eye_space(const OSG::Pnt3f& p, OSG::SimpleSceneManager* pSSM)
1075 if (!pSSM || !pSSM->getWindow() || pSSM->getWindow()->getMFPort()->size() == 0)
1076 return p;
1078 OSG::Viewport* pPort = _mgr->getWindow()->getPort(0);
1080 OSG::Pnt3f p_es;
1082 OSG::Matrix view;
1083 OSG::Int16 width = pPort->calcPixelWidth();
1084 OSG::Int16 height = pPort->calcPixelHeight();
1086 pPort->getCamera()->getViewing(view, width, height);
1088 view.multFull( p, p_es);
1090 return p_es;
1094 // transform vector from world space to eye space
1096 OSG::Vec3f Example::transform_to_eye_space(const OSG::Vec3f& v, OSG::SimpleSceneManager* pSSM)
1098 if (!pSSM || !pSSM->getWindow() || pSSM->getWindow()->getMFPort()->size() == 0)
1099 return v;
1101 OSG::Viewport* pPort = _mgr->getWindow()->getPort(0);
1103 OSG::Vec3f v_es;
1105 OSG::Matrix view;
1106 OSG::Int16 width = pPort->calcPixelWidth();
1107 OSG::Int16 height = pPort->calcPixelHeight();
1109 pPort->getCamera()->getViewing(view, width, height);
1111 view.multFull( v, v_es);
1113 return v_es;
1117 // the light uniform buffer object
1118 // see comment *) at the top of the file
1120 std::size_t Example::calc_light_buffer_size(const VecLightsT& lights)
1122 std::size_t ao = 0; // aligned offset
1123 std::size_t bo = 0; // base offset
1125 ao = align_offset( 16, bo); bo = ao + sizeof(OSG::Pnt4f); // OSG::Pnt3f position;
1126 ao = align_offset( 16, bo); bo = ao + sizeof(OSG::Vec4f); // OSG::Vec3f spot_direction;
1127 ao = align_offset( 16, bo); bo = ao + sizeof(OSG::Color4f); // OSG::Color3f Ia;
1128 ao = align_offset( 16, bo); bo = ao + sizeof(OSG::Color4f); // OSG::Color3f Id;
1129 ao = align_offset( 16, bo); bo = ao + sizeof(OSG::Color4f); // OSG::Color3f Is;
1130 ao = align_offset( 16, bo); bo = ao + sizeof(OSG::Vec4f); // OSG::Vec3f attenuation;
1131 ao = align_offset( 4, bo); bo = ao + sizeof(OSG::Real32); // OSG::Real32 spot_cos_cutoff;
1132 ao = align_offset( 4, bo); bo = ao + sizeof(OSG::Real32); // OSG::Real32 spot_exponent;
1133 ao = align_offset( 4, bo); bo = ao + sizeof(OSG::Int32); // OSG::Int32 type;
1134 ao = align_offset( 16, bo); bo = ao; // padding
1136 ao *= lights.size(); bo = ao; // array
1137 ao = align_offset( 16, bo); bo = ao; // padding
1139 return ao;
1142 std::vector<OSG::UInt8> Example::create_light_buffer(const VecLightsT& lights)
1144 std::size_t size = calc_light_buffer_size(lights);
1146 std::vector<OSG::UInt8> buffer(size);
1148 std::size_t ao = 0; // aligned offset
1149 std::size_t bo = 0; // base offset
1151 for (std::size_t i = 0; i < lights.size(); ++i)
1153 OSG::Pnt3f position_es = transform_to_eye_space(lights[i].position, _mgr);
1154 OSG::Vec3f spot_direction_es = transform_to_eye_space(lights[i].spot_direction, _mgr);
1156 ao = align_offset(16, bo);
1157 memcpy(&buffer[0] + ao, &position_es[0], sizeof(OSG::Pnt3f));
1158 bo = ao + sizeof(OSG::Pnt4f);
1160 ao = align_offset(16, bo);
1161 memcpy(&buffer[0] + ao, &spot_direction_es[0], sizeof(OSG::Vec3f));
1162 bo = ao + sizeof(OSG::Vec4f);
1164 ao = align_offset(16, bo);
1165 memcpy(&buffer[0] + ao, &lights[i].Ia[0], sizeof(OSG::Color3f));
1166 bo = ao + sizeof(OSG::Color4f);
1168 ao = align_offset(16, bo);
1169 memcpy(&buffer[0] + ao, &lights[i].Id[0], sizeof(OSG::Color3f));
1170 bo = ao + sizeof(OSG::Color4f);
1172 ao = align_offset(16, bo);
1173 memcpy(&buffer[0] + ao, &lights[i].Is[0], sizeof(OSG::Color3f));
1174 bo = ao + sizeof(OSG::Color4f);
1176 ao = align_offset(16, bo);
1177 memcpy(&buffer[0] + ao, &lights[i].attenuation[0], sizeof(OSG::Vec3f));
1178 bo = ao + sizeof(OSG::Vec4f);
1180 ao = align_offset( 4, bo);
1181 *(reinterpret_cast<OSG::Real32*>(&buffer[0] + ao)) = lights[i].spot_cos_cutoff;
1182 bo = ao + sizeof(OSG::Real32);
1184 ao = align_offset( 4, bo);
1185 *(reinterpret_cast<OSG::Real32*>(&buffer[0] + ao)) = lights[i].spot_exponent;
1186 bo = ao + sizeof(OSG::Real32);
1188 ao = align_offset( 4, bo);
1189 *(reinterpret_cast<OSG::Int32*>(&buffer[0] + ao)) = lights[i].type;
1190 bo = ao + sizeof(OSG::Int32);
1192 ao = align_offset( 16, bo); bo = ao; // padding
1195 return buffer;
1198 OSG::UniformBufferObjStd140ChunkTransitPtr Example::create_light_state(const VecLightsT& lights)
1200 OSG::UniformBufferObjStd140ChunkRefPtr ubo = OSG::UniformBufferObjStd140Chunk::create();
1202 std::vector<OSG::UInt8> buffer = create_light_buffer(lights);
1204 ubo->editMFBuffer()->setValues(buffer);
1205 ubo->setUsage(GL_DYNAMIC_DRAW);
1207 return OSG::UniformBufferObjStd140ChunkTransitPtr(ubo);
1210 void Example::update_light_state(OSG::UniformBufferObjStd140Chunk* ubo, const VecLightsT& lights)
1212 if (ubo) {
1213 std::vector<OSG::UInt8> buffer = create_light_buffer(lights);
1214 ubo->editMFBuffer()->setValues(buffer);
1218 std::size_t Example::calc_material_database_buffer_size(const VecMaterialsT& materials)
1220 std::size_t ao = 0; // aligned offset
1221 std::size_t bo = 0; // base offset
1223 ao = align_offset( 16, bo); bo = ao + sizeof(OSG::Color4f); // OSG::Color3f ambient;
1224 ao = align_offset( 16, bo); bo = ao + sizeof(OSG::Color4f); // OSG::Color3f diffuse;
1225 ao = align_offset( 16, bo); bo = ao + sizeof(OSG::Color4f); // OSG::Color3f specular;
1226 ao = align_offset( 16, bo); bo = ao + sizeof(OSG::Color4f); // OSG::Color3f emissive;
1227 ao = align_offset( 4, bo); bo = ao + sizeof(OSG::Real32); // OSG::Real32 opacity;
1228 ao = align_offset( 4, bo); bo = ao + sizeof(OSG::Real32); // OSG::Real32 shininess;
1229 ao = align_offset( 16, bo); bo = ao; // padding
1231 ao *= materials.size(); bo = ao; // array
1232 ao = align_offset( 16, bo); bo = ao; // padding
1234 return ao;
1237 std::vector<OSG::UInt8> Example::create_material_database_buffer(const VecMaterialsT& materials)
1239 std::size_t size = calc_material_database_buffer_size(materials);
1241 std::vector<OSG::UInt8> buffer(size);
1243 std::size_t ao = 0; // aligned offset
1244 std::size_t bo = 0; // base offset
1246 for (std::size_t i = 0; i < materials.size(); ++i)
1248 ao = align_offset(16, bo);
1249 memcpy(&buffer[0] + ao, &materials[i].ambient[0], sizeof(OSG::Color3f));
1250 bo = ao + sizeof(OSG::Color4f);
1252 ao = align_offset(16, bo);
1253 memcpy(&buffer[0] + ao, &materials[i].diffuse[0], sizeof(OSG::Color3f));
1254 bo = ao + sizeof(OSG::Color4f);
1256 ao = align_offset(16, bo);
1257 memcpy(&buffer[0] + ao, &materials[i].specular[0], sizeof(OSG::Color3f));
1258 bo = ao + sizeof(OSG::Color4f);
1260 ao = align_offset(16, bo);
1261 memcpy(&buffer[0] + ao, &materials[i].emissive[0], sizeof(OSG::Color3f));
1262 bo = ao + sizeof(OSG::Color4f);
1264 ao = align_offset( 4, bo);
1265 *(reinterpret_cast<OSG::Real32*>(&buffer[0] + ao)) = materials[i].opacity;
1266 bo = ao + sizeof(OSG::Real32);
1268 ao = align_offset( 4, bo);
1269 *(reinterpret_cast<OSG::Real32*>(&buffer[0] + ao)) = materials[i].shininess;
1270 bo = ao + sizeof(OSG::Real32);
1272 ao = align_offset( 16, bo); bo = ao; // padding
1275 return buffer;
1278 OSG::UniformBufferObjStd140ChunkTransitPtr Example::create_material_database_state(const VecMaterialsT& materials)
1280 OSG::UniformBufferObjStd140ChunkRefPtr ubo = OSG::UniformBufferObjStd140Chunk::create();
1282 std::vector<OSG::UInt8> buffer = create_material_database_buffer(materials);
1284 ubo->editMFBuffer()->setValues(buffer);
1285 ubo->setUsage(GL_STATIC_DRAW);
1287 return OSG::UniformBufferObjStd140ChunkTransitPtr(ubo);
1290 void Example::update_material_database_state(OSG::UniformBufferObjStd140Chunk* ubo, const VecMaterialsT& materials)
1292 if (ubo) {
1293 std::vector<OSG::UInt8> buffer = create_material_database_buffer(materials);
1294 ubo->editMFBuffer()->setValues(buffer);
1299 // the geomertry uniform buffer object
1301 std::size_t Example::calc_geometry_material_buffer_size()
1303 std::size_t ao = 0; // aligned offset
1304 std::size_t bo = 0; // base offset
1306 ao = align_offset( 4, bo); bo = ao + sizeof(OSG::UInt32); // OSG::UInt32 material_index;
1307 ao = align_offset( 16, bo); bo = ao; // padding
1309 return ao;
1312 std::vector<OSG::UInt8> Example::create_geometry_material_buffer(const GeomState& geom_state)
1314 std::size_t size = calc_geometry_material_buffer_size();
1316 std::vector<OSG::UInt8> buffer(size);
1318 std::size_t ao = 0; // aligned offset
1319 std::size_t bo = 0; // base offset
1321 ao = align_offset( 4, bo);
1322 *(reinterpret_cast<OSG::UInt32*>(&buffer[0] + ao)) = geom_state.material_index;
1323 bo = ao + sizeof(OSG::UInt32);
1325 return buffer;
1328 OSG::UniformBufferObjStd140ChunkTransitPtr Example::create_geometry_material_state(const GeomState& geom_state)
1330 OSG::UniformBufferObjStd140ChunkRefPtr ubo = OSG::UniformBufferObjStd140Chunk::create();
1332 std::vector<OSG::UInt8> buffer = create_geometry_material_buffer(geom_state);
1334 ubo->editMFBuffer()->setValues(buffer);
1335 ubo->setUsage(GL_DYNAMIC_DRAW);
1337 return OSG::UniformBufferObjStd140ChunkTransitPtr(ubo);
1340 void Example::update_geometry_material_state(OSG::UniformBufferObjStd140Chunk* ubo, const GeomState& geom_state)
1342 if (ubo) {
1343 std::vector<OSG::UInt8> buffer = create_geometry_material_buffer(geom_state);
1344 ubo->editMFBuffer()->setValues(buffer);
1348 void Example::create_hdr_stage()
1350 if (_hdrRoot)
1352 _hdrStage = OSG::HDR2Stage::create();
1354 setup_hdr_stage();
1356 _hdrRoot->setCore(_hdrStage);
1360 void Example::setup_hdr_stage()
1362 if (_hdrStage)
1364 _hdrStage->setApplyGamma (_gamma);
1365 _hdrStage->setAccurateGamma (_accurate_gamma);
1367 _hdrStage->setPerformBloom (_perform_bloom);
1368 _hdrStage->setBloomBackground (_bloom_background);
1370 _hdrStage->setForceBackground (_force_bgnd);
1371 _hdrStage->setUse_ITU_R_BT_709 (_use_ITU_R_BT_709);
1372 _hdrStage->setMipmapLevel (_mipmap_level);
1374 _hdrStage->setTarget (_result_index);
1375 _hdrStage->setCarryDepth (_carry_depth);
1377 _hdrStage->setColorBufferInternalFormat (GL_RGBA16F);
1378 _hdrStage->setColorBufferPixelFormat (GL_RGBA);
1379 _hdrStage->setColorBufferType (GL_FLOAT);
1381 _hdrStage->setDepthBufferInternalFormat (GL_DEPTH24_STENCIL8);
1382 _hdrStage->setDepthBufferPixelFormat (GL_DEPTH_STENCIL);
1383 _hdrStage->setDepthBufferType (GL_UNSIGNED_INT_24_8);
1385 _hdrStage->setLumBufferInternalFormat (GL_R32F);
1386 _hdrStage->setLumBufferPixelFormat (GL_RED);
1387 _hdrStage->setLumBufferType (GL_FLOAT);
1389 _hdrStage->setImageBufferInternalFormat (GL_RGB16F);
1390 _hdrStage->setImageBufferPixelFormat (GL_RGB);
1391 _hdrStage->setImageBufferType (GL_FLOAT);
1393 _hdrStage->setNumSamples (_num_samples);
1395 _hdrStage->setBloomThreshold (_hdrShaderData.bloomThreshold);
1396 _hdrStage->setBloomMagnitude (_hdrShaderData.bloomMagnitude);
1397 _hdrStage->setToneMappingMode (_hdrShaderData.toneMapTechnique);
1398 _hdrStage->setExposure (_hdrShaderData.exposure);
1399 _hdrStage->setKeyValue (_hdrShaderData.keyValue);
1400 _hdrStage->setAutoExposureMode (_hdrShaderData.autoExposure);
1401 _hdrStage->setWhiteLevel (_hdrShaderData.whiteLevel);
1402 _hdrStage->setFilmicShoulderStrenght (_hdrShaderData.shoulderStrength);
1403 _hdrStage->setFilmicLinearStrength (_hdrShaderData.linearStrength);
1404 _hdrStage->setFilmicLinearAngle (_hdrShaderData.linearAngle);
1405 _hdrStage->setFilmicToeStrength (_hdrShaderData.toeStrength);
1406 _hdrStage->setFilmicToeNumerator (_hdrShaderData.toeNumerator);
1407 _hdrStage->setFilmicToeDenominator (_hdrShaderData.toeDenominator);
1408 _hdrStage->setFilmicLinearWhite (_hdrShaderData.linearWhite);
1409 _hdrStage->setSaturation (_hdrShaderData.lumSaturation);
1410 _hdrStage->setDragoBias (_hdrShaderData.bias);
1411 _hdrStage->setTau (_hdrShaderData.tau);
1412 _hdrStage->setNumTaps (_hdrShaderData.nTaps);
1413 _hdrStage->setBlurGaussSigma (_hdrShaderData.sigma);
1414 _hdrStage->setUseLinChromCorrection (_hdrShaderData.useLinChromInterp);
1419 // Initialize GLUT & OpenSG and set up the scene
1421 int main(int argc, char **argv)
1423 Example example(argc, argv);
1425 // GLUT main loop
1426 glutMainLoop();
1428 #ifdef OSG_WITH_ANTTWEAKBAR
1429 TwTerminate();
1430 #endif
1432 return 0;
1435 /*---- Light Shader -------------------------------------------------------*/
1437 #define SHADER_EOL << std::endl <<
1440 // vertex shader program.
1442 std::string Example::get_vp_program()
1444 using namespace std;
1446 stringstream ost;
1448 ost << "#version 330 compatibility"
1449 << endl << ""
1450 << endl << "#extension GL_ARB_separate_shader_objects: enable"
1451 << endl << "#extension GL_ARB_uniform_buffer_object: enable"
1452 << endl << ""
1453 << endl << "out vec3 vNormalES; // eye space normal"
1454 << endl << "out vec3 vPositionES; // eye space position"
1455 << endl << ""
1456 << endl << "void main()"
1457 << endl << "{"
1458 << endl << " //"
1459 << endl << " // multiply the object space vertex position with the modelview matrix "
1460 << endl << " // to get the eye space vertex position"
1461 << endl << " //"
1462 << endl << " vPositionES = (gl_ModelViewMatrix * gl_Vertex).xyz;"
1463 << endl << ""
1464 << endl << " //"
1465 << endl << " // multiply the object space normal with the normal matrix (transpose of the inverse "
1466 << endl << " // model view matrix) to get the eye space normal"
1467 << endl << " //"
1468 << endl << " vNormalES = gl_NormalMatrix * gl_Normal;"
1469 << endl << ""
1470 << endl << " //"
1471 << endl << " // multiply the combiend modelview projection matrix with the object space vertex"
1472 << endl << " // position to get the clip space position"
1473 << endl << " //"
1474 << endl << " gl_Position = ftransform();"
1475 << endl << "}"
1476 << endl << ""
1477 << endl;
1479 return ost.str();
1483 // fragment shader program for bump mapping in surface local coordinates
1485 std::string Example::get_fp_program()
1487 using namespace std;
1489 stringstream ost;
1491 ost << "#version 330 compatibility"
1492 << endl << ""
1493 << endl << "#extension GL_ARB_separate_shader_objects: enable"
1494 << endl << "#extension GL_ARB_uniform_buffer_object: enable"
1495 << endl << ""
1496 << endl << "in vec3 vNormalES; // eye space normal"
1497 << endl << "in vec3 vPositionES; // eye space position"
1498 << endl << ""
1499 << endl << "uniform bool uRenderAmbient;"
1500 << endl << "uniform bool uRenderDiffuse;"
1501 << endl << "uniform bool uRenderSpecular;"
1502 << endl << "uniform bool uRenderEmissive;"
1503 << endl << ""
1504 << endl << "const int num_lights = 1;"
1505 << endl << "const int num_materials = 100;"
1506 << endl << ""
1507 << endl << "const int directional_light = 0;"
1508 << endl << "const int point_light = 1;"
1509 << endl << "const int spot_light = 2;"
1510 << endl << "const int no_light = 3;"
1511 << endl << ""
1512 << endl << "struct Light"
1513 << endl << "{"
1514 << endl << " vec4 position; // in eye space"
1515 << endl << " vec4 spot_direction; // in eye space"
1516 << endl << ""
1517 << endl << " vec4 Ia; // ambient max. Intensity"
1518 << endl << " vec4 Id; // diffuse max. Intensity"
1519 << endl << " vec4 Is; // specular max. Intensity"
1520 << endl << ""
1521 << endl << " vec4 attenuation; // (constant, linear, quadratic) with constant >= 1 and linear,quadratic >= 0"
1522 << endl << " "
1523 << endl << " float spot_cos_cutoff; // cosine cut of angle"
1524 << endl << ""
1525 << endl << " float spot_exponent; // [0-128]"
1526 << endl << " int type; // directional_light, point_light, spot_light, no_light"
1527 << endl << "};"
1528 << endl << ""
1529 << endl << "layout (std140) uniform Lights"
1530 << endl << "{"
1531 << endl << " Light light[num_lights];"
1532 << endl << "} lights;"
1533 << endl << ""
1534 << endl << "struct Material"
1535 << endl << "{"
1536 << endl << " vec4 ambient;"
1537 << endl << " vec4 diffuse;"
1538 << endl << " vec4 specular;"
1539 << endl << " vec4 emissive;"
1540 << endl << ""
1541 << endl << " float opacity;"
1542 << endl << " float shininess;"
1543 << endl << "};"
1544 << endl << ""
1545 << endl << "layout (std140) uniform Materials"
1546 << endl << "{"
1547 << endl << " Material material[num_materials];"
1548 << endl << "} materials;"
1549 << endl << ""
1550 << endl << ""
1551 << endl << "layout (std140) uniform GeomState"
1552 << endl << "{"
1553 << endl << " int material_index;"
1554 << endl << "} geom_state;"
1555 << endl << ""
1556 << endl << "const vec3 cCameraPositionES = vec3(0,0,0); // eye is at vec3(0,0,0) in eye space!"
1557 << endl << ""
1558 << endl << "layout(location = 0) out vec4 vFragColor;"
1559 << endl << ""
1560 << endl << "//"
1561 << endl << "// directional light contribution"
1562 << endl << "//"
1563 << endl << "vec3 directionalLight("
1564 << endl << " in int i, // light identifier, i.e. current light"
1565 << endl << " in int j, // material identifier"
1566 << endl << " in vec3 n, // vertex normal in eye space"
1567 << endl << " in vec3 v) // view direction in eye space"
1568 << endl << "{"
1569 << endl << " if (lights.light[i].type != directional_light)"
1570 << endl << " return vec3(0.0, 0.0, 0.0);"
1571 << endl << ""
1572 << endl << " //"
1573 << endl << " // the light direction in eye space"
1574 << endl << " //"
1575 << endl << " vec3 l = -lights.light[i].spot_direction.xyz; // we carry the directional light direction in the spot_direction slot"
1576 << endl << ""
1577 << endl << " //"
1578 << endl << " // the half vector"
1579 << endl << " //"
1580 << endl << " vec3 h = normalize(l + v);"
1581 << endl << ""
1582 << endl << " float n_dot_l = max(0.0, dot(n, l));"
1583 << endl << " float n_dot_h = max(0.0, dot(n, h));"
1584 << endl << ""
1585 << endl << " float m = materials.material[j].shininess;"
1586 << endl << ""
1587 << endl << " float pf; // power factor"
1588 << endl << ""
1589 << endl << " if (n_dot_l == 0.0)"
1590 << endl << " pf = 0.0;"
1591 << endl << " else"
1592 << endl << " pf = pow(n_dot_h, m);"
1593 << endl << ""
1594 << endl << " vec3 result = vec3(0);"
1595 << endl << ""
1596 << endl << " if (uRenderEmissive) result += materials.material[j].emissive.rgb;"
1597 << endl << " if (uRenderAmbient) result += lights.light[i].Ia.rgb * materials.material[j].ambient.rgb;"
1598 << endl << " if (uRenderDiffuse) result += lights.light[i].Id.rgb * materials.material[j].diffuse.rgb * n_dot_l; // / PI"
1599 << endl << " if (uRenderSpecular) result += lights.light[i].Is.rgb * materials.material[j].specular.rgb * (m+8)*0.0125 * pf; // * (m+8)/(8*PI)"
1600 << endl << ""
1601 << endl << " return result;"
1602 << endl << "}"
1603 << endl << ""
1604 << endl << "//"
1605 << endl << "// point light contribution"
1606 << endl << "//"
1607 << endl << "vec3 pointLight("
1608 << endl << " in int i, // light identifier, i.e. current light"
1609 << endl << " in int j, // material identifier"
1610 << endl << " in vec3 n, // vertex normal in eye space"
1611 << endl << " in vec3 v, // view direction in eye space"
1612 << endl << " in vec3 p) // vertex position in eye space"
1613 << endl << "{"
1614 << endl << " if (lights.light[i].type != point_light)"
1615 << endl << " return vec3(0.0, 0.0, 0.0);"
1616 << endl << ""
1617 << endl << " vec3 l = vec3(lights.light[i].position.xyz) - p; // direction from surface to light position"
1618 << endl << " float d = length(l); // distance from surface to light source"
1619 << endl << " l = normalize(l); // normalized direction from surface to light position"
1620 << endl << ""
1621 << endl << " //"
1622 << endl << " // the half vector"
1623 << endl << " //"
1624 << endl << " vec3 h = normalize(l + v);"
1625 << endl << ""
1626 << endl << " float n_dot_l = max(0.0, dot(n, l));"
1627 << endl << " float n_dot_h = max(0.0, dot(n, h));"
1628 << endl << ""
1629 << endl << " float m = materials.material[j].shininess;"
1630 << endl << ""
1631 << endl << " float pf; // power factor"
1632 << endl << ""
1633 << endl << " if (n_dot_l == 0.0)"
1634 << endl << " pf = 0.0;"
1635 << endl << " else"
1636 << endl << " pf = pow(n_dot_h, m);"
1637 << endl << ""
1638 << endl << " //"
1639 << endl << " // Compute attenuation"
1640 << endl << " //"
1641 << endl << " float attenuation = 1.0 / (lights.light[i].attenuation.x + "
1642 << endl << " (lights.light[i].attenuation.y * d) + "
1643 << endl << " (lights.light[i].attenuation.z * d * d));"
1644 << endl << ""
1645 << endl << " attenuation = clamp(attenuation, 0.0, 1.0);"
1646 << endl << ""
1647 << endl << " vec3 result = vec3(0);"
1648 << endl << ""
1649 << endl << " if (uRenderEmissive) result += materials.material[j].emissive.rgb;"
1650 << endl << " if (uRenderAmbient) result += lights.light[i].Ia.rgb * materials.material[j].ambient.rgb;"
1651 << endl << " if (uRenderDiffuse) result += lights.light[i].Id.rgb * materials.material[j].diffuse.rgb * n_dot_l; // / PI"
1652 << endl << " if (uRenderSpecular) result += lights.light[i].Is.rgb * materials.material[j].specular.rgb * (m+8)*0.0125 * pf; // * (m+8)/(8*PI)"
1653 << endl << ""
1654 << endl << " return result;"
1655 << endl << "}"
1656 << endl << ""
1657 << endl << "//"
1658 << endl << "// spot light contribution"
1659 << endl << "//"
1660 << endl << "vec3 spotLight("
1661 << endl << " in int i, // light identifier, i.e. current light"
1662 << endl << " in int j, // material identifier"
1663 << endl << " in vec3 n, // vertex normal in eye space"
1664 << endl << " in vec3 v, // view direction in eye space"
1665 << endl << " in vec3 p) // vertex position in eye space"
1666 << endl << "{"
1667 << endl << " if (lights.light[i].type != spot_light)"
1668 << endl << " return vec3(0.0, 0.0, 0.0);"
1669 << endl << ""
1670 << endl << " vec3 l = vec3(lights.light[i].position.xyz) - p; // direction from surface to light position"
1671 << endl << " float d = length(l); // distance from surface to light source"
1672 << endl << " l = normalize(l); // normalized direction from surface to light position"
1673 << endl << " "
1674 << endl << " vec3 s = lights.light[i].spot_direction.xyz; // spot direction"
1675 << endl << ""
1676 << endl << " //"
1677 << endl << " // the half vector"
1678 << endl << " //"
1679 << endl << " vec3 h = normalize(l + v);"
1680 << endl << ""
1681 << endl << " float n_dot_l = max(0.0, dot(n, l));"
1682 << endl << " float n_dot_h = max(0.0, dot(n, h));"
1683 << endl << " float l_dot_s = dot(-l, s);"
1684 << endl << ""
1685 << endl << " float m = materials.material[j].shininess;"
1686 << endl << ""
1687 << endl << " float pf; // power factor"
1688 << endl << ""
1689 << endl << " if (n_dot_l == 0.0)"
1690 << endl << " pf = 0.0;"
1691 << endl << " else"
1692 << endl << " pf = pow(n_dot_h, m);"
1693 << endl << ""
1694 << endl << " //"
1695 << endl << " // Compute attenuation"
1696 << endl << " //"
1697 << endl << " float attenuation = 1.0 / (lights.light[i].attenuation.x + "
1698 << endl << " (lights.light[i].attenuation.y * d) + "
1699 << endl << " (lights.light[i].attenuation.z * d * d));"
1700 << endl << ""
1701 << endl << " attenuation = clamp(attenuation, 0.0, 1.0);"
1702 << endl << ""
1703 << endl << " if (l_dot_s < lights.light[i].spot_cos_cutoff) "
1704 << endl << " attenuation = 0.0;"
1705 << endl << " else"
1706 << endl << " attenuation *= pow(l_dot_s, lights.light[i].spot_exponent);"
1707 << endl << ""
1708 << endl << " vec3 result = vec3(0);"
1709 << endl << ""
1710 << endl << " if (uRenderEmissive) result += materials.material[j].emissive.rgb;"
1711 << endl << " if (uRenderAmbient) result += lights.light[i].Ia.rgb * materials.material[j].ambient.rgb;"
1712 << endl << " if (uRenderDiffuse) result += lights.light[i].Id.rgb * materials.material[j].diffuse.rgb * n_dot_l; // / PI"
1713 << endl << " if (uRenderSpecular) result += lights.light[i].Is.rgb * materials.material[j].specular.rgb * (m+8)*0.0125 * pf; // * (m+8)/(8*PI)"
1714 << endl << ""
1715 << endl << " return result;"
1716 << endl << "}"
1717 << endl << ""
1718 << endl << "void main()"
1719 << endl << "{"
1720 << endl << " //"
1721 << endl << " // normalize the eye space normal"
1722 << endl << " //"
1723 << endl << " vec3 N = normalize(vNormalES);"
1724 << endl << ""
1725 << endl << " //"
1726 << endl << " // get the view vector and normalize it"
1727 << endl << " //"
1728 << endl << " vec3 V = normalize(cCameraPositionES - vPositionES);"
1729 << endl << ""
1730 << endl << " //"
1731 << endl << " // Integrate over all lights: Any unused light does not contribute and each light"
1732 << endl << " // contribute either from the directional light, the point light or the spot light."
1733 << endl << " //"
1734 << endl << " vec3 color = vec3(0.0, 0.0, 0.0);"
1735 << endl << " for (int i = 0; i < num_lights; ++i) {"
1736 << endl << " color += directionalLight(i, geom_state.material_index, N, V) "
1737 << endl << " + pointLight(i, geom_state.material_index, N, V, vPositionES) "
1738 << endl << " + spotLight(i, geom_state.material_index, N, V, vPositionES);"
1739 << endl << " }"
1740 << endl << " vFragColor = vec4(color, materials.material[geom_state.material_index ].opacity);"
1741 << endl << "}"
1742 << endl << ""
1743 << endl;
1745 return ost.str();
1748 /*---- Light --------------------------------------------------------------*/
1750 Light::Light()
1751 : position(0.f, 0.f, 0.f)
1752 , spot_direction(0.f, 1.f, 0.f)
1753 , Ia(1.f, 1.f, 1.f)
1754 , Id(1.f, 1.f, 1.f)
1755 , Is(1.f, 1.f, 1.f)
1756 , attenuation(1.f, 0.f, 0.f)
1757 , spot_cos_cutoff(cosf(45.f))
1758 , spot_exponent(1.f)
1759 , type(no_light)
1762 Light Light::create_light(Type e)
1764 Light l;
1765 l.type = e;
1767 switch (e) {
1768 case directional_light:
1769 l.spot_direction = OSG::Vec3f(1.f, 0.f, 0.f);
1770 break;
1771 case point_light:
1772 l.position = OSG::Pnt3f(0.f, 0.2f, 0.f);
1773 break;
1774 case spot_light:
1775 l.position = OSG::Pnt3f(0.f, 0.2f, 0.f); l.spot_direction = OSG::Pnt3f(0.f, 0.f, 0.f) - l.position;
1776 break;
1777 default:
1778 break;
1780 return l;
1783 /*---- Material -----------------------------------------------------------*/
1785 Material::Material()
1786 : ambient (0.f, 0.f, 0.f)
1787 , diffuse (0.f, 0.f, 0.f)
1788 , specular(0.f, 0.f, 0.f)
1789 , emissive(0.f, 0.f, 0.f)
1790 , opacity(1.f)
1791 , shininess(100.f)
1794 VecMaterialsT initialize_materials(std::size_t num) // helper to create materials
1796 VecMaterialsT materials;
1798 for (std::size_t i = 0; i < num; ++i)
1800 Material m;
1802 OSG::Real32 specular = OSG::RandomPoolManager::the()->getRandomReal32(0.5f, 1.f);
1804 m.diffuse.setRandom();
1805 m.ambient = 0.2f * m.diffuse;
1806 m.specular = OSG::Color3f(specular, specular, specular);
1807 m.emissive = OSG::RandomPoolManager::the()->getRandomReal32(0.1f, 1.f) * m.diffuse;
1808 m.opacity = 1.f;
1809 m.shininess = OSG::RandomPoolManager::the()->getRandomReal32(30.f, 300.f);
1811 materials.push_back(m);
1814 return materials;
1817 /*---- GeomState ----------------------------------------------------------*/
1819 GeomState::GeomState()
1820 : material_index(0)
1823 /*---- HDRShaderData ------------------------------------------------------*/
1825 HDRShaderData::HDRShaderData()
1826 : bloomThreshold(2.0f)
1827 , bloomMagnitude(0.0f)
1828 , toneMapTechnique(4)
1829 , exposure(0.0f)
1830 , keyValue(0.18f)
1831 , autoExposure(2)
1832 , whiteLevel(5.0f)
1833 , shoulderStrength(0.15f)
1834 , linearStrength(0.5f)
1835 , linearAngle(0.1f)
1836 , toeStrength(0.2f)
1837 , toeNumerator(0.02f)
1838 , toeDenominator(0.3f)
1839 , linearWhite(11.2f)
1840 , lumSaturation(1.0f)
1841 , bias(0.85f)
1842 , tau(1.25f)
1843 , nTaps(4)
1844 , sigma(0.8f)
1845 , useLinChromInterp(true)
1848 HDRShaderData::HDRShaderData(const HDRShaderData& rhs)
1849 : bloomThreshold(rhs.bloomThreshold)
1850 , bloomMagnitude(rhs.bloomMagnitude)
1851 , toneMapTechnique(rhs.toneMapTechnique)
1852 , exposure(rhs.exposure)
1853 , keyValue(rhs.keyValue)
1854 , autoExposure(rhs.autoExposure)
1855 , whiteLevel(rhs.whiteLevel)
1856 , shoulderStrength(rhs.shoulderStrength)
1857 , linearStrength(rhs.linearStrength)
1858 , linearAngle(rhs.linearAngle)
1859 , toeStrength(rhs.toeStrength)
1860 , toeNumerator(rhs.toeNumerator)
1861 , toeDenominator(rhs.toeDenominator)
1862 , linearWhite(rhs.linearWhite)
1863 , lumSaturation(rhs.lumSaturation)
1864 , bias(rhs.bias)
1865 , tau(rhs.tau)
1866 , nTaps(rhs.nTaps)
1867 , sigma(rhs.sigma)
1868 , useLinChromInterp(rhs.useLinChromInterp)
1871 HDRShaderData& HDRShaderData::operator=(const HDRShaderData& rhs)
1873 if (&rhs == this) return *this;
1875 bloomThreshold = rhs.bloomThreshold;
1876 bloomMagnitude = rhs.bloomMagnitude;
1877 toneMapTechnique = rhs.toneMapTechnique;
1878 exposure = rhs.exposure;
1879 keyValue = rhs.keyValue;
1880 autoExposure = rhs.autoExposure;
1881 whiteLevel = rhs.whiteLevel;
1882 shoulderStrength = rhs.shoulderStrength;
1883 linearStrength = rhs.linearStrength;
1884 linearAngle = rhs.linearAngle;
1885 toeStrength = rhs.toeStrength;
1886 toeNumerator = rhs.toeNumerator;
1887 toeDenominator = rhs.toeDenominator;
1888 linearWhite = rhs.linearWhite;
1889 lumSaturation = rhs.lumSaturation;
1890 bias = rhs.bias;
1891 tau = rhs.tau;
1892 nTaps = rhs.nTaps;
1893 sigma = rhs.sigma;
1894 useLinChromInterp = rhs.useLinChromInterp;
1896 return *this;
1899 HDRShaderData HDRShaderData::create_min_shader_data()
1901 HDRShaderData data;
1903 data.bloomThreshold = 0.0;
1904 data.bloomMagnitude = 0.0;
1905 data.toneMapTechnique = 0;
1906 data.exposure = -10.0;
1907 data.keyValue = 0.0;
1908 data.autoExposure = 0;
1909 data.whiteLevel = 0.0;
1910 data.shoulderStrength = 0.0;
1911 data.linearStrength = 0.0;
1912 data.linearAngle = 0.0;
1913 data.toeStrength = 0.0;
1914 data.toeNumerator = 0.0;
1915 data.toeDenominator = 0.0;
1916 data.linearWhite = 0.0;
1917 data.lumSaturation = 0.0;
1918 data.bias = 0.0;
1919 data.tau = 0.0;
1920 data.nTaps = 2;
1921 data.sigma = 0.5;
1923 return data;
1926 HDRShaderData HDRShaderData::create_max_shader_data()
1928 HDRShaderData data;
1930 data.bloomThreshold = 10.0;
1931 data.bloomMagnitude = 2.0;
1932 data.toneMapTechnique = 7;
1933 data.exposure = 10.0;
1934 data.keyValue = 1.0;
1935 data.autoExposure = 2;
1936 data.whiteLevel = 25.0;
1937 data.shoulderStrength = 2.0;
1938 data.linearStrength = 5.0;
1939 data.linearAngle = 1.0;
1940 data.toeStrength = 2.0;
1941 data.toeNumerator = 0.5;
1942 data.toeDenominator = 2.0;
1943 data.linearWhite = 20.0;
1944 data.lumSaturation = 4.0;
1945 data.bias = 1.0;
1946 data.tau = 40.0;
1947 data.nTaps = 10;
1948 data.sigma = 1.5;
1950 return data;
1953 /*---- AntTweakBar --------------------------------------------------------*/
1955 #ifdef OSG_WITH_ANTTWEAKBAR
1957 std::string sGenTwDefinition(float vMin, float vMax, float steps, int precision, const char* keyinc, const char* keydec, const char* msg, const char* grp = NULL)
1959 std::string result;
1960 std::stringstream stream;
1962 stream << "min=" << vMin << " "
1963 << "max=" << vMax << " "
1964 << "step=" << (vMax - vMin)/steps << " "
1965 << "precision=" << precision << " "
1966 << "keyIncr=" << keyinc << " "
1967 << "keyDecr=" << keydec << " "
1968 << "help='" << msg << "'";
1970 if (grp)
1971 stream << " " << "group=" << grp;
1973 result = stream.str();
1975 return result;
1978 std::string sGenTwDefinition(int vMin, int vMax, int delta, const char* keyinc, const char* keydec, const char* msg, const char* grp = NULL)
1980 std::string result;
1981 std::stringstream stream;
1983 stream << "min=" << vMin << " "
1984 << "max=" << vMax << " "
1985 << "step=" << delta << " "
1986 << "keyIncr=" << keyinc << " "
1987 << "keyDecr=" << keydec << " "
1988 << "help='" << msg << "'";
1990 if (grp)
1991 stream << " " << "group=" << grp;
1993 result = stream.str();
1995 return result;
1998 void TW_CALL ResetParametersCB(void *clientData)
2000 Example* example = reinterpret_cast<Example*>(clientData);
2001 example->ResetParameters();
2004 void TW_CALL SetSampleNumberCB(const void *value, void *clientData)
2006 Example* example = reinterpret_cast<Example*>(clientData);
2007 const int* num = reinterpret_cast<const int*>(value);
2008 example->SetSampleNumber(*num);
2011 void TW_CALL GetSampleNumberCB(void *value, void *clientData)
2013 Example* example = reinterpret_cast<Example*>(clientData);
2014 int* num = reinterpret_cast<int*>(value);
2015 *num = example->GetSampleNumber();
2018 void TW_CALL SetClearColorCB(const void *value, void *clientData)
2020 Example* example = reinterpret_cast<Example*>(clientData);
2021 const OSG::Color3f* num = reinterpret_cast<const OSG::Color3f*>(value);
2022 example->SetClearColor(*num);
2025 void TW_CALL GetClearColorCB(void *value, void *clientData)
2027 Example* example = reinterpret_cast<Example*>(clientData);
2028 OSG::Color3f* num = reinterpret_cast<OSG::Color3f*>(value);
2029 *num = example->GetClearColor();
2032 void TW_CALL SetForceBgndCB(const void *value, void *clientData)
2034 Example* example = reinterpret_cast<Example*>(clientData);
2035 const bool* num = reinterpret_cast<const bool*>(value);
2036 example->SetForceBgnd(*num);
2039 void TW_CALL GetForceBgndCB(void *value, void *clientData)
2041 Example* example = reinterpret_cast<Example*>(clientData);
2042 bool* num = reinterpret_cast<bool*>(value);
2043 *num = example->GetForceBgnd();
2046 void TW_CALL SetAjustLuminanceCB(const void *value, void *clientData)
2048 Example* example = reinterpret_cast<Example*>(clientData);
2049 const bool* num = reinterpret_cast<const bool*>(value);
2050 example->SetAjustLuminance(*num);
2053 void TW_CALL GetAjustLuminanceCB(void *value, void *clientData)
2055 Example* example = reinterpret_cast<Example*>(clientData);
2056 bool* num = reinterpret_cast<bool*>(value);
2057 *num = example->GetAjustLuminance();
2059 void TW_CALL SetSkyBgndIndexCB(const void *value, void *clientData)
2061 Example* example = reinterpret_cast<Example*>(clientData);
2062 const int* num = reinterpret_cast<const int*>(value);
2063 example->SetSkyBgndIndex(*num);
2066 void TW_CALL GetSkyBgndIndexCB(void *value, void *clientData)
2068 Example* example = reinterpret_cast<Example*>(clientData);
2069 int* num = reinterpret_cast<int*>(value);
2070 *num = example->GetSkyBgndIndex();
2073 void TW_CALL SetPerformBloomCB(const void *value, void *clientData)
2075 Example* example = reinterpret_cast<Example*>(clientData);
2076 const bool* num = reinterpret_cast<const bool*>(value);
2077 example->SetPerformBloom(*num);
2080 void TW_CALL GetPerformBloomCB(void *value, void *clientData)
2082 Example* example = reinterpret_cast<Example*>(clientData);
2083 bool* num = reinterpret_cast<bool*>(value);
2084 *num = example->GetPerformBloom();
2087 void TW_CALL SetBloomBackgroundCB(const void *value, void *clientData)
2089 Example* example = reinterpret_cast<Example*>(clientData);
2090 const bool* num = reinterpret_cast<const bool*>(value);
2091 example->SetBloomBackground(*num);
2094 void TW_CALL GetBloomBackgroundCB(void *value, void *clientData)
2096 Example* example = reinterpret_cast<Example*>(clientData);
2097 bool* num = reinterpret_cast<bool*>(value);
2098 *num = example->GetBloomBackground();
2101 void TW_CALL SetCarryDepthCB(const void *value, void *clientData)
2103 Example* example = reinterpret_cast<Example*>(clientData);
2104 const bool* num = reinterpret_cast<const bool*>(value);
2105 example->SetCarryDepth(*num);
2108 void TW_CALL GetCarryDepthCB(void *value, void *clientData)
2110 Example* example = reinterpret_cast<Example*>(clientData);
2111 bool* num = reinterpret_cast<bool*>(value);
2112 *num = example->GetCarryDepth();
2115 void TW_CALL SetResultIndexCB(const void *value, void *clientData)
2117 Example* example = reinterpret_cast<Example*>(clientData);
2118 const int* num = reinterpret_cast<const int*>(value);
2119 example->SetResultIndex(*num);
2122 void TW_CALL GetResultIndexCB(void *value, void *clientData)
2124 Example* example = reinterpret_cast<Example*>(clientData);
2125 int* num = reinterpret_cast<int*>(value);
2126 *num = example->GetResultIndex();
2129 void TW_CALL SetRenderEmissiveCB(const void *value, void *clientData)
2131 Example* example = reinterpret_cast<Example*>(clientData);
2132 const bool* num = reinterpret_cast<const bool*>(value);
2133 example->SetRenderEmissive(*num);
2136 void TW_CALL GetRenderEmissiveCB(void *value, void *clientData)
2138 Example* example = reinterpret_cast<Example*>(clientData);
2139 bool* num = reinterpret_cast<bool*>(value);
2140 *num = example->GetRenderEmissive();
2143 void TW_CALL SetRenderAmbientCB(const void *value, void *clientData)
2145 Example* example = reinterpret_cast<Example*>(clientData);
2146 const bool* num = reinterpret_cast<const bool*>(value);
2147 example->SetRenderAmbient(*num);
2150 void TW_CALL GetRenderAmbientCB(void *value, void *clientData)
2152 Example* example = reinterpret_cast<Example*>(clientData);
2153 bool* num = reinterpret_cast<bool*>(value);
2154 *num = example->GetRenderAmbient();
2157 void TW_CALL SetRenderDiffuseCB(const void *value, void *clientData)
2159 Example* example = reinterpret_cast<Example*>(clientData);
2160 const bool* num = reinterpret_cast<const bool*>(value);
2161 example->SetRenderDiffuse(*num);
2164 void TW_CALL GetRenderDiffuseCB(void *value, void *clientData)
2166 Example* example = reinterpret_cast<Example*>(clientData);
2167 bool* num = reinterpret_cast<bool*>(value);
2168 *num = example->GetRenderDiffuse();
2171 void TW_CALL SetRenderSpecularCB(const void *value, void *clientData)
2173 Example* example = reinterpret_cast<Example*>(clientData);
2174 const bool* num = reinterpret_cast<const bool*>(value);
2175 example->SetRenderSpecular(*num);
2178 void TW_CALL GetRenderSpecularCB(void *value, void *clientData)
2180 Example* example = reinterpret_cast<Example*>(clientData);
2181 bool* num = reinterpret_cast<bool*>(value);
2182 *num = example->GetRenderSpecular();
2185 void TW_CALL SetAccurateGammaCB(const void *value, void *clientData)
2187 Example* example = reinterpret_cast<Example*>(clientData);
2188 const bool* num = reinterpret_cast<const bool*>(value);
2189 example->SetAccurateGamma(*num);
2192 void TW_CALL GetAccurateGammaCB(void *value, void *clientData)
2194 Example* example = reinterpret_cast<Example*>(clientData);
2195 bool* num = reinterpret_cast<bool*>(value);
2196 *num = example->GetAccurateGamma();
2199 void TW_CALL SetGammaCB(const void *value, void *clientData)
2201 Example* example = reinterpret_cast<Example*>(clientData);
2202 const bool* num = reinterpret_cast<const bool*>(value);
2203 example->SetGamma(*num);
2206 void TW_CALL GetGammaCB(void *value, void *clientData)
2208 Example* example = reinterpret_cast<Example*>(clientData);
2209 bool* num = reinterpret_cast<bool*>(value);
2210 *num = example->GetGamma();
2213 void TW_CALL SetUseITURBT709CB(const void *value, void *clientData)
2215 Example* example = reinterpret_cast<Example*>(clientData);
2216 const bool* num = reinterpret_cast<const bool*>(value);
2217 example->SetUseITURBT709(*num);
2220 void TW_CALL GetUseITURBT709CB(void *value, void *clientData)
2222 Example* example = reinterpret_cast<Example*>(clientData);
2223 bool* num = reinterpret_cast<bool*>(value);
2224 *num = example->GetUseITURBT709();
2227 void TW_CALL SetMipmapLevelCB(const void *value, void *clientData)
2229 Example* example = reinterpret_cast<Example*>(clientData);
2230 const int* num = reinterpret_cast<const int*>(value);
2231 example->SetMipmapLevel(*num);
2234 void TW_CALL GetMipmapLevelCB(void *value, void *clientData)
2236 Example* example = reinterpret_cast<Example*>(clientData);
2237 int* num = reinterpret_cast<int*>(value);
2238 *num = example->GetMipmapLevel();
2241 void TW_CALL SetBloomThresholdCB(const void *value, void *clientData)
2243 Example* example = reinterpret_cast<Example*>(clientData);
2244 const float* num = reinterpret_cast<const float*>(value);
2245 example->SetBloomThreshold(*num);
2248 void TW_CALL GetBloomThresholdCB(void *value, void *clientData)
2250 Example* example = reinterpret_cast<Example*>(clientData);
2251 float* num = reinterpret_cast<float*>(value);
2252 *num = example->GetBloomThreshold();
2255 void TW_CALL SetBloomMagnitudeCB(const void *value, void *clientData)
2257 Example* example = reinterpret_cast<Example*>(clientData);
2258 const float* num = reinterpret_cast<const float*>(value);
2259 example->SetBloomMagnitude(*num);
2262 void TW_CALL GetBloomMagnitudeCB(void *value, void *clientData)
2264 Example* example = reinterpret_cast<Example*>(clientData);
2265 float* num = reinterpret_cast<float*>(value);
2266 *num = example->GetBloomMagnitude();
2269 void TW_CALL SetToneMapTechniqueCB(const void *value, void *clientData)
2271 Example* example = reinterpret_cast<Example*>(clientData);
2272 const int* num = reinterpret_cast<const int*>(value);
2273 example->SetToneMapTechnique(*num);
2276 void TW_CALL GetToneMapTechniqueCB(void *value, void *clientData)
2278 Example* example = reinterpret_cast<Example*>(clientData);
2279 int* num = reinterpret_cast<int*>(value);
2280 *num = example->GetToneMapTechnique();
2283 void TW_CALL SetExposureCB(const void *value, void *clientData)
2285 Example* example = reinterpret_cast<Example*>(clientData);
2286 const float* num = reinterpret_cast<const float*>(value);
2287 example->SetExposure(*num);
2290 void TW_CALL GetExposureCB(void *value, void *clientData)
2292 Example* example = reinterpret_cast<Example*>(clientData);
2293 float* num = reinterpret_cast<float*>(value);
2294 *num = example->GetExposure();
2297 void TW_CALL SetKeyValueCB(const void *value, void *clientData)
2299 Example* example = reinterpret_cast<Example*>(clientData);
2300 const float* num = reinterpret_cast<const float*>(value);
2301 example->SetKeyValue(*num);
2304 void TW_CALL GetKeyValueCB(void *value, void *clientData)
2306 Example* example = reinterpret_cast<Example*>(clientData);
2307 float* num = reinterpret_cast<float*>(value);
2308 *num = example->GetKeyValue();
2311 void TW_CALL SetAutoExposureCB(const void *value, void *clientData)
2313 Example* example = reinterpret_cast<Example*>(clientData);
2314 const int* num = reinterpret_cast<const int*>(value);
2315 example->SetAutoExposure(*num);
2318 void TW_CALL GetAutoExposureCB(void *value, void *clientData)
2320 Example* example = reinterpret_cast<Example*>(clientData);
2321 int* num = reinterpret_cast<int*>(value);
2322 *num = example->GetAutoExposure();
2325 void TW_CALL SetWhiteLevelCB(const void *value, void *clientData)
2327 Example* example = reinterpret_cast<Example*>(clientData);
2328 const float* num = reinterpret_cast<const float*>(value);
2329 example->SetWhiteLevel(*num);
2332 void TW_CALL GetWhiteLevelCB(void *value, void *clientData)
2334 Example* example = reinterpret_cast<Example*>(clientData);
2335 float* num = reinterpret_cast<float*>(value);
2336 *num = example->GetWhiteLevel();
2339 void TW_CALL SetShoulderStrengthCB(const void *value, void *clientData)
2341 Example* example = reinterpret_cast<Example*>(clientData);
2342 const float* num = reinterpret_cast<const float*>(value);
2343 example->SetShoulderStrength(*num);
2346 void TW_CALL GetShoulderStrengthCB(void *value, void *clientData)
2348 Example* example = reinterpret_cast<Example*>(clientData);
2349 float* num = reinterpret_cast<float*>(value);
2350 *num = example->GetShoulderStrength();
2353 void TW_CALL SetLinearStrengthCB(const void *value, void *clientData)
2355 Example* example = reinterpret_cast<Example*>(clientData);
2356 const float* num = reinterpret_cast<const float*>(value);
2357 example->SetLinearStrength(*num);
2360 void TW_CALL GetLinearStrengthCB(void *value, void *clientData)
2362 Example* example = reinterpret_cast<Example*>(clientData);
2363 float* num = reinterpret_cast<float*>(value);
2364 *num = example->GetLinearStrength();
2367 void TW_CALL SetLinearAngleCB(const void *value, void *clientData)
2369 Example* example = reinterpret_cast<Example*>(clientData);
2370 const float* num = reinterpret_cast<const float*>(value);
2371 example->SetLinearAngle(*num);
2374 void TW_CALL GetLinearAngleCB(void *value, void *clientData)
2376 Example* example = reinterpret_cast<Example*>(clientData);
2377 float* num = reinterpret_cast<float*>(value);
2378 *num = example->GetLinearAngle();
2381 void TW_CALL SetToeStrengthCB(const void *value, void *clientData)
2383 Example* example = reinterpret_cast<Example*>(clientData);
2384 const float* num = reinterpret_cast<const float*>(value);
2385 example->SetToeStrength(*num);
2388 void TW_CALL GetToeStrengthCB(void *value, void *clientData)
2390 Example* example = reinterpret_cast<Example*>(clientData);
2391 float* num = reinterpret_cast<float*>(value);
2392 *num = example->GetToeStrength();
2395 void TW_CALL SetToeNumeratorCB(const void *value, void *clientData)
2397 Example* example = reinterpret_cast<Example*>(clientData);
2398 const float* num = reinterpret_cast<const float*>(value);
2399 example->SetToeNumerator(*num);
2402 void TW_CALL GetToeNumeratorCB(void *value, void *clientData)
2404 Example* example = reinterpret_cast<Example*>(clientData);
2405 float* num = reinterpret_cast<float*>(value);
2406 *num = example->GetToeNumerator();
2409 void TW_CALL SetToeDenominatorCB(const void *value, void *clientData)
2411 Example* example = reinterpret_cast<Example*>(clientData);
2412 const float* num = reinterpret_cast<const float*>(value);
2413 example->SetToeDenominator(*num);
2416 void TW_CALL GetToeDenominatorCB(void *value, void *clientData)
2418 Example* example = reinterpret_cast<Example*>(clientData);
2419 float* num = reinterpret_cast<float*>(value);
2420 *num = example->GetToeDenominator();
2423 void TW_CALL SetLinearWhiteCB(const void *value, void *clientData)
2425 Example* example = reinterpret_cast<Example*>(clientData);
2426 const float* num = reinterpret_cast<const float*>(value);
2427 example->SetLinearWhite(*num);
2430 void TW_CALL GetLinearWhiteCB(void *value, void *clientData)
2432 Example* example = reinterpret_cast<Example*>(clientData);
2433 float* num = reinterpret_cast<float*>(value);
2434 *num = example->GetLinearWhite();
2437 void TW_CALL SetLumSaturationCB(const void *value, void *clientData)
2439 Example* example = reinterpret_cast<Example*>(clientData);
2440 const float* num = reinterpret_cast<const float*>(value);
2441 example->SetLumSaturation(*num);
2444 void TW_CALL GetLumSaturationCB(void *value, void *clientData)
2446 Example* example = reinterpret_cast<Example*>(clientData);
2447 float* num = reinterpret_cast<float*>(value);
2448 *num = example->GetLumSaturation();
2451 void TW_CALL SetBiasCB(const void *value, void *clientData)
2453 Example* example = reinterpret_cast<Example*>(clientData);
2454 const float* num = reinterpret_cast<const float*>(value);
2455 example->SetBias(*num);
2458 void TW_CALL GetBiasCB(void *value, void *clientData)
2460 Example* example = reinterpret_cast<Example*>(clientData);
2461 float* num = reinterpret_cast<float*>(value);
2462 *num = example->GetBias();
2465 void TW_CALL SetTauCB(const void *value, void *clientData)
2467 Example* example = reinterpret_cast<Example*>(clientData);
2468 const float* num = reinterpret_cast<const float*>(value);
2469 example->SetTau(*num);
2472 void TW_CALL GetTauCB(void *value, void *clientData)
2474 Example* example = reinterpret_cast<Example*>(clientData);
2475 float* num = reinterpret_cast<float*>(value);
2476 *num = example->GetTau();
2479 void TW_CALL SetNTapsCB(const void *value, void *clientData)
2481 Example* example = reinterpret_cast<Example*>(clientData);
2482 const int* num = reinterpret_cast<const int*>(value);
2483 example->SetNTaps(*num);
2486 void TW_CALL GetNTapsCB(void *value, void *clientData)
2488 Example* example = reinterpret_cast<Example*>(clientData);
2489 int* num = reinterpret_cast<int*>(value);
2490 *num = example->GetNTaps();
2493 void TW_CALL SetSigmaCB(const void *value, void *clientData)
2495 Example* example = reinterpret_cast<Example*>(clientData);
2496 const float* num = reinterpret_cast<const float*>(value);
2497 example->SetSigma(*num);
2500 void TW_CALL GetSigmaCB(void *value, void *clientData)
2502 Example* example = reinterpret_cast<Example*>(clientData);
2503 float* num = reinterpret_cast<float*>(value);
2504 *num = example->GetSigma();
2507 void TW_CALL SetUseLinChromInterpCB(const void *value, void *clientData)
2509 Example* example = reinterpret_cast<Example*>(clientData);
2510 const bool* num = reinterpret_cast<const bool*>(value);
2511 example->SetUseLinChromInterp(*num);
2514 void TW_CALL GetUseLinChromInterpCB(void *value, void *clientData)
2516 Example* example = reinterpret_cast<Example*>(clientData);
2517 bool* num = reinterpret_cast<bool*>(value);
2518 *num = example->GetUseLinChromInterp();
2521 void Example::ResetParameters()
2523 _hdrShaderData = _hdrShaderDataDefault;
2525 if (_hdrStage)
2526 create_hdr_stage();
2528 glutPostRedisplay();
2531 void Example::SetSampleNumber(int value)
2533 if (value < _num_samples)
2535 switch (_num_samples)
2537 case 0:
2538 break;
2539 case 4:
2540 _num_samples = 0;
2541 break;
2542 case 8:
2543 _num_samples = 4;
2544 break;
2545 case 16:
2546 _num_samples = 8;
2547 break;
2548 case 32:
2549 _num_samples = 16;
2550 break;
2553 else if (value > _num_samples)
2555 switch (_num_samples)
2557 case 0:
2558 _num_samples = 4;
2559 break;
2560 case 4:
2561 _num_samples = 8;
2562 break;
2563 case 8:
2564 _num_samples = 16;
2565 break;
2566 case 16:
2567 _num_samples = 32;
2568 break;
2569 case 32:
2570 break;
2574 if (_hdrStage)
2575 create_hdr_stage();
2577 glutPostRedisplay();
2580 int Example::GetSampleNumber() const
2582 return _num_samples;
2585 void Example::SetClearColor(const OSG::Color3f& value)
2587 _clear_color = value;
2589 _solidBgnd->setColor(_clear_color);
2591 glutPostRedisplay();
2594 const OSG::Color3f& Example::GetClearColor() const
2596 return _clear_color;
2599 void Example::SetForceBgnd(bool value)
2601 _force_bgnd = value;
2603 if (_hdrStage)
2604 _hdrStage->setForceBackground(_force_bgnd);
2606 glutPostRedisplay();
2609 bool Example::GetForceBgnd() const
2611 return _force_bgnd;
2614 void Example::SetAjustLuminance(bool value)
2616 _adjust_luminance = value;
2618 if (_hdrStage)
2619 _hdrStage->setAdjustLuminance(_adjust_luminance);
2621 glutPostRedisplay();
2624 bool Example::GetAjustLuminance() const
2626 return _adjust_luminance;
2629 void Example::SetPerformBloom(bool value)
2631 _perform_bloom = value;
2633 if (_hdrStage)
2634 create_hdr_stage();
2636 glutPostRedisplay();
2639 bool Example::GetPerformBloom() const
2641 return _perform_bloom;
2644 void Example::SetBloomBackground(bool value)
2646 _bloom_background = value;
2648 if (_hdrStage)
2649 _hdrStage->setBloomBackground(_bloom_background);
2651 glutPostRedisplay();
2654 bool Example::GetBloomBackground() const
2656 return _bloom_background;
2659 void Example::SetCarryDepth(bool value)
2661 _carry_depth = value;
2663 if (_hdrStage)
2664 create_hdr_stage();
2666 glutPostRedisplay();
2669 bool Example::GetCarryDepth() const
2671 return _carry_depth;
2674 void Example::SetSkyBgndIndex(int value)
2676 if (_skyBgnd_index != value)
2678 _skyBgnd_index = value;
2680 if (_skyBgnd_index < 0)
2681 _mgr->setBackground(_solidBgnd);
2682 else if (_skyBgnd_index < _vecSkyBgnd.size())
2683 _mgr->setBackground(_vecSkyBgnd[_skyBgnd_index].second);
2685 glutPostRedisplay();
2689 int Example::GetSkyBgndIndex() const
2691 return _skyBgnd_index;
2694 void Example::SetResultIndex(int value)
2696 if (_result_index != value)
2698 _result_index = value;
2700 if (_hdrStage)
2701 _hdrStage->setTarget(_result_index);
2703 glutPostRedisplay();
2707 int Example::GetResultIndex() const
2709 return _result_index;
2712 void Example::SetRenderEmissive(bool value)
2714 _render_emissive = value;
2715 _prog_chunk->updateUniformVariable("uRenderEmissive", _render_emissive);
2716 glutPostRedisplay();
2719 bool Example::GetRenderEmissive() const
2721 return _render_emissive;
2724 void Example::SetRenderAmbient(bool value)
2726 _render_ambient = value;
2727 _prog_chunk->updateUniformVariable("uRenderAmbient", _render_ambient);
2728 glutPostRedisplay();
2731 bool Example::GetRenderAmbient() const
2733 return _render_ambient;
2736 void Example::SetRenderDiffuse(bool value)
2738 _render_diffuse = value;
2739 _prog_chunk->updateUniformVariable("uRenderDiffuse", _render_diffuse);
2740 glutPostRedisplay();
2743 bool Example::GetRenderDiffuse() const
2745 return _render_diffuse;
2748 void Example::SetRenderSpecular(bool value)
2750 _render_specular = value;
2751 _prog_chunk->updateUniformVariable("uRenderSpecular", _render_specular);
2752 glutPostRedisplay();
2755 bool Example::GetRenderSpecular() const
2757 return _render_specular;
2760 void Example::SetAccurateGamma(bool value)
2762 _accurate_gamma = value;
2764 if (_hdrStage)
2765 _hdrStage->setAccurateGamma(_accurate_gamma);
2767 glutPostRedisplay();
2770 bool Example::GetAccurateGamma() const
2772 return _accurate_gamma;
2775 void Example::SetGamma(bool value)
2777 _gamma = value;
2779 if (_hdrStage)
2780 _hdrStage->setApplyGamma(_gamma);
2782 glutPostRedisplay();
2785 bool Example::GetGamma() const
2787 return _gamma;
2790 void Example::SetUseITURBT709(bool value)
2792 _use_ITU_R_BT_709 = value;
2794 if (_hdrStage)
2795 _hdrStage->setUse_ITU_R_BT_709(_use_ITU_R_BT_709);
2797 glutPostRedisplay();
2800 bool Example::GetUseITURBT709() const
2802 return _use_ITU_R_BT_709;
2805 void Example::SetMipmapLevel(int value)
2807 _mipmap_level = value;
2809 if (_hdrStage)
2810 _hdrStage->setMipmapLevel(_mipmap_level);
2812 glutPostRedisplay();
2815 int Example::GetMipmapLevel() const
2817 return _mipmap_level;
2820 void Example::SetBloomThreshold(float value)
2822 _hdrShaderData.bloomThreshold = value;
2824 if (_hdrStage)
2825 _hdrStage->setBloomThreshold(_hdrShaderData.bloomThreshold);
2827 glutPostRedisplay();
2830 float Example::GetBloomThreshold() const
2832 return _hdrShaderData.bloomThreshold;
2835 void Example::SetBloomMagnitude(float value)
2837 _hdrShaderData.bloomMagnitude = value;
2839 if (_hdrStage)
2840 _hdrStage->setBloomMagnitude(_hdrShaderData.bloomMagnitude);
2842 glutPostRedisplay();
2845 float Example::GetBloomMagnitude() const
2847 return _hdrShaderData.bloomMagnitude;
2850 void Example::SetToneMapTechnique(int value)
2852 _hdrShaderData.toneMapTechnique = value;
2854 if (_hdrStage)
2855 _hdrStage->setToneMappingMode(_hdrShaderData.toneMapTechnique);
2857 glutPostRedisplay();
2860 int Example::GetToneMapTechnique() const
2862 return _hdrShaderData.toneMapTechnique;
2865 void Example::SetExposure(float value)
2867 _hdrShaderData.exposure = value;
2869 if (_hdrStage)
2870 _hdrStage->setExposure(_hdrShaderData.exposure);
2872 glutPostRedisplay();
2875 float Example::GetExposure() const
2877 return _hdrShaderData.exposure;
2880 void Example::SetKeyValue(float value)
2882 _hdrShaderData.keyValue = value;
2884 if (_hdrStage)
2885 _hdrStage->setKeyValue(_hdrShaderData.keyValue);
2887 glutPostRedisplay();
2890 float Example::GetKeyValue() const
2892 return _hdrShaderData.keyValue;
2895 void Example::SetAutoExposure(int value)
2897 _hdrShaderData.autoExposure = value;
2899 if (_hdrStage)
2900 _hdrStage->setAutoExposureMode(_hdrShaderData.autoExposure);
2902 glutPostRedisplay();
2905 int Example::GetAutoExposure() const
2907 return _hdrShaderData.autoExposure;
2910 void Example::SetWhiteLevel(float value)
2912 _hdrShaderData.whiteLevel = value;
2914 if (_hdrStage)
2915 _hdrStage->setWhiteLevel(_hdrShaderData.whiteLevel);
2917 glutPostRedisplay();
2920 float Example::GetWhiteLevel() const
2922 return _hdrShaderData.whiteLevel;
2925 void Example::SetShoulderStrength(float value)
2927 _hdrShaderData.shoulderStrength = value;
2929 if (_hdrStage)
2930 _hdrStage->setFilmicShoulderStrenght(_hdrShaderData.shoulderStrength);
2932 glutPostRedisplay();
2935 float Example::GetShoulderStrength() const
2937 return _hdrShaderData.shoulderStrength;
2940 void Example::SetLinearStrength(float value)
2942 _hdrShaderData.linearStrength = value;
2944 if (_hdrStage)
2945 _hdrStage->setFilmicLinearStrength(_hdrShaderData.linearStrength);
2947 glutPostRedisplay();
2950 float Example::GetLinearStrength() const
2952 return _hdrShaderData.linearStrength;
2955 void Example::SetLinearAngle(float value)
2957 _hdrShaderData.linearAngle = value;
2959 if (_hdrStage)
2960 _hdrStage->setFilmicLinearAngle(_hdrShaderData.linearAngle);
2962 glutPostRedisplay();
2965 float Example::GetLinearAngle() const
2967 return _hdrShaderData.linearAngle;
2970 void Example::SetToeStrength(float value)
2972 _hdrShaderData.toeStrength = value;
2974 if (_hdrStage)
2975 _hdrStage->setFilmicToeStrength(_hdrShaderData.toeStrength);
2977 glutPostRedisplay();
2980 float Example::GetToeStrength() const
2982 return _hdrShaderData.toeStrength;
2985 void Example::SetToeNumerator(float value)
2987 _hdrShaderData.toeNumerator = value;
2989 if (_hdrStage)
2990 _hdrStage->setFilmicToeNumerator(_hdrShaderData.toeNumerator);
2992 glutPostRedisplay();
2995 float Example::GetToeNumerator() const
2997 return _hdrShaderData.toeNumerator;
3000 void Example::SetToeDenominator(float value)
3002 _hdrShaderData.toeDenominator = value;
3004 if (_hdrStage)
3005 _hdrStage->setFilmicToeDenominator(_hdrShaderData.toeDenominator);
3007 glutPostRedisplay();
3010 float Example::GetToeDenominator() const
3012 return _hdrShaderData.toeDenominator;
3015 void Example::SetLinearWhite(float value)
3017 _hdrShaderData.linearWhite = value;
3019 if (_hdrStage)
3020 _hdrStage->setFilmicLinearWhite(_hdrShaderData.linearWhite);
3022 glutPostRedisplay();
3025 float Example::GetLinearWhite() const
3027 return _hdrShaderData.linearWhite;
3030 void Example::SetLumSaturation(float value)
3032 _hdrShaderData.lumSaturation = value;
3034 if (_hdrStage)
3035 _hdrStage->setSaturation(_hdrShaderData.lumSaturation);
3037 glutPostRedisplay();
3040 float Example::GetLumSaturation() const
3042 return _hdrShaderData.lumSaturation;
3045 void Example::SetBias(float value)
3047 _hdrShaderData.bias = value;
3049 if (_hdrStage)
3050 _hdrStage->setDragoBias(_hdrShaderData.bias);
3052 glutPostRedisplay();
3055 float Example::GetBias() const
3057 return _hdrShaderData.bias;
3060 void Example::SetTau(float value)
3062 _hdrShaderData.tau = value;
3064 if (_hdrStage)
3065 _hdrStage->setTau(_hdrShaderData.tau);
3067 glutPostRedisplay();
3070 float Example::GetTau() const
3072 return _hdrShaderData.tau;
3075 void Example::SetNTaps(int value)
3077 _hdrShaderData.nTaps = value;
3079 if (_hdrStage)
3080 _hdrStage->setNumTaps(_hdrShaderData.nTaps);
3082 glutPostRedisplay();
3085 int Example::GetNTaps() const
3087 return _hdrShaderData.nTaps;
3090 void Example::SetSigma(float value)
3092 _hdrShaderData.sigma = value;
3094 if (_hdrStage)
3095 _hdrStage->setBlurGaussSigma(_hdrShaderData.sigma);
3097 glutPostRedisplay();
3100 float Example::GetSigma() const
3102 return _hdrShaderData.sigma;
3105 void Example::SetUseLinChromInterp(bool value)
3107 _hdrShaderData.useLinChromInterp = value;
3109 if (_hdrStage)
3110 _hdrStage->setUseLinChromCorrection(_hdrShaderData.useLinChromInterp);
3112 glutPostRedisplay();
3115 bool Example::GetUseLinChromInterp() const
3117 return _hdrShaderData.useLinChromInterp;
3120 void Example::setupTweakBar()
3122 if (_tweakbar) return;
3124 _tweakbar = TwNewBar("TweakBar");
3126 TwDefine(" GLOBAL help='This example is about tone mapping in OpenSG.' ");
3127 TwDefine(" TweakBar size='350 700' color='96 216 224' valueswidth=170");
3130 // Global group
3132 TwAddButton(_tweakbar, "Reset Parameters", ResetParametersCB, this, "key=r help='Reset all parameters back to default values'");
3133 TwAddVarRW(_tweakbar, "Pause Animation", TW_TYPE_BOOLCPP, &_pause, "key=SPACE help='Pause animation'");
3134 TwAddVarCB(_tweakbar, "Carry Depth", TW_TYPE_BOOLCPP, SetCarryDepthCB, GetCarryDepthCB, this, "help='Carry depth buffer to final render target'");
3137 // Group 'Luminance Adaption'
3139 TwAddVarCB(_tweakbar, "Adjust Luminance", TW_TYPE_BOOLCPP, SetAjustLuminanceCB, GetAjustLuminanceCB, this, "help='Toggle Luminance time dependent adjustment.' group='Luminance Adaption'");
3140 TwAddVarCB(_tweakbar, "Tau", TW_TYPE_FLOAT, SetTauCB, GetTauCB, this, sGenTwDefinition(_hdrShaderDataMin.tau, _hdrShaderDataMax.tau, 100, 2, "a", "A", "Luminance (eye) adaption time parameter.", "'Luminance Adaption'").c_str());
3143 // Group 'Gamma Correction'
3145 TwAddVarCB(_tweakbar, "Gamma", TW_TYPE_BOOLCPP, SetGammaCB, GetGammaCB, this, "key=g help='Apply Gamma correction at the end of the pipeline.' group='Gamma Correction'");
3146 TwAddVarCB(_tweakbar, "Accurate", TW_TYPE_BOOLCPP, SetAccurateGammaCB, GetAccurateGammaCB, this, "key=G help='Use accurate Gamma to linear mapping.' group='Gamma Correction'");
3149 // Group 'Bloom'
3151 TwAddVarCB(_tweakbar, "Bloom Pass", TW_TYPE_BOOLCPP, SetPerformBloomCB, GetPerformBloomCB, this, "help='Perform Bloom pass.' group=Bloom");
3152 TwAddVarCB(_tweakbar, "Bloom Background",TW_TYPE_BOOLCPP, SetBloomBackgroundCB, GetBloomBackgroundCB, this, "help='Perform Bloom pass.' group=Bloom");
3153 TwAddVarCB(_tweakbar, "Threshold", TW_TYPE_FLOAT, SetBloomThresholdCB, GetBloomThresholdCB, this, sGenTwDefinition(_hdrShaderDataMin.bloomThreshold, _hdrShaderDataMax.bloomThreshold, 100, 2, "t", "T", "Used by function CalcExposedColor of the Threshold shader: exposure -= bloomThreshold", "Bloom").c_str());
3154 TwAddVarCB(_tweakbar, "Magnitude", TW_TYPE_FLOAT, SetBloomMagnitudeCB, GetBloomMagnitudeCB, this, sGenTwDefinition(_hdrShaderDataMin.bloomMagnitude, _hdrShaderDataMax.bloomMagnitude, 100, 2, "u", "U", "Used by function main of the Composite shader: bloom *= bloomMagnitude", "Bloom").c_str());
3155 TwAddVarCB(_tweakbar, "Taps", TW_TYPE_INT32, SetNTapsCB, GetNTapsCB, this, sGenTwDefinition(_hdrShaderDataMin.nTaps, _hdrShaderDataMax.nTaps, 1, "p", "P", "Number if tap iterations used in the Bloom Blur shader.", "Bloom").c_str());
3156 TwAddVarCB(_tweakbar, "Sigma", TW_TYPE_FLOAT, SetSigmaCB, GetSigmaCB, this, sGenTwDefinition(_hdrShaderDataMin.sigma, _hdrShaderDataMax.sigma, 100, 2, "f", "F", "Used by function CalcGaussianWeight of the Blur shader.", "Bloom").c_str());
3159 // Group 'Tonemapping'
3161 TwAddVarCB(_tweakbar, "Luminance ITU-R-BT.709", TW_TYPE_BOOLCPP, SetUseITURBT709CB, GetUseITURBT709CB, this, "help='Calculate relative luminance according to ITU-R-BT.709.' group=Tonemapping");
3162 TwAddVarCB(_tweakbar, "Mipmap Level", TW_TYPE_INT32, SetMipmapLevelCB, GetMipmapLevelCB, this, sGenTwDefinition(-1, 12, 1, "z", "Z", "The Mipmap Level addresses the texture to be used for avg. luminance lookup. See Exposure render texture. Default is -1.", "Tonemapping").c_str());
3164 TwEnumVal toneMappingEnums[] = { {0, "None"}, {1, "Logarithmic"}, {2, "Exponential"}, {3, "Drago Logarithmic"}, {4, "Reinhard"}, {5, "Reinhard Modified"}, {6, "Filmic Hable"}, {7, "Filmic Uncharte2D"} };
3165 TwType toneMappingType = TwDefineEnum("ToneMappingType", toneMappingEnums, 8);
3166 TwAddVarCB(_tweakbar, "Technique", toneMappingType, SetToneMapTechniqueCB, GetToneMapTechniqueCB, this, "help='The tone mapping algorithm.' group=Tonemapping");
3168 TwEnumVal autoExposureEnums[] = { {0, "Manual"}, {1, "Geom. mean of lumi. (KeyValue)"}, {2, "Geom. mean of lumi. (Auto KeyValue)"} };
3169 TwType autoExposureType = TwDefineEnum("AutoExposureType", autoExposureEnums, 3);
3170 TwAddVarCB(_tweakbar, "AutoExposure", autoExposureType, SetAutoExposureCB, GetAutoExposureCB, this, "help='Algorithm to determine the exposure value.' group=Tonemapping");
3172 TwAddVarCB(_tweakbar, "Exposure", TW_TYPE_FLOAT, SetExposureCB, GetExposureCB, this, sGenTwDefinition(_hdrShaderDataMin.exposure, _hdrShaderDataMax.exposure, 100, 2, "e", "E", "Manual exposure: The HDR pixel value is then scaled by 2^exposure.", "Tonemapping").c_str());
3173 TwAddVarCB(_tweakbar, "KeyValue", TW_TYPE_FLOAT, SetKeyValueCB, GetKeyValueCB, this, sGenTwDefinition(_hdrShaderDataMin.keyValue, _hdrShaderDataMax.keyValue, 100, 2, "k", "K", "Used in the geometric mean calculation of the luminance. a \"key value\" is user-controlled, and is meant to be chosen based on whether the scene is \"high-key\" (bright, low contrast) or \"low-key\" (dark, high contrast).", "Tonemapping").c_str());
3174 TwAddVarCB(_tweakbar, "White Level", TW_TYPE_FLOAT, SetWhiteLevelCB, GetWhiteLevelCB, this, sGenTwDefinition(_hdrShaderDataMin.whiteLevel, _hdrShaderDataMax.whiteLevel, 10000, 4, "w", "W", "Sets what pixels are pure white in the image, producing a result similar to how exposure functions in a camera.", "Tonemapping").c_str());
3175 TwAddVarCB(_tweakbar, "Saturation", TW_TYPE_FLOAT, SetLumSaturationCB, GetLumSaturationCB, this, sGenTwDefinition(_hdrShaderDataMin.lumSaturation, _hdrShaderDataMax.lumSaturation, 100, 2, "l", "L", "Luminance saturation.", "Tonemapping").c_str());
3176 TwAddVarCB(_tweakbar, "Linear Sat Interp.", TW_TYPE_BOOLCPP, SetUseLinChromInterpCB, GetUseLinChromInterpCB, this, "help='Perform linear interpolation on color correction.' group=Tonemapping");
3178 TwAddVarCB(_tweakbar, "Shoulder Strength", TW_TYPE_FLOAT, SetShoulderStrengthCB, GetShoulderStrengthCB, this, sGenTwDefinition(_hdrShaderDataMin.shoulderStrength, _hdrShaderDataMax.shoulderStrength, 100, 2, "y", "Y", "Shoulder strength used in Uncharte2D Filmic Tonmapping.", "'Filmic Uncharte2D'").c_str());
3179 TwAddVarCB(_tweakbar, "Linear Strength", TW_TYPE_FLOAT, SetLinearStrengthCB, GetLinearStrengthCB, this, sGenTwDefinition(_hdrShaderDataMin.linearStrength, _hdrShaderDataMax.linearStrength, 100, 2, "x", "X", "Linear strength used in Uncharte2D Filmic Tonmapping.", "'Filmic Uncharte2D'").c_str());
3180 TwAddVarCB(_tweakbar, "Linear Angle", TW_TYPE_FLOAT, SetLinearAngleCB, GetLinearAngleCB, this, sGenTwDefinition(_hdrShaderDataMin.linearAngle, _hdrShaderDataMax.linearAngle, 100, 2, "c", "C", "Linear angle used in Uncharte2D Filmic Tonmapping.", "'Filmic Uncharte2D'").c_str());
3181 TwAddVarCB(_tweakbar, "Toe Strength", TW_TYPE_FLOAT, SetToeStrengthCB, GetToeStrengthCB, this, sGenTwDefinition(_hdrShaderDataMin.toeStrength, _hdrShaderDataMax.toeStrength, 100, 2, "v", "V", "Toe strength used in Uncharte2D Filmic Tonmapping.", "'Filmic Uncharte2D'").c_str());
3182 TwAddVarCB(_tweakbar, "Toe Numerator", TW_TYPE_FLOAT, SetToeNumeratorCB, GetToeNumeratorCB, this, sGenTwDefinition(_hdrShaderDataMin.toeNumerator, _hdrShaderDataMax.toeNumerator, 100, 2, "b", "B", "Toe numerator used in Uncharte2D Filmic Tonmapping.", "'Filmic Uncharte2D'").c_str());
3183 TwAddVarCB(_tweakbar, "Toe Denominator", TW_TYPE_FLOAT, SetToeDenominatorCB, GetToeDenominatorCB, this, sGenTwDefinition(_hdrShaderDataMin.toeDenominator, _hdrShaderDataMax.toeDenominator, 100, 2, "n", "N", "Toe denominator used in Uncharte2D Filmic Tonmapping.", "'Filmic Uncharte2D'").c_str());
3184 TwAddVarCB(_tweakbar, "Linear White", TW_TYPE_FLOAT, SetLinearWhiteCB, GetLinearWhiteCB, this, sGenTwDefinition(_hdrShaderDataMin.linearWhite, _hdrShaderDataMax.linearWhite, 1000, 2, "d", "D", "Linear white used in Uncharte2D Filmic Tonmapping.", "'Filmic Uncharte2D'").c_str());
3186 TwAddVarCB(_tweakbar, "Bias", TW_TYPE_FLOAT, SetBiasCB, GetBiasCB, this, sGenTwDefinition(_hdrShaderDataMin.bias, _hdrShaderDataMax.bias, 100, 2, "i", "I", "Bias parameter of the Drago Logarithmic Tonmapping.", "'Drago Logarithmic'").c_str());
3188 TwDefine("TweakBar/'Filmic Uncharte2D' group=Tonemapping");
3189 TwDefine("TweakBar/'Drago Logarithmic' group=Tonemapping");
3192 // Group 'Environment'
3194 TwAddVarCB(_tweakbar, "Sample Number", TW_TYPE_INT32, SetSampleNumberCB, GetSampleNumberCB, this, "help='Multisampling buffer sample number step=4' group=Environment");
3195 TwAddVarCB(_tweakbar, "Background Color", TW_TYPE_COLOR3F, SetClearColorCB, GetClearColorCB, this, "help='Background color used for rendering' group=Environment");
3196 TwAddVarCB(_tweakbar, "Force Background", TW_TYPE_BOOLCPP, SetForceBgndCB, GetForceBgndCB, this, "help='Force the background as defined by the user, i.e. do not allow tonemapping of the background.' group=Environment");
3198 std::vector<TwEnumVal> skyBoxeEnums;
3200 TwEnumVal val;
3201 val.Value = -1;
3202 val.Label = "No SkyBox";
3203 skyBoxeEnums.push_back(val);
3205 for (int i = 0; i < _vecSkyBgnd.size(); ++i)
3207 TwEnumVal val;
3208 val.Value = i;
3209 val.Label = _vecSkyBgnd[i].first.c_str();
3210 skyBoxeEnums.push_back(val);
3213 TwType skyBoxType = TwDefineEnum("SkyBoxType", &skyBoxeEnums[0], static_cast<unsigned int>(skyBoxeEnums.size()));
3214 TwAddVarCB(_tweakbar, "SkyBox", skyBoxType, SetSkyBgndIndexCB, GetSkyBgndIndexCB, this, "help='Available sky boxes' group=Environment");
3216 TwEnumVal renderTextureEnums[] = {
3217 { OSG::HDR2Stage::SCENE_TEXTURE, "Non Post Processed Scene"},
3218 { OSG::HDR2Stage::LUMINANCE_TEXTURE, "Luminance Map (No exp)"},
3219 { OSG::HDR2Stage::ADAPTED_LUMINANCE_TEXTURE, "Avaraged Luminance Map (exp)"},
3220 { OSG::HDR2Stage::THRESHOLD_TEXTURE, "Threshold Map"},
3221 { OSG::HDR2Stage::BLURRED_TEXTURE, "Bloom Blurred Map"},
3222 { OSG::HDR2Stage::COMPOSITE_TEXTURE, "Composite"},
3223 { OSG::HDR2Stage::EXPOSURE_TEXTURE, "Exposure Map"},
3224 { OSG::HDR2Stage::DEPTH_TEXTURE, "Depth Map"},
3225 { OSG::HDR2Stage::LINEARIZED_DEPTH_TEXTURE, "Linearized Depth Map"}
3228 { OSG::HDR2Stage::DOWN_SCALED_0, "Down Scale 0 Map"},
3229 { OSG::HDR2Stage::DOWN_SCALED_1, "Down Scale 1 Map"},
3230 { OSG::HDR2Stage::DOWN_SCALED_2, "Down Scale 2 Map"},
3231 { OSG::HDR2Stage::BLUR_TEXTURE, "BLUR Map"},
3232 { OSG::HDR2Stage::UPSCALED_SCALED_0, "Up Scale 0 MapDepth Map"},
3233 { OSG::HDR2Stage::UPSCALED_SCALED_1, "Up Scale 1 Map"},
3237 TwType renderTextureType = TwDefineEnum("RenderTextureType", renderTextureEnums, 15);//9);
3238 TwAddVarCB(_tweakbar, "Render Texture", renderTextureType, SetResultIndexCB, GetResultIndexCB, this, "help='The texture that is finally drawn' group=Environment");
3241 // Group 'Light'
3243 TwAddVarCB(_tweakbar, "Emissive", TW_TYPE_BOOLCPP, SetRenderEmissiveCB, GetRenderEmissiveCB, this, "help='Render emessive contribution.' group=Light");
3244 TwAddVarCB(_tweakbar, "Ambient", TW_TYPE_BOOLCPP, SetRenderAmbientCB, GetRenderAmbientCB, this, "help='Render ambient contribution.' group=Light");
3245 TwAddVarCB(_tweakbar, "Diffuse", TW_TYPE_BOOLCPP, SetRenderDiffuseCB, GetRenderDiffuseCB, this, "help='Render diffuse contribution.' group=Light");
3246 TwAddVarCB(_tweakbar, "Specular", TW_TYPE_BOOLCPP, SetRenderSpecularCB, GetRenderSpecularCB, this, "help='Render specular contribution.' group=Light");
3249 #endif