Merged changes to OpenSceneGraph-2.6 into trunk using :

svn merge -r 8729:8734 http://www.openscenegraph.org/svn/osg/OpenSceneGraph/branches/OpenSceneGraph-2.6 .
This commit is contained in:
Robert Osfield 2008-08-05 11:17:48 +00:00
parent 800ca9b8ed
commit 7f8183f64c
8 changed files with 115 additions and 114 deletions

View File

@ -26,7 +26,7 @@ PROJECT(OpenSceneGraph)
SET(OPENSCENEGRAPH_MAJOR_VERSION 2) SET(OPENSCENEGRAPH_MAJOR_VERSION 2)
SET(OPENSCENEGRAPH_MINOR_VERSION 6) SET(OPENSCENEGRAPH_MINOR_VERSION 6)
SET(OPENSCENEGRAPH_PATCH_VERSION 0) SET(OPENSCENEGRAPH_PATCH_VERSION 0)
SET(OPENSCENEGRAPH_SOVERSION 43) SET(OPENSCENEGRAPH_SOVERSION 44)
SET(OPENSCENEGRAPH_VERSION ${OPENSCENEGRAPH_MAJOR_VERSION}.${OPENSCENEGRAPH_MINOR_VERSION}.${OPENSCENEGRAPH_PATCH_VERSION}) SET(OPENSCENEGRAPH_VERSION ${OPENSCENEGRAPH_MAJOR_VERSION}.${OPENSCENEGRAPH_MINOR_VERSION}.${OPENSCENEGRAPH_PATCH_VERSION})

View File

@ -1,13 +1,13 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
* *
* This library is open source and may be redistributed and/or modified under * 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 * 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 * (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website. * included with this distribution, and on the openscenegraph.org website.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details. * OpenSceneGraph Public License for more details.
*/ */
@ -29,7 +29,7 @@ class OSG_EXPORT AutoTransform : public Transform
public : public :
AutoTransform(); AutoTransform();
AutoTransform(const AutoTransform& pat,const CopyOp& copyop=CopyOp::SHALLOW_COPY); AutoTransform(const AutoTransform& pat,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
virtual osg::Object* cloneType() const { return new AutoTransform (); } virtual osg::Object* cloneType() const { return new AutoTransform (); }
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new AutoTransform (*this,copyop); } virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new AutoTransform (*this,copyop); }
@ -48,12 +48,12 @@ class OSG_EXPORT AutoTransform : public Transform
inline void setRotation(const Quat& quat) { _rotation = quat; _matrixDirty=true; dirtyBound(); } inline void setRotation(const Quat& quat) { _rotation = quat; _matrixDirty=true; dirtyBound(); }
inline const Quat& getRotation() const { return _rotation; } inline const Quat& getRotation() const { return _rotation; }
inline void setScale(float scale) { setScale(osg::Vec3(scale,scale,scale)); } inline void setScale(float scale) { setScale(osg::Vec3(scale,scale,scale)); }
void setScale(const Vec3& scale); void setScale(const Vec3& scale);
inline const Vec3& getScale() const { return _scale; } inline const Vec3& getScale() const { return _scale; }
void setMinimumScale(float minimumScale) { _minimumScale = minimumScale; } void setMinimumScale(float minimumScale) { _minimumScale = minimumScale; }
float getMinimumScale() const { return _minimumScale; } float getMinimumScale() const { return _minimumScale; }
@ -62,7 +62,7 @@ class OSG_EXPORT AutoTransform : public Transform
inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); } inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); }
inline const Vec3& getPivotPoint() const { return _pivotPoint; } inline const Vec3& getPivotPoint() const { return _pivotPoint; }
void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; } void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; }
float getAutoUpdateEyeMovementTolerance() const { return _autoUpdateEyeMovementTolerance; } float getAutoUpdateEyeMovementTolerance() const { return _autoUpdateEyeMovementTolerance; }
@ -74,7 +74,7 @@ class OSG_EXPORT AutoTransform : public Transform
ROTATE_TO_SCREEN, ROTATE_TO_SCREEN,
ROTATE_TO_CAMERA ROTATE_TO_CAMERA
}; };
void setAutoRotateMode(AutoRotateMode mode) { _autoRotateMode = mode; _firstTimeToInitEyePoint = true; } void setAutoRotateMode(AutoRotateMode mode) { _autoRotateMode = mode; _firstTimeToInitEyePoint = true; }
AutoRotateMode getAutoRotateMode() const { return _autoRotateMode; } AutoRotateMode getAutoRotateMode() const { return _autoRotateMode; }
@ -83,8 +83,8 @@ class OSG_EXPORT AutoTransform : public Transform
bool getAutoScaleToScreen() const { return _autoScaleToScreen; } bool getAutoScaleToScreen() const { return _autoScaleToScreen; }
void setAutoScaleTransistionWidthRatio(float ratio) { _autoScaleTransitionWidthRatio = ratio; } void setAutoScaleTransitionWidthRatio(float ratio) { _autoScaleTransitionWidthRatio = ratio; }
float getAutoScaleTransistionWidthRatio() const { return _autoScaleTransitionWidthRatio; } float getAutoScaleTransitionWidthRatio() const { return _autoScaleTransitionWidthRatio; }
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const; virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
@ -95,7 +95,7 @@ class OSG_EXPORT AutoTransform : public Transform
protected : protected :
virtual ~AutoTransform() {} virtual ~AutoTransform() {}
Vec3 _position; Vec3 _position;
@ -105,17 +105,17 @@ class OSG_EXPORT AutoTransform : public Transform
AutoRotateMode _autoRotateMode; AutoRotateMode _autoRotateMode;
bool _autoScaleToScreen; bool _autoScaleToScreen;
mutable Quat _rotation; mutable Quat _rotation;
mutable Vec3 _scale; mutable Vec3 _scale;
mutable bool _firstTimeToInitEyePoint; mutable bool _firstTimeToInitEyePoint;
mutable osg::Vec3 _previousEyePoint; mutable osg::Vec3 _previousEyePoint;
mutable osg::Vec3 _previousLocalUp; mutable osg::Vec3 _previousLocalUp;
mutable Viewport::value_type _previousWidth; mutable Viewport::value_type _previousWidth;
mutable Viewport::value_type _previousHeight; mutable Viewport::value_type _previousHeight;
mutable osg::Matrix _previousProjection; mutable osg::Matrix _previousProjection;
mutable osg::Vec3 _previousPosition; mutable osg::Vec3 _previousPosition;
float _minimumScale; float _minimumScale;
float _maximumScale; float _maximumScale;
float _autoScaleTransitionWidthRatio; float _autoScaleTransitionWidthRatio;

