Rain trick

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Rain trick

Post by omaremad »

Making Rain with a particle system is pretty standard, rectangular particles can simulate rain streaks, however since irrlicht's particles have no axis align feature when you look up the streaks would give a incorrect appearance to the rain

Image

Here is some simple code for a rain system that handles this case:
Particle setup

Code: Select all

scene::IParticleSystemSceneNode* ps = 0;
    ps = smgr->addParticleSystemSceneNode(false);
    ps->setParent(smgr->getActiveCamera());
    scene::IParticleEmitter* em = ps->createBoxEmitter(
                                      core::aabbox3d<f32>(-10,-10,-10,20,20,20),
                                      core::vector3df(0.00f,0.00f,0.0f),
                                      700,1000,
                                      video::SColor(0,255,255,255), video::SColor(0,255,255,255),
                                      500,2000);
 
    ps->setEmitter(em);
    em->drop();
    scene::IParticleAffector* paf =
        ps->createGravityAffector(core::vector3df(0.00f,-0.25f, 0.0f), 1000);
 
    ps->addAffector(paf);
    paf->drop();
 
    ps->setMaterialFlag(video::EMF_LIGHTING, false);
    ps->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
    ps->setMaterialTexture(0, driver->getTexture("raindrop.png"));
main loop code

Code: Select all

core::vector3df camDir=smgr->getActiveCamera()->getTarget()-smgr->getActiveCamera()->getAbsolutePosition();
        camDir=camDir.normalize();
        f32 camPitch = camDir.dotProduct(core::vector3df(0,1,0));
        if(camPitch<0.0)
        camPitch = camDir.dotProduct(core::vector3df(0,-1,0));
        camPitch=(1.0f-camPitch)+0.01;
        ps->setParticleSize(core::dimension2d<f32>(0.05f, 1.5f*camPitch));
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
CuteAlien
Admin
Posts: 9634
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Rain trick

Post by CuteAlien »

Just noting that IParticleSystemSceneNode has a function setParticlesAreGlobal which switches beween local and global positions. It's been a while since I done something like that (snow), but I remember we used that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Rain trick

Post by devsh »

cmon, omaremad with your shader skill I was expecting hardware particles :) or at least HW billboards

but anyway, great work.. will be a lot of use for sparks in explosions
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Re: Rain trick

Post by xDan »

that's a great trick.

also a beautiful scene!
Kalango
Posts: 157
Joined: Thu Apr 26, 2007 12:46 am

Re: Rain trick

Post by Kalango »

You could try adding support to mesh particles and then build a custom scene node that alighns with the Y axis.
mesh particls are a nice feature for the engien, and the custom SN is easy business..
Post Reply