/////////////////////////////////////////////////////////////////////////// // // Realistic rain real-time simulation program // // Pierre Rousseau // /////////////////////////////////////////////////////////////////////////// // // Particle systems handling // /////////////////////////////////////////////////////////////////////////// #ifndef __RAIN_CLOSE_DROPS_PARTICLES__ #define __RAIN_CLOSE_DROPS_PARTICLES__ #include "CommonRain.h" #include "RainTextureFrameListener.h" #include "RainManualHardwareBillboardMeshLoader.h" #include "RainLight.h" /** Class : CloseDropsParticles * defines a rain system, with cameras and shaders */ class CloseDropsParticles { private : SceneManager *mSceneMgr; RainLightManager *mRainLightMgr; SceneNode *mParticlesNode, *mParentCam, *mParentSyst; // wide angle camera used to render the drops Ogre::Camera *mCamera; RenderTexture *dropsTexture; MaterialPtr dropsTexturesMaterial; // simulation textures, containing particle positions unsigned int mActiveParticlesCount; RenderTexture *particlePosTexture, *particlePosTextureBackup; BillboardSet *bbSet1, *bbSet2; // billboardsets for ping-pong position textures public : /** public variable : width of the particles */ float mRainWidth; /** public variable : wheight of the particles (for streaks) */ float mRainStreaksHeight; /** public functions */ /** constructor, taking in parameters : * - the SceneManager used in the scene * - the SceneNode to which the particle system should be attached * - the SceneNode to which the auxiliary camera (which we use to texture our drops) should be attached */ CloseDropsParticles(SceneManager *sceneMgr, SceneNode *parentSyst, SceneNode *parentCam); /** Destructor */ ~CloseDropsParticles(); /** function wich creates the lights (streetlights and bindings to light the drops) */ void createLights(); /** function to retrieve a pointer to the rainLightManager associate with this CloseDropsParticles */ RainLightManager *getLightManagerPtr(); /** function which updates the lights, if they are animated */ void updateLights(); /** function which creates the position texture and it's backup. should be called when initiaiting the rendering of the first frame (through frame listener) */ void definePosTextureAndBackup(); /** control function, to check what the textures look like */ void makeControlOverlay(); /** function to update one of the two position RTT's ; if set to true, the primary texture will be updated */ void updatePositionTexture(bool primary); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateFragmentProgramParameter(const String &name, float value); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateFragmentProgramParameter(const String &name, Ogre::Vector3 value); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateFragmentProgramParameter(const String &name, Ogre::Vector4 value); /** function to update the different shader parameters used to update the particles positions, or render them */ /** function to update the different shader parameters used to update the particles positions, or render them */ void updateShaderParameters(float tslf, float rainBbSide, float streaksHeight, int nbLights, Vector3 viewPos, Vector3 viewDir, Vector3 fallVect, Vector3 boxMin, Vector3 boxMax, Vector3 lastMove, Vector3 randomMove, int useShader); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateTimeSinceLastFrame(float tslf); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateRainBilboardSideLength(float rainBbSide); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateStreaksHeight(float streaksHeight); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateLightCount(float nbLights); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateViewPos(Vector3 viewPos); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateViewDir(Vector3 viewDir); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateFallVector(Vector3 fallVect); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateBoxMin(Vector3 boxMin); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateBoxMax(Vector3 boxMax); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateLastMove(Vector3 lastMove); /** function to update the different shader parameters used to update the particles positions, or render them */ void updateRandomMove(Vector3 randomMove); /** functions which hide the particle position billboards. billboards must be hidden when rendering the scene, and visible when updating the position texture */ void hidePositionBillboards() { bbSet1->setVisible(false); bbSet2->setVisible(false); } /** functions which show the particle position billboards. billboards must be hidden when rendering the scene, and visible when updating the position texture */ void showPositionBillboards() { bbSet1->setVisible(true); bbSet2->setVisible(true); } private : /** this function defines the material used to texture the particles */ void createMaterial(String name); /** creation of the auxiliary camera used to texture our particles */ Camera* createDropsCamera(); /** definition of the shader parameters used for the particles material */ void GPUmaterial(); /** function used to initialize the position texture */ void initializeBillboardsPositionTexture(); /** function which creates a simple quad mesh to use on our hardware billboards */ MeshPtr createHardwareBillboardMesh(String materialName, String meshName=BILLBOARD_MESH_NAME); /** function to update a billboard mesh created as a manual resource, used to give it the appropriate texture coordinates */ void modifyClonedHardwareBillboardMesh(MeshPtr &msh, int partNumber); /** function which initializes the vertex buffers and textures */ void initParticles(); /** function which defines the position renderTexture */ void createBillboardsPositionRenderTexture(RenderTexture *PSPosTexture, Vector3 nodePos, BillboardSet *bbSet); /** function which defines the material used to update the particles position texture */ void createBillboardsPositionTextureMaterial(String inputTextureName); }; #endif // __RAIN_CLOSE_DROPS_PARTICLES__