Author Topic: Rain with physics  (Read 5449 times)

I got around making rain with physics using Debris, don't get excited though, it lags to all forget rather quickly so I won't be releasing it and will only be handing it out to some curious individuals. It lags too much for multiplayer games and will barely allow for single player games given too many of the debris are out at any given time.

The setup

Brick underneath with events: onPlayerTouch -> namedBrick(A or B) -> spawnProjectile -> 0 0 -10 Weather Physics Rain 0 0 0 scale 1.0

Bricks overhead: 4 32x32 plates, All named A or B

There are other prop bricks present to see whether I got any hits on the sides (I did, although rarely, but still did). I only ever had 4 plates creating the debris-making projectiles at any given time. Any more then that lagged horrendously across the game no matter where you were. It was a fun little experiment to take my mind off of studies for a bit. You might also notice the splash explosions from the debris, then notice that they're above the ground by quite a distance. This is because the physics box radius of the debris is set to a minimum of 0.35, you can't go any smaller, so the debris are actually much bigger collision-wise then they appear. It's something I can't work around.


In conclusion, although the special effects are beautiful with this, the trade off is it lags way too much to be of any real use. So you won't be seeing physics weather for a good time unless some brain decides to rewrite a new debris-esq datablock that cuts down on everything needless in favor for a very simple and lag free debris. That's all a little over my head so count me out :P

Pics:









and Script for the curious and those looking for an easy reference to working physics-assisted debris:

Code: [Select]
datablock ParticleData(rainDebrisParticle)
{
dragCoefficient      = 1.2;
gravityCoefficient   = 0;
inheritedVelFactor   = 1.0;
constantAcceleration = 0.0;
lifetimeMS           = 100;
lifetimeVarianceMS   = 0;
textureName          = "base/data/particles/cloud";
spinSpeed = 10.0;
spinRandomMin = -500.0;
spinRandomMax = 500.0;
colors[0]     = "0.1 0.2 0.8 0.4";
colors[1]     = "0.1 0.1 0.6 0.2";
sizes[0]      = 0.08;
sizes[1]      = 0.05;

useInvAlpha = false;
};

datablock ParticleEmitterData(rainDebrisEmitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 0;
   velocityVariance = 0;
   ejectionOffset   = 0;
   thetaMin         = 0;
   thetaMax         = 50;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "rainDebrisParticle";
};

datablock ParticleData(rainDebriloveplosion1Particle)
{
dragCoefficient      = 0.0;
gravityCoefficient   = 0.2;
inheritedVelFactor   = 1.0;
constantAcceleration = 0.0;
lifetimeMS           = 100;
lifetimeVarianceMS   = 0;
textureName          = "base/data/particles/cloud";
spinSpeed = 10.0;
spinRandomMin = -500.0;
spinRandomMax = 500.0;
colors[0]     = "0.1 0.2 0.8 0.4";
colors[1]     = "0.1 0.1 0.6 0.0";
sizes[0]      = 0.15;
sizes[1]      = 0.15;

useInvAlpha = false;
};

datablock ParticleEmitterData(rainDebriloveplosion1Emitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 0;
   velocityVariance = 0;
   ejectionOffset   = 0;
   thetaMin         = 0;
   thetaMax         = 50;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "rainDebriloveplosion1Particle";
};

datablock ParticleData(rainDebriloveplosion2Particle)
{
dragCoefficient      = 0.0;
gravityCoefficient   = 0.2;
inheritedVelFactor   = 1.0;
constantAcceleration = 0.0;
lifetimeMS           = 100;
lifetimeVarianceMS   = 0;
textureName          = "base/data/particles/cloud";
spinSpeed = 10.0;
spinRandomMin = -500.0;
spinRandomMax = 500.0;
colors[0]     = "0.1 0.2 0.8 0.4";
colors[1]     = "0.1 0.1 0.6 0.2";
sizes[0]      = 0.10;
sizes[1]      = 0.05;

useInvAlpha = false;
};

datablock ParticleEmitterData(rainDebriloveplosion2Emitter)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 2;
   velocityVariance = 0;
   ejectionOffset   = 0;
   thetaMin         = 95;
   thetaMax         = 100;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "rainDebriloveplosion2Particle";
};

datablock ExplosionData(rainDebriloveplosion)
{
   explosionShape = "";
   //soundProfile = "";

   lifeTimeMS = 20;

   particleEmitter = rainDebriloveplosion1Emitter;
   particleDensity = 1;
   particleRadius = 0.0;

   emitter[0] = rainDebriloveplosion2Emitter;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = false;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "3.0 10.0 3.0";
   camShakeDuration = 0.5;
   camShakeRadius = 20.0;

   // Dynamic light
   lightStartRadius = 0;
   lightEndRadius = 0;
   lightStartColor = "0 0 0 0";
   lightEndColor = "0 0 0 0";

   damageRadius = 0;
   radiusDamage = 0;

   impulseRadius = 0;
   impulseForce = 0;
};

datablock DebrisData(rainMakerDebris)
{
   emitters = "rainDebrisEmitter";
   Explosion = "rainDebriloveplosion";

texture = "base/data/particles/cloud";

   elasticity = 0.0;
   friction = 0.2;
   numBounces = 1;
   bounceVariance = 0;
   explodeOnMaxBounce = true;
   staticOnMaxBounce = false;
   snapOnMaxBounce = false;
   minSpinSpeed = -500;
   maxSpinSpeed = 500;
   render2D = true;
   lifetime = 10.0;
   lifetimeVariance = 0.0;
   velocity = 35;
   velocityVariance = 5;
   fade = false;
   useRadiusMass = true;
   baseRadius = 0.01;
   gravModifier = 0.9;
   terminalVelocity = 80;
   ignoreWater = false;
};

