Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 14, 2012, 9:16:18 PM (11 years ago)
Author:
davidsa
Message:

Added Hardware Occlusion Query Capabilities for use in dynamic flare effects, this is still a pretty static implemenation, meaning it will fail with mutltiple HOQ objects on screen, also needs some tidying up and documentation at a later point

File:
1 edited

Legend:

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

    r9445 r9448  
    3838#include "graphics/Billboard.h"
    3939#include "CameraManager.h"
     40#include "RenderQueueListener.h"
     41
     42#include <OgreSphere.h>
     43#include <OgreRenderWindow.h>
    4044
    4145namespace orxonox
     
    4347    CreateFactory(LensFlare);
    4448   
    45     LensFlare::LensFlare(BaseObject* creator) : StaticEntity(creator)
     49    LensFlare::LensFlare(BaseObject* creator) : StaticEntity(creator), scale_(1.0f)
    4650    {
    4751        RegisterObject(LensFlare);
     
    5963    {
    6064        SUPER(LensFlare, XMLPort, xmlelement, mode);
     65        XMLPortParam(LensFlare, "scale", setScale, getScale, xmlelement, mode).defaultValues(1.0f);
    6166    }
    6267   
    6368    void LensFlare::registerVariables()
    6469    {
    65      
     70        registerVariable(this->scale_, VariableDirection::ToClient, new NetworkCallback<LensFlare>(this, &LensFlare::updateBillboardPositions));
    6671    }
    6772   
    6873    void LensFlare::createBillboards()
    6974    {
     75        this->occlusionBillboard_ = new Billboard(this);
     76        this->occlusionBillboard_->setMaterial("lensflare/hoq");
     77        this->occlusionBillboard_->setPosition(this->getPosition());
     78        this->occlusionBillboard_->setVisible(false);
     79        this->occlusionBillboard_->setRenderQueueGroup(RENDER_QUEUE_HOQ);
     80        this->attach(this->occlusionBillboard_);
     81       
    7082        Billboard* burst = new Billboard(this);
    7183        burst->setMaterial("lensflare/burst");
     
    7991        Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera(); //get active Ogre Camera Instance, so we can check whether the light source is visible
    8092        bool lightIsVisible=camera->isVisible(this->getPosition()); //is the light source visible from our point of view?
    81         int scale=camera->getPosition().distance(this->getPosition());
     93        this->cameraDistance_=camera->getPosition().distance(this->getPosition());
     94        unsigned int dimension=this->cameraDistance_*this->scale_;
    8295       
    83         Billboard* burst=static_cast<Billboard*>(getAttachedObject(0));
     96        this->occlusionBillboard_->setPosition(this->getPosition());
     97        this->occlusionBillboard_->setVisible(lightIsVisible);
     98        this->occlusionBillboard_->setDefaultDimensions(dimension,dimension);
     99       
     100        Billboard* burst=static_cast<Billboard*>(getAttachedObject(1));
    84101        burst->setPosition(this->getPosition());
    85102        burst->setVisible(lightIsVisible);
    86         burst->setDefaultDimensions(scale,scale);
     103        burst->setDefaultDimensions(dimension,dimension);
    87104    }
    88105
     
    92109        {
    93110            updateBillboardPositions();
     111            if(this->occlusionBillboard_->isVisible()) {
     112                unsigned int dimension=this->cameraDistance_*this->scale_;
     113                Ogre::Sphere* sphere=new Ogre::Sphere(this->getPosition(),dimension*0.25);
     114                Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera();
     115                float left, right, top, bottom;
     116                camera->projectSphere(*sphere,&left,&top,&right,&bottom);//approximate maximum pixel count of billboard with a sphere
     117                delete sphere;
     118               
     119                Ogre::RenderWindow* window = GraphicsManager::getInstance().getRenderWindow();
     120                float maxCount=(right-left)*(top-bottom)*window->getWidth()*window->getHeight()*0.25;
     121                float pixelCount=this->getScene()->getRenderQueueListener()->getPixelCount();//get pixel count
     122                float ratio=pixelCount/maxCount;
     123                //orxout() << "maxCount: " << maxCount << " HOQ: " << pixelCount << " ratio: " << ratio << std::endl;
     124                ColourValue* colour = new ColourValue(1.0f,1.0f,1.0f,ratio); //adjust alpha of billboard
     125               
     126                Billboard* burst=static_cast<Billboard*>(getAttachedObject(1));
     127                burst->setColour(*colour);
     128                delete colour;
     129            }
    94130        }
    95131    }
Note: See TracChangeset for help on using the changeset viewer.