Moved PrecipitationEffect node into osgParticle.

This commit is contained in:
Robert Osfield 2006-04-22 15:08:07 +00:00
parent f5f8754ec7
commit e8fa0433b3
14 changed files with 173 additions and 371 deletions

View File

@ -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

View File

@ -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)\

View File

@ -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.
*/

View File

@ -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 <osgParticle/Export>
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

View File

@ -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;
}

View File

@ -15,17 +15,7 @@
#include <osgUtil/CullVisitor>
#include <osgProducer/Viewer>
#include <osg/Point>
#include <osg/BlendFunc>
#include <osg/Texture2D>
#include <osg/PointSprite>
#include <osg/Program>
#include <osg/Fog>
#include <osg/Point>
#include <osg/PointSprite>
#include <osg/io_utils>
#include "PrecipitationEffect.h"
#include <osgParticle/PrecipitationEffect>
#if 0
osg::Node* createModel(osg::Node* loadedModel, osgParticle::PrecipitationParameters& parameters)

View File

@ -1,7 +0,0 @@
uniform sampler2D baseTexture;
varying vec4 colour;
void main (void)
{
gl_FragColor = colour * texture2D( baseTexture, gl_TexCoord[0].xy);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -1,8 +0,0 @@
uniform sampler2D baseTexture;
varying vec2 texCoord;
varying vec4 colour;
void main (void)
{
gl_FragColor = colour * texture2D( baseTexture, texCoord);
}

View File

@ -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;
}

View File

@ -24,10 +24,33 @@
#include <osgParticle/Export>
#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<osg::Geometry> _geometry;
mutable CellMatrixMap _currentCellMatrixMap;

View File

@ -17,6 +17,7 @@ CXXFILES =\
ParticleEffect.cpp\
ParticleProcessor.cpp\
ParticleSystem.cpp\
PrecipitationEffect.cpp\
ConnectedParticleSystem.cpp\
ParticleSystemUpdater.cpp\
Program.cpp\

View File

