Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/particles.cpp
| Show All 40 Lines | |||||
| } | } | ||||
| ParticleSystem::~ParticleSystem() | ParticleSystem::~ParticleSystem() | ||||
| { | { | ||||
| } | } | ||||
| void ParticleSystem::tag_update(Scene *scene) | void ParticleSystem::tag_update(Scene *scene) | ||||
| { | { | ||||
| scene->particle_system_manager->need_update = true; | scene->get_particle_system_manager()->need_update = true; | ||||
| } | } | ||||
| /* Particle System Manager */ | /* Particle System Manager */ | ||||
| ParticleSystemManager::ParticleSystemManager() | ParticleSystemManager::ParticleSystemManager() | ||||
| { | { | ||||
| need_update = true; | need_update = true; | ||||
| } | } | ||||
| ParticleSystemManager::~ParticleSystemManager() | ParticleSystemManager::~ParticleSystemManager() | ||||
| { | { | ||||
| } | } | ||||
| void ParticleSystemManager::device_update_particles(Device *, | void ParticleSystemManager::device_update_particles(Device *, | ||||
| DeviceScene *dscene, | DeviceScene *dscene, | ||||
| Scene *scene, | Scene *scene, | ||||
| Progress &progress) | Progress &progress) | ||||
| { | { | ||||
| /* count particles. | /* count particles. | ||||
| * adds one dummy particle at the beginning to avoid invalid lookups, | * adds one dummy particle at the beginning to avoid invalid lookups, | ||||
| * in case a shader uses particle info without actual particle data. */ | * in case a shader uses particle info without actual particle data. */ | ||||
| int num_particles = 1; | int num_particles = 1; | ||||
| for (size_t j = 0; j < scene->particle_systems.size(); j++) | foreach (ParticleSystem *psys, scene->get_particle_systems()) | ||||
| num_particles += scene->particle_systems[j]->particles.size(); | num_particles += psys->get_particles().size(); | ||||
| KernelParticle *kparticles = dscene->particles.alloc(num_particles); | KernelParticle *kparticles = dscene->particles.alloc(num_particles); | ||||
| /* dummy particle */ | /* dummy particle */ | ||||
| memset(kparticles, 0, sizeof(KernelParticle)); | memset(kparticles, 0, sizeof(KernelParticle)); | ||||
| int i = 1; | int i = 1; | ||||
| for (size_t j = 0; j < scene->particle_systems.size(); j++) { | foreach (ParticleSystem *psys, scene->get_particle_systems()) { | ||||
| ParticleSystem *psys = scene->particle_systems[j]; | foreach (const Particle &pa, psys->get_particles()) { | ||||
| for (size_t k = 0; k < psys->particles.size(); k++) { | |||||
| /* pack in texture */ | /* pack in texture */ | ||||
| Particle &pa = psys->particles[k]; | |||||
| kparticles[i].index = pa.index; | kparticles[i].index = pa.index; | ||||
| kparticles[i].age = pa.age; | kparticles[i].age = pa.age; | ||||
| kparticles[i].lifetime = pa.lifetime; | kparticles[i].lifetime = pa.lifetime; | ||||
| kparticles[i].size = pa.size; | kparticles[i].size = pa.size; | ||||
| kparticles[i].rotation = pa.rotation; | kparticles[i].rotation = pa.rotation; | ||||
| kparticles[i].location = float3_to_float4(pa.location); | kparticles[i].location = float3_to_float4(pa.location); | ||||
| kparticles[i].velocity = float3_to_float4(pa.velocity); | kparticles[i].velocity = float3_to_float4(pa.velocity); | ||||
| kparticles[i].angular_velocity = float3_to_float4(pa.angular_velocity); | kparticles[i].angular_velocity = float3_to_float4(pa.angular_velocity); | ||||
| Show All 12 Lines | void ParticleSystemManager::device_update(Device *device, | ||||
| DeviceScene *dscene, | DeviceScene *dscene, | ||||
| Scene *scene, | Scene *scene, | ||||
| Progress &progress) | Progress &progress) | ||||
| { | { | ||||
| if (!need_update) | if (!need_update) | ||||
| return; | return; | ||||
| scoped_callback_timer timer([scene](double time) { | scoped_callback_timer timer([scene](double time) { | ||||
| if (scene->update_stats) { | if (scene->get_update_stats()) { | ||||
| scene->update_stats->particles.times.add_entry({"device_update", time}); | scene->get_update_stats()->particles.times.add_entry({"device_update", time}); | ||||
| } | } | ||||
| }); | }); | ||||
| VLOG(1) << "Total " << scene->particle_systems.size() << " particle systems."; | VLOG(1) << "Total " << scene->get_particle_systems().size() << " particle systems."; | ||||
| device_free(device, dscene); | device_free(device, dscene); | ||||
| progress.set_status("Updating Particle Systems", "Copying Particles to device"); | progress.set_status("Updating Particle Systems", "Copying Particles to device"); | ||||
| device_update_particles(device, dscene, scene, progress); | device_update_particles(device, dscene, scene, progress); | ||||
| if (progress.get_cancel()) | if (progress.get_cancel()) | ||||
| return; | return; | ||||
| Show All 15 Lines | |||||