[845] | 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.8;
|
---|
| 13 | symmetry=0;
|
---|
| 14 | transparency=0.5;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | AdvancedParticleSystem::~AdvancedParticleSystem(void)
|
---|
| 18 | {
|
---|
| 19 | }
|
---|
| 20 | void AdvancedParticleSystem::displayLittle(Camera* cam)
|
---|
| 21 | {
|
---|
| 22 | m_LittleParticleSystem.RefreshCamera(cam);
|
---|
| 23 | m_LittleParticleSystem.RefreshBuffer();
|
---|
| 24 |
|
---|
| 25 | cam->SetViewandProjection();
|
---|
| 26 | glDisable(GL_TEXTURE_2D);
|
---|
| 27 | glDisable(GL_TEXTURE_RECTANGLE_NV);
|
---|
| 28 | glBindTexture(GL_TEXTURE_2D,m_BillboardTexture.getTextureHandler());
|
---|
| 29 | glEnable(GL_BLEND);
|
---|
| 30 | glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
---|
| 31 | m_LittleParticleSystem.RenderAsBillboard();
|
---|
| 32 | glDisable(GL_BLEND);
|
---|
| 33 | //glDisable(GL_TEXTURE_2D);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | void AdvancedParticleSystem::Display(Camera* cam,Vector LightPos)
|
---|
| 37 | {
|
---|
| 38 | //refresh Particle System
|
---|
| 39 | m_ParticleSystem.RefreshCamera(cam);
|
---|
| 40 | m_ParticleSystem.RefrBRadius_Dist();
|
---|
| 41 | m_ParticleSystem.SortParticles(true);
|
---|
| 42 | m_ParticleSystem.RefreshBuffer();
|
---|
| 43 |
|
---|
| 44 | CgProgram* ActualProgram;
|
---|
| 45 | if(depthcalc)
|
---|
| 46 | {
|
---|
| 47 | if(m_PSys_RenderMode==0)ActualProgram=&m_Psys_Depth_Default_Program;
|
---|
| 48 | if(m_PSys_RenderMode==1)ActualProgram=&m_Psys_Depth_Single_Phase_Program;
|
---|
| 49 | if(m_PSys_RenderMode>1)ActualProgram=&m_Psys_Depth_Multiple_Forward_Program;
|
---|
| 50 | }
|
---|
| 51 | else
|
---|
| 52 | {
|
---|
| 53 | if(m_PSys_RenderMode==0)ActualProgram=&m_Psys_Default_Program;
|
---|
| 54 | if(m_PSys_RenderMode==1)ActualProgram=&m_Psys_Single_Phase_Program;
|
---|
| 55 | if(m_PSys_RenderMode>1)ActualProgram=&m_Psys_Multiple_Forward_Program;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | ActualProgram->Enable();
|
---|
| 59 | CGparameter param;
|
---|
| 60 |
|
---|
| 61 | if(depthcalc)
|
---|
| 62 | {
|
---|
| 63 | param=cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"ObjTexture");
|
---|
| 64 | cgGLSetTextureParameter(param,m_ObjectsTexture.getColorTextureID());
|
---|
| 65 | cgGLEnableTextureParameter(param);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | param=cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"FrontTexture");
|
---|
| 69 | cgGLSetTextureParameter(param,m_FrontDepthTexture.getColorTextureID());
|
---|
| 70 | cgGLEnableTextureParameter(param);
|
---|
| 71 |
|
---|
| 72 | if(m_PSys_RenderMode>0)
|
---|
| 73 | {
|
---|
| 74 | param=cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"PhaseTexture");
|
---|
| 75 | cgGLSetTextureParameter(param,PhaseTexID);
|
---|
| 76 | cgGLEnableTextureParameter(param);
|
---|
| 77 |
|
---|
| 78 | param = cgGetNamedParameter(*ActualProgram->m_FragmentProgram, "Albedo");
|
---|
| 79 | cgGLSetParameter1d(param,albedo);
|
---|
| 80 | param = cgGetNamedParameter(*ActualProgram->m_FragmentProgram, "Symmetry");
|
---|
| 81 | cgGLSetParameter1d(param,symmetry2);
|
---|
| 82 |
|
---|
| 83 | param = cgGetNamedParameter(*ActualProgram->m_VertexProgram, "LightPosition");
|
---|
| 84 | cgGLSetParameter3fv(param,LightPos.GetArrayf());
|
---|
| 85 |
|
---|
| 86 | param = cgGetNamedParameter(*ActualProgram->m_VertexProgram, "EyePosition");
|
---|
| 87 | cgGLSetParameter3fv(param,cam->getPosition().GetArrayf());
|
---|
| 88 |
|
---|
| 89 | if(m_PSys_RenderMode>1)
|
---|
| 90 | {
|
---|
| 91 | m_LightCamera.SetViewandProjectionOrto();
|
---|
| 92 | cgGLSetStateMatrixParameter(cgGetNamedParameter(*ActualProgram->m_VertexProgram, "LightModelViewProj"),
|
---|
| 93 | CG_GL_MODELVIEW_PROJECTION_MATRIX,
|
---|
| 94 | CG_GL_MATRIX_IDENTITY);
|
---|
| 95 |
|
---|
| 96 | param=cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"Illum1");
|
---|
| 97 |
|
---|
| 98 | if(m_PSys_RenderMode==3)
|
---|
| 99 | cgGLSetTextureParameter(param,m_ScatteredIlumTexture.getColorTextureID());
|
---|
| 100 | else
|
---|
| 101 | cgGLSetTextureParameter(param,m_IllumTexture.getColorTextureID());
|
---|
| 102 |
|
---|
| 103 | cgGLEnableTextureParameter(param);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | param = cgGetNamedParameter(*ActualProgram->m_FragmentProgram, "Transparency");
|
---|
| 109 | cgGLSetParameter1d(param,transparency);
|
---|
| 110 |
|
---|
| 111 | param = cgGetNamedParameter(*ActualProgram->m_FragmentProgram, "LightColor");
|
---|
| 112 | cgGLSetParameter3dv(param,m_LightColor.GetArray());
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | if(depthcalc)
|
---|
| 116 | {
|
---|
| 117 | glDisable(GL_DEPTH_TEST);
|
---|
| 118 | }
|
---|
| 119 | else
|
---|
| 120 | {
|
---|
| 121 | glDepthMask(GL_FALSE);
|
---|
| 122 | }
|
---|
| 123 | glEnable(GL_BLEND);
|
---|
| 124 | glBlendFunc(GL_ONE,GL_SRC_ALPHA);
|
---|
| 125 | //glBlendEquationSeparateEXT(GL_FUNC_ADD,GL_FUNC_ADD);
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | cam->SetViewandProjection();
|
---|
| 129 |
|
---|
| 130 | glMatrixMode(GL_MODELVIEW);
|
---|
| 131 | glPushMatrix();
|
---|
| 132 | glTranslatef(m_ParticleSystem.getPosition().x,
|
---|
| 133 | m_ParticleSystem.getPosition().y,
|
---|
| 134 | m_ParticleSystem.getPosition().z);
|
---|
| 135 |
|
---|
| 136 | /*
|
---|
| 137 | glDisable(GL_BLEND);
|
---|
| 138 | glDisable(GL_LIGHTING);
|
---|
| 139 | glDisable(GL_TEXTURE_RECTANGLE_NV);
|
---|
| 140 | glDisable(GL_DEPTH_TEST);
|
---|
| 141 | */
|
---|
| 142 | m_ParticleSystem.RenderAsBillboard();
|
---|
| 143 |
|
---|
| 144 | glPopMatrix();
|
---|
| 145 |
|
---|
| 146 | glDisable(GL_BLEND);
|
---|
| 147 | glDepthMask(GL_TRUE);
|
---|
| 148 | glEnable(GL_DEPTH_TEST);
|
---|
| 149 | /*
|
---|
| 150 | if(depthcalc)cgGLDisableTextureParameter(cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"ObjTexture"));
|
---|
| 151 | cgGLDisableTextureParameter(cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"FrontTexture"));
|
---|
| 152 | if(m_PSys_RenderMode>1)cgGLDisableTextureParameter(cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"Illum1"));
|
---|
| 153 | */
|
---|
| 154 | m_Psys_Depth_Multiple_Forward_Program.Disable();
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | void AdvancedParticleSystem::displayillum(Camera* cam)
|
---|
| 158 | {
|
---|
| 159 | m_TempProg.Enable();
|
---|
| 160 |
|
---|
| 161 | m_DisplayImpostor.setObjSphereRadius(m_ParticleSystem.getBoundingRadius());
|
---|
| 162 | m_DisplayImpostor.setObjPosition(Vector(0,0,0));
|
---|
| 163 | m_DisplayImpostor.setViewCamera(cam);
|
---|
| 164 | m_DisplayImpostor.updateCamera(true);
|
---|
| 165 |
|
---|
| 166 | CGparameter param=cgGetNamedParameter(*m_TempProg.m_FragmentProgram,"Texture");
|
---|
| 167 | cgGLSetTextureParameter(param,m_IllumTexture.getColorTextureID());
|
---|
| 168 | cgGLEnableTextureParameter(param);
|
---|
| 169 |
|
---|
| 170 | glDisable(GL_BLEND);
|
---|
| 171 | //glEnable(GL_BLEND);
|
---|
| 172 | //glBlendFunc(GL_SRC_ALPHA,GL_NONE);
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | cam->SetViewandProjection();
|
---|
| 176 |
|
---|
| 177 | glPushMatrix();
|
---|
| 178 | glTranslatef(-1.1*m_ParticleSystem.getBoundingRadius(),0,0);
|
---|
| 179 | m_DisplayImpostor.Display();
|
---|
| 180 | glPopMatrix();
|
---|
| 181 |
|
---|
| 182 | glPushMatrix();
|
---|
| 183 | param=cgGetNamedParameter(*m_TempProg.m_FragmentProgram,"Texture");
|
---|
| 184 | cgGLSetTextureParameter(param,m_ScatteredIlumTexture.getColorTextureID());
|
---|
| 185 | cgGLEnableTextureParameter(param);
|
---|
| 186 |
|
---|
| 187 | glTranslatef(1.1*m_ParticleSystem.getBoundingRadius(),0,0);
|
---|
| 188 | m_DisplayImpostor.Display();
|
---|
| 189 | glPopMatrix();
|
---|
| 190 |
|
---|
| 191 | m_TempProg.Disable();
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | void AdvancedParticleSystem::Refresh(Camera* cam,Vector LightPos,unsigned int Dt,unsigned int TimefromSecond)
|
---|
| 197 | {
|
---|
| 198 | symmetry2=(symmetry+1)/2;
|
---|
| 199 |
|
---|
| 200 | //refresh Particle System
|
---|
| 201 | m_LittleParticleSystem.RefreshCamera(cam);
|
---|
| 202 | m_LittleParticleSystem.RefreshParticles(Dt,TimefromSecond);
|
---|
| 203 | m_LittleParticleSystem.RefrBRadius_Dist();
|
---|
| 204 | m_LittleParticleSystem.RefreshBuffer();
|
---|
| 205 |
|
---|
| 206 | m_ParticleSystem.m_LittleSystemRadius=m_LittleParticleSystem.getBoundingRadius();
|
---|
| 207 | m_ParticleSystem.RefreshParticles(Dt,TimefromSecond);
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | RefreshDepths(cam);
|
---|
| 211 |
|
---|
| 212 | if(m_PSys_RenderMode>1)RefreshIllumTextures(LightPos);
|
---|
| 213 | else m_ParticleSystem.RefrBRadius_Dist();
|
---|
| 214 |
|
---|
| 215 | //render objects inside bounding sphere
|
---|
| 216 | if(depthcalc)RenderObjectDepths(cam);
|
---|
| 217 |
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 |
|
---|
| 221 | void AdvancedParticleSystem::RefreshDepths(Camera* cam)
|
---|
| 222 | {
|
---|
| 223 | m_DisplayImpostor.setObjSphereRadius(m_LittleParticleSystem.getBoundingRadius());
|
---|
| 224 | m_DisplayImpostor.setObjPosition(m_LittleParticleSystem.getPosition());
|
---|
| 225 |
|
---|
| 226 | Camera* viewcam;
|
---|
| 227 | Vector dir=cam->getPosition()-m_LittleParticleSystem.getPosition();
|
---|
| 228 | double length=dir.Length();
|
---|
| 229 | if(length<m_LittleParticleSystem.getBoundingRadius())
|
---|
| 230 | {
|
---|
| 231 | viewcam=new Camera;
|
---|
| 232 | dir.Normalize();
|
---|
| 233 | Vector position=m_LittleParticleSystem.getPosition()+dir*(m_LittleParticleSystem.getBoundingRadius()+0.1);
|
---|
| 234 | viewcam->SetPosition(position);
|
---|
| 235 | }
|
---|
| 236 | else
|
---|
| 237 | {
|
---|
| 238 | viewcam=cam;
|
---|
| 239 | }
|
---|
| 240 | viewcam=cam;
|
---|
| 241 | m_DisplayImpostor.setViewCamera(viewcam);
|
---|
| 242 | m_DisplayImpostor.updateCamera(true);
|
---|
| 243 |
|
---|
| 244 | CGparameter param;
|
---|
| 245 |
|
---|
| 246 |
|
---|
| 247 | //FRONT DEPTH
|
---|
| 248 | // Enable Depth Render Target
|
---|
| 249 | m_FrontDepthTexture.ReleaseColorBuffer();
|
---|
| 250 | m_FrontDepthTexture.EnableTarget();
|
---|
| 251 |
|
---|
| 252 | CgProgram* ActualProgram;
|
---|
| 253 |
|
---|
| 254 | if(depthcalc)ActualProgram=&m_FrontDepthProgram;
|
---|
| 255 | else ActualProgram=&m_DensityOnlyProgram;
|
---|
| 256 |
|
---|
| 257 | //enable cg programs
|
---|
| 258 | ActualProgram->Enable();
|
---|
| 259 |
|
---|
| 260 | //bind textures to programs
|
---|
| 261 | if(depthcalc)
|
---|
| 262 | {
|
---|
| 263 | param=cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"frontTexture");
|
---|
| 264 | cgGLSetTextureParameter(param,m_BbFrontDepthTexture.getTextureHandler());
|
---|
| 265 | cgGLEnableTextureParameter(param);
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | param=cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"Texture");
|
---|
| 269 | cgGLSetTextureParameter(param,m_BillboardTexture.getTextureHandler());
|
---|
| 270 | cgGLEnableTextureParameter(param);
|
---|
| 271 |
|
---|
| 272 | //Render System
|
---|
| 273 | glClearColor(1,1,0,0);
|
---|
| 274 | glDisable(GL_DEPTH_TEST);
|
---|
| 275 |
|
---|
| 276 | m_DisplayImpostor.ApplyCameraTransformOrto();
|
---|
| 277 |
|
---|
| 278 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
| 279 | glEnable(GL_BLEND);
|
---|
| 280 |
|
---|
| 281 | glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);
|
---|
| 282 | glBlendEquationSeparateEXT(GL_MIN_EXT,GL_FUNC_ADD);
|
---|
| 283 |
|
---|
| 284 | m_LittleParticleSystem.RenderAsBillboard();
|
---|
| 285 |
|
---|
| 286 | //disable cg programs
|
---|
| 287 | if(depthcalc)cgGLDisableTextureParameter(cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"frontTexture"));
|
---|
| 288 | cgGLDisableTextureParameter(cgGetNamedParameter(*ActualProgram->m_FragmentProgram,"Texture"));
|
---|
| 289 | ActualProgram->Disable();
|
---|
| 290 |
|
---|
| 291 | m_FrontDepthTexture.DisableTarget();
|
---|
| 292 | m_FrontDepthTexture.BindColorBuffer();
|
---|
| 293 |
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 |
|
---|
| 297 | void AdvancedParticleSystem::Initialize()
|
---|
| 298 | {
|
---|
| 299 | InitSystems();
|
---|
| 300 |
|
---|
| 301 | m_FrontDepthTexture.Initialize(256,256,"rgba textureRECT");
|
---|
| 302 | m_FrontDepthProgram.SetProgramFiles("PSystemFrontDepthPrograms.cg","PSystemFrontDepthPrograms.cg");
|
---|
| 303 | m_FrontDepthProgram.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 304 | m_FrontDepthProgram.InitPrograms();
|
---|
| 305 |
|
---|
| 306 | m_DensityOnlyProgram.SetProgramFiles("PSystemDensityOnlyPrograms.cg","PSystemDensityOnlyPrograms.cg");
|
---|
| 307 | m_DensityOnlyProgram.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 308 | m_DensityOnlyProgram.InitPrograms();
|
---|
| 309 |
|
---|
| 310 |
|
---|
| 311 | //m_IllumTexture.Initialize(256,256,"rgba depth aux=4 textureRECT=aux");
|
---|
| 312 | m_IllumTexture.Initialize(256,256,"rgba textureRECT");
|
---|
| 313 | m_IllumProgram.SetProgramFiles("IllumPrograms.cg","IllumPrograms.cg");
|
---|
| 314 | m_IllumProgram.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 315 | m_IllumProgram.InitPrograms();
|
---|
| 316 |
|
---|
| 317 | m_TempProg.SetProgramFiles("SimplePrograms.cg","SimplePrograms.cg");
|
---|
| 318 | m_TempProg.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 319 | m_TempProg.InitPrograms();
|
---|
| 320 |
|
---|
| 321 | m_TempProg2.SetProgramFiles("SimplePrograms2.cg","SimplePrograms2.cg");
|
---|
| 322 | m_TempProg2.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 323 | m_TempProg2.InitPrograms();
|
---|
| 324 |
|
---|
| 325 | m_ObjectsTexture.Initialize(512,512,"r float=16 depth textureRECT");
|
---|
| 326 | m_ObjDepthProg.SetProgramFiles("ObjDepthPrograms.cg","ObjDepthPrograms.cg");
|
---|
| 327 | m_ObjDepthProg.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 328 | m_ObjDepthProg.InitPrograms();
|
---|
| 329 |
|
---|
| 330 | m_ScatteredIlumTexture.Initialize(256,256,"rgba textureRECT");
|
---|
| 331 | m_ScatterIllumProgram.SetProgramFiles("ScatterIllumPrograms.cg","ScatterIllumPrograms.cg");
|
---|
| 332 | m_ScatterIllumProgram.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 333 | m_ScatterIllumProgram.InitPrograms();
|
---|
| 334 |
|
---|
| 335 | //Particle system rendering programs
|
---|
| 336 |
|
---|
| 337 | m_Psys_Multiple_Forward_Program.SetProgramFiles("Psystem_Multiply_Forward.cg","Psystem_Multiply_Forward.cg");
|
---|
| 338 | m_Psys_Multiple_Forward_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 339 | m_Psys_Multiple_Forward_Program.InitPrograms();
|
---|
| 340 |
|
---|
| 341 | m_Psys_Depth_Multiple_Forward_Program.SetProgramFiles("Psystem_Multiply_Forward_Depth.cg","Psystem_Multiply_Forward_Depth.cg");
|
---|
| 342 | m_Psys_Depth_Multiple_Forward_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 343 | m_Psys_Depth_Multiple_Forward_Program.InitPrograms();
|
---|
| 344 |
|
---|
| 345 | m_Psys_Single_Phase_Program.SetProgramFiles("Psystem_Single_Phase.cg","Psystem_Single_Phase.cg");
|
---|
| 346 | m_Psys_Single_Phase_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 347 | m_Psys_Single_Phase_Program.InitPrograms();
|
---|
| 348 |
|
---|
| 349 | m_Psys_Depth_Single_Phase_Program.SetProgramFiles("Psystem_Single_Phase_Depth.cg","Psystem_Single_Phase_Depth.cg");
|
---|
| 350 | m_Psys_Depth_Single_Phase_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 351 | m_Psys_Depth_Single_Phase_Program.InitPrograms();
|
---|
| 352 |
|
---|
| 353 |
|
---|
| 354 | m_Psys_Default_Program.SetProgramFiles("Psystem_Default.cg","Psystem_Default.cg");
|
---|
| 355 | m_Psys_Default_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 356 | m_Psys_Default_Program.InitPrograms();
|
---|
| 357 |
|
---|
| 358 | m_Psys_Depth_Default_Program.SetProgramFiles("Psystem_Default_Depth.cg","Psystem_Default_Depth.cg");
|
---|
| 359 | m_Psys_Depth_Default_Program.SetProgramEntries("VertexProgram","FragmentProgram");
|
---|
| 360 | m_Psys_Depth_Default_Program.InitPrograms();
|
---|
| 361 |
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | void AdvancedParticleSystem::InitSystems()
|
---|
| 365 | {
|
---|
| 366 | //BiggerSystem
|
---|
| 367 | m_ParticleSystem.setPosition(Vector(0,0,0));
|
---|
| 368 | m_ParticleSystem.setQuota(30);
|
---|
| 369 | //m_ParticleSystem.m_Emitter.setPosition(Vector(0,-1.2,0));
|
---|
| 370 | m_ParticleSystem.m_Emitter.setSize(0.5);
|
---|
| 371 | m_ParticleSystem.m_Emitter.setSizevariation(0.5);
|
---|
| 372 | m_ParticleSystem.m_Emitter.setDirection(Vector(0,1,0));
|
---|
| 373 | m_ParticleSystem.m_Emitter.setVelocity(0);
|
---|
| 374 | m_ParticleSystem.m_Emitter.setRadius(1.2);
|
---|
| 375 | m_ParticleSystem.m_Emitter.setTimeToLive(0);
|
---|
| 376 | m_ParticleSystem.m_Emitter.setEmissionRate(0);
|
---|
| 377 |
|
---|
| 378 |
|
---|
| 379 | //SmallerSystem
|
---|
| 380 | m_LittleParticleSystem.setQuota(500);
|
---|
| 381 | m_LittleParticleSystem.m_Emitter.setTimeToLive(8000);
|
---|
| 382 | m_LittleParticleSystem.m_Emitter.setTimeToLiveVariation(0);
|
---|
| 383 | m_LittleParticleSystem.m_Emitter.setSize(0.3);
|
---|
| 384 | m_LittleParticleSystem.m_Emitter.setRadius(0.5);
|
---|
| 385 | m_LittleParticleSystem.m_Emitter.setSizevariation(0.3);
|
---|
| 386 | m_LittleParticleSystem.m_Emitter.setVelocity(0.1);
|
---|
| 387 | m_LittleParticleSystem.m_Emitter.setVelocityVariation(0.5);
|
---|
| 388 | //m_LittleParticleSystem.m_Emitter.setDirection(Vector(0,1,0));
|
---|
| 389 | m_LittleParticleSystem.m_Emitter.setEmissionRate(40);
|
---|
| 390 | //m_LittleParticleSystem.m_refreshonce=true;
|
---|
| 391 | //m_LittleParticleSystem.m_Emitter.setEmissionRate(0);//emit as much as possible
|
---|
| 392 |
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | void AdvancedParticleSystem::RefreshIllumTextures(Vector LightPos)
|
---|
| 396 | {
|
---|
| 397 | // refresh IllumImpostor
|
---|
| 398 | //create camera
|
---|
| 399 | m_LightCamera.SetPosition(LightPos);
|
---|
| 400 | m_IllumImpostor.setObjPosition(m_ParticleSystem.getPosition());
|
---|
| 401 | m_IllumImpostor.setObjSphereRadius(m_ParticleSystem.getBoundingRadius());
|
---|
| 402 | m_IllumImpostor.setViewCamera(&m_LightCamera);
|
---|
| 403 | m_IllumImpostor.updateCamera(true);
|
---|
| 404 | m_LightCamera=m_IllumImpostor.getOwnCamera();
|
---|
| 405 |
|
---|
| 406 | //Enable illumrendertargets
|
---|
| 407 | m_IllumTexture.ReleaseColorBuffer();
|
---|
| 408 | m_IllumTexture.EnableTarget();
|
---|
| 409 |
|
---|
| 410 |
|
---|
| 411 | glClearColor(1,1,1,1);
|
---|
| 412 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
| 413 | /* if(object_shadows)
|
---|
| 414 | {
|
---|
| 415 | glDisable(GL_LIGHTING);
|
---|
| 416 | glColor4f(0.2,0.2,0.2,0.2);
|
---|
| 417 | glutSolidTeapot(0.2);
|
---|
| 418 | }*/
|
---|
| 419 |
|
---|
| 420 | m_IllumProgram.Enable();
|
---|
| 421 |
|
---|
| 422 | CGparameter param;
|
---|
| 423 |
|
---|
| 424 | //render particle system
|
---|
| 425 | param=cgGetNamedParameter(*m_IllumProgram.m_FragmentProgram,"Texture");
|
---|
| 426 | cgGLSetTextureParameter(param,m_BillboardTexture.getTextureHandler());
|
---|
| 427 | cgGLEnableTextureParameter(param);
|
---|
| 428 |
|
---|
| 429 | param=cgGetNamedParameter(*m_IllumProgram.m_FragmentProgram,"PhaseTexture");
|
---|
| 430 | cgGLSetTextureParameter(param,PhaseTexID);
|
---|
| 431 | cgGLEnableTextureParameter(param);
|
---|
| 432 |
|
---|
| 433 | param = cgGetNamedParameter(*m_IllumProgram.m_FragmentProgram, "Albedo");
|
---|
| 434 | cgGLSetParameter1d(param,albedo);
|
---|
| 435 | param = cgGetNamedParameter(*m_IllumProgram.m_VertexProgram, "transparency");
|
---|
| 436 | cgGLSetParameter1d(param,transparency);
|
---|
| 437 | param = cgGetNamedParameter(*m_IllumProgram.m_FragmentProgram, "Symmetry");
|
---|
| 438 | cgGLSetParameter1d(param,symmetry2);
|
---|
| 439 |
|
---|
| 440 |
|
---|
| 441 | m_ParticleSystem.RefreshCamera(&m_LightCamera);
|
---|
| 442 | m_ParticleSystem.RefrBRadius_Dist();
|
---|
| 443 | m_ParticleSystem.SortParticles(false);
|
---|
| 444 | m_ParticleSystem.RefreshBuffer();
|
---|
| 445 |
|
---|
| 446 | //render
|
---|
| 447 | glEnable(GL_BLEND);
|
---|
| 448 | glBlendFunc(GL_NONE,GL_SRC_COLOR);
|
---|
| 449 |
|
---|
| 450 | //apply transform
|
---|
| 451 | m_LightCamera.SetViewandProjectionOrto();
|
---|
| 452 |
|
---|
| 453 | m_ParticleSystem.RenderAsBillboard();
|
---|
| 454 |
|
---|
| 455 | cgGLDisableTextureParameter(cgGetNamedParameter(*m_IllumProgram.m_FragmentProgram,"Texture"));
|
---|
| 456 | m_IllumProgram.Disable();
|
---|
| 457 |
|
---|
| 458 | //Disable illurendertargets
|
---|
| 459 | m_IllumTexture.DisableTarget();
|
---|
| 460 | m_IllumTexture.BindColorBuffer();
|
---|
| 461 |
|
---|
| 462 | if(m_PSys_RenderMode>2)
|
---|
| 463 | {
|
---|
| 464 | //Compute scattering
|
---|
| 465 | m_ScatteredIlumTexture.ReleaseColorBuffer();
|
---|
| 466 | m_ScatteredIlumTexture.EnableTarget();
|
---|
| 467 |
|
---|
| 468 | glDisable(GL_LIGHTING);
|
---|
| 469 | glDisable(GL_DEPTH_TEST);
|
---|
| 470 |
|
---|
| 471 | m_ScatterIllumProgram.Enable();
|
---|
| 472 |
|
---|
| 473 | param = cgGetNamedParameter(*m_ScatterIllumProgram.m_FragmentProgram, "Transparency");
|
---|
| 474 | cgGLSetParameter1f(param,transparency);
|
---|
| 475 | param = cgGetNamedParameter(*m_ScatterIllumProgram.m_FragmentProgram, "Albedo");
|
---|
| 476 | cgGLSetParameter1f(param,albedo);
|
---|
| 477 | param = cgGetNamedParameter(*m_ScatterIllumProgram.m_FragmentProgram, "Symmetry");
|
---|
| 478 | cgGLSetParameter1f(param,symmetry2);
|
---|
| 479 |
|
---|
| 480 | param=cgGetNamedParameter(*m_ScatterIllumProgram.m_FragmentProgram,"IllumTexture");
|
---|
| 481 | cgGLSetTextureParameter(param,m_IllumTexture.getColorTextureID());
|
---|
| 482 | cgGLEnableTextureParameter(param);
|
---|
| 483 |
|
---|
| 484 | param=cgGetNamedParameter(*m_ScatterIllumProgram.m_FragmentProgram,"PhaseTexture");
|
---|
| 485 | cgGLSetTextureParameter(param,PhaseTexID);
|
---|
| 486 | cgGLEnableTextureParameter(param);
|
---|
| 487 |
|
---|
| 488 | param=cgGetNamedParameter(*m_ScatterIllumProgram.m_FragmentProgram,"AngleTexture");
|
---|
| 489 | cgGLSetTextureParameter(param,AngleTexID);
|
---|
| 490 | cgGLEnableTextureParameter(param);
|
---|
| 491 |
|
---|
| 492 | m_IllumImpostor.DisplayScreenQuad();
|
---|
| 493 |
|
---|
| 494 | m_ScatterIllumProgram.Disable();
|
---|
| 495 |
|
---|
| 496 | m_ScatteredIlumTexture.DisableTarget();
|
---|
| 497 | m_ScatteredIlumTexture.BindColorBuffer();
|
---|
| 498 | }
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 | /*
|
---|
| 502 | void AdvancedParticleSystem::RefreshIllumTextures(Vector LightPos)
|
---|
| 503 | {
|
---|
| 504 | // refresh IllumImpostor
|
---|
| 505 | //create camera
|
---|
| 506 | m_LightCamera.SetPosition(LightPos);
|
---|
| 507 | m_IllumImpostor.setObjPosition(m_ParticleSystem.getPosition());
|
---|
| 508 | m_IllumImpostor.setObjSphereRadius(m_ParticleSystem.getBoundingRadius());
|
---|
| 509 | m_IllumImpostor.setViewCamera(&m_LightCamera);
|
---|
| 510 | m_IllumImpostor.updateCamera(true);
|
---|
| 511 | m_LightCamera=m_IllumImpostor.getOwnCamera();
|
---|
| 512 |
|
---|
| 513 | //Enable illumrendertargets
|
---|
| 514 | m_IllumTexture.EnableTarget();
|
---|
| 515 |
|
---|
| 516 | //set and clear bacground color and depth
|
---|
| 517 | const GLenum buffers[] = {
|
---|
| 518 | GL_AUX0,
|
---|
| 519 | GL_AUX1,
|
---|
| 520 | GL_AUX2,
|
---|
| 521 | GL_AUX3
|
---|
| 522 | };
|
---|
| 523 | for(int i=0;i<4;i++)
|
---|
| 524 | {
|
---|
| 525 | glDrawBuffer(buffers[i]);
|
---|
| 526 | glClearColor(1,1,1,1);
|
---|
| 527 | glClearDepth(1.0);
|
---|
| 528 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | glDrawBuffersATI(4, buffers);
|
---|
| 532 |
|
---|
| 533 | m_IllumProgram.Enable();
|
---|
| 534 |
|
---|
| 535 | CGparameter param;float transparency;
|
---|
| 536 |
|
---|
| 537 | if(object_shadows)
|
---|
| 538 | {
|
---|
| 539 | //render objects inside bounding sphere
|
---|
| 540 |
|
---|
| 541 | glEnable(GL_DEPTH_TEST);
|
---|
| 542 | glColor4f(0,0,0,1);
|
---|
| 543 |
|
---|
| 544 | param=cgGetNamedParameter(*m_IllumProgram.m_FragmentProgram,"Texture");
|
---|
| 545 | cgGLSetTextureParameter(param,0);
|
---|
| 546 | cgGLEnableTextureParameter(param); transparency=0.3;
|
---|
| 547 | param= cgGetNamedParameter(*m_IllumProgram.m_VertexProgram, "transparency");
|
---|
| 548 | cgGLSetParameter1f(param,transparency);
|
---|
| 549 | glutSolidTeapot(0.73);
|
---|
| 550 | glDisable(GL_DEPTH_TEST);
|
---|
| 551 | }
|
---|
| 552 |
|
---|
| 553 | //render particle system
|
---|
| 554 | param=cgGetNamedParameter(*m_IllumProgram.m_FragmentProgram,"Texture");
|
---|
| 555 | cgGLSetTextureParameter(param,m_BillboardTexture.getTextureHandler());
|
---|
| 556 | cgGLEnableTextureParameter(param);
|
---|
| 557 |
|
---|
| 558 | transparency=0.12;
|
---|
| 559 | param = cgGetNamedParameter(*m_IllumProgram.m_VertexProgram, "transparency");
|
---|
| 560 | cgGLSetParameter1f(param,transparency);
|
---|
| 561 |
|
---|
| 562 | m_ParticleSystem.RefreshCamera(&m_LightCamera);
|
---|
| 563 | m_ParticleSystem.SortParticles(true);
|
---|
| 564 | m_ParticleSystem.RefreshBuffer();
|
---|
| 565 |
|
---|
| 566 | //render
|
---|
| 567 | glEnable(GL_BLEND);
|
---|
| 568 | glBlendFunc(GL_NONE,GL_ONE_MINUS_SRC_ALPHA);
|
---|
| 569 |
|
---|
| 570 | //apply transform
|
---|
| 571 | m_LightCamera.SetViewandProjectionOrto();
|
---|
| 572 |
|
---|
| 573 | m_ParticleSystem.RenderAsBillboard();
|
---|
| 574 |
|
---|
| 575 | cgGLDisableTextureParameter(cgGetNamedParameter(*m_IllumProgram.m_FragmentProgram,"Texture"));
|
---|
| 576 | m_IllumProgram.Disable();
|
---|
| 577 |
|
---|
| 578 | glFinish();
|
---|
| 579 | //Disable illurendertargets
|
---|
| 580 | m_IllumTexture.DisableTarget();
|
---|
| 581 | }
|
---|
| 582 | */
|
---|
| 583 |
|
---|
| 584 | void AdvancedParticleSystem::RenderObjectDepths(Camera* cam)
|
---|
| 585 | {
|
---|
| 586 | m_ObjectsTexture.ReleaseColorBuffer();
|
---|
| 587 | m_ObjectsTexture.EnableTarget();
|
---|
| 588 |
|
---|
| 589 | m_ObjDepthProg.Enable();
|
---|
| 590 |
|
---|
| 591 | glClearColor(-100.0f,-100.0f,-100.0f,0.0f);
|
---|
| 592 | //glClearColor(0.0f,0.0f,1.0f,0.0f);
|
---|
| 593 | glEnable(GL_DEPTH_TEST);
|
---|
| 594 | glClearDepth(1.0);
|
---|
| 595 | glDepthFunc(GL_LEQUAL);
|
---|
| 596 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 597 |
|
---|
| 598 | cam->SetViewandProjection();
|
---|
| 599 | glDisable(GL_LIGHTING);
|
---|
| 600 | glDisable(GL_BLEND);
|
---|
| 601 | //render scene
|
---|
| 602 | this->theScene->Display(true);
|
---|
| 603 |
|
---|
| 604 | m_ObjDepthProg.Disable();
|
---|
| 605 |
|
---|
| 606 | m_ObjectsTexture.DisableTarget();
|
---|
| 607 | m_ObjectsTexture.BindColorBuffer();
|
---|
| 608 |
|
---|
| 609 | } |
---|