Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9466


Ignore:
Timestamp:
Nov 26, 2012, 3:58:05 PM (11 years ago)
Author:
davidsa
Message:

WIP: fixing max pixel calculation and size scaling of the billboards

Location:
code/branches/shaders/src/orxonox/graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/shaders/src/orxonox/graphics/LensFlare.cc

    r9464 r9466  
    4747    CreateFactory(LensFlare);
    4848   
    49     LensFlare::LensFlare(BaseObject* creator) : StaticEntity(creator), scale_(1.0f), fadeOnViewBorder_(true), fadeResolution_(7), fadeExponent_(2.0f), colour_(new ColourValue(1.0f,0.9f,0.9f,0.0f))
     49    LensFlare::LensFlare(BaseObject* creator) : StaticEntity(creator), scale_(1.0f), fadeOnViewBorder_(true), fadeResolution_(7), fadeExponent_(2.0f), colour_(new ColourValue(1.0f,0.9f,0.9f))
    5050    {
    5151        RegisterObject(LensFlare);
     
    137137        is the (point-)light source currently visible
    138138    */
    139     void LensFlare::updateBillboardStates(Vector3& viewDirection, unsigned int dimension, bool lightIsVisible)
     139    void LensFlare::updateBillboardStates(Vector3& viewDirection, float dimension, bool lightIsVisible)
    140140    {
    141141        //TODO: develop a more sane method for determining positions and scale factors of the flare components
     
    143143        int i=0;
    144144        float step=0.0f;
     145        Vector3 position=CameraManager::getInstance().getActiveCamera()->getOgreCamera()->getDerivedPosition();
    145146        for(std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) {
    146147            Billboard* billboard=static_cast<Billboard*>(*it);
    147148            billboard->setPosition(this->getPosition()-viewDirection*step);
    148149            billboard->setVisible(lightIsVisible);
    149             billboard->setDefaultDimensions((i==0?0.5f:1.0f)*(i>2?0.25f:1.0f)*dimension*std::pow((1.0f-step),-1.0f),(i==0?0.5f:1.0f)*(i>2?0.25f:1.0f)*dimension*std::pow((1.0f-step),-1.0f));
     150            billboard->setDefaultDimensions((i<0?0.5f:1.0f)*(i>2?0.25f:1.0f)*dimension*std::pow((1.0f-step),-1.0f),(i<0?0.5f:1.0f)*(i>2?0.25f:1.0f)*dimension*std::pow((1.0f-step),-1.0f));
    150151            step=0.25f*(i>2?(i-2):0);
    151152            i++;
     
    161162    void LensFlare::updateBillboardAlphas(float alpha)
    162163    {
    163         ColourValue* colour = new ColourValue(1.0f,1.0f,1.0f,alpha);
    164         *colour+=*this->colour_;
     164        this->colour_->a=alpha;
    165165        std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin();
    166166        it++;
    167         for(;it!=this->getAttachedObjects().end(); it++) {
     167        for(int i=0;it!=this->getAttachedObjects().end(); it++) {
     168            if(i==2)
     169            {
     170                this->colour_->a*=0.5f;
     171            }
    168172            Billboard* billboard=static_cast<Billboard*>(*it);
    169             billboard->setColour(*colour);
    170         }
    171         delete colour;
     173            billboard->setColour(*(this->colour_));
     174            i++;
     175        }
    172176    }
    173177   
     
    180184        the absolute amount of point samples that are currently captured by the camera of the view port
    181185    */
    182     unsigned int LensFlare::getPointCount(unsigned int dimension) const
     186    unsigned int LensFlare::getPointCount(float dimension) const
    183187    {
    184188        Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera();
    185189        Vector3 position = this->getPosition();
    186         Vector3 nX = camera->getOrientation().xAxis().normalisedCopy();
    187         Vector3 nY = camera->getOrientation().yAxis().normalisedCopy();
     190        Vector3 nX = camera->getDerivedOrientation().xAxis().normalisedCopy();
     191        Vector3 nY = camera->getDerivedOrientation().yAxis().normalisedCopy();
    188192        int halfRes=fadeResolution_/2;
    189         int resDim=dimension/fadeResolution_;
     193        float resDim=dimension/fadeResolution_;
    190194        unsigned int count=0;
    191195        for(int i=-halfRes;i<=halfRes;i++)
     
    209213            Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera(); //get active Ogre Camera Instance, so we can check whether the light source is visible
    210214            this->cameraDistance_=camera->getPosition().distance(this->getPosition());
    211             unsigned int dimension=this->cameraDistance_*this->scale_;
     215            float dimension=this->cameraDistance_*this->scale_;
    212216            if(!this->fadeOnViewBorder_)
    213217            {
    214218                this->fadeResolution_=3;//this is so we can still determine when the billboard has left the screen
    215219            }
    216             unsigned int pointCount=this->getPointCount(dimension/2);
    217             Vector3 viewDirection=this->getPosition()-camera->getPosition()-camera->getDerivedDirection()*this->cameraDistance_;
     220            unsigned int pointCount=this->getPointCount(dimension*0.5f);
     221            Vector3 viewDirection=this->getPosition()-camera->getDerivedPosition()-camera->getDerivedDirection()*this->cameraDistance_;
    218222            updateBillboardStates(viewDirection,dimension,pointCount>0);
    219223            if(pointCount>0) {
    220                 Ogre::Sphere* sphere=new Ogre::Sphere(this->getPosition(),dimension*0.25*0.5);//0.5 stems from the fact that we scaled down the occlusion billboard
     224                Ogre::Sphere* sphere=new Ogre::Sphere(this->getPosition(),dimension*0.25f);
    221225                float left, right, top, bottom;
    222226                camera->projectSphere(*sphere,&left,&top,&right,&bottom);//approximate maximum pixel count of billboard with a sphere
     
    224228               
    225229                Ogre::RenderWindow* window = GraphicsManager::getInstance().getRenderWindow();
    226                 float maxCount=(right-left)*(top-bottom)*window->getWidth()*window->getHeight()*0.25;
     230                float maxCount=(right-left)*(top-bottom)*window->getWidth()*window->getHeight()*0.25f;
    227231                float pixelCount=this->getScene()->getRenderQueueListener()->getPixelCount();//get pixel count
    228                 float ratio=(maxCount==0.0f)?0.0f:(pixelCount/maxCount);//prevent division by zero
     232                float ratio=(maxCount<0.0f)?0.0f:(pixelCount/maxCount);//prevent underflow and division by zero
    229233                float borderRatio=1.0f;
    230234                if(this->fadeOnViewBorder_)
  • code/branches/shaders/src/orxonox/graphics/LensFlare.h

    r9464 r9466  
    135135            void createBillboards();
    136136           
    137             void updateBillboardStates(Vector3& viewDirection, unsigned int dimension, bool isLightVisible);
     137            void updateBillboardStates(Vector3& viewDirection, float dimension, bool isLightVisible);
    138138           
    139139            void updateBillboardAlphas(float alpha);
    140140           
    141             unsigned int getPointCount(unsigned int dimension) const;
     141            unsigned int getPointCount(float dimension) const;
    142142           
    143143            Billboard* occlusionBillboard_;//!< this is a transparent billboard used solely for the Hardware Occlusion Query
    144             unsigned int cameraDistance_;//!< current distance of the lensflare center from the camera
     144            float cameraDistance_;//!< current distance of the lensflare center from the camera
    145145            float scale_;//!< this factor is used to scale the billboard to the desired size
    146146            bool fadeOnViewBorder_;//!< should the effect fade out on the border of the view?
Note: See TracChangeset for help on using the changeset viewer.