From e8fa0433b38a69b5e4a094d4425381e27a6ee3a2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 22 Apr 2006 15:08:07 +0000 Subject: [PATCH] Moved PrecipitationEffect node into osgParticle. --- VisualStudio/osgParticle/osgParticle.dsp | 4 + examples/osgprecipitation/GNUmakefile | 3 +- .../PrecipitationParameters.cpp | 13 -- .../PrecipitationParameters.h | 100 --------- examples/osgprecipitation/line_rain.vert | 40 ---- .../osgprecipitation/osgprecipitation.cpp | 12 +- examples/osgprecipitation/point_rain.frag | 7 - examples/osgprecipitation/point_rain.vert | 27 --- examples/osgprecipitation/quad_rain.vert | 43 ---- examples/osgprecipitation/rain.frag | 8 - examples/osgprecipitation/rain.vert | 49 ----- .../osgParticle/PrecipitationEffect | 32 ++- src/osgParticle/GNUmakefile | 1 + .../osgParticle}/PrecipitationEffect.cpp | 205 ++++++++++++------ 14 files changed, 173 insertions(+), 371 deletions(-) delete mode 100644 examples/osgprecipitation/PrecipitationParameters.cpp delete mode 100644 examples/osgprecipitation/PrecipitationParameters.h delete mode 100644 examples/osgprecipitation/line_rain.vert delete mode 100644 examples/osgprecipitation/point_rain.frag delete mode 100644 examples/osgprecipitation/point_rain.vert delete mode 100644 examples/osgprecipitation/quad_rain.vert delete mode 100644 examples/osgprecipitation/rain.frag delete mode 100644 examples/osgprecipitation/rain.vert rename examples/osgprecipitation/PrecipitationEffect.h => include/osgParticle/PrecipitationEffect (85%) rename {examples/osgprecipitation => src/osgParticle}/PrecipitationEffect.cpp (80%) diff --git a/VisualStudio/osgParticle/osgParticle.dsp b/VisualStudio/osgParticle/osgParticle.dsp index 8fe3a1eea..bc1695289 100644 --- a/VisualStudio/osgParticle/osgParticle.dsp +++ b/VisualStudio/osgParticle/osgParticle.dsp @@ -207,6 +207,10 @@ SOURCE=..\..\src\osgParticle\ParticleSystem.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osgParticle\PrecipitationEffect.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osgParticle\ConnectedParticleSystem.cpp # End Source File # Begin Source File diff --git a/examples/osgprecipitation/GNUmakefile b/examples/osgprecipitation/GNUmakefile index 92bb794f1..efe5555d3 100644 --- a/examples/osgprecipitation/GNUmakefile +++ b/examples/osgprecipitation/GNUmakefile @@ -2,10 +2,9 @@ TOPDIR = ../.. include $(TOPDIR)/Make/makedefs CXXFILES =\ - PrecipitationEffect.cpp\ osgprecipitation.cpp\ -LIBS += -losgProducer -lProducer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) +LIBS += -losgProducer -lProducer -losgParticle -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) INSTFILES = \ $(CXXFILES)\ diff --git a/examples/osgprecipitation/PrecipitationParameters.cpp b/examples/osgprecipitation/PrecipitationParameters.cpp deleted file mode 100644 index 543f95220..000000000 --- a/examples/osgprecipitation/PrecipitationParameters.cpp +++ /dev/null @@ -1,13 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ - diff --git a/examples/osgprecipitation/PrecipitationParameters.h b/examples/osgprecipitation/PrecipitationParameters.h deleted file mode 100644 index 8bfe2362b..000000000 --- a/examples/osgprecipitation/PrecipitationParameters.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ - -#ifndef OSGPARTICLE_PRECIPITATIONPARAMETERS -#define OSGPARTICLE_PRECIPITATIONPARAMETERS - -#include - -namespace osgParticle -{ - - struct PrecipitationParameters : public osg::Referenced - { - PrecipitationParameters(): - particleVelocity(0.0,0.0,-5.0), - particleSize(0.02), - particleColour(0.6, 0.6, 0.6, 1.0), - particleDensity(8.0), - cellSizeX(10.0f), - cellSizeY(10.0f), - cellSizeZ(10.0f), - nearTransition(25.0), - farTransition(100.0), - fogExponent(1.0), - fogDensity(0.001), - fogEnd(1000.0), - fogColour(0.5, 0.5, 0.5, 1.0), - clearColour(0.5, 0.5, 0.5, 1.0), - useFarLineSegments(false) - { - rain(0.5); - } - - void rain (float intensity) - { - particleVelocity = osg::Vec3(0.0,0.0,-2.0) + osg::Vec3(0.0,0.0,-10.0)*intensity; - particleSize = 0.01 + 0.02*intensity; - particleColour = osg::Vec4(0.6, 0.6, 0.6, 1.0) - osg::Vec4(0.1, 0.1, 0.1, 1.0)* intensity; - particleDensity = intensity * 8.5f; - cellSizeX = 5.0f / (0.25f+intensity); - cellSizeY = 5.0f / (0.25f+intensity); - cellSizeZ = 5.0f; - farTransition = 100.0f - 60.0f*sqrtf(intensity); - fogExponent = 1.0f; - fogDensity = 0.005f*intensity; - fogEnd = 250/(0.01 + intensity); - fogColour.set(0.5, 0.5, 0.5, 1.0); - clearColour.set(0.5, 0.5, 0.5, 1.0); - useFarLineSegments = false; - } - - void snow(float intensity) - { - particleVelocity = osg::Vec3(0.0,0.0,-0.75) + osg::Vec3(0.0,0.0,-0.25)*intensity; - particleSize = 0.02 + 0.03*intensity; - particleColour = osg::Vec4(0.85f, 0.85f, 0.85f, 1.0f) - osg::Vec4(0.1f, 0.1f, 0.1f, 1.0f)* intensity; - particleDensity = intensity * 8.2f; - cellSizeX = 5.0f / (0.25f+intensity); - cellSizeY = 5.0f / (0.25f+intensity); - cellSizeZ = 5.0f; - farTransition = 100.0f - 60.0f*sqrtf(intensity); - fogExponent = 1.0f; - fogDensity = 0.02f*intensity; - fogEnd = 150.0f/(0.01f + intensity); - fogColour.set(0.6, 0.6, 0.6, 1.0); - clearColour.set(0.6, 0.6, 0.6, 1.0); - useFarLineSegments = false; - } - - osg::BoundingBox boundingBox; - osg::Vec3 particleVelocity; - float particleSize; - osg::Vec4 particleColour; - float particleDensity; - float cellSizeX; - float cellSizeY; - float cellSizeZ; - float nearTransition; - float farTransition; - float fogExponent; - float fogDensity; - float fogEnd; - osg::Vec4 fogColour; - osg::Vec4 clearColour; - bool useFarLineSegments; - }; - -} - -#endif diff --git a/examples/osgprecipitation/line_rain.vert b/examples/osgprecipitation/line_rain.vert deleted file mode 100644 index 19072258f..000000000 --- a/examples/osgprecipitation/line_rain.vert +++ /dev/null @@ -1,40 +0,0 @@ -uniform float inversePeriod; -uniform vec4 particleColour; -uniform float particleSize; - -uniform float osg_FrameTime; -uniform float osg_DeltaFrameTime; - -varying vec4 colour; -varying vec2 texCoord; - -void main(void) -{ - float offset = gl_Vertex.z; - float startTime = gl_MultiTexCoord1.x; - texCoord = gl_MultiTexCoord0.xy; - - vec4 v_previous = gl_Vertex; - v_previous.z = fract( (osg_FrameTime - startTime)*inversePeriod - offset); - - vec4 v_current = v_previous; - v_current.z += (osg_DeltaFrameTime*inversePeriod); - - - colour = particleColour; - - vec4 v1 = gl_ModelViewMatrix * v_current; - vec4 v2 = gl_TextureMatrix[0] * v_previous; - - vec3 dv = v2.xyz - v1.xyz; - - vec2 dv_normalized = normalize(dv.xy); - dv.xy += dv_normalized * particleSize; - - float area = length(dv.xy); - colour.a = (particleSize)/area; - - v1.xyz += dv*texCoord.y; - - gl_Position = gl_ProjectionMatrix * v1; -} diff --git a/examples/osgprecipitation/osgprecipitation.cpp b/examples/osgprecipitation/osgprecipitation.cpp index 2d8d817f3..bfeaa723e 100644 --- a/examples/osgprecipitation/osgprecipitation.cpp +++ b/examples/osgprecipitation/osgprecipitation.cpp @@ -15,17 +15,7 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "PrecipitationEffect.h" +#include #if 0 osg::Node* createModel(osg::Node* loadedModel, osgParticle::PrecipitationParameters& parameters) diff --git a/examples/osgprecipitation/point_rain.frag b/examples/osgprecipitation/point_rain.frag deleted file mode 100644 index d71594f05..000000000 --- a/examples/osgprecipitation/point_rain.frag +++ /dev/null @@ -1,7 +0,0 @@ -uniform sampler2D baseTexture; -varying vec4 colour; - -void main (void) -{ - gl_FragColor = colour * texture2D( baseTexture, gl_TexCoord[0].xy); -} diff --git a/examples/osgprecipitation/point_rain.vert b/examples/osgprecipitation/point_rain.vert deleted file mode 100644 index f9fee55e9..000000000 --- a/examples/osgprecipitation/point_rain.vert +++ /dev/null @@ -1,27 +0,0 @@ -uniform float inversePeriod; -uniform vec4 particleColour; -uniform float particleSize; - -uniform float osg_FrameTime; - -varying vec4 colour; - -void main(void) -{ - float offset = gl_Vertex.z; - float startTime = gl_MultiTexCoord1.x; - - vec4 v_current = gl_Vertex; - v_current.z = fract( (osg_FrameTime - startTime)*inversePeriod - offset); - - colour = particleColour; - - gl_Position = gl_ModelViewProjectionMatrix * v_current; - - float pointSize = abs(1280.0*particleSize / gl_Position.w); - - //gl_PointSize = max(ceil(pointSize),2); - gl_PointSize = ceil(pointSize); - - colour.a = 0.05+(pointSize*pointSize)/(gl_PointSize*gl_PointSize); -} diff --git a/examples/osgprecipitation/quad_rain.vert b/examples/osgprecipitation/quad_rain.vert deleted file mode 100644 index 4080e9882..000000000 --- a/examples/osgprecipitation/quad_rain.vert +++ /dev/null @@ -1,43 +0,0 @@ -uniform float inversePeriod; -uniform vec4 particleColour; -uniform float particleSize; - -uniform float osg_FrameTime; -uniform float osg_DeltaFrameTime; - -varying vec4 colour; -varying vec2 texCoord; - -void main(void) -{ - float offset = gl_Vertex.z; - float startTime = gl_MultiTexCoord1.x; - texCoord = gl_MultiTexCoord0.xy; - - vec4 v_previous = gl_Vertex; - v_previous.z = fract( (osg_FrameTime - startTime)*inversePeriod - offset); - - vec4 v_current = v_previous; - v_current.z += (osg_DeltaFrameTime*inversePeriod); - - - colour = particleColour; - - vec4 v1 = gl_ModelViewMatrix * v_current; - vec4 v2 = gl_TextureMatrix[0] * v_previous; - - vec3 dv = v2.xyz - v1.xyz; - - vec2 dv_normalized = normalize(dv.xy); - dv.xy += dv_normalized * particleSize; - vec2 dp = vec2( -dv_normalized.y, dv_normalized.x ) * particleSize; - - float area = length(dv.xy); - colour.a = 0.05+(particleSize)/area; - - - v1.xyz += dv*texCoord.y; - v1.xy += dp*texCoord.x; - - gl_Position = gl_ProjectionMatrix * v1; -} diff --git a/examples/osgprecipitation/rain.frag b/examples/osgprecipitation/rain.frag deleted file mode 100644 index 7f7be861b..000000000 --- a/examples/osgprecipitation/rain.frag +++ /dev/null @@ -1,8 +0,0 @@ -uniform sampler2D baseTexture; -varying vec2 texCoord; -varying vec4 colour; - -void main (void) -{ - gl_FragColor = colour * texture2D( baseTexture, texCoord); -} diff --git a/examples/osgprecipitation/rain.vert b/examples/osgprecipitation/rain.vert deleted file mode 100644 index 703b1847b..000000000 --- a/examples/osgprecipitation/rain.vert +++ /dev/null @@ -1,49 +0,0 @@ -uniform vec3 position; -uniform vec3 dv_i; -uniform vec3 dv_j; -uniform vec3 dv_k; - -uniform float inversePeriod; -uniform float startTime; -uniform vec4 particleColour; - -uniform float osg_FrameTime; -uniform float osg_DeltaFrameTime; -uniform mat4 previousModelViewMatrix; - -varying vec4 colour; -varying vec2 texCoord; - -void main(void) -{ - const float particleSize = 0.01; - const float particleSize2 = 0.0001;//particleSize*particleSize; - - vec3 pos = position + (gl_Vertex.x*dv_i) + (dv_j * gl_Vertex.y); - - float offset = gl_Vertex.z; - texCoord = gl_MultiTexCoord0.xy; - - vec3 v_previous = pos + dv_k * fract( (osg_FrameTime - startTime)*inversePeriod - offset); - vec3 v_current = v_previous + dv_k * (osg_DeltaFrameTime*inversePeriod); - - colour = particleColour; - - vec4 v1 = gl_ModelViewMatrix * vec4(v_current,1.0); - vec4 v2 = previousModelViewMatrix * vec4(v_previous,1.0); - - vec3 dv = v2.xyz - v1.xyz; - - vec2 dv_normalized = normalize(dv.xy); - dv.xy += dv_normalized * particleSize; - vec2 dp = vec2( -dv_normalized.y, dv_normalized.x ) * particleSize; - - float area = length(dv.xy)*length(dp); - colour.a = 0.2+(particleSize2)/area; - - - v1.xyz += dv*texCoord.y; - v1.xy += dp*texCoord.x; - - gl_Position = gl_ProjectionMatrix * v1; -} diff --git a/examples/osgprecipitation/PrecipitationEffect.h b/include/osgParticle/PrecipitationEffect similarity index 85% rename from examples/osgprecipitation/PrecipitationEffect.h rename to include/osgParticle/PrecipitationEffect index aea67a45f..d04c7893f 100644 --- a/examples/osgprecipitation/PrecipitationEffect.h +++ b/include/osgParticle/PrecipitationEffect @@ -24,10 +24,33 @@ #include -#include "PrecipitationParameters.h" - namespace osgParticle { + struct OSGPARTICLE_EXPORT PrecipitationParameters : public osg::Referenced + { + PrecipitationParameters(); + + void rain (float intensity); + + void snow(float intensity); + + osg::BoundingBox boundingBox; + osg::Vec3 particleVelocity; + float particleSize; + osg::Vec4 particleColour; + float particleDensity; + float cellSizeX; + float cellSizeY; + float cellSizeZ; + float nearTransition; + float farTransition; + float fogExponent; + float fogDensity; + float fogEnd; + osg::Vec4 fogColour; + osg::Vec4 clearColour; + bool useFarLineSegments; + }; class OSGPARTICLE_EXPORT PrecipitationEffect : public osg::Group { @@ -78,6 +101,9 @@ namespace osgParticle virtual bool supports(const osg::PrimitiveIndexFunctor&) const { return false; } virtual void accept(osg::PrimitiveIndexFunctor&) const {} + void setRequiresPreviousMatrix(bool flag) { _requiresPreviousMatrix = flag; } + bool getRequiresPreviousMatrix() const { return _requiresPreviousMatrix; } + void setGeometry(osg::Geometry* geom) { _geometry = geom; } osg::Geometry* getGeometry() { return _geometry.get(); } const osg::Geometry* getGeometry() const { return _geometry.get(); } @@ -133,6 +159,8 @@ namespace osgParticle virtual ~PrecipitationDrawable() {} + bool _requiresPreviousMatrix; + osg::ref_ptr _geometry; mutable CellMatrixMap _currentCellMatrixMap; diff --git a/src/osgParticle/GNUmakefile b/src/osgParticle/GNUmakefile index 2335a8366..993c3236d 100644 --- a/src/osgParticle/GNUmakefile +++ b/src/osgParticle/GNUmakefile @@ -17,6 +17,7 @@ CXXFILES =\ ParticleEffect.cpp\ ParticleProcessor.cpp\ ParticleSystem.cpp\ + PrecipitationEffect.cpp\ ConnectedParticleSystem.cpp\ ParticleSystemUpdater.cpp\ Program.cpp\ diff --git a/examples/osgprecipitation/PrecipitationEffect.cpp b/src/osgParticle/PrecipitationEffect.cpp similarity index 80% rename from examples/osgprecipitation/PrecipitationEffect.cpp rename to src/osgParticle/PrecipitationEffect.cpp index 3045d4712..e3394aa73 100644 --- a/examples/osgprecipitation/PrecipitationEffect.cpp +++ b/src/osgParticle/PrecipitationEffect.cpp @@ -11,7 +11,6 @@ * OpenSceneGraph Public License for more details. */ -#include "PrecipitationEffect.h" #include @@ -21,6 +20,8 @@ #include #include +#include + #include #include #include @@ -33,6 +34,17 @@ static float random(float min,float max) { return min + (max-min)*(float)rand()/ static void fillSpotLightImage(unsigned char* ptr, const osg::Vec4& centerColour, const osg::Vec4& backgroudColour, unsigned int size, float power) { + if (size==1) + { + float r = 0.5f; + osg::Vec4 color = centerColour*r+backgroudColour*(1.0f-r); + *ptr++ = (unsigned char)((color[0])*255.0f); + *ptr++ = (unsigned char)((color[1])*255.0f); + *ptr++ = (unsigned char)((color[2])*255.0f); + *ptr++ = (unsigned char)((color[3])*255.0f); + return; + } + float mid = (float(size)-1.0f)*0.5f; float div = 2.0f/float(size); for(unsigned int r=0;r lock(_mutex); - PrecipitationDrawableSet& precipitationDrawableSet = _viewDrawableMap[viewIndentifier]; + PrecipitationDrawableSet* precipitationDrawableSet = 0; - if (!precipitationDrawableSet._quadPrecipitationDrawable) { - precipitationDrawableSet._quadPrecipitationDrawable = new PrecipitationDrawable; - precipitationDrawableSet._quadPrecipitationDrawable->setGeometry(_quadGeometry.get()); - precipitationDrawableSet._quadPrecipitationDrawable->setStateSet(_quadStateSet.get()); + OpenThreads::ScopedLock lock(_mutex); + precipitationDrawableSet = &(_viewDrawableMap[viewIndentifier]); + } + + if (!precipitationDrawableSet->_quadPrecipitationDrawable) + { + osg::notify(osg::NOTICE)<<"Setting up"<_quadPrecipitationDrawable = new PrecipitationDrawable; + precipitationDrawableSet->_quadPrecipitationDrawable->setRequiresPreviousMatrix(true); + precipitationDrawableSet->_quadPrecipitationDrawable->setGeometry(_quadGeometry.get()); + precipitationDrawableSet->_quadPrecipitationDrawable->setStateSet(_quadStateSet.get()); - precipitationDrawableSet._linePrecipitationDrawable = new PrecipitationDrawable; - precipitationDrawableSet._linePrecipitationDrawable->setGeometry(_lineGeometry.get()); - precipitationDrawableSet._linePrecipitationDrawable->setStateSet(_lineStateSet.get()); + precipitationDrawableSet->_linePrecipitationDrawable = new PrecipitationDrawable; + precipitationDrawableSet->_linePrecipitationDrawable->setRequiresPreviousMatrix(true); + precipitationDrawableSet->_linePrecipitationDrawable->setGeometry(_lineGeometry.get()); + precipitationDrawableSet->_linePrecipitationDrawable->setStateSet(_lineStateSet.get()); - precipitationDrawableSet._pointPrecipitationDrawable = new PrecipitationDrawable; - precipitationDrawableSet._pointPrecipitationDrawable->setGeometry(_pointGeometry.get()); - precipitationDrawableSet._pointPrecipitationDrawable->setStateSet(_pointStateSet.get()); + precipitationDrawableSet->_pointPrecipitationDrawable = new PrecipitationDrawable; + precipitationDrawableSet->_pointPrecipitationDrawable->setRequiresPreviousMatrix(false); + precipitationDrawableSet->_pointPrecipitationDrawable->setGeometry(_pointGeometry.get()); + precipitationDrawableSet->_pointPrecipitationDrawable->setStateSet(_pointStateSet.get()); } - cull(precipitationDrawableSet, cv); + cull(*precipitationDrawableSet, cv); cv->pushStateSet(_precipitationStateSet.get()); float depth = 0.0f; - if (!precipitationDrawableSet._quadPrecipitationDrawable->getCurrentCellMatrixMap().empty()) + if (!precipitationDrawableSet->_quadPrecipitationDrawable->getCurrentCellMatrixMap().empty()) { - cv->pushStateSet(precipitationDrawableSet._quadPrecipitationDrawable->getStateSet()); - cv->addDrawableAndDepth(precipitationDrawableSet._quadPrecipitationDrawable.get(),&cv->getModelViewMatrix(),depth); + cv->pushStateSet(precipitationDrawableSet->_quadPrecipitationDrawable->getStateSet()); + cv->addDrawableAndDepth(precipitationDrawableSet->_quadPrecipitationDrawable.get(),&cv->getModelViewMatrix(),depth); cv->popStateSet(); } - if (!precipitationDrawableSet._linePrecipitationDrawable->getCurrentCellMatrixMap().empty()) + if (!precipitationDrawableSet->_linePrecipitationDrawable->getCurrentCellMatrixMap().empty()) { - cv->pushStateSet(precipitationDrawableSet._linePrecipitationDrawable->getStateSet()); - cv->addDrawableAndDepth(precipitationDrawableSet._linePrecipitationDrawable.get(),&cv->getModelViewMatrix(),depth); + cv->pushStateSet(precipitationDrawableSet->_linePrecipitationDrawable->getStateSet()); + cv->addDrawableAndDepth(precipitationDrawableSet->_linePrecipitationDrawable.get(),&cv->getModelViewMatrix(),depth); cv->popStateSet(); } - if (!precipitationDrawableSet._pointPrecipitationDrawable->getCurrentCellMatrixMap().empty()) + if (!precipitationDrawableSet->_pointPrecipitationDrawable->getCurrentCellMatrixMap().empty()) { - cv->pushStateSet(precipitationDrawableSet._pointPrecipitationDrawable->getStateSet()); - cv->addDrawableAndDepth(precipitationDrawableSet._pointPrecipitationDrawable.get(),&cv->getModelViewMatrix(),depth); + cv->pushStateSet(precipitationDrawableSet->_pointPrecipitationDrawable->getStateSet()); + cv->addDrawableAndDepth(precipitationDrawableSet->_pointPrecipitationDrawable.get(),&cv->getModelViewMatrix(),depth); cv->popStateSet(); } @@ -286,36 +351,17 @@ void PrecipitationEffect::update() _origin.set(0.0f, 0.0f, 0.0f); } - setUpGeometries(_parameters->particleDensity * cellVolume); + setUpGeometries((int)(_parameters->particleDensity * cellVolume)); { OpenThreads::ScopedLock lock(_mutex); - for(ViewDrawableMap::iterator itr=_viewDrawableMap.begin(); - itr!=_viewDrawableMap.end(); - ++itr) - { - PrecipitationDrawableSet& precipitationDrawableSet = itr->second; - precipitationDrawableSet._quadPrecipitationDrawable = new PrecipitationDrawable; - precipitationDrawableSet._quadPrecipitationDrawable->setGeometry(_quadGeometry.get()); - precipitationDrawableSet._quadPrecipitationDrawable->setStateSet(_quadStateSet.get()); - - precipitationDrawableSet._linePrecipitationDrawable = new PrecipitationDrawable; - precipitationDrawableSet._linePrecipitationDrawable->setGeometry(_lineGeometry.get()); - precipitationDrawableSet._linePrecipitationDrawable->setStateSet(_lineStateSet.get()); - - precipitationDrawableSet._pointPrecipitationDrawable = new PrecipitationDrawable; - precipitationDrawableSet._pointPrecipitationDrawable->setGeometry(_pointGeometry.get()); - precipitationDrawableSet._pointPrecipitationDrawable->setStateSet(_pointStateSet.get()); - - } + _viewDrawableMap.clear(); } // set up state/ { _precipitationStateSet = new osg::StateSet; - const osg::BoundingBox& bb = _parameters->boundingBox; - osg::Uniform* inversePeriodUniform = new osg::Uniform("inversePeriod",1.0f/_period); _precipitationStateSet->addUniform(inversePeriodUniform); // float @@ -659,7 +705,9 @@ void PrecipitationEffect::setUpGeometries(unsigned int numParticles) void PrecipitationEffect::cull(PrecipitationDrawableSet& pds, osgUtil::CullVisitor* cv) const { +#ifdef DO_TIMING osg::Timer_t startTick = osg::Timer::instance()->tick(); +#endif pds._quadPrecipitationDrawable->newFrame(); pds._linePrecipitationDrawable->newFrame(); @@ -719,10 +767,13 @@ void PrecipitationEffect::cull(PrecipitationDrawableSet& pds, osgUtil::CullVisit } } - osg::Timer_t endTick = osg::Timer::instance()->tick(); - // osg::notify(osg::NOTICE)<<"time for cull "<delta_m(startTick,endTick)<<"ms numTested="<getCurrentCellMatrixMap().size()<<" lines "<getCurrentCellMatrixMap().size()<<" points "<getCurrentCellMatrixMap().size()<tick(); + + osg::notify(osg::NOTICE)<<"time for cull "<delta_m(startTick,endTick)<<"ms numTested="<getCurrentCellMatrixMap().size()<<" lines "<getCurrentCellMatrixMap().size()<<" points "<getCurrentCellMatrixMap().size()<glMultiTexCoord1f(GL_TEXTURE0+1, itr->second.second); // load cells current modelview matrix - glMatrixMode( GL_MODELVIEW ); - glLoadMatrix(itr->second.first.ptr()); - - - CellMatrixMap::const_iterator pitr = _previousCellMatrixMap.find(itr->first); - if (pitr != _previousCellMatrixMap.end()) + if (_requiresPreviousMatrix) { - // load previous frame modelview matrix for motion blurr effect - glMatrixMode( GL_TEXTURE ); - glLoadMatrix(pitr->second.first.ptr()); + glMatrixMode( GL_MODELVIEW ); + glLoadMatrix(itr->second.first.ptr()); + + + CellMatrixMap::const_iterator pitr = _previousCellMatrixMap.find(itr->first); + if (pitr != _previousCellMatrixMap.end()) + { + // load previous frame modelview matrix for motion blurr effect + glMatrixMode( GL_TEXTURE ); + glLoadMatrix(pitr->second.first.ptr()); + } + else + { + // use current modelview matrix as "previous" frame value, cancelling motion blurr effect + glMatrixMode( GL_TEXTURE ); + glLoadMatrix(itr->second.first.ptr()); + } } else { - // use current modelview matrix as "previous" frame value, cancelling motion blurr effect - glMatrixMode( GL_TEXTURE ); - glLoadMatrix(itr->second.first.ptr()); + glLoadMatrix(itr->second.first.ptr()); } _geometry->draw(state); @@ -833,9 +897,12 @@ void PrecipitationEffect::PrecipitationDrawable::drawImplementation(osg::State& } // restore OpenGL matrices - glMatrixMode( GL_TEXTURE ); - glPopMatrix(); - glMatrixMode( GL_MODELVIEW ); + if (_requiresPreviousMatrix) + { + glPopMatrix(); + glMatrixMode( GL_MODELVIEW ); + } + glPopMatrix();