2 #include "Create2DCloud.h"
3 #include "ObjectModel.h"
7 #include "PostProcess.h"
8 #include "LuminanceCalculation.h"
9 #include "AtmosphereMie.h"
10 #include "AtmosphereHimmel.h"
11 #include "TerrainMIE.h"
12 #include "TerrainHimmel.h"
13 #include "TerrainGeometry.h"
14 #include "ReflectionCamera.h"
15 #include "CloudCreator.h"
16 #include "Atmosphereprecompute.h"
18 #include "PerlinCloudState.h"
19 #include "CirrusCloudState.h"
20 #include "CirrusStratusCloudState.h"
21 #include "CirrusCumulusCloudState.h"
22 #include "AltStratusCloudState.h"
29 #include "DataCloud.h"
32 #include "SkydomeMie.h"
33 #include "PerlinNoiseCloud.h"
35 #include "CirrusCumulus.h"
36 #include "CSGObject.h"
38 #include "ContrailUpdate.h"
39 #include "LuminanceCalculation.h"
41 #include <osg/PolygonMode>
42 #include <osg/ShapeDrawable>
44 #include <osg/Program>
46 #include <osg/Uniform>
53 #include "BlurShadow.h"
54 #include "LightShaft.h"
55 #include "LightShaft2.h"
60 namespace osgCloudyDay
69 virtual void operator () (
const osg::Camera& )
const
86 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
88 osgUtil::CullVisitor* cv =
dynamic_cast<osgUtil::CullVisitor*
>(nv);
89 osg::ref_ptr<osg::Geode> geometry =
dynamic_cast<osg::Geode*
> (node);
91 std::cerr <<
"CullDebugGeometryCallback1" << std::endl;
94 std::cerr <<
"CullDebugGeometryCallback2" << std::endl;
101 #ifdef SHADOW_MAPPING
104 geometry->getOrCreateStateSet()->getUniform(
"viewMatrix_light")->set(
Scene::GetLightCamera()->getViewMatrix());
105 geometry->getOrCreateStateSet()->getUniform(
"viewMatrixInv_light")->set(osg::Matrix::inverse(
Scene::GetLightCamera()->getViewMatrix()));
106 geometry->getOrCreateStateSet()->getUniform(
"modelViewMatrix_light")->set(
Scene::GetLightCamera()->getViewMatrix());
108 geometry->getOrCreateStateSet()->addUniform(
new osg::Uniform(
"color_tex", 0));
109 geometry->getOrCreateStateSet()->addUniform(
new osg::Uniform(
"shadow_tex", 1));
110 geometry->getOrCreateStateSet()->addUniform(
new osg::Uniform(
"depth_tex", 2));
112 geometry->getOrCreateStateSet()->setTextureAttribute( 0, osgCloudyDay::CloudScene::tex_clouds );
137 void drawImplementation(osg::RenderInfo& renderInfo)
const
139 if (_internalOptimizedGeometry.valid())
141 _internalOptimizedGeometry->drawImplementation(renderInfo);
145 osg::State& state = *renderInfo.getState();
147 bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE;
148 if (checkForGLErrors) state.checkGLErrors(
"start of Geometry::drawImplementation()");
150 bool useFastPath = areFastPathsUsed();
153 bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported();
154 bool handleVertexAttributes = !_vertexAttribList.empty();
156 osg::ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
158 arrayDispatchers.reset();
159 arrayDispatchers.setUseVertexAttribAlias(useFastPath && state.getUseVertexAttributeAliasing());
160 arrayDispatchers.setUseGLBeginEndAdapter(!useFastPath);
162 arrayDispatchers.activateNormalArray(_normalData.binding, _normalData.array.get(), _normalData.indices.get());
163 arrayDispatchers.activateColorArray(_colorData.binding, _colorData.array.get(), _colorData.indices.get());
164 arrayDispatchers.activateSecondaryColorArray(_secondaryColorData.binding, _secondaryColorData.array.get(), _secondaryColorData.indices.get());
165 arrayDispatchers.activateFogCoordArray(_fogCoordData.binding, _fogCoordData.array.get(), _fogCoordData.indices.get());
167 if (handleVertexAttributes)
169 for(
unsigned int unit=0;unit<_vertexAttribList.size();++unit)
171 arrayDispatchers.activateVertexAttribArray(_vertexAttribList[unit].binding, unit, _vertexAttribList[unit].array.get(), _vertexAttribList[unit].indices.get());
176 arrayDispatchers.dispatch(BIND_OVERALL,0);
178 state.lazyDisablingOfVertexAttributes();
183 if( _vertexData.array.valid() )
184 state.setVertexPointer(_vertexData.array.get());
186 if (_normalData.binding==BIND_PER_VERTEX && _normalData.array.valid())
187 state.setNormalPointer(_normalData.array.get());
189 if (_colorData.binding==BIND_PER_VERTEX && _colorData.array.valid())
190 state.setColorPointer(_colorData.array.get());
192 if (_secondaryColorData.binding==BIND_PER_VERTEX && _secondaryColorData.array.valid())
193 state.setSecondaryColorPointer(_secondaryColorData.array.get());
195 if (_fogCoordData.binding==BIND_PER_VERTEX && _fogCoordData.array.valid())
196 state.setFogCoordPointer(_fogCoordData.array.get());
198 for(
unsigned int unit=0;unit<_texCoordList.size();++unit)
200 const osg::Array* array = _texCoordList[unit].array.get();
201 if (array) state.setTexCoordPointer(unit,array);
204 if( handleVertexAttributes )
206 for(
unsigned int index = 0; index < _vertexAttribList.size(); ++index )
208 const osg::Array* array = _vertexAttribList[index].array.get();
209 const AttributeBinding ab = _vertexAttribList[index].binding;
210 if( ab == BIND_PER_VERTEX && array )
212 state.setVertexAttribPointer( index, array, _vertexAttribList[index].normalize );
219 for(
unsigned int unit=0;unit<_texCoordList.size();++unit)
221 arrayDispatchers.activateTexCoordArray(BIND_PER_VERTEX, unit, _texCoordList[unit].array.get(), _texCoordList[unit].indices.get());
224 arrayDispatchers.activateVertexArray(BIND_PER_VERTEX, _vertexData.array.get(), _vertexData.indices.get());
227 state.applyDisablingOfVertexAttributes();
229 bool bindPerPrimitiveSetActive = arrayDispatchers.active(BIND_PER_PRIMITIVE_SET);
230 bool bindPerPrimitiveActive = arrayDispatchers.active(BIND_PER_PRIMITIVE);
232 if (checkForGLErrors) state.checkGLErrors(
"Geometry::drawImplementation() after vertex arrays setup.");
242 for(
unsigned int primitiveSetNum=0; primitiveSetNum!= _primitives.size() ; ++primitiveSetNum)
245 if (bindPerPrimitiveSetActive)
246 arrayDispatchers.dispatch(BIND_PER_PRIMITIVE_SET, primitiveSetNum);
248 const osg::PrimitiveSet* primitiveset = _primitives[primitiveSetNum].get();
254 osg::State& state = *renderInfo.getState();
266 primitiveset->draw(state, usingVertexBufferObjects);
272 state.unbindVertexBufferObject();
273 state.unbindElementBufferObject();
275 if (checkForGLErrors) state.checkGLErrors(
"end of Geometry::drawImplementation().");
288 void Initialize(
int width,
int size,
osgCloudyDay::CloudState*& clouds, std::vector<osgCloudyDay::Cloud2DState> cloud2dstates, std::vector<int> m_ids, std::vector<std::string> reflection_models, std::vector<std::string> reflection_tex,
osgCloudyDay::Fog* fog, std::vector<std::string> luds);
311 osg::ref_ptr<osg::Camera>
GetHUD();
328 osg::ref_ptr<osg::Node> GetObjectModel(
int);
332 static Scene* m_scene;
401 void Create2DClouds(std::vector<osgCloudyDay::Cloud2DState> cloud2dstates);
447 osg::ref_ptr<osg::Camera> camera_lightshaft;
448 osg::ref_ptr<osg::Group> lightView_scene;
450 osg::ref_ptr<osg::Group> scene;
451 osg::ref_ptr<osg::Group> cube_scene;
452 osg::ref_ptr<osg::Group> hud;
458 osg::ref_ptr<osg::Texture2D> tex_ortho;
462 osg::ref_ptr<osg::Group> scene2;
482 osg::ref_ptr<osg::Geode> debug_geode;
483 osg::ref_ptr<osg::Geode> debug_geode2;
484 osg::ref_ptr<osg::Geode> debug_geode3;