@ -11,7 +11,6 @@
* OpenSceneGraph Public License for more details.
*/
#include "PrecipitationEffect.h"
#include<OpenThreads/ScopedLock>
@ -21,6 +20,8 @@
#include<osgUtil/CullVisitor>
#include<osgUtil/GLObjectsVisitor>
#include <osgParticle/PrecipitationEffect>
#include <osg/Notify>
#include <osg/io_utils>
#include <osg/Timer>
@ -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<size;++r)
@ -91,6 +103,50 @@ static osg::Image* createSpotLightImage(const osg::Vec4& centerColour, const osg
}
PrecipitationParameters::PrecipitationParameters()
{
rain(0.5);
}
void PrecipitationParameters::rain(float intensity)
{
particleVelocity = osg::Vec3(0.0,0.0,-2.0) + osg::Vec3(0.0,0.0,-5.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;
nearTransition = 25.f;
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 PrecipitationParameters::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;
nearTransition = 25.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;
}
PrecipitationEffect::PrecipitationEffect()
{
setParameters(new PrecipitationParameters);
@ -162,47 +218,56 @@ void PrecipitationEffect::traverse(osg::NodeVisitor& nv)
ViewIdenitifier viewIndentifier(cv, nv.getNodePath());
{
OpenThreads::ScopedLock<OpenThreads::Mutex> 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());
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());
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
precipitationDrawableSet = &(_viewDrawableMap[viewIndentifier]);
}
cull(precipitationDrawableSet, cv);
if (!precipitationDrawableSet->_quadPrecipitationDrawable)
{
osg::notify(osg::NOTICE)<<"Setting up"<<std::endl;
precipitationDrawableSet->_quadPrecipitationDrawable = new PrecipitationDrawable;
precipitationDrawableSet->_quadPrecipitationDrawable->setRequiresPreviousMatrix(true);
precipitationDrawableSet->_quadPrecipitationDrawable->setGeometry(_quadGeometry.get());
precipitationDrawableSet->_quadPrecipitationDrawable->setStateSet(_quadStateSet.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->setRequiresPreviousMatrix(false);
precipitationDrawableSet->_pointPrecipitationDrawable->setGeometry(_pointGeometry.get());
precipitationDrawableSet->_pointPrecipitationDrawable->setStateSet(_pointStateSet.get());
}
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<OpenThreads::Mutex> 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
}
}
#ifdef DO_TIMING
osg::Timer_t endTick = osg::Timer::instance()->tick();
// osg::notify(osg::NOTICE)<<"time for cull "<<osg::Timer::instance()->delta_m(startTick,endTick)<<"ms numTested="<<numTested<<" numInFrustum"<<numInFrustum<<std::endl;
// osg::notify(osg::NOTICE)<<" quads "<<pds._quadPrecipitationDrawable->getCurrentCellMatrixMap().size()<<" lines "<<pds._linePrecipitationDrawable->getCurrentCellMatrixMap().size()<<" points "<<pds._pointPrecipitationDrawable->getCurrentCellMatrixMap().size()<<std::endl;
osg::notify(osg::NOTICE)<<"time for cull "<<osg::Timer::instance()->delta_m(startTick,endTick)<<"ms numTested="<<numTested<<" numInFrustum"<<numInFrustum<<std::endl;
osg::notify(osg::NOTICE)<<" quads "<<pds._quadPrecipitationDrawable->getCurrentCellMatrixMap().size()<<" lines "<<pds._linePrecipitationDrawable->getCurrentCellMatrixMap().size()<<" points "<<pds._pointPrecipitationDrawable->getCurrentCellMatrixMap().size()<<std::endl;
#endif
}
bool PrecipitationEffect::build(const osg::Vec3 eyeLocal, int i, int j, int k, float startTime, PrecipitationDrawableSet& pds, osg::Polytope& frustum, osgUtil::CullVisitor* cv) const
@ -779,13 +830,16 @@ bool PrecipitationEffect::build(const osg::Vec3 eyeLocal, int i, int j, int k, f
//
////////////////////////////////////////////////////////////////////////////////////////////////////
PrecipitationEffect::PrecipitationDrawable::PrecipitationDrawable()
PrecipitationEffect::PrecipitationDrawable::PrecipitationDrawable():
_requiresPreviousMatrix(true)
{
setSupportsDisplayList(false);
}
PrecipitationEffect::PrecipitationDrawable::PrecipitationDrawable(const PrecipitationDrawable& copy, const osg::CopyOp& copyop):
Drawable(copy,copyop)
Drawable(copy,copyop),
_requiresPreviousMatrix(copy._requiresPreviousMatrix),
_geometry(copy._geometry)
{
}
@ -797,10 +851,13 @@ void PrecipitationEffect::PrecipitationDrawable::drawImplementation(osg::State&
// save OpenGL matrices
glPushMatrix();
if (_requiresPreviousMatrix)
{
state.setActiveTextureUnit(0);
glMatrixMode( GL_TEXTURE );
glPushMatrix();
state.setActiveTextureUnit(0);
}
for(CellMatrixMap::const_iterator itr = _currentCellMatrixMap.begin();
itr != _currentCellMatrixMap.end();
@ -810,6 +867,8 @@ void PrecipitationEffect::PrecipitationDrawable::drawImplementation(osg::State&
extensions->glMultiTexCoord1f(GL_TEXTURE0+1, itr->second.second);
// load cells current modelview matrix
if (_requiresPreviousMatrix)
{
glMatrixMode( GL_MODELVIEW );
glLoadMatrix(itr->second.first.ptr());
@ -827,15 +886,23 @@ void PrecipitationEffect::PrecipitationDrawable::drawImplementation(osg::State&
glMatrixMode( GL_TEXTURE );
glLoadMatrix(itr->second.first.ptr());
}
}
else
{
glLoadMatrix(itr->second.first.ptr());
}
_geometry->draw(state);
}
// restore OpenGL matrices
glMatrixMode( GL_TEXTURE );
if (_requiresPreviousMatrix)
{
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
}
glPopMatrix();