- daylight effects for unit particles ( best use with mode "black" )

- meadow has good looking mist in night now
- startdelay for particles
This commit is contained in:
Titus Tscharntke 2012-01-07 20:24:54 +00:00
parent 1f60d2606a
commit e05984d527
10 changed files with 78 additions and 37 deletions

View File

@ -43,7 +43,8 @@ ParticleSystemType::ParticleSystemType() {
teamcolorNoEnergy=false;
teamcolorEnergy=false;
alternations=false;
alternations=0;
particleSystemStartDelay=0;
texture=NULL;
model=NULL;
minmaxEnabled=false;
@ -101,6 +102,7 @@ void ParticleSystemType::copyAll(const ParticleSystemType &src) {
this->teamcolorNoEnergy = src.teamcolorNoEnergy;
this->teamcolorEnergy = src.teamcolorEnergy;
this->alternations = src.alternations;
this->particleSystemStartDelay= src.particleSystemStartDelay;
for(Children::iterator it = children.begin(); it != children.end(); ++it) {
UnitParticleSystemType *child = *it;
@ -239,6 +241,11 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
const XmlNode *alternatingNode= particleSystemNode->getChild("alternations");
alternations= alternatingNode->getAttribute("value")->getIntValue();
}
//particleSystemStartDelay
if(particleSystemNode->hasChild("particleSystemStartDelay")){
const XmlNode *node= particleSystemNode->getChild("particleSystemStartDelay");
particleSystemStartDelay= node->getAttribute("value")->getIntValue();
}
//mode
if(particleSystemNode->hasChild("mode")) {
const XmlNode *modeNode= particleSystemNode->getChild("mode");
@ -293,6 +300,7 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){
ats->setTeamcolorNoEnergy(teamcolorNoEnergy);
ats->setTeamcolorEnergy(teamcolorEnergy);
ats->setAlternations(alternations);
ats->setParticleSystemStartDelay(particleSystemStartDelay);
ats->setBlendMode(ParticleSystem::strToBlendMode(mode));
}

View File

@ -69,6 +69,7 @@ protected:
bool teamcolorNoEnergy;
bool teamcolorEnergy;
int alternations;
int particleSystemStartDelay;
typedef std::list<UnitParticleSystemType*> Children;
Children children;

View File

@ -839,7 +839,7 @@ void Renderer::setupLighting() {
assertGl();
//sun/moon light
Vec3f lightColor= computeLightColor(time);
Vec3f lightColor= timeFlow->computeLightColor();
Vec3f fogColor= world->getTileset()->getFogColor();
Vec4f lightPos= timeFlow->isDay()? computeSunPos(time): computeMoonPos(time);
nearestLightPos= lightPos;
@ -4183,7 +4183,7 @@ void Renderer::renderObjects(const int renderFps) {
const Texture2D *fowTex = world->getMinimap()->getFowTexture();
const Pixmap2D *fowTexPixmap = fowTex->getPixmapConst();
Vec3f baseFogColor = world->getTileset()->getFogColor() * computeLightColor(world->getTimeFlow()->getTime());
Vec3f baseFogColor = world->getTileset()->getFogColor() * world->getTimeFlow()->computeLightColor();
bool modelRenderStarted = false;
@ -6461,35 +6461,6 @@ Vec4f Renderer::computeMoonPos(float time) {
#endif
}
Vec3f Renderer::computeLightColor(float time) {
const Tileset *tileset= game->getWorld()->getTileset();
Vec3f color;
const float transition= 2;
const float dayStart= TimeFlow::dawn;
const float dayEnd= TimeFlow::dusk-transition;
const float nightStart= TimeFlow::dusk;
const float nightEnd= TimeFlow::dawn-transition;
if(time>dayStart && time<dayEnd) {
color= tileset->getSunLightColor();
}
else if(time>nightStart || time<nightEnd) {
color= tileset->getMoonLightColor();
}
else if(time>=dayEnd && time<=nightStart) {
color= tileset->getSunLightColor().lerp((time-dayEnd)/transition, tileset->getMoonLightColor());
}
else if(time>=nightEnd && time<=dayStart) {
color= tileset->getMoonLightColor().lerp((time-nightEnd)/transition, tileset->getSunLightColor());
}
else {
assert(false);
color= tileset->getSunLightColor();
}
return color;
}
Vec4f Renderer::computeWaterColor(float waterLevel, float cellHeight) {
const float waterFactor= 1.5f;
return Vec4f(1.f, 1.f, 1.f, clamp((waterLevel-cellHeight)*waterFactor, 0.f, 1.f));

View File

@ -581,7 +581,6 @@ private:
float computeMoonAngle(float time);
Vec4f computeSunPos(float time);
Vec4f computeMoonPos(float time);
Vec3f computeLightColor(float time);
Vec4f computeWaterColor(float waterLevel, float cellHeight);
void checkExtension(const string &extension, const string &msg);

View File

@ -40,8 +40,9 @@ UnitParticleSystemType::UnitParticleSystemType() : ParticleSystemType() {
relativeDirection = false;
fixed = false;
staticParticleCount = 0;
isVisibleAtNight = false;
isVisibleAtDay = false;
isVisibleAtNight = true;
isVisibleAtDay = true;
isDaylightAffected = false;
radiusBasedStartenergy = false;
delay = 0;
lifetime = 0;
@ -146,6 +147,15 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin
isVisibleAtDay=true;
}
//isDaylightAffected
if(particleSystemNode->hasChild("isDaylightAffected")){
const XmlNode *node= particleSystemNode->getChild("isDaylightAffected");
isDaylightAffected= node->getAttribute("value")->getBoolValue();
}
else {
isDaylightAffected=false;
}
//radiusBasedStartenergy
if(particleSystemNode->hasChild("radiusBasedStartenergy")){
const XmlNode *isVisibleAtDayNode= particleSystemNode->getChild("radiusBasedStartenergy");
@ -217,9 +227,11 @@ const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){
ups->setTeamcolorNoEnergy(teamcolorNoEnergy);
ups->setTeamcolorEnergy(teamcolorEnergy);
ups->setAlternations(alternations);
ups->setParticleSystemStartDelay(particleSystemStartDelay);
ups->setIsVisibleAtNight(isVisibleAtNight);
ups->setIsVisibleAtDay(isVisibleAtDay);
ups->setIsDaylightAffected(isDaylightAffected);
ups->setStaticParticleCount(staticParticleCount);
ups->setRadius(radius);
ups->setMinRadius(minRadius);

View File

@ -58,6 +58,7 @@ protected:
int staticParticleCount;
bool isVisibleAtNight;
bool isVisibleAtDay;
bool isDaylightAffected;
bool radiusBasedStartenergy;
int delay;
int lifetime;

View File

@ -55,6 +55,7 @@ void TimeFlow::update() {
soundRenderer.stopAmbient(ambientSounds->getNight());
UnitParticleSystem::isNight=false;
}
UnitParticleSystem::lightColor=computeLightColor();
if((lastTime<dawn && time>=dawn) || firstTime){
@ -94,4 +95,35 @@ void TimeFlow::update() {
// return (this->time>=time) && (this->time<time+timeInc);
//}
Vec3f TimeFlow::computeLightColor() const {
Vec3f color;
float time=getTime();
const float transition= 2;
const float dayStart= TimeFlow::dawn;
const float dayEnd= TimeFlow::dusk-transition;
const float nightStart= TimeFlow::dusk;
const float nightEnd= TimeFlow::dawn-transition;
if(time>dayStart && time<dayEnd) {
color= tileset->getSunLightColor();
}
else if(time>nightStart || time<nightEnd) {
color= tileset->getMoonLightColor();
}
else if(time>=dayEnd && time<=nightStart) {
color= tileset->getSunLightColor().lerp((time-dayEnd)/transition, tileset->getMoonLightColor());
}
else if(time>=nightEnd && time<=dayStart) {
color= tileset->getMoonLightColor().lerp((time-nightEnd)/transition, tileset->getSunLightColor());
}
else {
assert(false);
color= tileset->getSunLightColor();
}
return color;
}
}}//end namespace

View File

@ -57,6 +57,7 @@ public:
bool isTotalNight() const {return time<dawn+1.f || time>dusk-1.f;}
float getTimeInc() const {return timeInc;}
Vec3f computeLightColor() const;
void update();
private:
//bool isAproxTime(float time) const;

View File

@ -132,6 +132,7 @@ protected:
bool teamcolorNoEnergy;
bool teamcolorEnergy;
int alternations;
int particleSystemStartDelay;
ParticleObserver *particleObserver;
public:
@ -173,6 +174,7 @@ public:
void setTeamcolorNoEnergy(bool teamcolorNoEnergy) {this->teamcolorNoEnergy= teamcolorNoEnergy;}
void setTeamcolorEnergy(bool teamcolorEnergy) {this->teamcolorEnergy= teamcolorEnergy;}
void setAlternations(int alternations) {this->alternations= alternations;}
void setParticleSystemStartDelay(int delay) {this->particleSystemStartDelay= delay;}
virtual void setFactionColor(Vec3f factionColor);
static BlendMode strToBlendMode(const string &str);
@ -269,6 +271,7 @@ protected:
class UnitParticleSystem: public GameParticleSystem{
public:
static bool isNight;
static Vec3f lightColor;
private:
float radius;
float minRadius;
@ -296,6 +299,7 @@ public:
float rotation;
bool isVisibleAtNight;
bool isVisibleAtDay;
bool isDaylightAffected;
bool radiusBasedStartenergy;
int staticParticleCount;
int delay;
@ -339,6 +343,7 @@ public:
void setPrimitive(Primitive primitive) {this->primitive= primitive;}
void setStaticParticleCount(int staticParticleCount){this->staticParticleCount= staticParticleCount;}
void setIsVisibleAtNight(bool value) {this->isVisibleAtNight= value;}
void setIsDaylightAffected(bool value) {this->isDaylightAffected= value;}
void setIsVisibleAtDay(bool value) {this->isVisibleAtDay= value;}
void setRadiusBasedStartenergy(bool value) {this->radiusBasedStartenergy= value;}
void setShape(Shape shape) {this->shape= shape;}

View File

@ -74,6 +74,7 @@ ParticleSystem::ParticleSystem(int particleCount) {
teamcolorNoEnergy= false;
teamcolorEnergy= false;
alternations= 0;
particleSystemStartDelay= 0;
}
ParticleSystem::~ParticleSystem(){
@ -97,8 +98,10 @@ void ParticleSystem::update(){
if(aliveParticleCount > (int) particles.size()){
throw runtime_error("aliveParticleCount >= particles.size()");
}
if(state != sPause){
if(particleSystemStartDelay>0){
particleSystemStartDelay--;
}
else if(state != sPause){
for(int i= 0; i < aliveParticleCount; ++i){
updateParticle(&particles[i]);
@ -527,6 +530,7 @@ void GameParticleSystem::setTween(float relative,float absolute) {
// UnitParticleSystem
// ===========================================================================
bool UnitParticleSystem::isNight= false;
Vec3f UnitParticleSystem::lightColor=Vec3f(1.0f,1.0f,1.0f);
UnitParticleSystem::UnitParticleSystem(int particleCount):
GameParticleSystem(particleCount),
@ -549,6 +553,7 @@ UnitParticleSystem::UnitParticleSystem(int particleCount):
isVisibleAtNight= true;
isVisibleAtDay= true;
isDaylightAffected= false;
cRotation= Vec3f(1.0f, 1.0f, 1.0f);
fixedAddition= Vec3f(0.0f, 0.0f, 0.0f);
@ -736,6 +741,12 @@ void UnitParticleSystem::updateParticle(Particle *p){
}
p->speed+= p->accel;
p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio);
if(isDaylightAffected)
{
p->color.x=p->color.x*lightColor.x;
p->color.y=p->color.y*lightColor.y;
p->color.z=p->color.z*lightColor.z;
}
p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio);
if(state == ParticleSystem::sFade || staticParticleCount < 1){
p->energy--;