1 | #pragma once
|
---|
2 | #include <My3DGraphRes/ParticleSystem.h>
|
---|
3 | #include <My3DGraphRes/Texture.h>
|
---|
4 | #include <My3DGraphRes/Impostor.h>
|
---|
5 | #include <RttRes/RenderTexture.h>
|
---|
6 | #include <MyCgRes/CgProgram.h>
|
---|
7 | #include <My3DGraphRes/Scene.h>
|
---|
8 | #include <My3DGraphRes/ThirdPersonCamera.h>
|
---|
9 |
|
---|
10 | /**
|
---|
11 | @brief Implements a hierarchical particle system.
|
---|
12 |
|
---|
13 | A hierarchical particle system is a particle system made out of a smaller particle systems.
|
---|
14 | First an image of the smaller particle system should be rendered, than this image can be multiplied
|
---|
15 | and be used as sprite images to form the bigger system.
|
---|
16 |
|
---|
17 | To avoid incorrect depth culling caused by the simplifications made by considering a group of particles
|
---|
18 | as a single quad we have to take into acount some additional depth information too.
|
---|
19 | We also render the the closest and the furthest depth values of the smaller system in the view camera's space.
|
---|
20 | During display this depth information can be used to estimate the length of the light ray segment
|
---|
21 | travelled in the medium and alter the opacity of the particles respectively.
|
---|
22 |
|
---|
23 | This particle system implementation also deals with light scattering inside the medium.
|
---|
24 | It builds a layered light absorption texture which stores the amount of absorped light in
|
---|
25 | different depths from lightsource. With the use of the illumination texture we can approximate self shadowing of the medium.
|
---|
26 | This implementation uses four layers and stores it in the four channels of a texture.
|
---|
27 | This way no 3D textures are needed, and the light absorption (illumination) texture can be generated in a single render pass.
|
---|
28 |
|
---|
29 | During rendering a mie scattering model is used to compute the amount of scattered light.
|
---|
30 | To speed up calculations phase function values are read back from a 2D look-up texture (phase texture).
|
---|
31 | */
|
---|
32 | class AdvancedParticleSystem
|
---|
33 | {
|
---|
34 | public:
|
---|
35 | AdvancedParticleSystem(void);
|
---|
36 | ~AdvancedParticleSystem(void);
|
---|
37 |
|
---|
38 | private:
|
---|
39 | //!Impostor to display
|
---|
40 | Impostor m_DisplayImpostor;
|
---|
41 | //!Impostor for illumination calculation
|
---|
42 | Impostor m_IllumImpostor;
|
---|
43 |
|
---|
44 | //not used
|
---|
45 | RenderTexture m_DisplayTexture;
|
---|
46 | //!Illumination texture
|
---|
47 | RenderTexture m_IllumTexture;
|
---|
48 | //! Stores nearest and furthest distances of the particles from the camera and also the opacity
|
---|
49 | RenderTexture m_FrontDepthTexture;
|
---|
50 | //not used
|
---|
51 | RenderTexture m_BackDepthTexture;
|
---|
52 | //! Stores nearest distances of the scene objects from the camera
|
---|
53 | RenderTexture m_ObjectsTexture;
|
---|
54 | //! A motion blurred version of the illumination texture to avoid abrupt changes
|
---|
55 | RenderTexture m_ScatteredIlumTexture;
|
---|
56 |
|
---|
57 | //cg programs
|
---|
58 | CgProgram m_IllumProgram;
|
---|
59 | CgProgram m_FrontDepthProgram;
|
---|
60 | CgProgram m_DensityOnlyProgram;
|
---|
61 | CgProgram m_DisplayProgram;
|
---|
62 | CgProgram m_Psys_Depth_Multiple_Forward_Program;
|
---|
63 | CgProgram m_TempProg;CgProgram m_TempProg2;
|
---|
64 | CgProgram m_ObjDepthProg;
|
---|
65 | CgProgram m_ScatterIllumProgram;
|
---|
66 | CgProgram m_Psys_Multiple_Forward_Program;
|
---|
67 | CgProgram m_Psys_Single_Phase_Program;
|
---|
68 | CgProgram m_Psys_Depth_Single_Phase_Program;
|
---|
69 | CgProgram m_Psys_Depth_Default_Program;
|
---|
70 | CgProgram m_Psys_Default_Program;
|
---|
71 |
|
---|
72 | //Camera m_LightCamera;
|
---|
73 | ThirdPersonCamera m_LightCamera;
|
---|
74 |
|
---|
75 | float* m_SceneTransformMatrix;
|
---|
76 |
|
---|
77 | public:
|
---|
78 | bool m_HasSceneTransformMatrix;
|
---|
79 |
|
---|
80 | Scene* theScene;
|
---|
81 | bool object_shadows;
|
---|
82 | bool depthcalc;
|
---|
83 | int m_PSys_RenderMode;
|
---|
84 | //! albedo of the particles
|
---|
85 | float albedo;
|
---|
86 | //! scattering symmetry of the scattering (used in phase function calculation)
|
---|
87 | float symmetry;
|
---|
88 | //only helper attribute
|
---|
89 | float symmetry2;
|
---|
90 | //! transparency of the particles
|
---|
91 | float transparency;
|
---|
92 | unsigned int PhaseTexID;
|
---|
93 | unsigned int AngleTexID;
|
---|
94 | Vector m_LightColor;
|
---|
95 | Vector m_LightPosition;
|
---|
96 |
|
---|
97 | //! particle system made ot of a smaller system
|
---|
98 | ParticleSystem m_ParticleSystem;
|
---|
99 | //! smaller particle system
|
---|
100 | ParticleSystem m_LittleParticleSystem;
|
---|
101 |
|
---|
102 | //Billboard display texture
|
---|
103 | Texture m_BillboardTexture;
|
---|
104 | Texture m_BbBackDepthTexture;
|
---|
105 | Texture m_BbFrontDepthTexture;
|
---|
106 |
|
---|
107 | //! renders the particle system from the given camera using the given light position
|
---|
108 | void Display(Camera* cam,Vector LightPos);
|
---|
109 | //! refreshes the particle system
|
---|
110 | void Refresh(Camera* cam,
|
---|
111 | Vector LightPos,
|
---|
112 | unsigned int Dt,
|
---|
113 | unsigned int TimefromSecond);
|
---|
114 | //! generates front and back depth textures od the smaller particle system
|
---|
115 | void RefreshDepths(Camera* cam);
|
---|
116 | //not used
|
---|
117 | void RefreshDepthswithSpheres(Camera* cam);
|
---|
118 | //! initialize textures and gpu programs
|
---|
119 | void Initialize();
|
---|
120 | //! initialize the two particle systems
|
---|
121 | void InitSystems();
|
---|
122 | //! generates scene depth texture
|
---|
123 | void RenderObjectDepths(Camera* cam);
|
---|
124 |
|
---|
125 | //for debug
|
---|
126 | void displayillum(Camera* cam);
|
---|
127 | void displayLittle(Camera* cam);
|
---|
128 | void displaytexture(int tex);
|
---|
129 |
|
---|
130 | /**
|
---|
131 | @brief refreshes the illumination texture
|
---|
132 |
|
---|
133 | The illumination texture is a four layered texture, each layer stored in the separate color channels.
|
---|
134 | */
|
---|
135 | void RefreshIllumTextures(Vector LightPos);
|
---|
136 |
|
---|
137 | void DecreaseAlbedo(){albedo-=0.01;if(albedo<0)albedo=0;}
|
---|
138 | void IncreaseAlbedo(){albedo+=0.01;if(albedo>1)albedo=1;}
|
---|
139 | void DecreaseTransparency(){transparency-=0.05;if(transparency<0)transparency=0;}
|
---|
140 | void IncreaseTransparency(){transparency+=0.05;if(transparency>1)transparency=1;}
|
---|
141 | void DecreaseSymmetry(){symmetry-=0.01;if(symmetry<-1)symmetry=-1;}
|
---|
142 | void IncreaseSymmetry(){symmetry+=0.01;if(symmetry>1)symmetry=1;}
|
---|
143 |
|
---|
144 | void setSceneTransformMatrix(float* matr){m_HasSceneTransformMatrix=true;m_SceneTransformMatrix=matr;}
|
---|
145 | };
|
---|
146 |
|
---|