1 | #include "advancedparticlesystem.h"
|
---|
2 | #include <glh/glh_glut.h>
|
---|
3 | using namespace glh;
|
---|
4 | #include <random.h>
|
---|
5 |
|
---|
6 |
|
---|
7 | AdvancedParticleSystem::AdvancedParticleSystem(void)
|
---|
8 | {
|
---|
9 | object_shadows=false;
|
---|
10 | depthcalc=true;
|
---|
11 | m_PSys_RenderMode=3;
|
---|
12 | albedo=0.91;
|
---|
13 | symmetry=0.02;
|
---|
14 | transparency=0.55;
|
---|
15 | m_HasSceneTransformMatrix=false;
|
---|
16 | }
|
---|
17 |
|
---|
18 | AdvancedParticleSystem::~AdvancedParticleSystem(void)
|
---|
19 | {
|
---|
20 | }
|
---|
21 | void AdvancedParticleSystem::displayLittle(Camera* cam)
|
---|
22 | {
|
---|
23 | m_LittleParticleSystem.RefreshCamera(cam);
|
---|
24 | m_LittleParticleSystem.RefreshBuffer();
|
---|
25 |
|
---|
26 | cam->SetViewandProjection();
|
---|
27 | glDisable(GL_TEXTURE_2D);
|
---|
28 | glDisable(GL_TEXTURE_RECTANGLE_NV);
|
---|
29 | glBindTexture(GL_TEXTURE_2D,m_BillboardTexture.getTextureHandler());
|
---|
30 | glEnable(GL_BLEND);
|
---|
31 | glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
---|
32 | m_LittleParticleSystem.RenderAsBillboard();
|
---|
33 | glDisable(GL_BLEND);
|
---|
34 | //glDisable(GL_TEXTURE_2D);
|
---|
35 | }
|
---|
36 |
|
---|
37 | void AdvancedParticleSystem::Display(Camera* cam,Vector LightPos)
|
---|
38 | {
|
---|
39 | //refresh Particle System
|
---|
40 | m_ParticleSystem.RefreshCamera(cam);
|
---|
41 | m_ParticleSystem.RefrBRadius_Dist();
|
---|
42 | m_ParticleSystem.SortParticles(true);
|
---|
43 | m_ParticleSystem.RefreshBuffer();
|
---|
44 |
|
---|
45 | CgProgram* ActualProgram;
|
---|
46 | if(depthcalc)
|
---|
47 | {
|
---|
48 | if(m_PSys_RenderMode==0)ActualProgram=&m_Psys_Depth_Default_Program;
|
---|
49 | if(m_PSys_RenderMode==1)ActualProgram=&m_Psys_Depth_Single_Phase_Program;
|
---|
50 | if(m_PSys_RenderMode>1)ActualProgram=&m_Psys_Depth_Multiple_Forward_Program;
|
---|
51 | }
|
---|
52 | else
|
---|
53 | {
|
---|
54 | if(m_PSys_RenderMode==0)ActualProgram=&m_Psys_Default_Program;
|
---|
55 | if(m_PSys_RenderMode==1)ActualProgram=&m_Psys_Single_Phase_Program;
|
---|
56 | if(m_PSys_RenderMode>1)ActualProgram=&m_Psys_Multiple_Forward_Program;
|
---|
57 | }
|
---|
58 |
|
---|
59 | ActualProgram->Enable();
|
---|
60 | CGparameter param;
|
---|
61 |
|
---|
62 | if(depthcalc)
|
---|
63 | {
|
---|
64 | param=cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"ObjTexture");
|
---|
65 | cgGLSetTextureParameter(param,m_ObjectsTexture.getColorTextureID());
|
---|
66 | cgGLEnableTextureParameter(param);
|
---|
67 | }
|
---|
68 |
|
---|
69 | param=cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"FrontTexture");
|
---|
70 | cgGLSetTextureParameter(param,m_FrontDepthTexture.getColorTextureID());
|
---|
71 | cgGLEnableTextureParameter(param);
|
---|
72 |
|
---|
73 | if(m_PSys_RenderMode>0)
|
---|
74 | {
|
---|
75 | param=cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"PhaseTexture");
|
---|
76 | cgGLSetTextureParameter(param,PhaseTexID);
|
---|
77 | cgGLEnableTextureParameter(param);
|
---|
78 |
|
---|
79 | param = cgGetNamedParameter(*ActualProgram->m_FragmentProgram, "Albedo");
|
---|
80 | cgGLSetParameter1d(param,albedo);
|
---|
81 | param = cgGetNamedParameter(*ActualProgram->m_FragmentProgram, "Symmetry");
|
---|
82 | cgGLSetParameter1d(param,symmetry2);
|
---|
83 |
|
---|
84 | param = cgGetNamedParameter(*ActualProgram->m_VertexProgram, "LightPosition");
|
---|
85 | cgGLSetParameter3fv(param,LightPos.GetArrayf());
|
---|
86 |
|
---|
87 | param = cgGetNamedParameter(*ActualProgram->m_VertexProgram, "EyePosition");
|
---|
88 | cgGLSetParameter3fv(param,cam->getPosition().GetArrayf());
|
---|
89 |
|
---|
90 | if(m_PSys_RenderMode>1)
|
---|
91 | {
|
---|
92 | m_LightCamera.SetViewandProjectionOrto();
|
---|
93 | cgGLSetStateMatrixParameter(cgGetNamedParameter(*ActualProgram->m_VertexProgram, "LightModelViewProj"),
|
---|
94 | CG_GL_MODELVIEW_PROJECTION_MATRIX,
|
---|
95 | CG_GL_MATRIX_IDENTITY);
|
---|
96 |
|
---|
97 | param=cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"Illum1");
|
---|
98 |
|
---|
99 | if(m_PSys_RenderMode==3)
|
---|
100 | cgGLSetTextureParameter(param,m_ScatteredIlumTexture.getColorTextureID());
|
---|
101 | else
|
---|
102 | cgGLSetTextureParameter(param,m_IllumTexture.getColorTextureID());
|
---|
103 |
|
---|
104 | cgGLEnableTextureParameter(param);
|
---|
105 | }
|
---|
106 |
|
---|
107 | }
|
---|
108 |
|
---|
109 | param = cgGetNamedParameter(*ActualProgram->m_FragmentProgram, "Transparency");
|
---|
110 | cgGLSetParameter1d(param,transparency);
|
---|
111 |
|
---|
112 | param = cgGetNamedParameter(*ActualProgram->m_FragmentProgram, "LightColor");
|
---|
113 | cgGLSetParameter3fv(param,m_LightColor.GetArray());
|
---|
114 |
|
---|
115 |
|
---|
116 | if(depthcalc)
|
---|
117 | {
|
---|
118 | glDisable(GL_DEPTH_TEST);
|
---|
119 | }
|
---|
120 | else
|
---|
121 | {
|
---|
122 | glDepthMask(GL_FALSE);
|
---|
123 | }
|
---|
124 | glEnable(GL_BLEND);
|
---|
125 | glBlendFunc(GL_ONE,GL_SRC_ALPHA);
|
---|
126 | //glBlendEquationSeparateEXT(GL_FUNC_ADD,GL_FUNC_ADD);
|
---|
127 |
|
---|
128 |
|
---|
129 | cam->SetViewandProjectionNew();
|
---|
130 |
|
---|
131 | glMatrixMode(GL_MODELVIEW);
|
---|
132 | glPushMatrix();
|
---|
133 | glTranslatef(m_ParticleSystem.getPosition().x,
|
---|
134 | m_ParticleSystem.getPosition().y,
|
---|
135 | m_ParticleSystem.getPosition().z);
|
---|
136 |
|
---|
137 | /*
|
---|
138 | glDisable(GL_BLEND);
|
---|
139 | glDisable(GL_LIGHTING);
|
---|
140 | glDisable(GL_TEXTURE_RECTANGLE_NV);
|
---|
141 | glDisable(GL_DEPTH_TEST);
|
---|
142 | */
|
---|
143 | m_ParticleSystem.RenderAsBillboard();
|
---|
144 |
|
---|
145 | glPopMatrix();
|
---|
146 |
|
---|
147 | glDisable(GL_BLEND);
|
---|
148 | glDepthMask(GL_TRUE);
|
---|
149 | glEnable(GL_DEPTH_TEST);
|
---|
150 | /*
|
---|
151 | if(depthcalc)cgGLDisableTextureParameter(cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"ObjTexture"));
|
---|
152 | cgGLDisableTextureParameter(cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"FrontTexture"));
|
---|
153 | if(m_PSys_RenderMode>1)cgGLDisableTextureParameter(cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"Illum1"));
|
---|
154 | */
|
---|
155 | m_Psys_Depth_Multiple_Forward_Program.Disable();
|
---|
156 | }
|
---|
157 |
|
---|
158 | void AdvancedParticleSystem::displayillum(Camera* cam)
|
---|
159 | {
|
---|
160 | m_TempProg.Enable();
|
---|
161 |
|
---|
162 | m_DisplayImpostor.setObjSphereRadius(m_ParticleSystem.getBoundingRadius());
|
---|
163 | m_DisplayImpostor.setObjPosition(Vector(0,0,0));
|
---|
164 | m_DisplayImpostor.setViewCamera(cam);
|
---|
165 | m_DisplayImpostor.updateCamera(true);
|
---|
166 |
|
---|
167 | CGparameter param=cgGetNamedParameter(*m_TempProg.m_FragmentProgram,"Texture");
|
---|
168 | cgGLSetTextureParameter(param,m_IllumTexture.getColorTextureID());
|
---|
169 | cgGLEnableTextureParameter(param);
|
---|
170 |
|
---|
171 | glDisable(GL_BLEND);
|
---|
172 | //glEnable(GL_BLEND);
|
---|
173 | //glBlendFunc(GL_SRC_ALPHA,GL_NONE);
|
---|
174 |
|
---|
175 |
|
---|
176 | cam->SetViewandProjection();
|
---|
177 |
|
---|
178 | glPushMatrix();
|
---|
179 | glTranslatef(-1.1*m_ParticleSystem.getBoundingRadius(),0,0);
|
---|
180 | m_DisplayImpostor.Display();
|
---|
181 | glPopMatrix();
|
---|
182 |
|
---|
183 | glPushMatrix();
|
---|
184 | param=cgGetNamedParameter(*m_TempProg.m_FragmentProgram,"Texture");
|
---|
185 | cgGLSetTextureParameter(param,m_ScatteredIlumTexture.getColorTextureID());
|
---|
186 | cgGLEnableTextureParameter(param);
|
---|
187 |
|
---|
188 | glTranslatef(1.1*m_ParticleSystem.getBoundingRadius(),0,0);
|
---|
189 | m_DisplayImpostor.Display();
|
---|
190 | glPopMatrix();
|
---|
191 |
|
---|
192 | m_TempProg.Disable();
|
---|
193 |
|
---|
194 |
|
---|
195 | }
|
---|
196 |
|
---|
197 | void AdvancedParticleSystem::displaytexture(int tex)
|
---|
198 | {
|
---|
199 | unsigned int texID;
|
---|
200 | int u=256,v=256;
|
---|
201 | if(tex==0)//composite texture
|
---|
202 | {
|
---|
203 | texID=m_FrontDepthTexture.getColorTextureID();
|
---|
204 | }
|
---|
205 | if(tex==1)//illumination texture
|
---|
206 | {
|
---|
207 | texID=m_IllumTexture.getColorTextureID();
|
---|
208 | }
|
---|
209 | if(tex==2)//illumination texture
|
---|
210 | {
|
---|
211 | texID=m_ScatteredIlumTexture.getColorTextureID();
|
---|
212 | }
|
---|
213 |
|
---|
214 | m_TempProg.SetFragmentTexParam("Texture",texID);
|
---|
215 | m_TempProg.Enable();
|
---|
216 | m_DisplayImpostor.DisplayScreenQuad(u,v);
|
---|
217 | m_TempProg.DisableFragmentTexParam("Texture");
|
---|
218 | m_TempProg.Disable();
|
---|
219 | }
|
---|
220 |
|
---|
221 | void AdvancedParticleSystem::Refresh(Camera* cam,Vector LightPos,unsigned int Dt,unsigned int TimefromSecond)
|
---|
222 | {
|
---|
223 | static int r=0;
|
---|
224 | symmetry2=(symmetry+1)/2;
|
---|
225 |
|
---|
226 | //refresh Particle System
|
---|
227 | m_LittleParticleSystem.RefreshCamera(cam);
|
---|
228 |
|
---|
229 | m_LittleParticleSystem.RefreshParticles(Dt,TimefromSecond);
|
---|
230 |
|
---|
231 | m_LittleParticleSystem.RefrBRadius_Dist();
|
---|
232 | m_LittleParticleSystem.RefreshBuffer();
|
---|
233 |
|
---|
234 | m_ParticleSystem.m_LittleSystemRadius=m_LittleParticleSystem.getBoundingRadius();
|
---|
235 |
|
---|
236 | m_ParticleSystem.RefreshParticles(Dt,TimefromSecond);
|
---|
237 |
|
---|
238 | RefreshDepths(cam);
|
---|
239 |
|
---|
240 | if(m_PSys_RenderMode>1)RefreshIllumTextures(LightPos);
|
---|
241 | else m_ParticleSystem.RefrBRadius_Dist();
|
---|
242 |
|
---|
243 | //render objects inside bounding sphere
|
---|
244 | if(depthcalc)RenderObjectDepths(cam);
|
---|
245 | }
|
---|
246 |
|
---|
247 |
|
---|
248 | void AdvancedParticleSystem::RefreshDepths(Camera* cam)
|
---|
249 | {
|
---|
250 | Camera viewcam;
|
---|
251 | viewcam.setNearClipDistance(0);
|
---|
252 | viewcam.setFarClipDistance(2*m_LittleParticleSystem.getBoundingRadius());
|
---|
253 | viewcam.setCorners(-m_LittleParticleSystem.getBoundingRadius(),
|
---|
254 | m_LittleParticleSystem.getBoundingRadius(),
|
---|
255 | m_LittleParticleSystem.getBoundingRadius(),
|
---|
256 | -m_LittleParticleSystem.getBoundingRadius());
|
---|
257 | viewcam.SetUpVector(cam->getUpVector());
|
---|
258 | viewcam.setRightVector(cam->getRightVector());
|
---|
259 | viewcam.setLookAt(m_LittleParticleSystem.getPosition());
|
---|
260 | Vector dir=(cam->getPosition()-cam->getLookAt()).Normalize();
|
---|
261 | viewcam.SetPosition(viewcam.getLookAt()+dir*m_LittleParticleSystem.getBoundingRadius());
|
---|
262 |
|
---|
263 | CGparameter param;
|
---|
264 |
|
---|
265 | //FRONT DEPTH
|
---|
266 |
|
---|
267 | CgProgram* ActualProgram;
|
---|
268 |
|
---|
269 | if(depthcalc)
|
---|
270 | {
|
---|
271 | ActualProgram=&m_FrontDepthProgram;
|
---|
272 | ActualProgram->SetFragmentTexParam("frontTexture",m_BbFrontDepthTexture.getTextureHandler());
|
---|
273 | }
|
---|
274 | else ActualProgram=&m_DensityOnlyProgram;
|
---|
275 |
|
---|
276 | ActualProgram->SetFragmentTexParam("Texture",m_BillboardTexture.getTextureHandler());
|
---|
277 |
|
---|
278 | // Enable Depth Render Target
|
---|
279 | m_FrontDepthTexture.EnablewithColorRelease();
|
---|
280 |
|
---|
281 | //enable cg programs
|
---|
282 | ActualProgram->Enable();
|
---|
283 |
|
---|
284 |
|
---|
285 | //Render System
|
---|
286 | glClearColor(1,1,0,0);
|
---|
287 | glDisable(GL_DEPTH_TEST);
|
---|
288 |
|
---|
289 | //m_DisplayImpostor.ApplyCameraTransformOrto();
|
---|
290 | viewcam.SetViewandProjectionOrto();
|
---|
291 |
|
---|
292 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
293 | glEnable(GL_BLEND);
|
---|
294 |
|
---|
295 | glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);
|
---|
296 | glBlendEquationSeparateEXT(GL_MIN_EXT,GL_FUNC_ADD);
|
---|
297 |
|
---|
298 | m_LittleParticleSystem.RenderAsBillboard();
|
---|
299 |
|
---|
300 | //disable cg programs
|
---|
301 |
|
---|
302 | if(depthcalc)ActualProgram->DisableFragmentTexParam("frontTexture");
|
---|
303 | ActualProgram->Disable();
|
---|
304 | //ilutGLScreenie();
|
---|
305 | m_FrontDepthTexture.DisablewithColorBind();
|
---|
306 | }
|
---|
307 |
|
---|
308 |
|
---|
309 | void AdvancedParticleSystem::Initialize()
|
---|
310 | {
|
---|
311 | InitSystems();
|
---|
312 |
|
---|
313 | m_FrontDepthTexture.Initialize(256,256,"rgba textureRECT",true,true);
|
---|
314 | m_FrontDepthProgram.SetProgramFiles("PSystemFrontDepthPrograms.cg","PSystemFrontDepthPrograms.cg");
|
---|
315 | m_FrontDepthProgram.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
316 | m_FrontDepthProgram.InitPrograms();
|
---|
317 |
|
---|
318 | m_DensityOnlyProgram.SetProgramFiles("PSystemDensityOnlyPrograms.cg","PSystemDensityOnlyPrograms.cg");
|
---|
319 | m_DensityOnlyProgram.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
320 | m_DensityOnlyProgram.InitPrograms();
|
---|
321 |
|
---|
322 |
|
---|
323 | //m_IllumTexture.Initialize(256,256,"rgba depth aux=4 textureRECT=aux");
|
---|
324 | m_IllumTexture.Initialize(256,256,"rgba textureRECT",true,true);
|
---|
325 | m_IllumProgram.SetProgramFiles("IllumPrograms.cg","IllumPrograms.cg");
|
---|
326 | m_IllumProgram.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
327 | m_IllumProgram.InitPrograms();
|
---|
328 |
|
---|
329 | m_TempProg.SetProgramFiles("SimplePrograms.cg","SimplePrograms.cg");
|
---|
330 | m_TempProg.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
331 | m_TempProg.InitPrograms();
|
---|
332 | /*
|
---|
333 | m_TempProg2.SetProgramFiles("SimplePrograms2.cg","SimplePrograms2.cg");
|
---|
334 | m_TempProg2.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
335 | m_TempProg2.InitPrograms();
|
---|
336 | */
|
---|
337 | m_ObjectsTexture.Initialize(512,512,"r float=16 depth textureRECT");
|
---|
338 | m_ObjDepthProg.SetProgramFiles("ObjDepthPrograms.cg","ObjDepthPrograms.cg");
|
---|
339 | m_ObjDepthProg.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
340 | m_ObjDepthProg.InitPrograms();
|
---|
341 |
|
---|
342 | m_ScatteredIlumTexture.Initialize(256,256,"rgba textureRECT",true,true);
|
---|
343 | m_ScatterIllumProgram.SetProgramFiles("ScatterIllumPrograms.cg","ScatterIllumPrograms.cg");
|
---|
344 | m_ScatterIllumProgram.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
345 | m_ScatterIllumProgram.InitPrograms();
|
---|
346 | m_ScatteredIlumTexture.EnablewithColorRelease();
|
---|
347 | glClearColor(0,0,0,0);
|
---|
348 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
349 | m_ScatteredIlumTexture.DisablewithColorBind();
|
---|
350 |
|
---|
351 |
|
---|
352 | //Particle system rendering programs
|
---|
353 |
|
---|
354 | m_Psys_Multiple_Forward_Program.SetProgramFiles("Psystem_Multiply_Forward.cg","Psystem_Multiply_Forward.cg");
|
---|
355 | m_Psys_Multiple_Forward_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
356 | m_Psys_Multiple_Forward_Program.InitPrograms();
|
---|
357 |
|
---|
358 | m_Psys_Depth_Multiple_Forward_Program.SetProgramFiles("Psystem_Multiply_Forward_Depth.cg","Psystem_Multiply_Forward_Depth.cg");
|
---|
359 | m_Psys_Depth_Multiple_Forward_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
360 | m_Psys_Depth_Multiple_Forward_Program.InitPrograms();
|
---|
361 |
|
---|
362 | m_Psys_Single_Phase_Program.SetProgramFiles("Psystem_Single_Phase.cg","Psystem_Single_Phase.cg");
|
---|
363 | m_Psys_Single_Phase_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
364 | m_Psys_Single_Phase_Program.InitPrograms();
|
---|
365 |
|
---|
366 | m_Psys_Depth_Single_Phase_Program.SetProgramFiles("Psystem_Single_Phase_Depth.cg","Psystem_Single_Phase_Depth.cg");
|
---|
367 | m_Psys_Depth_Single_Phase_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
368 | m_Psys_Depth_Single_Phase_Program.InitPrograms();
|
---|
369 |
|
---|
370 |
|
---|
371 | m_Psys_Default_Program.SetProgramFiles("Psystem_Default.cg","Psystem_Default.cg");
|
---|
372 | m_Psys_Default_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
373 | m_Psys_Default_Program.InitPrograms();
|
---|
374 |
|
---|
375 | m_Psys_Depth_Default_Program.SetProgramFiles("Psystem_Default_Depth.cg","Psystem_Default_Depth.cg");
|
---|
376 | m_Psys_Depth_Default_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
377 | m_Psys_Depth_Default_Program.InitPrograms();
|
---|
378 |
|
---|
379 | }
|
---|
380 |
|
---|
381 | void AdvancedParticleSystem::InitSystems()
|
---|
382 | {
|
---|
383 | //BiggerSystem
|
---|
384 | m_ParticleSystem.m_Emitter.setPositionsFile("cloud.txt");
|
---|
385 | m_ParticleSystem.m_Emitter.setOffset(0.01);
|
---|
386 |
|
---|
387 | m_ParticleSystem.setQuota(100);
|
---|
388 | m_ParticleSystem.m_Emitter.setSize(4.2);
|
---|
389 | m_ParticleSystem.m_Emitter.setSizevariation(0.5);
|
---|
390 | m_ParticleSystem.m_Emitter.setDirection(Vector(0,0,1));
|
---|
391 | m_ParticleSystem.m_Emitter.setVelocity(0);
|
---|
392 | m_ParticleSystem.m_Emitter.setRadius(1.0);
|
---|
393 | m_ParticleSystem.m_Emitter.setTimeToLive(0);
|
---|
394 | m_ParticleSystem.m_Emitter.setEmissionRate(0);
|
---|
395 |
|
---|
396 | //SmallerSystem
|
---|
397 |
|
---|
398 | m_LittleParticleSystem.setQuota(400);
|
---|
399 | m_LittleParticleSystem.m_Emitter.setTimeToLive(6000);
|
---|
400 | m_LittleParticleSystem.m_Emitter.setTimeToLiveVariation(2000);
|
---|
401 | m_LittleParticleSystem.m_Emitter.setSize(0.2);
|
---|
402 | m_LittleParticleSystem.m_Emitter.setRadius(0.92);
|
---|
403 | m_LittleParticleSystem.m_Emitter.setSizevariation(0.8);
|
---|
404 | m_LittleParticleSystem.m_Emitter.setVelocity(0.07);
|
---|
405 | m_LittleParticleSystem.m_Emitter.setVelocityVariation(0.5);
|
---|
406 | m_LittleParticleSystem.m_Emitter.setEmissionRate(150);
|
---|
407 |
|
---|
408 |
|
---|
409 | }
|
---|
410 |
|
---|
411 | void AdvancedParticleSystem::RefreshIllumTextures(Vector LightPos)
|
---|
412 | {
|
---|
413 | // refresh IllumImpostor
|
---|
414 | //refresh camera
|
---|
415 | m_ParticleSystem.RefrBRadius_Dist(true);
|
---|
416 | m_LightCamera.setLookAt(m_ParticleSystem.getPosition());
|
---|
417 | Vector tolight=LightPos-m_ParticleSystem.getPosition();
|
---|
418 | tolight.Normalize();
|
---|
419 | tolight=tolight*m_ParticleSystem.getBoundingRadius();
|
---|
420 | Vector newpos=m_ParticleSystem.getPosition()+tolight;
|
---|
421 | m_LightCamera.SetPosition(newpos);
|
---|
422 |
|
---|
423 | m_LightCamera.setNearClipDistance(0);
|
---|
424 | m_LightCamera.setFarClipDistance(2*m_ParticleSystem.getBoundingRadius());
|
---|
425 | m_LightCamera.setCorners(-m_ParticleSystem.getBoundingRadius(),
|
---|
426 | m_ParticleSystem.getBoundingRadius(),
|
---|
427 | m_ParticleSystem.getBoundingRadius(),
|
---|
428 | -m_ParticleSystem.getBoundingRadius());
|
---|
429 |
|
---|
430 |
|
---|
431 | //cg parameters
|
---|
432 | m_IllumProgram.SetFragmentTexParam("Texture",m_BillboardTexture.getTextureHandler());
|
---|
433 |
|
---|
434 | m_IllumProgram.SetFragmentTexParam("PhaseTexture",PhaseTexID);
|
---|
435 | m_IllumProgram.SetFragmentParam1f("Albedo",albedo);
|
---|
436 | m_IllumProgram.SetVertexParam1f("transparency",transparency);
|
---|
437 | m_IllumProgram.SetFragmentParam1f("Symmetry",symmetry2);
|
---|
438 |
|
---|
439 | //Enable illumrendertarget
|
---|
440 | m_IllumTexture.EnablewithColorRelease();
|
---|
441 |
|
---|
442 | glClearColor(1,1,1,1);
|
---|
443 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
444 |
|
---|
445 | m_IllumProgram.Enable();
|
---|
446 |
|
---|
447 | CGparameter param;
|
---|
448 |
|
---|
449 | //sort: front to back
|
---|
450 | m_ParticleSystem.SortFromCamera(&m_LightCamera, false,false,true);
|
---|
451 |
|
---|
452 | //render
|
---|
453 | glEnable(GL_BLEND);
|
---|
454 | glBlendFunc(GL_NONE,GL_SRC_COLOR);
|
---|
455 |
|
---|
456 | //apply transform
|
---|
457 | m_LightCamera.SetViewandProjectionOrto();
|
---|
458 |
|
---|
459 | m_ParticleSystem.RenderAsBillboard();
|
---|
460 |
|
---|
461 | m_IllumProgram.DisableFragmentTexParam("Texture");
|
---|
462 | m_IllumProgram.DisableFragmentTexParam("PhaseTexture");
|
---|
463 | m_IllumProgram.Disable();
|
---|
464 |
|
---|
465 | //Disable illurendertargets
|
---|
466 | m_IllumTexture.DisablewithColorBind();
|
---|
467 |
|
---|
468 |
|
---|
469 | //here should come the filtering pass but it is not working properly so:
|
---|
470 | //just blend the new image with the previous result to avoid abrupt changes (some kind of motion blur)
|
---|
471 | //so m_ScatteredIlumTexture is not the filtered but the motion blurred illumination texture
|
---|
472 | m_TempProg.SetFragmentTexParam("Texture",m_IllumTexture.getColorTextureID());
|
---|
473 | m_ScatteredIlumTexture.EnablewithColorRelease();
|
---|
474 |
|
---|
475 | glBlendColorEXT(1,1,1,0.08);
|
---|
476 | glEnable(GL_BLEND);
|
---|
477 | glBlendFunc(GL_CONSTANT_ALPHA_EXT,GL_ONE_MINUS_CONSTANT_ALPHA_EXT);
|
---|
478 |
|
---|
479 | m_TempProg.Enable();
|
---|
480 | m_DisplayImpostor.DisplayScreenQuad(256,256);
|
---|
481 | m_TempProg.Disable();
|
---|
482 |
|
---|
483 | m_ScatteredIlumTexture.DisablewithColorBind();
|
---|
484 |
|
---|
485 | m_TempProg.DisableFragmentTexParam("Texture");
|
---|
486 | }
|
---|
487 |
|
---|
488 |
|
---|
489 |
|
---|
490 | void AdvancedParticleSystem::RenderObjectDepths(Camera* cam)
|
---|
491 | {
|
---|
492 | m_ObjectsTexture.ReleaseColorBuffer();
|
---|
493 | m_ObjectsTexture.EnableTarget();
|
---|
494 |
|
---|
495 | m_ObjDepthProg.Enable();
|
---|
496 |
|
---|
497 | glClearColor(-100.0f,-100.0f,-100.0f,0.0f);
|
---|
498 | //glClearColor(0.0f,0.0f,1.0f,0.0f);
|
---|
499 | glEnable(GL_DEPTH_TEST);
|
---|
500 | glClearDepth(1.0);
|
---|
501 | glDepthFunc(GL_LEQUAL);
|
---|
502 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
503 |
|
---|
504 | cam->SetViewandProjectionNew();
|
---|
505 | glDisable(GL_LIGHTING);
|
---|
506 | glDisable(GL_BLEND);
|
---|
507 |
|
---|
508 | //render scene
|
---|
509 | if(m_HasSceneTransformMatrix)
|
---|
510 | {
|
---|
511 | glMatrixMode(GL_MODELVIEW);
|
---|
512 | glPushMatrix();
|
---|
513 | glLoadMatrixf(m_SceneTransformMatrix);
|
---|
514 | this->theScene->Display(true);
|
---|
515 | glPopMatrix();
|
---|
516 | }
|
---|
517 | else
|
---|
518 | {
|
---|
519 | this->theScene->Display(true);
|
---|
520 | }
|
---|
521 |
|
---|
522 | m_ObjDepthProg.Disable();
|
---|
523 |
|
---|
524 | m_ObjectsTexture.DisableTarget();
|
---|
525 | m_ObjectsTexture.BindColorBuffer();
|
---|
526 |
|
---|
527 | } |
---|