datablock ExplosionData(rainMakerExplosion)
{
   explosionShape = "";
   //soundProfile = "";

   lifeTimeMS = 150;

   debris = rainMakerDebris;
   debrisNum = 100;                   //Yeah, 100 loving debris per explosion would lag anyone to death. It's likely actually less then that, I reckon around 30 is the default max.
   debrisNumVariance = 10;
   debrisPhiMin = 0;
   debrisPhiMax = 360;
   debrisThetaMin = 0;
   debrisThetaMax = 50;
   debrisVelocity = 20;
   debrisVelocityVariance = 15;

   //particleEmitter = positionTestEmitter;
   //particleDensity = 10;
   //particleRadius = 0.2;

   //emitter[0] = testEmitter;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = false;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "3.0 10.0 3.0";
   camShakeDuration = 0.5;
   camShakeRadius = 20.0;

   // Dynamic light
   lightStartRadius = 0;
   lightEndRadius = 0;
   lightStartColor = "0 0 0 0";
   lightEndColor = "0 0 0 0";

   damageRadius = 0;
   radiusDamage = 0;

   impulseRadius = 0;
   impulseForce = 0;
};

AddDamageType("TankShellDirect",   '<bitmap:add-ons/Projectile_GravityRocket/rocket> %1',    '%2 <bitmap:add-ons/Projectile_GravityRocket/rocket> %1',1,1);
AddDamageType("TankShellRadius",   '<bitmap:add-ons/Projectile_GravityRocket/rocketRadius> %1',    '%2 <bitmap:add-ons/Projectile_GravityRocket/rocketRadius> %1',1,0);
datablock ProjectileData(rainMakerProjectile)
{
   projectileShapeName = "base/data/shapes/empty.dts";
   directDamage        = 0;
   directDamageType = $DamageType::TankShellDirect;
   radiusDamageType = $DamageType::TankShellRadius;
   impactImpulse    = 0;
   verticalImpulse    = 0;
   explosion           = rainMakerExplosion;
   //particleEmitter     = none;

   brickExplosionRadius = 0;
   brickExplosionImpact = false;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 0;             
   brickExplosionMaxVolume = 0;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 0;  //max volume of bricks that we can destroy if they aren't connected to the ground (should always be >= brickExplosionMaxVolume)

   //sound = none;

   muzzleVelocity      = 20;
   velInheritFactor    = 1.0;

   armingDelay         = 100;
   lifetime            = 100;
   fadeDelay           = 100;
   bounceElasticity    = 0.99;
   bounceFriction      = 0.0;
   isBallistic         = true;
   gravityMod = 0.0;

   hasLight    = false;
   lightRadius = 5.0;
   lightColor  = "1 0.5 0.0";

   explodeOnDeath = 1;

   uiName = "Weather Physics Rain"; //There will likely be many more physics-assisted weather effects, so I'll name it this way to keep it in order
};

Interesting stuff there Mix, shame it lags like ass.

Shouldn't the rain particles be more of a pale/light blue?

Anyway, it looks great, although...
shame it lags like ass.
...this is quite true, unfortunately :(

This could be achieved with particles and raycasting, couldn't it?
Just saying. Also, those have started to fly in random directions there. And float/bounce. :\

Isn't this possible with projectiles?  It'd lag a bit, though.

Isn't this possible with projectiles?  It'd lag a bit, though.
Yeah.

I don't thinkit would lag as much.. as long as you didnt have 1000 emmiters coming out of them or something.

This could be achieved with particles and raycasting, couldn't it?
Just saying.

I have no idea.

Also, those have started to fly in random directions there. And float/bounce. :\

It looks better in action, like there's crazy wind and stuff blowing the rain all over the place. It could have been fine-tuned a bit more but when I saw the lag generated I kind of gave up.

Yeah.

I don't thinkit would lag as much.. as long as you didnt have 1000 emmiters coming out of them or something.

Well they had 1 emitter each. That would be the next test, making a mesh for the rain drops without emitter and seeing how that goes. I don't think it will make much of a difference honestly because I'm pretty sure by now it's the physics aspects of the debris that's causing the lag.

I have no idea.

It looks better in action, like there's crazy wind and stuff blowing the rain all over the place. It could have been fine-tuned a bit more but when I saw the lag generated I kind of gave up.

Well they had 1 emitter each. That would be the next test, making a mesh for the rain drops without emitter and seeing how that goes. I don't think it will make much of a difference honestly because I'm pretty sure by now it's the physics aspects of the debris that's causing the lag.

Try it with a simple ball model.
No emitters.

I think projectiles would be a better way to go. Though I really wouldn't know.

« Last Edit: June 02, 2009, 04:18:49 PM by Flying Ace »

Luckily there is a built in way to fake precipitation physics with the engine, using splash images for map precipitation. Autumn Pond (rainy) map uses them if anyone wants an example of how it works. It's just a 4 frame bitmap animation that happens when any raindrop hits an object. Definitely not real rain physics, but fakes it well enough.

Luckily there is a built in way to fake precipitation physics with the engine, using splash images for map precipitation. Autumn Pond (rainy) map uses them if anyone wants an example of how it works. It's just a 4 frame bitmap animation that happens when any raindrop hits an object. Definitely not real rain physics, but fakes it well enough.

I heard there was precipitation effects for maps and such, I recon it has all the features needed for low-lag precipitation like eye-sight rendering and low-distance rendering and stuff.

I had doubts it was part of this TGE version but now that you mention it I'll have to go look it up.

Makes me wish the TGE rain collided with bricks :(

what about rain with 1x1 bricks? :o

Makes me wish the TGE rain collided with bricks :(

Aye thought so. Until that's ironed out I don't think we'll be getting physics rain sadly