[Orxonox-commit 4831] r9500 - code/branches/shaders/src/orxonox/graphics
davidsa at orxonox.net
davidsa at orxonox.net
Mon Dec 10 15:26:50 CET 2012
Author: davidsa
Date: 2012-12-10 15:26:49 +0100 (Mon, 10 Dec 2012)
New Revision: 9500
Modified:
code/branches/shaders/src/orxonox/graphics/LensFlare.cc
code/branches/shaders/src/orxonox/graphics/LensFlare.h
Log:
Added nested Class Lens to LensFlare, to simplify lens flare configuration and some of the methods. Might also be used to define presets in the future.
Modified: code/branches/shaders/src/orxonox/graphics/LensFlare.cc
===================================================================
--- code/branches/shaders/src/orxonox/graphics/LensFlare.cc 2012-12-10 14:17:37 UTC (rev 9499)
+++ code/branches/shaders/src/orxonox/graphics/LensFlare.cc 2012-12-10 14:26:49 UTC (rev 9500)
@@ -50,6 +50,15 @@
{
RegisterObject(LensFlare);
+ this->lensConfiguration_=new std::vector<LensFlare::Lens*>();
+ this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/burst"),1.0f,1.0f,1.0f)); //main burst
+ this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/bursthalo"),0.7f,0.9f,1.0f)); //halo around main burst
+ this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo1"),0.4f,0.2f,0.8f)); //all the different distanced lenses
+ this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo2"),0.7f,0.3f,0.7f));
+ this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo3"),0.3f,0.4f,0.6f));
+ this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo3"),0.1f,0.8f,0.4f));
+ this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo1"),0.15f,0.5f,0.35f));
+
this->createBillboards();
this->registerVariables();
@@ -66,6 +75,7 @@
XMLPortParam(LensFlare, "fadeOnViewBorder", setFadeOnViewBorder, isFadeOnViewBorder, xmlelement, mode).defaultValues(true);
XMLPortParam(LensFlare, "fadeResolution", setFadeResolution, getFadeResolution, xmlelement, mode).defaultValues(7);
XMLPortParam(LensFlare, "fadeExponent", setFadeExponent, getFadeExponent, xmlelement, mode).defaultValues(2.0f);
+ XMLPortParam(LensFlare, "colour", setColour, getColour, xmlelement, mode);
}
void LensFlare::registerVariables()
@@ -81,7 +91,6 @@
*/
void LensFlare::createBillboards()
{
- //TODO: add more billboards, possibly do some cleaning up, by using a loop
this->occlusionBillboard_ = new Billboard(this);
this->occlusionBillboard_->setMaterial("lensflare/hoq");
this->occlusionBillboard_->setVisible(false);
@@ -89,35 +98,13 @@
this->occlusionBillboard_->setRenderQueueGroup(RENDER_QUEUE_HOQ);
this->attach(this->occlusionBillboard_);
- Billboard* burst = new Billboard(this);
- burst->setMaterial("lensflare/burst");
- burst->disableFrustumCulling();
- burst->setVisible(true);
- this->attach(burst);
-
- Billboard* bursthalo = new Billboard(this);
- bursthalo->setMaterial("lensflare/bursthalo");
- bursthalo->disableFrustumCulling();
- bursthalo->setVisible(true);
- this->attach(bursthalo);
-
- bursthalo = new Billboard(this);
- bursthalo->setMaterial("lensflare/halo1");
- bursthalo->disableFrustumCulling();
- bursthalo->setVisible(true);
- this->attach(bursthalo);
-
- bursthalo = new Billboard(this);
- bursthalo->setMaterial("lensflare/halo2");
- bursthalo->disableFrustumCulling();
- bursthalo->setVisible(true);
- this->attach(bursthalo);
-
- bursthalo = new Billboard(this);
- bursthalo->setMaterial("lensflare/halo3");
- bursthalo->disableFrustumCulling();
- bursthalo->setVisible(true);
- this->attach(bursthalo);
+ for(std::vector<LensFlare::Lens*>::iterator it = lensConfiguration_->begin(); it != lensConfiguration_->end(); ++it) {
+ Billboard* lensPart=new Billboard(this);
+ lensPart->setMaterial(*(*it)->material_);
+ lensPart->disableFrustumCulling();
+ lensPart->setVisible(true);
+ this->attach(lensPart);
+ }
}
/**
@@ -132,16 +119,16 @@
*/
void LensFlare::updateBillboardStates(Vector3& viewDirection, float dimension, bool lightIsVisible)
{
- //TODO: develop a more sane method for determining positions and scale factors of the flare components
- //A good solution would probably be to introduce a data structure which stores a lens flare configuration
- int i=0;
- float step=0.0f;
- for(std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) {
+ this->occlusionBillboard_->setDefaultDimensions(dimension*0.5f,dimension*0.5f);
+ this->occlusionBillboard_->setVisible(lightIsVisible);
+ std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin();
+ it++;
+ for(int i=0; it != this->getAttachedObjects().end(); it++) {
Billboard* billboard=static_cast<Billboard*>(*it);
- billboard->setPosition(-viewDirection*step);
+ LensFlare::Lens* lens=lensConfiguration_->at(i);
+ billboard->setPosition(-viewDirection*(1.0f-lens->position_));
billboard->setVisible(lightIsVisible);
- 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));
- step=0.25f*(i>2?(i-2):0);
+ billboard->setDefaultDimensions(dimension*lens->scale_,dimension*lens->scale_);
i++;
}
}
@@ -158,12 +145,11 @@
std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin();
it++;
for(int i=0;it!=this->getAttachedObjects().end(); it++) {
- if(i==2)
- {
- this->colour_->a*=0.33f;
- }
+ ColourValue* cur=new ColourValue(0,0,0,0);
+ (*cur)+= *(this->colour_);
+ cur->a*=lensConfiguration_->at(i)->alpha_;
Billboard* billboard=static_cast<Billboard*>(*it);
- billboard->setColour(*(this->colour_));
+ billboard->setColour(*cur);
i++;
}
}
Modified: code/branches/shaders/src/orxonox/graphics/LensFlare.h
===================================================================
--- code/branches/shaders/src/orxonox/graphics/LensFlare.h 2012-12-10 14:17:37 UTC (rev 9499)
+++ code/branches/shaders/src/orxonox/graphics/LensFlare.h 2012-12-10 14:26:49 UTC (rev 9500)
@@ -45,7 +45,7 @@
#include "graphics/Billboard.h"
namespace orxonox
-{
+{
/**
@brief
This class adds a configurable LensFlare effect by adding multiple billboards for the several components of lens flare.
@@ -60,6 +60,26 @@
// obviously we shouldn't use too many of these effects anyways, since they use a lot of processing power, so not sure whether it's worth implementing a solution that works for multiple lens flares on screen
class _OrxonoxExport LensFlare : public StaticEntity, public Tickable
{
+ /**
+ @brief
+ This is a nested Class used to easily set properties of the different sublenses of a LensFlare effect
+ */
+ class Lens
+ {
+ public:
+ std::string* material_;//!< Which material should the Lens use, current choices include burst, bursthalo, halo1, halo2, halo3
+ float alpha_;//!< Which base alpha value should the Lens use
+ float scale_;//!< Which base scale should the Lens Flare have
+ 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
+ Lens(std::string* material, float alpha, float scale, float position)
+ {
+ this->material_=material;
+ this->alpha_=alpha;
+ this->scale_=scale;
+ this->position_=position;
+ }
+ };
+
public:
LensFlare(BaseObject* creator);
virtual ~LensFlare();
@@ -71,6 +91,26 @@
/**
@brief
+ This sets the base colour of the billboards
+ @param colour
+ Vector3 containing r,g,b values
+ */
+ inline void setColour(const ColourValue& colour)
+ {
+ this->colour_->r=colour.r;
+ this->colour_->g=colour.g;
+ this->colour_->b=colour.b;
+ }
+ /**
+ @brief
+ This returns the current base colour of the billboards
+ @return a Vector3 containing r,g,b values
+ */
+ inline const ColourValue& getColour() const
+ { return *(new ColourValue(this->colour_->r,this->colour_->g,this->colour_->b)); }
+
+ /**
+ @brief
This sets the resolution of the out-of-screen-fade-effect
the higher the resolution, the smoother the transition, but it will also have a greater impact on the performance
@@ -140,13 +180,13 @@
unsigned int getPointCount(float dimension) const;
+ std::vector<Lens*>* lensConfiguration_;//!< this stores the lensConfiguration
Billboard* occlusionBillboard_;//!< this is a transparent billboard used solely for the Hardware Occlusion Query
float cameraDistance_;//!< current distance of the lensflare center from the camera
float scale_;//!< this factor is used to scale the billboard to the desired size
bool fadeOnViewBorder_;//!< should the effect fade out on the border of the view?
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
float fadeExponent_;//!< this determines how fast the flare fades away as it gets obstructed
- //TODO: add XML port for colour manipulation
ColourValue* colour_;//!< this stores the base colour of the light
};
}
More information about the Orxonox-commit
mailing list