Changeset 9464 for code/branches/shaders/src/orxonox/graphics
- Timestamp:
- Nov 25, 2012, 7:43:59 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
r9461 r9464 47 47 CreateFactory(LensFlare); 48 48 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)) 50 50 { 51 51 RegisterObject(LensFlare); … … 97 97 burst->setVisible(true); 98 98 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); 99 127 } 100 128 … … 102 130 @brief 103 131 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 104 134 @param dimension 105 135 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) 108 140 { 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; 110 145 for(std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) { 111 146 Billboard* billboard=static_cast<Billboard*>(*it); 112 billboard->setPosition(this->getPosition() );147 billboard->setPosition(this->getPosition()-viewDirection*step); 113 148 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++; 115 152 } 116 153 } … … 125 162 { 126 163 ColourValue* colour = new ColourValue(1.0f,1.0f,1.0f,alpha); 164 *colour+=*this->colour_; 127 165 std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); 128 166 it++; … … 176 214 this->fadeResolution_=3;//this is so we can still determine when the billboard has left the screen 177 215 } 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); 180 219 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 182 221 float left, right, top, bottom; 183 222 camera->projectSphere(*sphere,&left,&top,&right,&bottom);//approximate maximum pixel count of billboard with a sphere … … 187 226 float maxCount=(right-left)*(top-bottom)*window->getWidth()*window->getHeight()*0.25; 188 227 float pixelCount=this->getScene()->getRenderQueueListener()->getPixelCount();//get pixel count 189 float ratio=(maxCount==0 )?0:(pixelCount/maxCount);//prevent division by zero228 float ratio=(maxCount==0.0f)?0.0f:(pixelCount/maxCount);//prevent division by zero 190 229 float borderRatio=1.0f; 191 230 if(this->fadeOnViewBorder_) … … 193 232 borderRatio=((float) pointCount)/(((float) fadeResolution_)*((float) fadeResolution_));//ratio for the border fade 194 233 } 195 196 234 //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_))); 198 236 } 199 237 } -
code/branches/shaders/src/orxonox/graphics/LensFlare.h
r9461 r9464 135 135 void createBillboards(); 136 136 137 void updateBillboardStates( unsigned int dimension, bool isLightVisible);137 void updateBillboardStates(Vector3& viewDirection, unsigned int dimension, bool isLightVisible); 138 138 139 139 void updateBillboardAlphas(float alpha); … … 147 147 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 148 148 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 149 151 }; 150 152 }
Note: See TracChangeset
for help on using the changeset viewer.