View File

@ -22,7 +22,7 @@ extern "C" {
#define OPENSCENEGRAPH_MAJOR_VERSION 2 #define OPENSCENEGRAPH_MAJOR_VERSION 2
#define OPENSCENEGRAPH_MINOR_VERSION 6 #define OPENSCENEGRAPH_MINOR_VERSION 6
#define OPENSCENEGRAPH_PATCH_VERSION 0 #define OPENSCENEGRAPH_PATCH_VERSION 0
#define OPENSCENEGRAPH_SOVERSION 43 #define OPENSCENEGRAPH_SOVERSION 44
/** /**
* osgGetVersion() returns the library version number. * osgGetVersion() returns the library version number.

View File

@ -1,29 +1,29 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
* *
* This library is open source and may be redistributed and/or modified under * 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 * 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 * (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website. * included with this distribution, and on the openscenegraph.org website.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details. * OpenSceneGraph Public License for more details.
*/ */
/* ParallelSplitShadowMap written by Adrian Egli /* ParallelSplitShadowMap written by Adrian Egli
* *
* this version has still a bug in mutli-thread application (flickering problem) * this version has still a bug in mutli-thread application (flickering problem)
* to avoid the flickering problem try osgShadow --pssm --SingleThreaded your_scene.ive * to avoid the flickering problem try osgShadow --pssm --SingleThreaded your_scene.ive
* *
* The Parallel Split Shadow Map only supports directional light for simulating the shadow. * The Parallel Split Shadow Map only supports directional light for simulating the shadow.
* It's one of the most robust algorithm for huge terrain sun light's shadow simulation, if * It's one of the most robust algorithm for huge terrain sun light's shadow simulation, if
* you need to shadow a terrain, or another huge scene, you should use Parallel Split Shadow Map * you need to shadow a terrain, or another huge scene, you should use Parallel Split Shadow Map
* or at least test it against your scene. Have fun. * or at least test it against your scene. Have fun.
* *
*/ */
#ifndef OSGSHADOW_ParallelSplitShadowMap #ifndef OSGSHADOW_ParallelSplitShadowMap
#define OSGSHADOW_ParallelSplitShadowMap 1 #define OSGSHADOW_ParallelSplitShadowMap 1
#include <osg/Camera> #include <osg/Camera>
@ -35,16 +35,16 @@
namespace osgShadow { namespace osgShadow {
class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
{ {
public: public:
ParallelSplitShadowMap(osg::Geode** debugGroup=NULL, int icountplanes=3); ParallelSplitShadowMap(osg::Geode** debugGroup=NULL, int icountplanes=3);
ParallelSplitShadowMap(const ParallelSplitShadowMap& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); ParallelSplitShadowMap(const ParallelSplitShadowMap& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgShadow, ParallelSplitShadowMap); META_Object(osgShadow, ParallelSplitShadowMap);
/** Initialize the ShadowedScene and local cached data structures.*/ /** Initialize the ShadowedScene and local cached data structures.*/
virtual void init(); virtual void init();
@ -69,21 +69,21 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
/** Set the texture resolution */ /** Set the texture resolution */
inline void setTextureResolution(unsigned int resolution) { _resolution = resolution; } inline void setTextureResolution(unsigned int resolution) { _resolution = resolution; }
/** Set the max far distance */ /** Set the max far distance */
inline void setMaxFarDistance(double farDist) { _setMaxFarDistance = farDist; _isSetMaxFarDistance = true; } inline void setMaxFarDistance(double farDist) { _setMaxFarDistance = farDist; _isSetMaxFarDistance = true; }
/** Set the factor for moving the virtual camera behind the real camera*/ /** Set the factor for moving the virtual camera behind the real camera*/
inline void setMoveVCamBehindRCamFactor(double distFactor ) { _move_vcam_behind_rcam_factor = distFactor; } inline void setMoveVCamBehindRCamFactor(double distFactor ) { _move_vcam_behind_rcam_factor = distFactor; }
/** Set min near distance for splits */ /** Set min near distance for splits */
inline void setMinNearDistanceForSplits(double nd){ _split_min_near_dist=nd; } inline void setMinNearDistanceForSplits(double nd){ _split_min_near_dist=nd; }
/** set a user defined light for shadow simulation (sun light, ... ) /** set a user defined light for shadow simulation (sun light, ... )
* when this light get passed to pssm, the scene's light are no longer collected * when this light get passed to pssm, the scene's light are no longer collected
* and simulated. just this user passed light, it needs to be a directional light. * and simulated. just this user passed light, it needs to be a directional light.
*/ */
inline void setUserLight(osg::Light* light) { _userLight = light; } inline void setUserLight(osg::Light* light) { _userLight = light; }
/** Set the values for the ambient bias the shader will use.*/ /** Set the values for the ambient bias the shader will use.*/
void setAmbientBias(const osg::Vec2& ambientBias ); void setAmbientBias(const osg::Vec2& ambientBias );
@ -92,32 +92,32 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
*/ */
class OSGSHADOW_EXPORT FragmentShaderGenerator : public osg::Referenced { class OSGSHADOW_EXPORT FragmentShaderGenerator : public osg::Referenced {
public: public:
/** /**
* generate the GLSL fragement shader * generate the GLSL fragement shader
*/ */
virtual std::string generateGLSL_FragmentShader_BaseTex(bool debug, unsigned int splitCount,double textureRes, bool filtered, unsigned int nbrSplits,unsigned int textureOffset); virtual std::string generateGLSL_FragmentShader_BaseTex(bool debug, unsigned int splitCount,double textureRes, bool filtered, unsigned int nbrSplits,unsigned int textureOffset);
}; };
/** set fragment shader generator */ /** set fragment shader generator */
inline void setFragmentShaderGenerator(FragmentShaderGenerator* fsw) { _FragmentShaderGenerator = fsw;} inline void setFragmentShaderGenerator(FragmentShaderGenerator* fsw) { _FragmentShaderGenerator = fsw;}
/** enable / disable shadow filtering */ /** enable / disable shadow filtering */
inline void enableShadowGLSLFiltering(bool filtering = true) { _GLSL_shadow_filtered = filtering; } inline void enableShadowGLSLFiltering(bool filtering = true) { _GLSL_shadow_filtered = filtering; }
enum SplitCalcMode { enum SplitCalcMode {
SPLIT_LINEAR, SPLIT_LINEAR,
SPLIT_EXP SPLIT_EXP
}; };
/** set split calculation mode */ /** set split calculation mode */
inline void setSplitCalculationMode(SplitCalcMode scm=SPLIT_EXP) { _SplitCalcMode = scm; } inline void setSplitCalculationMode(SplitCalcMode scm=SPLIT_EXP) { _SplitCalcMode = scm; }
protected : protected :
virtual ~ParallelSplitShadowMap() {} virtual ~ParallelSplitShadowMap() {}
struct PSSMShadowSplitTexture { struct PSSMShadowSplitTexture {
// RTT // RTT
osg::ref_ptr<osg::Camera> _camera; osg::ref_ptr<osg::Camera> _camera;
@ -157,7 +157,7 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
private: private:
void calculateFrustumCorners(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners); void calculateFrustumCorners(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
void calculateLightInitalPosition(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners); void calculateLightInitialPosition(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
void calculateLightNearFarFormFrustum(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners); void calculateLightNearFarFormFrustum(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
void calculateLightViewProjectionFormFrustum(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners); void calculateLightViewProjectionFormFrustum(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
@ -180,13 +180,13 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
double _split_min_near_dist; double _split_min_near_dist;
double _move_vcam_behind_rcam_factor; double _move_vcam_behind_rcam_factor;
osg::ref_ptr<osg::Light> _userLight; osg::ref_ptr<osg::Light> _userLight;
osg::ref_ptr<FragmentShaderGenerator> _FragmentShaderGenerator; osg::ref_ptr<FragmentShaderGenerator> _FragmentShaderGenerator;
bool _GLSL_shadow_filtered; bool _GLSL_shadow_filtered;
SplitCalcMode _SplitCalcMode; SplitCalcMode _SplitCalcMode;
osg::Uniform* _ambientBiasUniform; osg::Uniform* _ambientBiasUniform;
osg::Vec2d _ambientBias; osg::Vec2d _ambientBias;

View File

@ -41,7 +41,7 @@ void AutoTransform::write(DataOutputStream* out){
{ {
out->writeFloat(getMinimumScale()); out->writeFloat(getMinimumScale());
out->writeFloat(getMaximumScale()); out->writeFloat(getMaximumScale());
out->writeFloat(getAutoScaleTransistionWidthRatio()); out->writeFloat(getAutoScaleTransitionWidthRatio());
} }
out->writeQuat(getRotation()); out->writeQuat(getRotation());
@ -76,7 +76,7 @@ void AutoTransform::read(DataInputStream* in){
{ {
setMinimumScale(in->readFloat()); setMinimumScale(in->readFloat());
setMaximumScale(in->readFloat()); setMaximumScale(in->readFloat());
setAutoScaleTransistionWidthRatio(in->readFloat()); setAutoScaleTransitionWidthRatio(in->readFloat());
} }
setRotation(in->readQuat()); setRotation(in->readQuat());

View File

@ -140,12 +140,13 @@ bool AutoTransform_readLocalData(Object& obj, Input& fr)
iteratorAdvanced = true; iteratorAdvanced = true;
} }
if (fr.matchSequence("autoScaleTransistionWidthRatio %f")) if (fr.matchSequence("autoScaleTransistionWidthRatio %f") ||
fr.matchSequence("autoScaleTransitionWidthRatio %f"))
{ {
float ratio; float ratio;
fr[1].getFloat(ratio); fr[1].getFloat(ratio);
transform.setAutoScaleTransistionWidthRatio(ratio); transform.setAutoScaleTransitionWidthRatio(ratio);
fr += 2; fr += 2;
iteratorAdvanced = true; iteratorAdvanced = true;
@ -181,9 +182,9 @@ bool AutoTransform_writeLocalData(const Object& obj, Output& fw)
fw.indent()<<"autoScaleToScreen "<<(transform.getAutoScaleToScreen()?"TRUE":"FALSE")<<std::endl; fw.indent()<<"autoScaleToScreen "<<(transform.getAutoScaleToScreen()?"TRUE":"FALSE")<<std::endl;
if (transform.getAutoScaleTransistionWidthRatio()!=0.25) if (transform.getAutoScaleTransitionWidthRatio()!=0.25)
{ {
fw.indent()<<"autoScaleTransistionWidthRatio "<<transform.getAutoScaleTransistionWidthRatio()<<std::endl; fw.indent()<<"autoScaleTransitionWidthRatio "<<transform.getAutoScaleTransitionWidthRatio()<<std::endl;
} }
return true; return true;

View File

@ -53,9 +53,9 @@ using namespace osgShadow;
#define TEXTURE_RESOLUTION 1024 #define TEXTURE_RESOLUTION 1024
#define ZNEAR_MIN_FROM_LIGHT_SOURCE 5.0 #define ZNEAR_MIN_FROM_LIGHT_SOURCE 5.0
#define MOVE_VIRTUAL_CAMERA_BEHIND_REAL_CAMERA_FACTOR 0.0 #define MOVE_VIRTUAL_CAMERA_BEHIND_REAL_CAMERA_FACTOR 0.0
//#define SHOW_SHADOW_TEXTURE_DEBUG // DEPTH instead of color for debug information texture display in a rectangle //#define SHOW_SHADOW_TEXTURE_DEBUG // DEPTH instead of color for debug information texture display in a rectangle
@ -64,19 +64,19 @@ using namespace osgShadow;
#ifndef SHADOW_TEXTURE_DEBUG #ifndef SHADOW_TEXTURE_DEBUG
#define SHADOW_TEXTURE_GLSL #define SHADOW_TEXTURE_GLSL
#endif #endif
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// FragmentShaderGenerator // FragmentShaderGenerator
std::string ParallelSplitShadowMap::FragmentShaderGenerator::generateGLSL_FragmentShader_BaseTex( std::string ParallelSplitShadowMap::FragmentShaderGenerator::generateGLSL_FragmentShader_BaseTex(
bool debug, bool debug,
unsigned int splitCount, unsigned int splitCount,
double textureRes, double textureRes,
bool filtered, bool filtered,
unsigned int nbrSplits, unsigned int nbrSplits,
unsigned int textureOffset unsigned int textureOffset
) { ) {
std::stringstream sstr; std::stringstream sstr;
/// base texture /// base texture
sstr << "uniform sampler2D baseTexture; " << std::endl; sstr << "uniform sampler2D baseTexture; " << std::endl;
sstr << "uniform float enableBaseTexture; " << std::endl; sstr << "uniform float enableBaseTexture; " << std::endl;
@ -88,7 +88,7 @@ std::string ParallelSplitShadowMap::FragmentShaderGenerator::generateGLSL_Fragme
} }
sstr << "void main(void)" << std::endl; sstr << "void main(void)" << std::endl;
sstr << "{" << std::endl; sstr << "{" << std::endl;
@ -101,15 +101,15 @@ std::string ParallelSplitShadowMap::FragmentShaderGenerator::generateGLSL_Fragme
sstr << "float map" << i << " = step(zShadow"<<i-1<<",testZ)*step(testZ, zShadow"<<i<<");"<< std::endl;//DEBUG sstr << "float map" << i << " = step(zShadow"<<i-1<<",testZ)*step(testZ, zShadow"<<i<<");"<< std::endl;//DEBUG
} }
if (filtered) { if (filtered) {
sstr << " float fTexelSize="<< (sqrt(2.0) / textureRes ) <<";" << std::endl; sstr << " float fTexelSize="<< (sqrt(2.0) / textureRes ) <<";" << std::endl;
} }
for (unsigned int i=0;i<nbrSplits;i++) { for (unsigned int i=0;i<nbrSplits;i++) {
if (!filtered) { if (!filtered) {
sstr << " float shadow" << i <<" = shadow2DProj( shadowTexture" << i <<",gl_TexCoord[" << (i+textureOffset) <<"]).r;" << std::endl; sstr << " float shadow" << i <<" = shadow2DProj( shadowTexture" << i <<",gl_TexCoord[" << (i+textureOffset) <<"]).r;" << std::endl;
} else { } else {
// filter the shadow (look up) // filter the shadow (look up)
sstr << " float shadowOrg" << i <<" = shadow2DProj( shadowTexture" << i <<",gl_TexCoord[" << (i+textureOffset) <<"]).r;" << std::endl; sstr << " float shadowOrg" << i <<" = shadow2DProj( shadowTexture" << i <<",gl_TexCoord[" << (i+textureOffset) <<"]).r;" << std::endl;
sstr << " float shadow0" << i <<" = shadow2DProj( shadowTexture" << i <<",gl_TexCoord[" << (i+textureOffset) <<"]+vec4(-fTexelSize,-fTexelSize,0,0) ).r;" << std::endl; sstr << " float shadow0" << i <<" = shadow2DProj( shadowTexture" << i <<",gl_TexCoord[" << (i+textureOffset) <<"]+vec4(-fTexelSize,-fTexelSize,0,0) ).r;" << std::endl;
@ -125,11 +125,11 @@ std::string ParallelSplitShadowMap::FragmentShaderGenerator::generateGLSL_Fragme
} }
sstr << " shadow" << i <<" = step(0.25,shadow" << i <<");" << std::endl; // reduce shadow artefacts sstr << " shadow" << i <<" = step(0.25,shadow" << i <<");" << std::endl; // reduce shadow artefacts
} }
sstr << " float term0 = (1.0-shadow0)*map0; " << std::endl; sstr << " float term0 = (1.0-shadow0)*map0; " << std::endl;
for (unsigned int i=1;i<nbrSplits;i++) { for (unsigned int i=1;i<nbrSplits;i++) {
sstr << " float term" << i << " = map"<< i << "*(1.0-shadow"<<i<<");"<< std::endl; sstr << " float term" << i << " = map"<< i << "*(1.0-shadow"<<i<<");"<< std::endl;
} }
@ -163,7 +163,7 @@ std::string ParallelSplitShadowMap::FragmentShaderGenerator::generateGLSL_Fragme
sstr << " vec4 color = gl_Color*( 1.0 - sumTerm ) + (sumTerm)* gl_Color*vec4(c0,(1.0-c0)*c1,(1.0-c0)*(1.0-c1)*c2,1.0); " << std::endl; sstr << " vec4 color = gl_Color*( 1.0 - sumTerm ) + (sumTerm)* gl_Color*vec4(c0,(1.0-c0)*c1,(1.0-c0)*(1.0-c1)*c2,1.0); " << std::endl;
switch(nbrSplits){ switch(nbrSplits){
case 1: sstr << " color = color*0.75 + vec4(map0,0,0,1.0)*0.25; " << std::endl;break; case 1: sstr << " color = color*0.75 + vec4(map0,0,0,1.0)*0.25; " << std::endl;break;
case 2: sstr << " color = color*0.75 + vec4(map0,map1,0,1.0)*0.25; " << std::endl;break; case 2: sstr << " color = color*0.75 + vec4(map0,map1,0,1.0)*0.25; " << std::endl;break;
@ -173,13 +173,13 @@ std::string ParallelSplitShadowMap::FragmentShaderGenerator::generateGLSL_Fragme
case 6: sstr << " color = color*0.75 + vec4(map0+map3+map5,map1+map3+map4,map2+map4+map5,1.0)*0.25; " << std::endl; break; case 6: sstr << " color = color*0.75 + vec4(map0+map3+map5,map1+map3+map4,map2+map4+map5,1.0)*0.25; " << std::endl; break;
default: break; default: break;
} }
} else { } else {
sstr << " vec4 color = gl_Color; "<< std::endl; sstr << " vec4 color = gl_Color; "<< std::endl;
} }
@ -194,7 +194,7 @@ std::string ParallelSplitShadowMap::FragmentShaderGenerator::generateGLSL_Fragme
sstr << " gl_FragColor.a = (color*(1.0-enableBaseTextureFilter) + colorTex*enableBaseTextureFilter).a; "<< std::endl; sstr << " gl_FragColor.a = (color*(1.0-enableBaseTextureFilter) + colorTex*enableBaseTextureFilter).a; "<< std::endl;
sstr << "}"<< std::endl; sstr << "}"<< std::endl;
//std::cout << sstr.str() << std::endl; //std::cout << sstr.str() << std::endl;
@ -344,7 +344,7 @@ void ParallelSplitShadowMap::init(){
osg::StateSet* stateset = pssmShadowSplitTexture._camera->getOrCreateStateSet(); osg::StateSet* stateset = pssmShadowSplitTexture._camera->getOrCreateStateSet();
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
float factor = _polgyonOffset.x(); float factor = _polgyonOffset.x();
float units = _polgyonOffset.y(); float units = _polgyonOffset.y();
@ -356,7 +356,7 @@ void ParallelSplitShadowMap::init(){
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
if ( ! _GLSL_shadow_filtered ) { if ( ! _GLSL_shadow_filtered ) {
// if not glsl filtering enabled then we should force front face culling to reduce the number of shadow artefacts. // if not glsl filtering enabled then we should force front face culling to reduce the number of shadow artefacts.
osg::ref_ptr<osg::CullFace> cull_face = new osg::CullFace; osg::ref_ptr<osg::CullFace> cull_face = new osg::CullFace;
cull_face->setMode(osg::CullFace::FRONT); cull_face->setMode(osg::CullFace::FRONT);
@ -396,7 +396,7 @@ void ParallelSplitShadowMap::init(){
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// GLSL PROGRAMS // GLSL PROGRAMS
osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT,
_FragmentShaderGenerator->generateGLSL_FragmentShader_BaseTex( _FragmentShaderGenerator->generateGLSL_FragmentShader_BaseTex(
_debug_color_in_GLSL, _debug_color_in_GLSL,
iCameras, iCameras,
@ -407,7 +407,7 @@ void ParallelSplitShadowMap::init(){
).c_str()); ).c_str());
program->addShader(fragment_shader); program->addShader(fragment_shader);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// UNIFORMS // UNIFORMS
std::stringstream strST; strST << "shadowTexture" << (pssmShadowSplitTexture._textureUnit-_textureUnitOffset); std::stringstream strST; strST << "shadowTexture" << (pssmShadowSplitTexture._textureUnit-_textureUnitOffset);
@ -419,7 +419,7 @@ void ParallelSplitShadowMap::init(){
_ambientBiasUniform = new osg::Uniform("ambientBias",_ambientBias); _ambientBiasUniform = new osg::Uniform("ambientBias",_ambientBias);
pssmShadowSplitTexture._stateset->addUniform(_ambientBiasUniform); pssmShadowSplitTexture._stateset->addUniform(_ambientBiasUniform);
} }
std::stringstream strzShadow; strzShadow << "zShadow" << (pssmShadowSplitTexture._textureUnit-_textureUnitOffset); std::stringstream strzShadow; strzShadow << "zShadow" << (pssmShadowSplitTexture._textureUnit-_textureUnitOffset);
pssmShadowSplitTexture._farDistanceSplit = new osg::Uniform(strzShadow.str().c_str(),1.0f); pssmShadowSplitTexture._farDistanceSplit = new osg::Uniform(strzShadow.str().c_str(),1.0f);
@ -571,7 +571,7 @@ void ParallelSplitShadowMap::cull(osgUtil::CullVisitor& cv){
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
const osg::Light* selectLight = 0; const osg::Light* selectLight = 0;
/// light pos and light direction /// light pos and light direction
osg::Vec4 lightpos; osg::Vec4 lightpos;
osg::Vec3 lightDirection; osg::Vec3 lightDirection;
@ -605,7 +605,7 @@ void ParallelSplitShadowMap::cull(osgUtil::CullVisitor& cv){
lightpos = _userLight->getPosition(); lightpos = _userLight->getPosition();
lightDirection = _userLight->getDirection(); lightDirection = _userLight->getDirection();
selectLight = _userLight.get(); selectLight = _userLight.get();
} }
if (selectLight) if (selectLight)
{ {
@ -617,7 +617,7 @@ void ParallelSplitShadowMap::cull(osgUtil::CullVisitor& cv){
{ {
PSSMShadowSplitTexture pssmShadowSplitTexture = it->second; PSSMShadowSplitTexture pssmShadowSplitTexture = it->second;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// SETUP pssmShadowSplitTexture for rendering // SETUP pssmShadowSplitTexture for rendering
// //
@ -641,7 +641,7 @@ void ParallelSplitShadowMap::cull(osgUtil::CullVisitor& cv){
// Init Light (Directional Light) // Init Light (Directional Light)
// //
calculateLightInitalPosition(pssmShadowSplitTexture,pCorners); calculateLightInitialPosition(pssmShadowSplitTexture,pCorners);
// Calculate near and far for light view // Calculate near and far for light view
// //
@ -682,7 +682,7 @@ void ParallelSplitShadowMap::cull(osgUtil::CullVisitor& cv){
// do RTT camera traversal // do RTT camera traversal
pssmShadowSplitTexture._camera->accept(cv); pssmShadowSplitTexture._camera->accept(cv);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// DEBUG // DEBUG
if ( _displayTexturesGroupingNode ) { if ( _displayTexturesGroupingNode ) {
@ -781,11 +781,11 @@ void ParallelSplitShadowMap::calculateFrustumCorners(
delete[] pSplitDistances; delete[] pSplitDistances;
} }
pssmShadowSplitTexture._split_far = camFar; pssmShadowSplitTexture._split_far = camFar;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// TRANSFORM frustum corners (Optimized for Orthogonal) /// TRANSFORM frustum corners (Optimized for Orthogonal)
@ -805,7 +805,7 @@ void ParallelSplitShadowMap::calculateFrustumCorners(
frustumCorners[4] = const_pointFarTL * invProjViewMat; frustumCorners[4] = const_pointFarTL * invProjViewMat;
frustumCorners[5] = const_pointFarBL * invProjViewMat; frustumCorners[5] = const_pointFarBL * invProjViewMat;
frustumCorners[6] = const_pointNearBL* invProjViewMat; frustumCorners[6] = const_pointNearBL* invProjViewMat;
frustumCorners[7] = const_pointNearTL* invProjViewMat; frustumCorners[7] = const_pointNearTL* invProjViewMat;
//std::cout << "camFar : "<<pssmShadowSplitTexture._splitID << " / " << camNear << "," << camFar << std::endl; //std::cout << "camFar : "<<pssmShadowSplitTexture._splitID << " / " << camNear << "," << camFar << std::endl;
} }
@ -813,14 +813,14 @@ void ParallelSplitShadowMap::calculateFrustumCorners(
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// //
// compute directional light initial position; // compute directional light initial position;
void ParallelSplitShadowMap::calculateLightInitalPosition(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners){ void ParallelSplitShadowMap::calculateLightInitialPosition(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners){
pssmShadowSplitTexture._frustumSplitCenter = frustumCorners[0]; pssmShadowSplitTexture._frustumSplitCenter = frustumCorners[0];
for(int i=1;i<8;i++) { for(int i=1;i<8;i++) {
pssmShadowSplitTexture._frustumSplitCenter +=frustumCorners[i]; pssmShadowSplitTexture._frustumSplitCenter +=frustumCorners[i];
} }
pssmShadowSplitTexture._frustumSplitCenter /= 8.0; pssmShadowSplitTexture._frustumSplitCenter /= 8.0;
// //
// To avoid edge problems, scale the frustum so // To avoid edge problems, scale the frustum so
// that it's at least a few pixels larger // that it's at least a few pixels larger
@ -830,7 +830,7 @@ void ParallelSplitShadowMap::calculateLightInitalPosition(PSSMShadowSplitTexture
// scale by adding offset from center // scale by adding offset from center
frustumCorners[i]+=(frustumCorners[i]-pssmShadowSplitTexture._frustumSplitCenter)*(0.75); frustumCorners[i]+=(frustumCorners[i]-pssmShadowSplitTexture._frustumSplitCenter)*(0.75);
} }
} }
void ParallelSplitShadowMap::calculateLightNearFarFormFrustum( void ParallelSplitShadowMap::calculateLightNearFarFormFrustum(
@ -845,20 +845,20 @@ void ParallelSplitShadowMap::calculateLightNearFarFormFrustum(
for(int i=0;i<8;i++) { for(int i=0;i<8;i++) {
double dist_z_from_light = fabs(pssmShadowSplitTexture._lightDirection*(frustumCorners[i] - pssmShadowSplitTexture._frustumSplitCenter)); double dist_z_from_light = fabs(pssmShadowSplitTexture._lightDirection*(frustumCorners[i] - pssmShadowSplitTexture._frustumSplitCenter));
if ( zFar < dist_z_from_light ) zFar = dist_z_from_light; if ( zFar < dist_z_from_light ) zFar = dist_z_from_light;
} }
// update camera position and look at center // update camera position and look at center
pssmShadowSplitTexture._lightCameraSource = pssmShadowSplitTexture._frustumSplitCenter - pssmShadowSplitTexture._lightDirection*(zFar+_split_min_near_dist); pssmShadowSplitTexture._lightCameraSource = pssmShadowSplitTexture._frustumSplitCenter - pssmShadowSplitTexture._lightDirection*(zFar+_split_min_near_dist);
pssmShadowSplitTexture._lightCameraTarget = pssmShadowSplitTexture._frustumSplitCenter + pssmShadowSplitTexture._lightDirection*(zFar); pssmShadowSplitTexture._lightCameraTarget = pssmShadowSplitTexture._frustumSplitCenter + pssmShadowSplitTexture._lightDirection*(zFar);
// calculate [zNear,zFar] // calculate [zNear,zFar]
zFar = (-DBL_MAX); zFar = (-DBL_MAX);
double zNear(DBL_MAX); double zNear(DBL_MAX);
for(int i=0;i<8;i++) { for(int i=0;i<8;i++) {
double dist_z_from_light = fabs(pssmShadowSplitTexture._lightDirection*(frustumCorners[i] - pssmShadowSplitTexture._lightCameraSource)); double dist_z_from_light = fabs(pssmShadowSplitTexture._lightDirection*(frustumCorners[i] - pssmShadowSplitTexture._lightCameraSource));
if ( zFar < dist_z_from_light ) zFar = dist_z_from_light; if ( zFar < dist_z_from_light ) zFar = dist_z_from_light;
if ( zNear > dist_z_from_light ) zNear = dist_z_from_light; if ( zNear > dist_z_from_light ) zNear = dist_z_from_light;
} }
// update near - far plane // update near - far plane
pssmShadowSplitTexture._lightNear = max(zNear - _split_min_near_dist - 0.01,0.01); pssmShadowSplitTexture._lightNear = max(zNear - _split_min_near_dist - 0.01,0.01);
pssmShadowSplitTexture._lightFar = zFar; pssmShadowSplitTexture._lightFar = zFar;
@ -874,37 +874,37 @@ void ParallelSplitShadowMap::calculateLightViewProjectionFormFrustum(PSSMShadowS
// calculate the camera's coordinate system // calculate the camera's coordinate system
osg::Vec3d camEye,camCenter,camUp; osg::Vec3d camEye,camCenter,camUp;
pssmShadowSplitTexture._cameraView.getLookAt(camEye,camCenter,camUp); pssmShadowSplitTexture._cameraView.getLookAt(camEye,camCenter,camUp);
osg::Vec3d viewDir(camCenter-camEye); osg::Vec3d viewDir(camCenter-camEye);
osg::Vec3d camRight(camUp^viewDir); osg::Vec3d camRight(camUp^viewDir);
// we force to have normalized vectors (camera's view) // we force to have normalized vectors (camera's view)
camUp.normalize(); camUp.normalize();
viewDir.normalize(); viewDir.normalize();
camRight.normalize(); camRight.normalize();
// use quaternion -> numerical more robust // use quaternion -> numerical more robust
osg::Quat qRot; osg::Quat qRot;
qRot.makeRotate(viewDir,pssmShadowSplitTexture._lightDirection); qRot.makeRotate(viewDir,pssmShadowSplitTexture._lightDirection);
osg::Vec3d top = qRot * camUp; osg::Vec3d top = qRot * camUp;
osg::Vec3d right = qRot * camRight; osg::Vec3d right = qRot * camRight;
// calculate the camera's frustum right,right,bottom,top parameters // calculate the camera's frustum right,right,bottom,top parameters
double maxRight(-DBL_MAX),maxTop(-DBL_MAX); double maxRight(-DBL_MAX),maxTop(-DBL_MAX);
double minRight(DBL_MAX),minTop(DBL_MAX); double minRight(DBL_MAX),minTop(DBL_MAX);
for(int i(0); i < 8; i++) for(int i(0); i < 8; i++)
{ {
osg::Vec3d diffCorner(pssmShadowSplitTexture._lightCameraSource - frustumCorners[i]); osg::Vec3d diffCorner(pssmShadowSplitTexture._lightCameraSource - frustumCorners[i]);
double lright(diffCorner*right); double lright(diffCorner*right);
double lTop(diffCorner*top); double lTop(diffCorner*top);
if ( lright > maxRight ) maxRight = lright; if ( lright > maxRight ) maxRight = lright;
if ( lTop > maxTop ) maxTop = lTop; if ( lTop > maxTop ) maxTop = lTop;
if ( lright < minRight ) minRight = lright; if ( lright < minRight ) minRight = lright;
if ( lTop < minTop ) minTop = lTop; if ( lTop < minTop ) minTop = lTop;
} }
// make the camera view matrix // make the camera view matrix
pssmShadowSplitTexture._camera->setViewMatrixAsLookAt(pssmShadowSplitTexture._lightCameraSource,pssmShadowSplitTexture._lightCameraTarget,top); pssmShadowSplitTexture._camera->setViewMatrixAsLookAt(pssmShadowSplitTexture._lightCameraSource,pssmShadowSplitTexture._lightCameraTarget,top);
@ -918,7 +918,7 @@ void ParallelSplitShadowMap::calculateLightViewProjectionFormFrustum(PSSMShadowS
osg::Vec3d vProjCamFraValue = (camEye + viewDir * pssmShadowSplitTexture._split_far) * (pssmShadowSplitTexture._cameraView * pssmShadowSplitTexture._cameraProj); osg::Vec3d vProjCamFraValue = (camEye + viewDir * pssmShadowSplitTexture._split_far) * (pssmShadowSplitTexture._cameraView * pssmShadowSplitTexture._cameraProj);
pssmShadowSplitTexture._farDistanceSplit->set((float)vProjCamFraValue.z()); pssmShadowSplitTexture._farDistanceSplit->set((float)vProjCamFraValue.z());
#endif #endif
} }

View File

@ -179,14 +179,14 @@ BEGIN_OBJECT_REFLECTOR(osg::AutoTransform)
__bool__getAutoScaleToScreen, __bool__getAutoScaleToScreen,
"", "",
""); "");
I_Method1(void, setAutoScaleTransistionWidthRatio, IN, float, ratio, I_Method1(void, setAutoScaleTransitionWidthRatio, IN, float, ratio,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__void__setAutoScaleTransistionWidthRatio__float, __void__setAutoScaleTransitionWidthRatio__float,
"", "",
""); "");
I_Method0(float, getAutoScaleTransistionWidthRatio, I_Method0(float, getAutoScaleTransitionWidthRatio,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__float__getAutoScaleTransistionWidthRatio, __float__getAutoScaleTransitionWidthRatio,
"", "",
""); "");
I_Method2(bool, computeLocalToWorldMatrix, IN, osg::Matrix &, matrix, IN, osg::NodeVisitor *, nv, I_Method2(bool, computeLocalToWorldMatrix, IN, osg::Matrix &, matrix, IN, osg::NodeVisitor *, nv,
@ -216,9 +216,9 @@ BEGIN_OBJECT_REFLECTOR(osg::AutoTransform)
I_SimpleProperty(bool, AutoScaleToScreen, I_SimpleProperty(bool, AutoScaleToScreen,
__bool__getAutoScaleToScreen, __bool__getAutoScaleToScreen,
__void__setAutoScaleToScreen__bool); __void__setAutoScaleToScreen__bool);
I_SimpleProperty(float, AutoScaleTransistionWidthRatio, I_SimpleProperty(float, AutoScaleTransitionWidthRatio,
__float__getAutoScaleTransistionWidthRatio, __float__getAutoScaleTransitionWidthRatio,
__void__setAutoScaleTransistionWidthRatio__float); __void__setAutoScaleTransitionWidthRatio__float);
I_SimpleProperty(float, AutoUpdateEyeMovementTolerance, I_SimpleProperty(float, AutoUpdateEyeMovementTolerance,
__float__getAutoUpdateEyeMovementTolerance, __float__getAutoUpdateEyeMovementTolerance,
__void__setAutoUpdateEyeMovementTolerance__float); __void__setAutoUpdateEyeMovementTolerance__float);