Changeset 9448 for code/branches/shaders/src/orxonox/graphics
- Timestamp:
- Nov 14, 2012, 9:16:18 PM (12 years ago)
- Location:
- code/branches/shaders/src/orxonox/graphics
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/shaders/src/orxonox/graphics/Billboard.cc
r8706 r9448 171 171 } 172 172 } 173 174 void Billboard::setRenderQueueGroup(unsigned char groupID) 175 { 176 Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); 177 if( bSet != NULL ) 178 { 179 bSet->setRenderQueueGroup(groupID); 180 } 181 } 173 182 } -
code/branches/shaders/src/orxonox/graphics/Billboard.h
r8706 r9448 81 81 82 82 void setDefaultDimensions(float width, float height); 83 84 void setRenderQueueGroup(unsigned char groupID); 83 85 84 86 -
code/branches/shaders/src/orxonox/graphics/LensFlare.cc
r9445 r9448 38 38 #include "graphics/Billboard.h" 39 39 #include "CameraManager.h" 40 #include "RenderQueueListener.h" 41 42 #include <OgreSphere.h> 43 #include <OgreRenderWindow.h> 40 44 41 45 namespace orxonox … … 43 47 CreateFactory(LensFlare); 44 48 45 LensFlare::LensFlare(BaseObject* creator) : StaticEntity(creator) 49 LensFlare::LensFlare(BaseObject* creator) : StaticEntity(creator), scale_(1.0f) 46 50 { 47 51 RegisterObject(LensFlare); … … 59 63 { 60 64 SUPER(LensFlare, XMLPort, xmlelement, mode); 65 XMLPortParam(LensFlare, "scale", setScale, getScale, xmlelement, mode).defaultValues(1.0f); 61 66 } 62 67 63 68 void LensFlare::registerVariables() 64 69 { 65 70 registerVariable(this->scale_, VariableDirection::ToClient, new NetworkCallback<LensFlare>(this, &LensFlare::updateBillboardPositions)); 66 71 } 67 72 68 73 void LensFlare::createBillboards() 69 74 { 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 70 82 Billboard* burst = new Billboard(this); 71 83 burst->setMaterial("lensflare/burst"); … … 79 91 Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera(); //get active Ogre Camera Instance, so we can check whether the light source is visible 80 92 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_; 82 95 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)); 84 101 burst->setPosition(this->getPosition()); 85 102 burst->setVisible(lightIsVisible); 86 burst->setDefaultDimensions( scale,scale);103 burst->setDefaultDimensions(dimension,dimension); 87 104 } 88 105 … … 92 109 { 93 110 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 } 94 130 } 95 131 } -
code/branches/shaders/src/orxonox/graphics/LensFlare.h
r9445 r9448 40 40 #include "OgreBillboardSet.h" 41 41 42 #include "core/GraphicsManager.h" 42 43 #include "util/Math.h" 43 44 #include "worldentities/StaticEntity.h" … … 54 55 David 'davidsa' Salvisberg 55 56 */ 57 //TODO: The Hardware Occlusion only works properly for a single Flare on the screen, 58 // if we have multiple strong lights it'll become way more complicated to determine how much of every object is occluded individually 59 // there's below a 100 render queue groups, so maybe we should take turns for each object to be tested, so we only have one of the objects rendered at a time 60 // obviously we shouldn't use too much of these effects anyways, since they use a lot of performance, so not sure whether it's worth implementing a solution that works for multiple lens flares on screen 56 61 class _OrxonoxExport LensFlare : public StaticEntity, public Tickable 57 62 { … … 59 64 LensFlare(BaseObject* creator); 60 65 virtual ~LensFlare(); 66 67 inline void setScale(float scale) 68 { this->scale_=scale; } 69 inline float getScale() 70 { return this->scale_; } 61 71 62 72 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); … … 72 82 73 83 void updateBillboardPositions(); 84 85 Billboard* occlusionBillboard_; 86 unsigned int cameraDistance_; 87 float scale_; 74 88 }; 75 89 }
Note: See TracChangeset
for help on using the changeset viewer.