Changeset 53


Ignore:
Timestamp:
May 28, 2010, 10:18:54 AM (14 years ago)
Author:
Torben Dannhauer
Message:

Update to use osg for sky fog instead OpenGL.

this way the osg fog feature "radialFog" can be used.

Location:
osgVisual
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/include/sky_Silverlining/skySilverLining_skyDrawable.h

    r32 r53  
    2222
    2323#include <osg/Drawable>
     24#include <osg/CoordinateSystemNode>
     25#include <osg/Fog>
     26
    2427#include <osgViewer/Viewer>
    2528#include <OpenThreads/ScopedLock>
     
    4043public:
    4144        skySilverLining_skyDrawable();
    42         skySilverLining_skyDrawable(osgViewer::Viewer* view);
     45        skySilverLining_skyDrawable(osgViewer::Viewer* view, osg::CoordinateSystemNode* csn_);
    4346
    4447    virtual bool isSameKindAs(const Object* obj) const {
     
    5861        void addCloudLayer(cloudLayerSlot *cloudLayerSlot_);
    5962
     63        void shutdown();
     64
    6065protected:
    6166        void setLighting(SilverLining::Atmosphere *atm) const;
     
    7176        mutable std::vector<cloudLayerSlot*> cloudLayerSlots;
    7277        bool newCloudLayersToAdd;
     78        osg::ref_ptr<osg::CoordinateSystemNode> sceneRoot;
    7379};
    7480
  • osgVisual/src/sky_Silverlining/skySilverLining_skyDrawable.cpp

    r31 r53  
    4343}
    4444
    45 skySilverLining_skyDrawable::skySilverLining_skyDrawable(osgViewer::Viewer* view)
     45skySilverLining_skyDrawable::skySilverLining_skyDrawable(osgViewer::Viewer* view,  osg::CoordinateSystemNode* csn_)
    4646        : osg::Drawable()
    4747        , _view(view)
     
    5353        cloudLayerSlots.clear();
    5454        newCloudLayersToAdd = false;
     55        sceneRoot = csn_;
    5556}
    5657
     
    8687void skySilverLining_skyDrawable::setSceneFog(SilverLining::Atmosphere *atmosphere) const
    8788{   
    88         glEnable(GL_FOG);
    89     glFogi(GL_FOG_MODE, GL_EXP);
     89        //glEnable(GL_FOG);
     90 //   glFogi(GL_FOG_MODE, GL_EXP);
     91
     92        ////float hazeR, hazeG, hazeB;
     93        ////double hazeDepth, hazeDensity;
     94        ////atmosphere->GetHaze(hazeR, hazeG, hazeB, hazeDepth, hazeDensity);
     95
     96 //   //hazeDensity = 1.0 / 40000;
     97        ////hazeDensity = 0;
     98        //float hazeDensity = 1.0 / atmosphere->GetConditions()->GetVisibility();
     99
     100 //   // Decrease fog density with altitude, to avoid fog effects through the vacuum of space.
     101 //   static const double H = 8435.0; // Pressure scale height of Earth's atmosphere
     102 //   double isothermalEffect = exp(-(atmosphere->GetConditions()->GetLocation().GetAltitude() / H));     
     103 //   if (isothermalEffect <= 0) isothermalEffect = 1E-9;
     104 //   if (isothermalEffect > 1.0) isothermalEffect = 1.0;
     105 //   hazeDensity *= isothermalEffect;
     106
     107 //   bool silverLiningHandledTheFog = false;
     108
     109 //   if (atmosphere->GetFogEnabled())
     110 //   {
     111 //           float density, r, g, b;
     112 //           // Note, the fog color returned is already lit
     113 //           atmosphere->GetFogSettings(&density, &r, &g, &b);
     114
     115 //           if (density > hazeDensity)
     116 //           {
     117 //                   glFogf(GL_FOG_DENSITY, density);
     118
     119 //                   GLfloat fogColor[4] = {r, g, b, 1.0};
     120 //                   glFogfv(GL_FOG_COLOR, fogColor);
     121
     122 //                   silverLiningHandledTheFog = true;
     123 //           }
     124 //   }
     125 //   
     126 //   if (!silverLiningHandledTheFog)
     127 //   {
     128 //           GLfloat fogColor[4];
     129 //           //atmosphere->GetHorizonColor(yaw, &fogColor[0], &fogColor[1], &fogColor[2]);     // New version of this call: SL_1.94 /** \todo transmit the yaw value of the center channel to all slaves for consistent fog color. */
     130        //              atmosphere->GetHorizonColor( 0, &fogColor[0], &fogColor[1], &fogColor[2]);
     131 //           glFogfv(GL_FOG_COLOR, fogColor);
     132
     133 //           glFogf(GL_FOG_DENSITY, hazeDensity);
     134 //   }
     135
     136
     137
     138
     139
     140       
     141        osg::ref_ptr<osg::Fog> fog = new osg::Fog;
     142    fog->setMode(osg::Fog::EXP);
     143        //fog->setUseRadialFog( true );
     144
     145        //_objectsNode  = erde oder object, das mit nebel bedacht werden soll   
     146        sceneRoot->getOrCreateStateSet()->setAttributeAndModes(fog.get());
    90147
    91148        //float hazeR, hazeG, hazeB;
     
    114171            if (density > hazeDensity)
    115172            {
    116                     glFogf(GL_FOG_DENSITY, density);
    117 
    118                     GLfloat fogColor[4] = {r, g, b, 1.0};
    119                     glFogfv(GL_FOG_COLOR, fogColor);
    120 
    121                     silverLiningHandledTheFog = true;
     173                                fog->setDensity(density);
     174                                fog->setColor(osg::Vec4(r, g, b, 1.0));
     175
     176                                silverLiningHandledTheFog = true;
    122177            }
    123178    }
     
    125180    if (!silverLiningHandledTheFog)
    126181    {
    127             GLfloat fogColor[4];
    128             //atmosphere->GetHorizonColor(yaw, &fogColor[0], &fogColor[1], &fogColor[2]);       // New version of this call: SL_1.94 /** \todo transmit the yaw value of the center channel to all slaves for consistent fog color. */
    129                         atmosphere->GetHorizonColor( 0, &fogColor[0], &fogColor[1], &fogColor[2]);
    130             glFogfv(GL_FOG_COLOR, fogColor);
    131 
    132             glFogf(GL_FOG_DENSITY, hazeDensity);
     182                float r, g, b;
     183                atmosphere->GetHorizonColor(0, &r, &g, &b);// New version of this call: since SL_1.94 /** \todo transmit the yaw value of the center channel to all slaves for consistent fog color. */
     184
     185                fog->setDensity(hazeDensity);
     186                fog->setColor(osg::Vec4(r, g, b, 1.0));
    133187    }
    134188
    135 
    136  //   _fog = new osg::Fog;
    137         //_objectsNode  = erde oder object, das mit nebel bedacht werden soll   
    138         //_objectsNode->getOrCreateStateSet()->setAttributeAndModes(_fog.get());
    139 
    140         //fog->setMode(osg::Fog::EXP);
    141 
    142  //   float hazeDensity = 0;//1.0 / 10000.0; //0.000075f
    143  //   bool silverLiningHandledTheFog = false;
    144 
    145  //   if (atmosphere->GetFogEnabled())
    146  //   {
    147  //       float density, r, g, b;
    148  //       atmosphere->GetFogSettings(&density, &r, &g, &b);
    149 
    150  //       if (density > hazeDensity)
    151  //       {
    152  //           fog->setDensity(density);
    153  //           fog->setColor(osg::Vec4(r, g, b, 1.0));
    154 
    155  //           silverLiningHandledTheFog = true;
    156  //       }
    157  //   }
    158 
    159  //   if (!silverLiningHandledTheFog)
    160  //   {
    161  //       float r, g, b;
    162  //       atmosphere->GetHorizonColor(0, &r, &g, &b);
    163 
    164  //       fog->setDensity(hazeDensity);
    165  //       fog->setColor(osg::Vec4(r, g, b, 1.0));
    166  //   }
    167189}
    168190
     
    278300        }
    279301}
     302
     303void skySilverLining_skyDrawable::shutdown()
     304{
     305        sceneRoot = NULL;
     306}
  • osgVisual/src/sky_Silverlining/visual_skySilverLining.cpp

    r31 r53  
    164164    // Add the sky (calls Atmosphere::BeginFrame and handles initialization once you're in
    165165    // the rendering thread)
    166         skyDrawable = new skySilverLining_skyDrawable(viewer);
     166        skyDrawable = new skySilverLining_skyDrawable(viewer, sceneRoot);
    167167
    168168        osg::Camera *mainCamera = viewer->getCamera();
     
    244244    // Add the sky (calls Atmosphere::BeginFrame and handles initialization once you're in
    245245    // the rendering thread)
    246         skyDrawable = new skySilverLining_skyDrawable(viewer);
     246        skyDrawable = new skySilverLining_skyDrawable(viewer, sceneRoot);
    247247 
    248248        if (!useProjMatrixCallback)
     
    301301
    302302        setTime(16,00,23);
    303         setVisibility(50000);
     303        setVisibility(5000);
     304        //AtmosphericConditions::SetFog()// use this for simulation real fog.
     305
     306
    304307
    305308        //Todo: secure memory-manager of timer*. oder remove paragraph
     
    371374
    372375                // delete drawables
     376                skyDrawable->shutdown();
    373377                this->removeDrawable(skyDrawable);
    374378                this->removeDrawable(cloudsDrawable);
     
    382386                atmosphere->GetConditions()->SetVisibility( visibility_ );
    383387        }
     388
    384389}
    385390
Note: See TracChangeset for help on using the changeset viewer.