source: GTP/trunk/App/Demos/Illum/Rain/include/RainCloseDropsParticles.h @ 2221

Revision 2221, 7.3 KB checked in by plemenos, 18 years ago (diff)
  • Property svn:executable set to *
Line 
1
2///////////////////////////////////////////////////////////////////////////
3//
4//              Realistic rain real-time simulation program
5//
6//              Pierre Rousseau
7//
8///////////////////////////////////////////////////////////////////////////
9//
10//              Particle systems handling
11//
12///////////////////////////////////////////////////////////////////////////
13
14#ifndef __RAIN_CLOSE_DROPS_PARTICLES__
15#define __RAIN_CLOSE_DROPS_PARTICLES__
16
17
18#include "CommonRain.h"
19#include "RainTextureFrameListener.h"
20#include "RainManualHardwareBillboardMeshLoader.h"
21#include "RainLight.h"
22
23
24
25
26
27
28/** Class : CloseDropsParticles
29  * defines a rain system, with cameras and shaders
30  */
31class CloseDropsParticles
32{
33private :
34    SceneManager *mSceneMgr;
35    RainLightManager *mRainLightMgr;
36    SceneNode *mParticlesNode, *mParentCam, *mParentSyst;
37
38    // wide angle camera used to render the drops
39    Ogre::Camera *mCamera;
40    RenderTexture *dropsTexture;
41    MaterialPtr dropsTexturesMaterial;
42
43    // simulation textures, containing particle positions
44    unsigned int mActiveParticlesCount;
45    RenderTexture *particlePosTexture, *particlePosTextureBackup;
46
47    BillboardSet *bbSet1, *bbSet2; // billboardsets for ping-pong position textures
48
49
50public :
51    /** public variable : width of the particles */
52    float mRainWidth;
53    /** public variable : wheight of the particles (for streaks) */
54    float mRainStreaksHeight;
55
56
57    /** public functions */
58
59    /** constructor, taking in parameters :
60      *   - the SceneManager used in the scene
61      *   - the SceneNode to which the particle system should be attached
62      *   - the SceneNode to which the auxiliary camera (which we use to texture our drops) should be attached
63      */
64    CloseDropsParticles(SceneManager *sceneMgr, SceneNode *parentSyst, SceneNode *parentCam);
65
66    /** Destructor */
67    ~CloseDropsParticles();
68
69    /** function wich creates the lights (streetlights and bindings to light the drops) */
70    void createLights();
71
72    /** function to retrieve a pointer to the rainLightManager associate with this CloseDropsParticles */
73    RainLightManager *getLightManagerPtr();
74
75    /** function which updates the lights, if they are animated */
76    void updateLights();
77
78    /** function which creates the position texture and it's backup. should be called when initiaiting the rendering of the first frame (through frame listener) */
79    void definePosTextureAndBackup();
80
81    /** control function, to check what the textures look like */
82    void makeControlOverlay();
83
84    /** function to update one of the two position RTT's ; if set to true, the primary texture will be updated */
85    void updatePositionTexture(bool primary);
86
87    /** function to update the different shader parameters used to update the particles positions, or render them */
88    void updateFragmentProgramParameter(const String &name, float value);
89    /** function to update the different shader parameters used to update the particles positions, or render them */
90    void updateFragmentProgramParameter(const String &name, Ogre::Vector3 value);
91    /** function to update the different shader parameters used to update the particles positions, or render them */
92    void updateFragmentProgramParameter(const String &name, Ogre::Vector4 value);
93    /** function to update the different shader parameters used to update the particles positions, or render them */
94
95    /** function to update the different shader parameters used to update the particles positions, or render them */
96    void updateShaderParameters(float tslf, float rainBbSide, float streaksHeight, int nbLights,
97                                Vector3 viewPos, Vector3 viewDir, Vector3 fallVect, Vector3 boxMin, Vector3 boxMax, Vector3 lastMove, Vector3 randomMove, int useShader);
98
99
100    /** function to update the different shader parameters used to update the particles positions, or render them */
101    void updateTimeSinceLastFrame(float tslf);
102    /** function to update the different shader parameters used to update the particles positions, or render them */
103    void updateRainBilboardSideLength(float rainBbSide);
104    /** function to update the different shader parameters used to update the particles positions, or render them */
105    void updateStreaksHeight(float streaksHeight);
106    /** function to update the different shader parameters used to update the particles positions, or render them */
107    void updateLightCount(float nbLights);
108    /** function to update the different shader parameters used to update the particles positions, or render them */
109    void updateViewPos(Vector3 viewPos);
110    /** function to update the different shader parameters used to update the particles positions, or render them */
111    void updateViewDir(Vector3 viewDir);
112    /** function to update the different shader parameters used to update the particles positions, or render them */
113    void updateFallVector(Vector3 fallVect);
114    /** function to update the different shader parameters used to update the particles positions, or render them */
115    void updateBoxMin(Vector3 boxMin);
116    /** function to update the different shader parameters used to update the particles positions, or render them */
117    void updateBoxMax(Vector3 boxMax);
118    /** function to update the different shader parameters used to update the particles positions, or render them */
119    void updateLastMove(Vector3 lastMove);
120    /** function to update the different shader parameters used to update the particles positions, or render them */
121    void updateRandomMove(Vector3 randomMove);
122
123    /** functions which hide the particle position billboards.
124        billboards must be hidden when rendering the scene, and visible when updating the position texture */
125    void hidePositionBillboards()
126    {
127        bbSet1->setVisible(false);
128        bbSet2->setVisible(false);
129    }
130    /** functions which show the particle position billboards.
131        billboards must be hidden when rendering the scene, and visible when updating the position texture */
132    void showPositionBillboards()
133    {
134        bbSet1->setVisible(true);
135        bbSet2->setVisible(true);
136    }
137
138private :
139
140    /** this function defines the material used to texture the particles */
141    void createMaterial(String name);
142
143    /** creation of the auxiliary camera used to texture our particles */
144    Camera* createDropsCamera();
145
146    /** definition of the shader parameters used for the particles material */
147    void GPUmaterial();
148   
149    /** function used to initialize the position texture */
150    void initializeBillboardsPositionTexture();
151   
152    /** function which creates a simple quad mesh to use on our hardware billboards */
153    MeshPtr createHardwareBillboardMesh(String materialName, String meshName=BILLBOARD_MESH_NAME);
154
155    /** function to update a billboard mesh created as a manual resource, used to give it the appropriate texture coordinates */
156    void modifyClonedHardwareBillboardMesh(MeshPtr &msh, int partNumber);
157
158    /** function which initializes the vertex buffers and textures */
159    void initParticles();
160   
161    /** function which defines the position renderTexture */
162    void createBillboardsPositionRenderTexture(RenderTexture *PSPosTexture, Vector3 nodePos, BillboardSet *bbSet);
163
164    /** function which defines the material used to update the particles position texture */
165    void createBillboardsPositionTextureMaterial(String inputTextureName);
166};
167
168
169
170
171#endif // __RAIN_CLOSE_DROPS_PARTICLES__
Note: See TracBrowser for help on using the repository browser.