Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 25, 2012, 7:43:59 PM (12 years ago)
Author:
davidsa
Message:

Updated orxonox::LensFlare, the effect has been expanded by several layers, this needs a lot of tidying up and is only a rough implementation for demonstrative purposes

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

Legend:

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

    r9461 r9464  
    4747    CreateFactory(LensFlare);
    4848   
    49     LensFlare::LensFlare(BaseObject* creator) : StaticEntity(creator), scale_(1.0f), fadeOnViewBorder_(true), fadeResolution_(7), fadeExponent_(2.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,0.0f))
    5050    {
    5151        RegisterObject(LensFlare);
     
    9797        burst->setVisible(true);
    9898        this->attach(burst);
     99       
     100        Billboard* bursthalo = new Billboard(this);
     101        bursthalo->setMaterial("lensflare/bursthalo");
     102        bursthalo->setPosition(this->getPosition());
     103        bursthalo->disableFrustumCulling();
     104        bursthalo->setVisible(true);
     105        this->attach(bursthalo);
     106       
     107        bursthalo = new Billboard(this);
     108        bursthalo->setMaterial("lensflare/halo1");
     109        bursthalo->setPosition(this->getPosition());
     110        bursthalo->disableFrustumCulling();
     111        bursthalo->setVisible(true);
     112        this->attach(bursthalo);
     113       
     114        bursthalo = new Billboard(this);
     115        bursthalo->setMaterial("lensflare/halo2");
     116        bursthalo->setPosition(this->getPosition());
     117        bursthalo->disableFrustumCulling();
     118        bursthalo->setVisible(true);
     119        this->attach(bursthalo);
     120       
     121        bursthalo = new Billboard(this);
     122        bursthalo->setMaterial("lensflare/halo3");
     123        bursthalo->setPosition(this->getPosition());
     124        bursthalo->disableFrustumCulling();
     125        bursthalo->setVisible(true);
     126        this->attach(bursthalo);
    99127    }
    100128
     
    102130    @brief
    103131        This function updates the states of all the billboards, i.e. their positions, visibilty and dimensions
     132    @param viewDirection
     133        normalised vector pointing from the current camera to the point light center
    104134    @param dimension
    105135        the current dimension of the main billboard, we're always using square billboards
    106     */
    107     void LensFlare::updateBillboardStates(unsigned int dimension, bool lightIsVisible)
     136    @param lightIsVisible
     137        is the (point-)light source currently visible
     138    */
     139    void LensFlare::updateBillboardStates(Vector3& viewDirection, unsigned int dimension, bool lightIsVisible)
    108140    {
    109         //TODO: position and dimensions need to be calculated for everything but the main burst of the flare
     141        //TODO: develop a more sane method for determining positions and scale factors of the flare components
     142        //A good solution would probably be to introduce a data structure which stores a lens flare configuration
     143        int i=0;
     144        float step=0.0f;
    110145        for(std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) {
    111146            Billboard* billboard=static_cast<Billboard*>(*it);
    112             billboard->setPosition(this->getPosition());
     147            billboard->setPosition(this->getPosition()-viewDirection*step);
    113148            billboard->setVisible(lightIsVisible);
    114             billboard->setDefaultDimensions(dimension,dimension);
     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            step=0.25f*(i>2?(i-2):0);
     151            i++;
    115152        }
    116153    }
     
    125162    {
    126163        ColourValue* colour = new ColourValue(1.0f,1.0f,1.0f,alpha);
     164        *colour+=*this->colour_;
    127165        std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin();
    128166        it++;
     
    176214                this->fadeResolution_=3;//this is so we can still determine when the billboard has left the screen
    177215            }
    178             unsigned int pointCount=this->getPointCount(dimension);
    179             updateBillboardStates(dimension,pointCount>0);
     216            unsigned int pointCount=this->getPointCount(dimension/2);
     217            Vector3 viewDirection=this->getPosition()-camera->getPosition()-camera->getDerivedDirection()*this->cameraDistance_;
     218            updateBillboardStates(viewDirection,dimension,pointCount>0);
    180219            if(pointCount>0) {
    181                 Ogre::Sphere* sphere=new Ogre::Sphere(this->getPosition(),dimension*0.25);
     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
    182221                float left, right, top, bottom;
    183222                camera->projectSphere(*sphere,&left,&top,&right,&bottom);//approximate maximum pixel count of billboard with a sphere
     
    187226                float maxCount=(right-left)*(top-bottom)*window->getWidth()*window->getHeight()*0.25;
    188227                float pixelCount=this->getScene()->getRenderQueueListener()->getPixelCount();//get pixel count
    189                 float ratio=(maxCount==0)?0:(pixelCount/maxCount);//prevent division by zero
     228                float ratio=(maxCount==0.0f)?0.0f:(pixelCount/maxCount);//prevent division by zero
    190229                float borderRatio=1.0f;
    191230                if(this->fadeOnViewBorder_)
     
    193232                    borderRatio=((float) pointCount)/(((float) fadeResolution_)*((float) fadeResolution_));//ratio for the border fade
    194233                }
    195                
    196234                //update alpha values of all billboards except the HOQ billboard
    197                 this->updateBillboardAlphas(std::min(1.0f,std::pow(std::min(ratio,borderRatio),2.0f)));
     235                this->updateBillboardAlphas(std::min(1.0f,std::pow(std::min(ratio,borderRatio),this->fadeExponent_)));
    198236            }
    199237        }
  • code/branches/shaders/src/orxonox/graphics/LensFlare.h

    r9461 r9464  
    135135            void createBillboards();
    136136           
    137             void updateBillboardStates(unsigned int dimension, bool isLightVisible);
     137            void updateBillboardStates(Vector3& viewDirection, unsigned int dimension, bool isLightVisible);
    138138           
    139139            void updateBillboardAlphas(float alpha);
     
    147147            unsigned int fadeResolution_;//!< how many points should be sampled per axis for the screen border fade. High number => smooth fade, but uses more processing power
    148148            float fadeExponent_;//!< this determines how fast the flare fades away as it gets obstructed
     149            //TODO: add XML port for colour manipulation
     150            ColourValue* colour_;//!< this stores the base colour of the light
    149151    };
    150152}
Note: See TracChangeset for help on using the changeset viewer.