Changeset 9466 for code/branches/shaders/src/orxonox/graphics
- Timestamp:
- Nov 26, 2012, 3:58:05 PM (12 years ago)
- Location:
- code/branches/shaders/src/orxonox/graphics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/shaders/src/orxonox/graphics/LensFlare.cc
r9464 r9466 47 47 CreateFactory(LensFlare); 48 48 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)) 50 50 { 51 51 RegisterObject(LensFlare); … … 137 137 is the (point-)light source currently visible 138 138 */ 139 void LensFlare::updateBillboardStates(Vector3& viewDirection, unsigned int dimension, bool lightIsVisible)139 void LensFlare::updateBillboardStates(Vector3& viewDirection, float dimension, bool lightIsVisible) 140 140 { 141 141 //TODO: develop a more sane method for determining positions and scale factors of the flare components … … 143 143 int i=0; 144 144 float step=0.0f; 145 Vector3 position=CameraManager::getInstance().getActiveCamera()->getOgreCamera()->getDerivedPosition(); 145 146 for(std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) { 146 147 Billboard* billboard=static_cast<Billboard*>(*it); 147 148 billboard->setPosition(this->getPosition()-viewDirection*step); 148 149 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)); 150 151 step=0.25f*(i>2?(i-2):0); 151 152 i++; … … 161 162 void LensFlare::updateBillboardAlphas(float alpha) 162 163 { 163 ColourValue* colour = new ColourValue(1.0f,1.0f,1.0f,alpha); 164 *colour+=*this->colour_; 164 this->colour_->a=alpha; 165 165 std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); 166 166 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 } 168 172 Billboard* billboard=static_cast<Billboard*>(*it); 169 billboard->setColour(* colour);170 }171 delete colour;173 billboard->setColour(*(this->colour_)); 174 i++; 175 } 172 176 } 173 177 … … 180 184 the absolute amount of point samples that are currently captured by the camera of the view port 181 185 */ 182 unsigned int LensFlare::getPointCount( unsigned int dimension) const186 unsigned int LensFlare::getPointCount(float dimension) const 183 187 { 184 188 Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera(); 185 189 Vector3 position = this->getPosition(); 186 Vector3 nX = camera->get Orientation().xAxis().normalisedCopy();187 Vector3 nY = camera->get Orientation().yAxis().normalisedCopy();190 Vector3 nX = camera->getDerivedOrientation().xAxis().normalisedCopy(); 191 Vector3 nY = camera->getDerivedOrientation().yAxis().normalisedCopy(); 188 192 int halfRes=fadeResolution_/2; 189 int resDim=dimension/fadeResolution_;193 float resDim=dimension/fadeResolution_; 190 194 unsigned int count=0; 191 195 for(int i=-halfRes;i<=halfRes;i++) … … 209 213 Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera(); //get active Ogre Camera Instance, so we can check whether the light source is visible 210 214 this->cameraDistance_=camera->getPosition().distance(this->getPosition()); 211 unsigned int dimension=this->cameraDistance_*this->scale_;215 float dimension=this->cameraDistance_*this->scale_; 212 216 if(!this->fadeOnViewBorder_) 213 217 { 214 218 this->fadeResolution_=3;//this is so we can still determine when the billboard has left the screen 215 219 } 216 unsigned int pointCount=this->getPointCount(dimension /2);217 Vector3 viewDirection=this->getPosition()-camera->get Position()-camera->getDerivedDirection()*this->cameraDistance_;220 unsigned int pointCount=this->getPointCount(dimension*0.5f); 221 Vector3 viewDirection=this->getPosition()-camera->getDerivedPosition()-camera->getDerivedDirection()*this->cameraDistance_; 218 222 updateBillboardStates(viewDirection,dimension,pointCount>0); 219 223 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 billboard224 Ogre::Sphere* sphere=new Ogre::Sphere(this->getPosition(),dimension*0.25f); 221 225 float left, right, top, bottom; 222 226 camera->projectSphere(*sphere,&left,&top,&right,&bottom);//approximate maximum pixel count of billboard with a sphere … … 224 228 225 229 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; 227 231 float pixelCount=this->getScene()->getRenderQueueListener()->getPixelCount();//get pixel count 228 float ratio=(maxCount ==0.0f)?0.0f:(pixelCount/maxCount);//preventdivision by zero232 float ratio=(maxCount<0.0f)?0.0f:(pixelCount/maxCount);//prevent underflow and division by zero 229 233 float borderRatio=1.0f; 230 234 if(this->fadeOnViewBorder_) -
code/branches/shaders/src/orxonox/graphics/LensFlare.h
r9464 r9466 135 135 void createBillboards(); 136 136 137 void updateBillboardStates(Vector3& viewDirection, unsigned int dimension, bool isLightVisible);137 void updateBillboardStates(Vector3& viewDirection, float dimension, bool isLightVisible); 138 138 139 139 void updateBillboardAlphas(float alpha); 140 140 141 unsigned int getPointCount( unsigned int dimension) const;141 unsigned int getPointCount(float dimension) const; 142 142 143 143 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 camera144 float cameraDistance_;//!< current distance of the lensflare center from the camera 145 145 float scale_;//!< this factor is used to scale the billboard to the desired size 146 146 bool fadeOnViewBorder_;//!< should the effect fade out on the border of the view?
Note: See TracChangeset
for help on using the changeset viewer.