Changeset 11078
- Timestamp:
- Jan 19, 2016, 10:49:57 PM (9 years ago)
- Location:
- code/branches/shaders_merge/src/orxonox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/shaders_merge/src/orxonox/Scene.cc
r11073 r11078 98 98 this->rootSceneNode_ = this->sceneManager_->getRootSceneNode(); 99 99 100 this->renderQueueListener_ = nullptr; 100 101 this->radar_ = nullptr; 101 102 } … … 125 126 126 127 if (GameMode::showsGraphics()) 128 { 129 this->sceneManager_->removeRenderQueueListener(this->renderQueueListener_); 130 delete this->renderQueueListener_; 127 131 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); 132 } 128 133 else 129 134 delete this->sceneManager_; -
code/branches/shaders_merge/src/orxonox/graphics/LensFlare.cc
r11075 r11078 46 46 RegisterClass(LensFlare); 47 47 48 LensFlare::LensFlare(Context* context) : StaticEntity(context), scale_(1.0f), fadeOnViewBorder_(true), fadeResolution_(7), fadeExponent_(2.0f) , colour_(new ColourValue(1.0f,0.9f,0.9f))48 LensFlare::LensFlare(Context* context) : StaticEntity(context), scale_(1.0f), fadeOnViewBorder_(true), fadeResolution_(7), fadeExponent_(2.0f) 49 49 { 50 50 RegisterObject(LensFlare); 51 51 52 this->lensConfiguration_=new std::vector<LensFlare::Lens*>(); 53 this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/burst"),1.0f,1.0f,1.0f)); //main burst 54 this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/burst"),0.7f,1.2f,1.05f)); //secondary burst 55 this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/bursthalo"),0.7f,0.9f,1.0f)); //halo around main burst 56 this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/ring"),0.1f,2.5f,0.9f)); //all the different distanced lenses 57 this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/iris"),0.1f,0.2f,0.5f)); 58 this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo5"),0.1f,0.3f,0.45f)); 59 this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo5"),0.4f,0.2f,0.35f)); 60 this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/iris"),0.1f,0.4f,0.25f)); 61 this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo4"),0.05f,0.2f,0.2f)); 52 this->lensConfiguration_.emplace_back("lensflare/burst", 1.0f, 1.0f, 1.0f); //main burst 53 this->lensConfiguration_.emplace_back("lensflare/burst", 0.7f, 1.2f, 1.05f); //secondary burst 54 this->lensConfiguration_.emplace_back("lensflare/bursthalo", 0.7f, 0.9f, 1.0f); //halo around main burst 55 this->lensConfiguration_.emplace_back("lensflare/ring", 0.1f, 2.5f, 0.9f); //all the different distanced lenses 56 this->lensConfiguration_.emplace_back("lensflare/iris", 0.1f, 0.2f, 0.5f); 57 this->lensConfiguration_.emplace_back("lensflare/halo5", 0.1f, 0.3f, 0.45f); 58 this->lensConfiguration_.emplace_back("lensflare/halo5", 0.4f, 0.2f, 0.35f); 59 this->lensConfiguration_.emplace_back("lensflare/iris", 0.1f, 0.4f, 0.25f); 60 this->lensConfiguration_.emplace_back("lensflare/halo4", 0.05f, 0.2f, 0.2f); 62 61 63 62 this->createBillboards(); … … 100 99 this->attach(this->occlusionBillboard_); 101 100 102 for(std::vector<LensFlare::Lens*>::iterator it = lensConfiguration_->begin(); it != lensConfiguration_->end(); ++it) { 103 Billboard* lensPart=new Billboard(this->getContext()); 104 lensPart->setMaterial(*(*it)->material_); 101 for (const LensFlare::Lens& lens : lensConfiguration_) 102 { 103 Billboard* lensPart = new Billboard(this->getContext()); 104 lensPart->setMaterial(lens.material_); 105 105 lensPart->disableFrustumCulling(); 106 106 lensPart->setVisible(true); … … 119 119 is the (point-)light source currently visible 120 120 */ 121 void LensFlare::updateBillboardStates( Vector3& viewDirection, float dimension, bool lightIsVisible)121 void LensFlare::updateBillboardStates(const Vector3& viewDirection, float dimension, bool lightIsVisible) 122 122 { 123 this->occlusionBillboard_->setDefaultDimensions(dimension *0.5f,dimension*0.5f);123 this->occlusionBillboard_->setDefaultDimensions(dimension * 0.5f, dimension * 0.5f); 124 124 this->occlusionBillboard_->setVisible(lightIsVisible); 125 std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); 126 it++; 127 for(int i=0; it != this->getAttachedObjects().end(); it++) { 128 Billboard* billboard=static_cast<Billboard*>(*it); 129 LensFlare::Lens* lens=lensConfiguration_->at(i); 130 billboard->setPosition(-viewDirection*(1.0f-lens->position_)); 125 126 int i = 0; 127 for (WorldEntity* attachedObject : this->getAttachedObjects()) 128 { 129 Billboard* billboard = orxonox_cast<Billboard*>(attachedObject); 130 if (billboard == this->occlusionBillboard_) 131 continue; 132 const LensFlare::Lens& lens = lensConfiguration_.at(i); 133 billboard->setPosition(-viewDirection * (1.0f - lens.position_)); 131 134 billboard->setVisible(lightIsVisible); 132 billboard->setDefaultDimensions(dimension *lens->scale_,dimension*lens->scale_);135 billboard->setDefaultDimensions(dimension * lens.scale_, dimension * lens.scale_); 133 136 i++; 134 137 } … … 143 146 void LensFlare::updateBillboardAlphas(float alpha) 144 147 { 145 this->colour_->a=alpha; 146 std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); 147 it++; 148 for(int i=0;it!=this->getAttachedObjects().end(); it++) { 149 ColourValue* cur=new ColourValue(0,0,0,0); 150 (*cur)+= *(this->colour_); 151 cur->a*=lensConfiguration_->at(i)->alpha_; 152 Billboard* billboard=static_cast<Billboard*>(*it); 153 billboard->setColour(*cur); 148 ColourValue cur = this->colour_; 149 150 int i = 0; 151 for (WorldEntity* attachedObject : this->getAttachedObjects()) 152 { 153 Billboard* billboard = orxonox_cast<Billboard*>(attachedObject); 154 if (billboard == this->occlusionBillboard_) 155 continue; 156 cur.a = alpha * lensConfiguration_.at(i).alpha_; 157 billboard->setColour(cur); 154 158 i++; 155 159 } … … 166 170 unsigned int LensFlare::getPointCount(float dimension) const 167 171 { 168 Ogre::Camera* camera =CameraManager::getInstance().getActiveCamera()->getOgreCamera();172 Ogre::Camera* camera = CameraManager::getInstance().getActiveCamera()->getOgreCamera(); 169 173 Vector3 position = this->getWorldPosition(); 170 174 Vector3 nX = camera->getDerivedOrientation().xAxis().normalisedCopy(); 171 175 Vector3 nY = camera->getDerivedOrientation().yAxis().normalisedCopy(); 172 int halfRes =fadeResolution_/2;173 float resDim =dimension/fadeResolution_;174 unsigned int count =0;175 for (int i=-halfRes;i<=halfRes;i++)176 { 177 for (int j=-halfRes;j<=halfRes;j++)176 int halfRes = fadeResolution_ / 2; 177 float resDim = dimension / fadeResolution_; 178 unsigned int count = 0; 179 for (int i = -halfRes; i <= halfRes; i++) 180 { 181 for (int j = -halfRes; j <= halfRes; j++) 178 182 { 179 Vector3 point =position+(i*resDim)*nX+(j*resDim)*nY;//generate point samples180 if (camera->isVisible(point))183 Vector3 point = position + (i*resDim) * nX + (j*resDim) * nY;//generate point samples 184 if (camera->isVisible(point)) 181 185 { 182 186 count++; … … 191 195 if(this->isVisible()) 192 196 { 193 Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera(); //get active Ogre Camera Instance, so we can check whether the light source is visible 194 this->cameraDistance_=camera->getDerivedPosition().distance(this->getPosition()); 195 float dimension=this->cameraDistance_*this->scale_; 196 if(!this->fadeOnViewBorder_) 197 // get the current distance of the lensflare center from the camera 198 Ogre::Camera* camera = CameraManager::getInstance().getActiveCamera()->getOgreCamera(); //get active Ogre Camera Instance, so we can check whether the light source is visible 199 float cameraDistance = camera->getDerivedPosition().distance(this->getPosition()); 200 float dimension = cameraDistance * this->scale_; 201 if (!this->fadeOnViewBorder_) 197 202 { 198 this->fadeResolution_ =3;//this is so we can still determine when the billboard has left the screen203 this->fadeResolution_ = 3;//this is so we can still determine when the billboard has left the screen 199 204 } 200 unsigned int pointCount=this->getPointCount(dimension*0.25f*this->scale_); 201 Vector3 viewDirection=this->getWorldPosition()-camera->getDerivedPosition()-camera->getDerivedDirection()*this->cameraDistance_; 202 updateBillboardStates(viewDirection,dimension,pointCount>0); 203 if(pointCount>0) { 204 Ogre::Sphere* sphere=new Ogre::Sphere(this->getPosition(),dimension*0.25f*this->scale_); 205 unsigned int pointCount = this->getPointCount(dimension * 0.25f * this->scale_); 206 Vector3 viewDirection = this->getWorldPosition() - camera->getDerivedPosition() - camera->getDerivedDirection() * cameraDistance; 207 this->updateBillboardStates(viewDirection, dimension, pointCount > 0); 208 if (pointCount > 0) 209 { 210 Ogre::Sphere sphere(this->getPosition(), dimension * 0.25f * this->scale_); 205 211 float left, right, top, bottom; 206 camera->projectSphere(*sphere,&left,&top,&right,&bottom);//approximate maximum pixel count of billboard with a sphere 207 delete sphere; 212 camera->projectSphere(sphere, &left, &top, &right, &bottom);//approximate maximum pixel count of billboard with a sphere 208 213 209 214 Ogre::RenderWindow* window = GraphicsManager::getInstance().getRenderWindow(); 210 float maxCount =(right-left)*(top-bottom)*window->getWidth()*window->getHeight()*0.25f;211 float pixelCount=this->getScene()->getRenderQueueListener()->getPixelCount();//get pixel count212 float ratio =(maxCount<0.0f)?0.0f:(pixelCount/maxCount);//prevent underflow and division by zero213 float borderRatio =1.0f;214 if (this->fadeOnViewBorder_)215 float maxCount = (right - left) * (top - bottom) * window->getWidth() * window->getHeight() * 0.25f; 216 unsigned int pixelCount = this->getScene()->getRenderQueueListener()->getPixelCount();//get pixel count 217 float ratio = (maxCount < 0.0f) ? 0.0f : (1.0f * pixelCount / maxCount);//prevent underflow and division by zero 218 float borderRatio = 1.0f; 219 if (this->fadeOnViewBorder_) 215 220 { 216 borderRatio =((float) pointCount)/(((float) fadeResolution_)*((float) fadeResolution_));//ratio for the border fade221 borderRatio = ((float) pointCount) / (((float) fadeResolution_) * ((float) fadeResolution_));//ratio for the border fade 217 222 } 218 223 //update alpha values of all billboards except the HOQ billboard 219 this->updateBillboardAlphas(std::min(1.0f, std::pow(std::min(ratio,borderRatio),this->fadeExponent_)));224 this->updateBillboardAlphas(std::min(1.0f, std::pow(std::min(ratio, borderRatio), this->fadeExponent_))); 220 225 } 221 226 } -
code/branches/shaders_merge/src/orxonox/graphics/LensFlare.h
r11075 r11078 67 67 { 68 68 public: 69 std::string *material_;//!< Which material should the Lens use, current choices include burst, bursthalo, halo1, halo2, halo369 std::string material_;//!< Which material should the Lens use, current choices include burst, bursthalo, halo1, halo2, halo3 70 70 float alpha_;//!< Which base alpha value should the Lens use 71 71 float scale_;//!< Which base scale should the Lens Flare have 72 72 float position_;//!< This defines how far along the view direction the flare should be positioned, e.g. 0.5 would position the flare halfway between the viewer and the base burst, 0 at the camera, 1 at the burst 73 Lens (std::string*material, float alpha, float scale, float position)73 Lens (const std::string& material, float alpha, float scale, float position) 74 74 { 75 this->material_ =material;76 this->alpha_ =alpha;77 this->scale_ =scale;78 this->position_ =position;75 this->material_ = material; 76 this->alpha_ = alpha; 77 this->scale_ = scale; 78 this->position_ = position; 79 79 } 80 80 }; … … 85 85 86 86 inline void setScale(float scale) 87 { this->scale_ =scale; }87 { this->scale_ = scale; } 88 88 inline float getScale() const 89 89 { return this->scale_; } … … 96 96 */ 97 97 inline void setColour(const ColourValue& colour) 98 { 99 this->colour_->r=colour.r; 100 this->colour_->g=colour.g; 101 this->colour_->b=colour.b; 102 } 98 { this->colour_ = colour; } 103 99 /** 104 100 @brief … … 107 103 */ 108 104 inline const ColourValue& getColour() const 109 { return *(new ColourValue(this->colour_->r,this->colour_->g,this->colour_->b)); }105 { return this->colour_; } 110 106 111 107 /** … … 121 117 */ 122 118 inline void setFadeResolution(unsigned int fadeResolution) 123 { this->fadeResolution_ =fadeResolution>0?fadeResolution:1; }119 { this->fadeResolution_ = fadeResolution > 0 ? fadeResolution : 1; } 124 120 /** 125 121 @brief … … 137 133 */ 138 134 inline void setFadeExponent(float exponent) 139 { this->fadeExponent_ =exponent; }135 { this->fadeExponent_ = exponent; } 140 136 /** 141 137 @brief … … 153 149 */ 154 150 inline void setFadeOnViewBorder(bool fadeOnViewBorder) 155 { this->fadeOnViewBorder_ =fadeOnViewBorder; }151 { this->fadeOnViewBorder_ = fadeOnViewBorder; } 156 152 /** 157 153 @brief … … 174 170 void createBillboards(); 175 171 176 void updateBillboardStates( Vector3& viewDirection, float dimension, bool isLightVisible);172 void updateBillboardStates(const Vector3& viewDirection, float dimension, bool isLightVisible); 177 173 178 174 void updateBillboardAlphas(float alpha); … … 180 176 unsigned int getPointCount(float dimension) const; 181 177 182 std::vector<Lens *>*lensConfiguration_;//!< this stores the lensConfiguration178 std::vector<Lens> lensConfiguration_;//!< this stores the lensConfiguration 183 179 Billboard* occlusionBillboard_;//!< this is a transparent billboard used solely for the Hardware Occlusion Query 184 float cameraDistance_;//!< current distance of the lensflare center from the camera185 180 float scale_;//!< this factor is used to scale the billboard to the desired size 186 181 bool fadeOnViewBorder_;//!< should the effect fade out on the border of the view? 187 182 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 188 183 float fadeExponent_;//!< this determines how fast the flare fades away as it gets obstructed 189 ColourValue *colour_;//!< this stores the base colour of the light184 ColourValue colour_;//!< this stores the base colour of the light 190 185 }; 191 186 }
Note: See TracChangeset
for help on using the changeset viewer.