Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2012-08-31 21:27:08 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2012-08-31 21:27:08 +0400
commitf0d247748408bd10f49c54d3a28a925e37683c4b (patch)
treeb47851a73399e6b30c501550ec9024897d65c186 /intern/cycles/render/particles.cpp
parent5ecff7a240514e8f16e17aa163c6f0055b9edaf2 (diff)
Fix for #32184 and redesign of particle storage in Cycles.
The particle data used by the Particle Info node was stored in cycles as a list in each object. This is a problem when the particle emitter mesh is hidden: Objects in cycles are only intended as instances of renderable meshes, so when hiding the emitter mesh the particle data doesn't get stored either. Also the particle data can potentially be copied to multiple instances of the same object, which is a waste of texture space. The solution in this patch is to make a completely separate list of particle systems in the Cycles scene data. This way the particle data can be generated even when the emitter object itself is not visible.
Diffstat (limited to 'intern/cycles/render/particles.cpp')
-rw-r--r--intern/cycles/render/particles.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/intern/cycles/render/particles.cpp b/intern/cycles/render/particles.cpp
new file mode 100644
index 00000000000..539a2333506
--- /dev/null
+++ b/intern/cycles/render/particles.cpp
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "device.h"
+#include "particles.h"
+#include "scene.h"
+
+#include "util_foreach.h"
+#include "util_map.h"
+#include "util_progress.h"
+#include "util_vector.h"
+
+CCL_NAMESPACE_BEGIN
+
+/* Particle System */
+
+ParticleSystem::ParticleSystem()
+{
+}
+
+ParticleSystem::~ParticleSystem()
+{
+}
+
+void ParticleSystem::tag_update(Scene *scene)
+{
+ scene->particle_system_manager->need_update = true;
+}
+
+/* Particle System Manager */
+
+ParticleSystemManager::ParticleSystemManager()
+{
+ need_update = true;
+}
+
+ParticleSystemManager::~ParticleSystemManager()
+{
+}
+
+void ParticleSystemManager::device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
+{
+ /* count particles.
+ * adds one dummy particle at the beginning to avoid invalid lookups,
+ * in case a shader uses particle info without actual particle data.
+ */
+ int num_particles = 1;
+ foreach(ParticleSystem *psys, scene->particle_systems)
+ num_particles += psys->particles.size();
+
+ float4 *particles = dscene->particles.resize(PARTICLE_SIZE*num_particles);
+
+ /* dummy particle */
+ particles[0] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+
+ int i = 1;
+ foreach(ParticleSystem *psys, scene->particle_systems) {
+ foreach(Particle &pa, psys->particles) {
+ /* pack in texture */
+ int offset = i*PARTICLE_SIZE;
+
+ particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, 0.0f);
+
+ i++;
+
+ if(progress.get_cancel()) return;
+ }
+ }
+
+ device->tex_alloc("__particles", dscene->particles);
+}
+
+void ParticleSystemManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
+{
+ if(!need_update)
+ return;
+
+ device_free(device, dscene);
+
+ if(scene->particle_systems.size() == 0)
+ return;
+
+ progress.set_status("Updating Particle Systems", "Copying Particles to device");
+ device_update_particles(device, dscene, scene, progress);
+
+ if(progress.get_cancel()) return;
+
+ need_update = false;
+}
+
+void ParticleSystemManager::device_free(Device *device, DeviceScene *dscene)
+{
+ device->tex_free(dscene->particles);
+ dscene->particles.clear();
+}
+
+void ParticleSystemManager::tag_update(Scene *scene)
+{
+ need_update = true;
+}
+
+CCL_NAMESPACE_END
+