vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Lights.h
Go to the documentation of this file.
1 #pragma once
2 
3 //VRECKO
4 #include <vrecko/Ability.h>
5 #include <vrecko/PluginManager.h>
6 #include <vrecko/World.h>
7 #include <vrecko/Scene.h>
8 
9 //Lights
10 #include <osg/LightSource>
11 #include <osg/Light>
12 #include <osg/LightModel>
13 
14 //XML
15 #include <helpers/XercesXMLUtils.h>
16 #include <vrecko/ReaderWriter.h>
17 #include <xercesc/parsers/XercesDOMParser.hpp>
18 
19 //Shadows
20 #include <osgShadow/ShadowMap>
21 #include <osgShadow/SoftShadowMap>
22 #include <osgShadow/ShadowTexture>
23 #include <osgShadow/LightSpacePerspectiveShadowMap>
24 #include <osg/CullFace>
25 
26 //Billboarding
27 #include <osg/BlendFunc>
28 #include <osg/AlphaFunc>
29 #include <osg/Geometry>
30 #include <osg/Texture2D>
31 #include <osgDB/readFile>
32 #include <osg/Depth>
33 
34 #include <cmath>
35 #include <sstream>
36 #include <iostream>
37 
38 
39 namespace APLightsEditor
40 {
41 
42 class Lights : public vrecko::Ability
43 {
44 private:
45  osg::ref_ptr<osg::Group> lightGroup;
46  //Shadow techniques
47  osg::ref_ptr<osgShadow::ShadowMap> sm;
48  osg::ref_ptr<osgShadow::SoftShadowMap> ssm;
49  //osg::ref_ptr<osgShadow::ShadowTexture> lispSM;
50 
51  osg::ref_ptr<osg::ClearNode> clearColor;
52  osg::ref_ptr<osg::LightModel> lightModel;
53  osg::ref_ptr<osg::StateSet> lightSS;
54  std::vector<osg::Node*> flares;
55  unsigned int maxLights;
56  int shadowLightID;
57  int sunID;
58  osg::Vec4 sunDate; //saved as osg::Vec4(day,month,year,hour*60+minute)
59 
60  osg::ref_ptr<osg::Uniform> maximum;
61 
62  //global illumination variables
63  osg::ref_ptr<osg::Camera> ndCamera;
64  osg::ref_ptr<osg::Camera> ndCameraBack;
65  osg::ref_ptr<osg::Camera> doCamera;
66  osg::ref_ptr<osg::Camera> bounceCamera;
67  osg::ref_ptr<osg::Camera> blurXCamera;
68  osg::ref_ptr<osg::Camera> blurYCamera;
69  osg::ref_ptr<osg::StateSet> ndSS;
70  osg::ref_ptr<osg::StateSet> ndBSS;
71  osg::ref_ptr<osg::StateSet> doSS;
72  osg::ref_ptr<osg::StateSet> bounceSS;
73  osg::ref_ptr<osg::StateSet> blurXSS;
74  osg::ref_ptr<osg::StateSet> blurYSS;
75  osg::Vec2 giTextureSize;
76  osg::Vec2 viewportSize;
77 
78  std::string envMapPath;
80  //Sun computation
81  void clamp(double clampValue, double& number);
82  double computeSunSunriseOrSunset(int day, int month, int year, bool sunrise);
83 public:
140  bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *pParametersNode);
141 
143  {
147 
148  } shadowMode;
149 
151  {
154 
155  } shadeMode;
156 
157  enum giModes
158  {
162 
163  } giMode;
164 
165  virtual void preInitialize();
166  virtual void postInitialize();
167 
168  //Constructor, destructor
169  Lights(void);
170  ~Lights(void);
174  void InitializeGI();
184  int add(osg::Vec4 position = osg::Vec4(0,0,0,1),
185  osg::Vec3 direction = osg::Vec3(0,0,-1),
186  float spotCutOff = 180,
187  float spotExp = 0);
194  int add(osg::LightSource* lightSource);
199  int addSun(int day, int month, int year, int hour, int minute, osg::Vec4* sunPosition = NULL);
204  bool remove(int lightNum);
208  bool removeAll();
212  int size();
216  osg::Light* at(int lightNum);
220  osg::LightSource* getLightSource(int lightNum);
224  osg::Light* getLight(int lightNum);
229  bool setLightVisibility(int lightNum, bool on);
234  bool setActiveShadowLight(int lightNum);
238  void enableShadows(bool OnOrOff);
247  bool isShadowsEnabled();
251  void setClearColor(osg::Vec4 color);
255  osg::Vec4& getClearColor();
278  void setGlobalAmbient(osg::Vec4 color);
282  const osg::Vec4 getGlobalAmbient() { return lightModel->getAmbientIntensity(); }
286  int getDOSampleCount();
290  float getDORadius();
294  int getBounceSampleCount();
298  float getBounceRadius();
302  int getBlurSize();
306  void setDOSampleCount(int count);
310  void setDORadius(float radius);
314  void setBounceSampleCount(int count);
318  void setBounceRadius(float radius);
322  void setBlurSize(int size);
326  void createFlare(int lightNum);
330  const osg::Vec4& getSunDate() { return sunDate; }
334  osgShadow::ShadowTechnique* getShadowTechnique();
338  std::vector<osg::Node*>& getFlares() { return flares; }
342  osg::Texture2D* createBuffer(osg::Vec2 textureSize, osg::Texture::FilterMode filter,
343  osg::Texture::WrapMode wrap, GLint internalFormat, GLenum sourceFormat);
347  void setUpCamera(osg::ref_ptr<osg::Camera> camera, osg::Vec2 textureSize, osg::ref_ptr<osg::StateSet> camSS,
348  osg::ref_ptr<osg::Shader> vert, osg::ref_ptr<osg::Shader> frag);
349 
350 };
351 }