Use xrange() rather than range() for loop iterations.
[blender.git] / source / blender / blenkernel / intern / scene.c
1 /*  scene.c
2  *  
3  * 
4  * $Id$
5  *
6  * ***** BEGIN GPL LICENSE BLOCK *****
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL LICENSE BLOCK *****
30  */
31
32 #include <stdio.h>
33 #include <string.h>
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #ifndef WIN32 
40 #include <unistd.h>
41 #else
42 #include <io.h>
43 #endif
44 #include "MEM_guardedalloc.h"
45
46 #include "DNA_armature_types.h" 
47 #include "DNA_color_types.h"
48 #include "DNA_constraint_types.h"
49 #include "DNA_curve_types.h"
50 #include "DNA_group_types.h"
51 #include "DNA_lamp_types.h"
52 #include "DNA_material_types.h"
53 #include "DNA_meta_types.h"
54 #include "DNA_object_types.h"
55 #include "DNA_scene_types.h"
56 #include "DNA_scriptlink_types.h"
57 #include "DNA_texture_types.h"
58 #include "DNA_userdef_types.h"
59
60 #include "BKE_action.h"                 
61 #include "BKE_anim.h"
62 #include "BKE_armature.h"               
63 #include "BKE_bad_level_calls.h"
64 #include "BKE_colortools.h"
65 #include "BKE_constraint.h"
66 #include "BKE_depsgraph.h"
67 #include "BKE_global.h"
68 #include "BKE_group.h"
69 #include "BKE_ipo.h"
70 #include "BKE_idprop.h"
71 #include "BKE_image.h"
72 #include "BKE_key.h"
73 #include "BKE_library.h"
74 #include "BKE_main.h"
75 #include "BKE_node.h"
76 #include "BKE_object.h"
77 #include "BKE_scene.h"
78 #include "BKE_sculpt.h"
79 #include "BKE_world.h"
80 #include "BKE_utildefines.h"
81
82 #include "BIF_previewrender.h"
83 #include "BIF_editseq.h"
84
85 #include "BPY_extern.h"
86 #include "BLI_arithb.h"
87 #include "BLI_blenlib.h"
88
89 #include "nla.h"
90
91 #ifdef WIN32
92 #else
93 #include <sys/time.h>
94 #endif
95
96 void free_avicodecdata(AviCodecData *acd)
97 {
98         if (acd) {
99                 if (acd->lpFormat){
100                         MEM_freeN(acd->lpFormat);
101                         acd->lpFormat = NULL;
102                         acd->cbFormat = 0;
103                 }
104                 if (acd->lpParms){
105                         MEM_freeN(acd->lpParms);
106                         acd->lpParms = NULL;
107                         acd->cbParms = 0;
108                 }
109         }
110 }
111
112 void free_qtcodecdata(QuicktimeCodecData *qcd)
113 {
114         if (qcd) {
115                 if (qcd->cdParms){
116                         MEM_freeN(qcd->cdParms);
117                         qcd->cdParms = NULL;
118                         qcd->cdSize = 0;
119                 }
120         }
121 }
122
123 /* copy_scene moved to src/header_info.c... should be back */
124
125 /* do not free scene itself */
126 void free_scene(Scene *sce)
127 {
128         Base *base;
129
130         base= sce->base.first;
131         while(base) {
132                 base->object->id.us--;
133                 base= base->next;
134         }
135         /* do not free objects! */
136
137         BLI_freelistN(&sce->base);
138         free_editing(sce->ed);
139         if(sce->radio) MEM_freeN(sce->radio);
140         sce->radio= 0;
141         
142         BPY_free_scriptlink(&sce->scriptlink);
143         if (sce->r.avicodecdata) {
144                 free_avicodecdata(sce->r.avicodecdata);
145                 MEM_freeN(sce->r.avicodecdata);
146                 sce->r.avicodecdata = NULL;
147         }
148         if (sce->r.qtcodecdata) {
149                 free_qtcodecdata(sce->r.qtcodecdata);
150                 MEM_freeN(sce->r.qtcodecdata);
151                 sce->r.qtcodecdata = NULL;
152         }
153         if (sce->r.ffcodecdata.properties) {
154                 IDP_FreeProperty(sce->r.ffcodecdata.properties);
155                 MEM_freeN(sce->r.ffcodecdata.properties);
156                 sce->r.ffcodecdata.properties = NULL;
157         }
158         
159         BLI_freelistN(&sce->markers);
160         BLI_freelistN(&sce->transform_spaces);
161         BLI_freelistN(&sce->r.layers);
162         
163         if(sce->toolsettings){
164                 MEM_freeN(sce->toolsettings);
165                 sce->toolsettings = NULL;       
166         }
167         
168         if (sce->theDag) {
169                 free_forest(sce->theDag);
170                 MEM_freeN(sce->theDag);
171         }
172         
173         if(sce->nodetree) {
174                 ntreeFreeTree(sce->nodetree);
175                 MEM_freeN(sce->nodetree);
176         }
177
178         sculptdata_free(sce);
179 }
180
181 Scene *add_scene(char *name)
182 {
183         Scene *sce;
184         ParticleEditSettings *pset;
185         int a;
186
187         sce= alloc_libblock(&G.main->scene, ID_SCE, name);
188         sce->lay= 1;
189         sce->selectmode= SCE_SELECT_VERTEX;
190         sce->editbutsize= 0.1;
191         sce->autokey_mode= U.autokey_mode;
192         
193         sce->r.mode= R_GAMMA;
194         sce->r.cfra= 1;
195         sce->r.sfra= 1;
196         sce->r.efra= 250;
197         sce->r.xsch= 320;
198         sce->r.ysch= 256;
199         sce->r.xasp= 1;
200         sce->r.yasp= 1;
201         sce->r.xparts= 4;
202         sce->r.yparts= 4;
203         sce->r.size= 100;
204         sce->r.planes= 24;
205         sce->r.quality= 90;
206         sce->r.framapto= 100;
207         sce->r.images= 100;
208         sce->r.framelen= 1.0;
209         sce->r.frs_sec= 25;
210         sce->r.frs_sec_base= 1;
211         sce->r.ocres = 128;
212         
213         sce->r.bake_mode= 1;    /* prevent to include render stuff here */
214         sce->r.bake_filter= 2;
215         sce->r.bake_osa= 5;
216         sce->r.bake_flag= R_BAKE_CLEAR;
217         sce->r.bake_normal_space= R_BAKE_SPACE_TANGENT;
218         
219         sce->r.xplay= 640;
220         sce->r.yplay= 480;
221         sce->r.freqplay= 60;
222         sce->r.depth= 32;
223         
224         sce->r.threads= 1;
225         
226         sce->r.stereomode = 1;  // no stereo
227
228         sce->r.simplify_subsurf= 6;
229         sce->r.simplify_particles= 1.0f;
230         sce->r.simplify_shadowsamples= 16;
231         sce->r.simplify_aosss= 1.0f;
232
233         sce->r.cineonblack= 95;
234         sce->r.cineonwhite= 685;
235         sce->r.cineongamma= 1.7f;
236         
237         sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings),"Tool Settings Struct");
238         sce->toolsettings->cornertype=1;
239         sce->toolsettings->degr = 90; 
240         sce->toolsettings->step = 9;
241         sce->toolsettings->turn = 1;                            
242         sce->toolsettings->extr_offs = 1; 
243         sce->toolsettings->doublimit = 0.001;
244         sce->toolsettings->segments = 32;
245         sce->toolsettings->rings = 32;
246         sce->toolsettings->vertices = 32;
247         sce->toolsettings->editbutflag = 1;
248         sce->toolsettings->uvcalc_radius = 1.0f;
249         sce->toolsettings->uvcalc_cubesize = 1.0f;
250         sce->toolsettings->uvcalc_mapdir = 1;
251         sce->toolsettings->uvcalc_mapalign = 1;
252         sce->toolsettings->unwrapper = 1;
253         sce->toolsettings->select_thresh= 0.01f;
254         sce->toolsettings->jointrilimit = 0.8f;
255
256         pset= &sce->toolsettings->particle;
257         pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
258         pset->emitterdist= 0.25f;
259         pset->totrekey= 5;
260         pset->totaddkey= 5;
261         pset->brushtype= PE_BRUSH_NONE;
262         for(a=0; a<PE_TOT_BRUSH; a++) {
263                 pset->brush[a].strength= 50;
264                 pset->brush[a].size= 50;
265                 pset->brush[a].step= 10;
266         }
267         pset->brush[PE_BRUSH_CUT].strength= 100;
268         
269         sce->jumpframe = 10;
270         sce->audio.mixrate = 44100;
271
272         strcpy(sce->r.backbuf, "//backbuf");
273         strcpy(sce->r.pic, U.renderdir);
274
275         BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
276         sce->r.osa= 8;
277
278         sculptdata_init(sce);
279
280         /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
281         scene_add_render_layer(sce);
282         
283         return sce;
284 }
285
286 Base *object_in_scene(Object *ob, Scene *sce)
287 {
288         Base *base;
289         
290         base= sce->base.first;
291         while(base) {
292                 if(base->object == ob) return base;
293                 base= base->next;
294         }
295         return NULL;
296 }
297
298 void set_scene_bg(Scene *sce)
299 {
300         Base *base;
301         Object *ob;
302         Group *group;
303         GroupObject *go;
304         int flag;
305         
306         // Note: this here is defined in editseq.c (BIF_editseq.h), NOT in blenkernel! 
307         clear_last_seq();
308         
309         G.scene= sce;
310         
311         /* check for cyclic sets, for reading old files but also for definite security (py?) */
312         scene_check_setscene(G.scene);
313         
314         /* deselect objects (for dataselect) */
315         for(ob= G.main->object.first; ob; ob= ob->id.next)
316                 ob->flag &= ~(SELECT|OB_FROMGROUP);
317
318         /* group flags again */
319         for(group= G.main->group.first; group; group= group->id.next) {
320                 go= group->gobject.first;
321                 while(go) {
322                         if(go->ob) go->ob->flag |= OB_FROMGROUP;
323                         go= go->next;
324                 }
325         }
326
327         /* sort baselist */
328         DAG_scene_sort(sce);
329         
330         /* ensure dags are built for sets */
331         for(sce= sce->set; sce; sce= sce->set)
332                 if(sce->theDag==NULL)
333                         DAG_scene_sort(sce);
334
335         /* copy layers and flags from bases to objects */
336         for(base= G.scene->base.first; base; base= base->next) {
337                 ob= base->object;
338                 ob->lay= base->lay;
339                 
340                 /* group patch... */
341                 base->flag &= ~(OB_FROMGROUP);
342                 flag= ob->flag & (OB_FROMGROUP);
343                 base->flag |= flag;
344                 
345                 /* not too nice... for recovering objects with lost data */
346                 if(ob->pose==NULL) base->flag &= ~OB_POSEMODE;
347                 ob->flag= base->flag;
348                 
349                 ob->ctime= -1234567.0;  /* force ipo to be calculated later */
350         }
351         /* no full animation update, this to enable render code to work (render code calls own animation updates) */
352         
353         /* do we need FRAMECHANGED in set_scene? */
354 //      if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
355 }
356
357 /* called from creator.c */
358 void set_scene_name(char *name)
359 {
360         Scene *sce;
361
362         for (sce= G.main->scene.first; sce; sce= sce->id.next) {
363                 if (BLI_streq(name, sce->id.name+2)) {
364                         set_scene_bg(sce);
365                         return;
366                 }
367         }
368         
369         error("Can't find scene: %s", name);
370 }
371
372 /* used by metaballs
373  * doesnt return the original duplicated object, only dupli's
374  */
375 int next_object(int val, Base **base, Object **ob)
376 {
377         static ListBase *duplilist= NULL;
378         static DupliObject *dupob;
379         static int fase;
380         int run_again=1;
381         
382         /* init */
383         if(val==0) {
384                 fase= F_START;
385                 dupob= NULL;
386         }
387         else {
388
389                 /* run_again is set when a duplilist has been ended */
390                 while(run_again) {
391                         run_again= 0;
392
393                         /* the first base */
394                         if(fase==F_START) {
395                                 *base= G.scene->base.first;
396                                 if(*base) {
397                                         *ob= (*base)->object;
398                                         fase= F_SCENE;
399                                 }
400                                 else {
401                                     /* exception: empty scene */
402                                         if(G.scene->set && G.scene->set->base.first) {
403                                                 *base= G.scene->set->base.first;
404                                                 *ob= (*base)->object;
405                                                 fase= F_SET;
406                                         }
407                                 }
408                         }
409                         else {
410                                 if(*base && fase!=F_DUPLI) {
411                                         *base= (*base)->next;
412                                         if(*base) *ob= (*base)->object;
413                                         else {
414                                                 if(fase==F_SCENE) {
415                                                         /* scene is finished, now do the set */
416                                                         if(G.scene->set && G.scene->set->base.first) {
417                                                                 *base= G.scene->set->base.first;
418                                                                 *ob= (*base)->object;
419                                                                 fase= F_SET;
420                                                         }
421                                                 }
422                                         }
423                                 }
424                         }
425                         
426                         if(*base == NULL) fase= F_START;
427                         else {
428                                 if(fase!=F_DUPLI) {
429                                         if( (*base)->object->transflag & OB_DUPLI) {
430                                                 /* groups cannot be duplicated for mballs yet, 
431                                                 this enters eternal loop because of 
432                                                 makeDispListMBall getting called inside of group_duplilist */
433                                                 if((*base)->object->dup_group == NULL) {
434                                                         duplilist= object_duplilist(G.scene, (*base)->object);
435                                                         
436                                                         dupob= duplilist->first;
437
438                                                         if(!dupob)
439                                                                 free_object_duplilist(duplilist);
440                                                 }
441                                         }
442                                 }
443                                 /* handle dupli's */
444                                 if(dupob) {
445                                         
446                                         Mat4CpyMat4(dupob->ob->obmat, dupob->mat);
447                                         
448                                         (*base)->flag |= OB_FROMDUPLI;
449                                         *ob= dupob->ob;
450                                         fase= F_DUPLI;
451                                         
452                                         dupob= dupob->next;
453                                 }
454                                 else if(fase==F_DUPLI) {
455                                         fase= F_SCENE;
456                                         (*base)->flag &= ~OB_FROMDUPLI;
457                                         
458                                         for(dupob= duplilist->first; dupob; dupob= dupob->next) {
459                                                 Mat4CpyMat4(dupob->ob->obmat, dupob->omat);
460                                         }
461                                         
462                                         free_object_duplilist(duplilist);
463                                         duplilist= NULL;
464                                         run_again= 1;
465                                 }
466                         }
467                 }
468         }
469         
470         return fase;
471 }
472
473 Object *scene_find_camera(Scene *sc)
474 {
475         Base *base;
476         
477         for (base= sc->base.first; base; base= base->next)
478                 if (base->object->type==OB_CAMERA)
479                         return base->object;
480
481         return NULL;
482 }
483
484
485 Base *scene_add_base(Scene *sce, Object *ob)
486 {
487         Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
488         BLI_addhead(&sce->base, b);
489
490         b->object= ob;
491         b->flag= ob->flag;
492         b->lay= ob->lay;
493
494         return b;
495 }
496
497 void scene_deselect_all(Scene *sce)
498 {
499         Base *b;
500
501         for (b= sce->base.first; b; b= b->next) {
502                 b->flag&= ~SELECT;
503                 b->object->flag= b->flag;
504         }
505 }
506
507 void scene_select_base(Scene *sce, Base *selbase)
508 {
509         scene_deselect_all(sce);
510
511         selbase->flag |= SELECT;
512         selbase->object->flag= selbase->flag;
513
514         sce->basact= selbase;
515 }
516
517 /* checks for cycle, returns 1 if it's all OK */
518 int scene_check_setscene(Scene *sce)
519 {
520         Scene *scene;
521         int a, totscene;
522         
523         if(sce->set==NULL) return 1;
524         
525         totscene= 0;
526         for(scene= G.main->scene.first; scene; scene= scene->id.next)
527                 totscene++;
528         
529         for(a=0, scene=sce; scene->set; scene=scene->set, a++) {
530                 /* more iterations than scenes means we have a cycle */
531                 if(a > totscene) {
532                         /* the tested scene gets zero'ed, that's typically current scene */
533                         sce->set= NULL;
534                         return 0;
535                 }
536         }
537
538         return 1;
539 }
540
541 static void scene_update(Scene *sce, unsigned int lay)
542 {
543         Base *base;
544         Object *ob;
545         
546         if(sce->theDag==NULL)
547                 DAG_scene_sort(sce);
548         
549         DAG_scene_update_flags(sce, lay);   // only stuff that moves or needs display still
550         
551         for(base= sce->base.first; base; base= base->next) {
552                 ob= base->object;
553                 
554                 object_handle_update(ob);   // bke_object.h
555                 
556                 /* only update layer when an ipo */
557                 if(ob->ipo && has_ipo_code(ob->ipo, OB_LAY) ) {
558                         base->lay= ob->lay;
559                 }
560         }
561 }
562
563 /* applies changes right away, does all sets too */
564 void scene_update_for_newframe(Scene *sce, unsigned int lay)
565 {
566         Scene *scene= sce;
567         
568         /* clears all BONE_UNKEYED flags for every pose's pchans */
569         framechange_poses_clear_unkeyed();
570         
571         /* object ipos are calculated in where_is_object */
572         do_all_data_ipos();
573         
574         if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
575
576         /* sets first, we allow per definition current scene to have dependencies on sets */
577         for(sce= sce->set; sce; sce= sce->set)
578                 scene_update(sce, lay);
579
580         scene_update(scene, lay);
581 }
582
583 /* return default layer, also used to patch old files */
584 void scene_add_render_layer(Scene *sce)
585 {
586         SceneRenderLayer *srl;
587         int tot= 1 + BLI_countlist(&sce->r.layers);
588         
589         srl= MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
590         sprintf(srl->name, "%d RenderLayer", tot);
591         BLI_addtail(&sce->r.layers, srl);
592
593         /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */
594         srl->lay= (1<<20) -1;
595         srl->layflag= 0x7FFF;   /* solid ztra halo edge strand */
596         srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z;
597 }
598
599 /* Initialize 'permanent' sculpt data that is saved with file kept after
600    switching out of sculptmode. */
601 void sculptdata_init(Scene *sce)
602 {
603         SculptData *sd;
604
605         if(!sce)
606                 return;
607
608         sd= &sce->sculptdata;
609
610         if(sd->cumap) {
611                 curvemapping_free(sd->cumap);
612                 sd->cumap = NULL;
613         }
614
615         memset(sd, 0, sizeof(SculptData));
616
617         sd->drawbrush.size = sd->smoothbrush.size = sd->pinchbrush.size =
618                 sd->inflatebrush.size = sd->grabbrush.size =
619                 sd->layerbrush.size = sd->flattenbrush.size = 50;
620         sd->drawbrush.strength = sd->smoothbrush.strength =
621                 sd->pinchbrush.strength = sd->inflatebrush.strength =
622                 sd->grabbrush.strength = sd->layerbrush.strength =
623                 sd->flattenbrush.strength = 25;
624         sd->drawbrush.dir = sd->pinchbrush.dir = sd->inflatebrush.dir = sd->layerbrush.dir= 1;
625         sd->drawbrush.flag = sd->smoothbrush.flag =
626                 sd->pinchbrush.flag = sd->inflatebrush.flag =
627                 sd->layerbrush.flag = sd->flattenbrush.flag = 0;
628         sd->drawbrush.view= 0;
629         sd->brush_type= DRAW_BRUSH;
630         sd->texact= -1;
631         sd->texfade= 1;
632         sd->averaging= 1;
633         sd->texsep= 0;
634         sd->texrept= SCULPTREPT_DRAG;
635         sd->flags= SCULPT_DRAW_BRUSH;
636         sd->tablet_size=3;
637         sd->tablet_strength=10;
638         sd->rake=0;
639         sculpt_reset_curve(sd);
640 }
641
642 void sculptdata_free(Scene *sce)
643 {
644         SculptData *sd= &sce->sculptdata;
645         int a;
646
647         sculptsession_free(sce);
648
649         for(a=0; a<MAX_MTEX; a++) {
650                 MTex *mtex= sd->mtex[a];
651                 if(mtex) {
652                         if(mtex->tex) mtex->tex->id.us--;
653                         MEM_freeN(mtex);
654                 }
655         }
656
657         curvemapping_free(sd->cumap);
658         sd->cumap = NULL;
659 }
660
661 void sculpt_vertexusers_free(SculptSession *ss)
662 {
663         if(ss && ss->vertex_users){
664                 MEM_freeN(ss->vertex_users);
665                 MEM_freeN(ss->vertex_users_mem);
666                 ss->vertex_users= NULL;
667                 ss->vertex_users_mem= NULL;
668                 ss->vertex_users_size= 0;
669         }
670 }
671
672 void sculptsession_free(Scene *sce)
673 {
674         SculptSession *ss= sce->sculptdata.session;
675         if(ss) {
676                 if(ss->projverts)
677                         MEM_freeN(ss->projverts);
678                 if(ss->mats)
679                         MEM_freeN(ss->mats);
680
681                 if(ss->radialcontrol)
682                         MEM_freeN(ss->radialcontrol);
683
684                 sculpt_vertexusers_free(ss);
685                 if(ss->texcache)
686                         MEM_freeN(ss->texcache);
687                 MEM_freeN(ss);
688                 sce->sculptdata.session= NULL;
689         }
690 }
691
692 /*  Default curve approximates 0.5 * (cos(pi * x) + 1), with 0 <= x <= 1 */
693 void sculpt_reset_curve(SculptData *sd)
694 {
695         CurveMap *cm = NULL;
696
697         if(!sd->cumap)
698                 sd->cumap = curvemapping_add(1, 0, 0, 1, 1);
699
700         cm = sd->cumap->cm;
701
702         if(cm->curve)
703                 MEM_freeN(cm->curve);
704         cm->curve= MEM_callocN(6*sizeof(CurveMapPoint), "curve points");
705         cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
706         cm->totpoint= 6;
707         cm->curve[0].x= 0;
708         cm->curve[0].y= 1;
709         cm->curve[1].x= 0.1;
710         cm->curve[1].y= 0.97553;
711         cm->curve[2].x= 0.3;
712         cm->curve[2].y= 0.79389;
713         cm->curve[3].x= 0.9;
714         cm->curve[3].y= 0.02447;
715         cm->curve[4].x= 0.7;
716         cm->curve[4].y= 0.20611;
717         cm->curve[5].x= 1;
718         cm->curve[5].y= 0;
719
720         curvemapping_changed(sd->cumap, 0);
721 }
722
723 /* render simplification */
724
725 int get_render_subsurf_level(RenderData *r, int lvl)
726 {
727         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
728                 return MIN2(r->simplify_subsurf, lvl);
729         else
730                 return lvl;
731 }
732
733 int get_render_child_particle_number(RenderData *r, int num)
734 {
735         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
736                 return (int)(r->simplify_particles*num);
737         else
738                 return num;
739 }
740
741 int get_render_shadow_samples(RenderData *r, int samples)
742 {
743         if(G.rt == 1 && (r->mode & R_SIMPLIFY) && samples > 0)
744                 return MIN2(r->simplify_shadowsamples, samples);
745         else
746                 return samples;
747 }
748
749 float get_render_aosss_error(RenderData *r, float error)
750 {
751         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
752                 return ((1.0f-r->simplify_aosss)*10.0f + 1.0f)*error;
753         else
754                 return error;
755 }
756