Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011, Blender Foundation. | 2 * Copyright 2011, Blender Foundation. |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or | 4 * This program is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU General Public License | 5 * modify it under the terms of the GNU General Public License |
6 * as published by the Free Software Foundation; either version 2 | 6 * as published by the Free Software Foundation; either version 2 |
7 * of the License, or (at your option) any later version. | 7 * of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software Foundation, | 15 * along with this program; if not, write to the Free Software Foundation, |
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 */ | 17 */ |
18 | 18 |
19 #include "device.h" | 19 #include "device.h" |
20 #include "light.h" | 20 #include "light.h" |
21 #include "mesh.h" | 21 #include "mesh.h" |
22 #include "object.h" | 22 #include "object.h" |
23 #include "scene.h" | 23 #include "scene.h" |
24 | 24 |
25 #include "util_foreach.h" | 25 #include "util_foreach.h" |
26 #include "util_map.h" | 26 #include "util_map.h" |
27 #include "util_progress.h" | 27 #include "util_progress.h" |
28 #include "util_vector.h" | |
28 | 29 |
29 CCL_NAMESPACE_BEGIN | 30 CCL_NAMESPACE_BEGIN |
30 | 31 |
31 /* Object */ | 32 /* Object */ |
32 | 33 |
33 Object::Object() | 34 Object::Object() |
34 { | 35 { |
35 name = ""; | 36 name = ""; |
36 mesh = NULL; | 37 mesh = NULL; |
37 tfm = transform_identity(); | 38 tfm = transform_identity(); |
38 visibility = ~0; | 39 visibility = ~0; |
39 random_id = 0; | 40 random_id = 0; |
40 pass_id = 0; | 41 pass_id = 0; |
42 particle_id = 0; | |
41 bounds = BoundBox::empty; | 43 bounds = BoundBox::empty; |
42 motion.pre = transform_identity(); | 44 motion.pre = transform_identity(); |
43 motion.post = transform_identity(); | 45 motion.post = transform_identity(); |
44 use_motion = false; | 46 use_motion = false; |
45 use_holdout = false; | 47 use_holdout = false; |
46 } | 48 } |
47 | 49 |
48 Object::~Object() | 50 Object::~Object() |
49 { | 51 { |
50 } | 52 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 need_update = true; | 140 need_update = true; |
139 } | 141 } |
140 | 142 |
141 ObjectManager::~ObjectManager() | 143 ObjectManager::~ObjectManager() |
142 { | 144 { |
143 } | 145 } |
144 | 146 |
145 void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene , Scene *scene, Progress& progress) | 147 void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene , Scene *scene, Progress& progress) |
146 { | 148 { |
147 float4 *objects = dscene->objects.resize(OBJECT_SIZE*scene->objects.size ()); | 149 float4 *objects = dscene->objects.resize(OBJECT_SIZE*scene->objects.size ()); |
150 /* XXX why using OBJECT_SIZE for flag texture as well? */ | |
brechtvl
2012/06/08 15:24:24
I guess this can be removed? Otherwise don't under
lukas.toenne
2012/06/08 16:04:36
I was a bit confused why you are using the OBJECT_
| |
148 uint *object_flag = dscene->object_flag.resize(OBJECT_SIZE*scene->object s.size()); | 151 uint *object_flag = dscene->object_flag.resize(OBJECT_SIZE*scene->object s.size()); |
149 int i = 0; | 152 int i = 0; |
150 map<Mesh*, float> surface_area_map; | 153 map<Mesh*, float> surface_area_map; |
151 Scene::MotionType need_motion = scene->need_motion(); | 154 Scene::MotionType need_motion = scene->need_motion(); |
152 | 155 |
153 foreach(Object *ob, scene->objects) { | 156 foreach(Object *ob, scene->objects) { |
154 Mesh *mesh = ob->mesh; | 157 Mesh *mesh = ob->mesh; |
155 uint flag = 0; | 158 uint flag = 0; |
156 | 159 |
157 /* compute transformations */ | 160 /* compute transformations */ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 | 196 |
194 surface_area += triangle_area(p1, p2, p3); | 197 surface_area += triangle_area(p1, p2, p3); |
195 } | 198 } |
196 } | 199 } |
197 | 200 |
198 /* pack in texture */ | 201 /* pack in texture */ |
199 int offset = i*OBJECT_SIZE; | 202 int offset = i*OBJECT_SIZE; |
200 | 203 |
201 memcpy(&objects[offset], &tfm, sizeof(float4)*3); | 204 memcpy(&objects[offset], &tfm, sizeof(float4)*3); |
202 memcpy(&objects[offset+3], &itfm, sizeof(float4)*3); | 205 memcpy(&objects[offset+3], &itfm, sizeof(float4)*3); |
203 » » objects[offset+6] = make_float4(surface_area, pass_id, random_nu mber, 0.0f); | 206 » » objects[offset+6] = make_float4(surface_area, pass_id, random_nu mber, __int_as_float(ob->particle_id)); |
204 | 207 |
205 if(need_motion == Scene::MOTION_PASS) { | 208 if(need_motion == Scene::MOTION_PASS) { |
206 /* motion transformations, is world/object space dependi ng if mesh | 209 /* motion transformations, is world/object space dependi ng if mesh |
207 comes with deformed position in object space, or if w e transform | 210 comes with deformed position in object space, or if w e transform |
208 the shading point in world space */ | 211 the shading point in world space */ |
209 Transform mtfm_pre = ob->motion.pre; | 212 Transform mtfm_pre = ob->motion.pre; |
210 Transform mtfm_post = ob->motion.post; | 213 Transform mtfm_post = ob->motion.post; |
211 | 214 |
212 if(!mesh->attributes.find(ATTR_STD_MOTION_PRE)) | 215 if(!mesh->attributes.find(ATTR_STD_MOTION_PRE)) |
213 mtfm_pre = mtfm_pre * itfm; | 216 mtfm_pre = mtfm_pre * itfm; |
(...skipping 25 matching lines...) Expand all Loading... | |
239 | 242 |
240 i++; | 243 i++; |
241 | 244 |
242 if(progress.get_cancel()) return; | 245 if(progress.get_cancel()) return; |
243 } | 246 } |
244 | 247 |
245 device->tex_alloc("__objects", dscene->objects); | 248 device->tex_alloc("__objects", dscene->objects); |
246 device->tex_alloc("__object_flag", dscene->object_flag); | 249 device->tex_alloc("__object_flag", dscene->object_flag); |
247 } | 250 } |
248 | 251 |
252 void ObjectManager::device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) | |
253 { | |
254 /* count particles. | |
255 * adds one dummy particle at the beginning to avoid invalid lookups, | |
256 * in case a shader uses particle info without actual particle data. | |
257 */ | |
258 int num_particles = 1; | |
259 foreach(Object *ob, scene->objects) | |
260 num_particles += ob->particles.size(); | |
261 ········ | |
262 float4 *particles = dscene->particles.resize(PARTICLE_SIZE*num_particles ); | |
263 ········ | |
264 /* dummy particle */ | |
265 particles[0] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); | |
266 ········ | |
267 int i = 1; | |
268 foreach(Object *ob, scene->objects) { | |
269 foreach(Particle &pa, ob->particles) { | |
270 /* pack in texture */ | |
271 int offset = i*PARTICLE_SIZE; | |
272 ························ | |
273 particles[offset] = make_float4(pa.age, pa.lifetime, 0.0 f, 0.0f); | |
274 ························ | |
275 i++; | |
276 ························ | |
277 if(progress.get_cancel()) return; | |
278 } | |
279 } | |
280 ········ | |
281 device->tex_alloc("__particles", dscene->particles); | |
282 } | |
283 | |
249 void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *sc ene, Progress& progress) | 284 void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *sc ene, Progress& progress) |
250 { | 285 { |
251 if(!need_update) | 286 if(!need_update) |
252 return; | 287 return; |
253 ········ | 288 ········ |
254 device_free(device, dscene); | 289 device_free(device, dscene); |
255 | 290 |
256 if(scene->objects.size() == 0) | 291 if(scene->objects.size() == 0) |
257 return; | 292 return; |
258 | 293 |
259 /* set object transform matrices, before applying static transforms */ | 294 /* set object transform matrices, before applying static transforms */ |
260 progress.set_status("Updating Objects", "Copying Transformations to devi ce"); | 295 progress.set_status("Updating Objects", "Copying Transformations to devi ce"); |
261 device_update_transforms(device, dscene, scene, progress); | 296 device_update_transforms(device, dscene, scene, progress); |
262 | 297 |
263 if(progress.get_cancel()) return; | 298 if(progress.get_cancel()) return; |
264 | 299 |
265 /* prepare for static BVH building */ | 300 /* prepare for static BVH building */ |
266 /* todo: do before to support getting object level coords? */ | 301 /* todo: do before to support getting object level coords? */ |
267 if(scene->params.bvh_type == SceneParams::BVH_STATIC) { | 302 if(scene->params.bvh_type == SceneParams::BVH_STATIC) { |
268 progress.set_status("Updating Objects", "Applying Static Transfo rmations"); | 303 progress.set_status("Updating Objects", "Applying Static Transfo rmations"); |
269 apply_static_transforms(scene, progress); | 304 apply_static_transforms(scene, progress); |
270 } | 305 } |
271 | 306 |
272 if(progress.get_cancel()) return; | 307 if(progress.get_cancel()) return; |
273 | 308 |
309 progress.set_status("Updating Objects", "Copying Particles to device"); | |
310 device_update_particles(device, dscene, scene, progress); | |
311 ········ | |
312 if(progress.get_cancel()) return; | |
313 ········ | |
274 need_update = false; | 314 need_update = false; |
275 } | 315 } |
276 | 316 |
277 void ObjectManager::device_free(Device *device, DeviceScene *dscene) | 317 void ObjectManager::device_free(Device *device, DeviceScene *dscene) |
278 { | 318 { |
279 device->tex_free(dscene->objects); | 319 device->tex_free(dscene->objects); |
280 dscene->objects.clear(); | 320 dscene->objects.clear(); |
281 | 321 |
282 device->tex_free(dscene->object_flag); | 322 device->tex_free(dscene->object_flag); |
283 dscene->object_flag.clear(); | 323 dscene->object_flag.clear(); |
324 ········ | |
325 device->tex_free(dscene->particles); | |
326 dscene->particles.clear(); | |
284 } | 327 } |
285 | 328 |
286 void ObjectManager::apply_static_transforms(Scene *scene, Progress& progress) | 329 void ObjectManager::apply_static_transforms(Scene *scene, Progress& progress) |
287 { | 330 { |
288 /* todo: normals and displacement should be done before applying transfo rm! */ | 331 /* todo: normals and displacement should be done before applying transfo rm! */ |
289 /* todo: create objects/meshes in right order! */ | 332 /* todo: create objects/meshes in right order! */ |
290 | 333 |
291 /* counter mesh users */ | 334 /* counter mesh users */ |
292 map<Mesh*, int> mesh_users; | 335 map<Mesh*, int> mesh_users; |
293 bool motion_blur = scene->need_motion() == Scene::MOTION_BLUR; | 336 bool motion_blur = scene->need_motion() == Scene::MOTION_BLUR; |
(...skipping 26 matching lines...) Expand all Loading... | |
320 | 363 |
321 void ObjectManager::tag_update(Scene *scene) | 364 void ObjectManager::tag_update(Scene *scene) |
322 { | 365 { |
323 need_update = true; | 366 need_update = true; |
324 scene->mesh_manager->need_update = true; | 367 scene->mesh_manager->need_update = true; |
325 scene->light_manager->need_update = true; | 368 scene->light_manager->need_update = true; |
326 } | 369 } |
327 | 370 |
328 CCL_NAMESPACE_END | 371 CCL_NAMESPACE_END |
329 | 372 |
OLD | NEW |