svn merge -r 15688:15908 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender-staging.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         
192         sce->r.mode= R_GAMMA;
193         sce->r.cfra= 1;
194         sce->r.sfra= 1;
195         sce->r.efra= 250;
196         sce->r.xsch= 320;
197         sce->r.ysch= 256;
198         sce->r.xasp= 1;
199         sce->r.yasp= 1;
200         sce->r.xparts= 4;
201         sce->r.yparts= 4;
202         sce->r.size= 100;
203         sce->r.planes= 24;
204         sce->r.quality= 90;
205         sce->r.framapto= 100;
206         sce->r.images= 100;
207         sce->r.framelen= 1.0;
208         sce->r.frs_sec= 25;
209         sce->r.frs_sec_base= 1;
210         sce->r.ocres = 128;
211         
212         sce->r.bake_mode= 1;    /* prevent to include render stuff here */
213         sce->r.bake_filter= 2;
214         sce->r.bake_osa= 5;
215         sce->r.bake_flag= R_BAKE_CLEAR;
216         sce->r.bake_normal_space= R_BAKE_SPACE_TANGENT;
217         
218         sce->r.xplay= 640;
219         sce->r.yplay= 480;
220         sce->r.freqplay= 60;
221         sce->r.depth= 32;
222         
223         sce->r.threads= 1;
224         
225         sce->r.stereomode = 1;  // no stereo
226
227         sce->r.simplify_subsurf= 6;
228         sce->r.simplify_particles= 1.0f;
229         sce->r.simplify_shadowsamples= 16;
230         sce->r.simplify_aosss= 1.0f;
231
232         sce->r.cineonblack= 95;
233         sce->r.cineonwhite= 685;
234         sce->r.cineongamma= 1.7f;
235         
236         sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings),"Tool Settings Struct");
237         sce->toolsettings->cornertype=1;
238         sce->toolsettings->degr = 90; 
239         sce->toolsettings->step = 9;
240         sce->toolsettings->turn = 1;                            
241         sce->toolsettings->extr_offs = 1; 
242         sce->toolsettings->doublimit = 0.001;
243         sce->toolsettings->segments = 32;
244         sce->toolsettings->rings = 32;
245         sce->toolsettings->vertices = 32;
246         sce->toolsettings->editbutflag = 1;
247         sce->toolsettings->uvcalc_radius = 1.0f;
248         sce->toolsettings->uvcalc_cubesize = 1.0f;
249         sce->toolsettings->uvcalc_mapdir = 1;
250         sce->toolsettings->uvcalc_mapalign = 1;
251         sce->toolsettings->unwrapper = 1;
252         sce->toolsettings->select_thresh= 0.01f;
253         sce->toolsettings->jointrilimit = 0.8f;
254
255         pset= &sce->toolsettings->particle;
256         pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
257         pset->emitterdist= 0.25f;
258         pset->totrekey= 5;
259         pset->totaddkey= 5;
260         pset->brushtype= PE_BRUSH_NONE;
261         for(a=0; a<PE_TOT_BRUSH; a++) {
262                 pset->brush[a].strength= 50;
263                 pset->brush[a].size= 50;
264                 pset->brush[a].step= 10;
265         }
266         pset->brush[PE_BRUSH_CUT].strength= 100;
267         
268         sce->jumpframe = 10;
269         sce->audio.mixrate = 44100;
270
271         strcpy(sce->r.backbuf, "//backbuf");
272         strcpy(sce->r.pic, U.renderdir);
273
274         BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
275         sce->r.osa= 8;
276
277         sculptdata_init(sce);
278
279         /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
280         scene_add_render_layer(sce);
281         
282         return sce;
283 }
284
285 Base *object_in_scene(Object *ob, Scene *sce)
286 {
287         Base *base;
288         
289         base= sce->base.first;
290         while(base) {
291                 if(base->object == ob) return base;
292                 base= base->next;
293         }
294         return NULL;
295 }
296
297 void set_scene_bg(Scene *sce)
298 {
299         Base *base;
300         Object *ob;
301         Group *group;
302         GroupObject *go;
303         int flag;
304         
305         // Note: this here is defined in editseq.c (BIF_editseq.h), NOT in blenkernel! 
306         clear_last_seq();
307         
308         G.scene= sce;
309         
310         /* check for cyclic sets, for reading old files but also for definite security (py?) */
311         scene_check_setscene(G.scene);
312         
313         /* deselect objects (for dataselect) */
314         for(ob= G.main->object.first; ob; ob= ob->id.next)
315                 ob->flag &= ~(SELECT|OB_FROMGROUP);
316
317         /* group flags again */
318         for(group= G.main->group.first; group; group= group->id.next) {
319                 go= group->gobject.first;
320                 while(go) {
321                         if(go->ob) go->ob->flag |= OB_FROMGROUP;
322                         go= go->next;
323                 }
324         }
325
326         /* sort baselist */
327         DAG_scene_sort(sce);
328         
329         /* ensure dags are built for sets */
330         for(sce= sce->set; sce; sce= sce->set)
331                 if(sce->theDag==NULL)
332                         DAG_scene_sort(sce);
333
334         /* copy layers and flags from bases to objects */
335         for(base= G.scene->base.first; base; base= base->next) {
336                 ob= base->object;
337                 ob->lay= base->lay;
338                 
339                 /* group patch... */
340                 base->flag &= ~(OB_FROMGROUP);
341                 flag= ob->flag & (OB_FROMGROUP);
342                 base->flag |= flag;
343                 
344                 /* not too nice... for recovering objects with lost data */
345                 if(ob->pose==NULL) base->flag &= ~OB_POSEMODE;
346                 ob->flag= base->flag;
347                 
348                 ob->ctime= -1234567.0;  /* force ipo to be calculated later */
349         }
350         /* no full animation update, this to enable render code to work (render code calls own animation updates) */
351         
352         /* do we need FRAMECHANGED in set_scene? */
353 //      if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
354 }
355
356 /* called from creator.c */
357 void set_scene_name(char *name)
358 {
359         Scene *sce;
360
361         for (sce= G.main->scene.first; sce; sce= sce->id.next) {
362                 if (BLI_streq(name, sce->id.name+2)) {
363                         set_scene_bg(sce);
364                         return;
365                 }
366         }
367         
368         error("Can't find scene: %s", name);
369 }
370
371 /* used by metaballs
372  * doesnt return the original duplicated object, only dupli's
373  */
374 int next_object(int val, Base **base, Object **ob)
375 {
376         static ListBase *duplilist= NULL;
377         static DupliObject *dupob;
378         static int fase;
379         int run_again=1;
380         
381         /* init */
382         if(val==0) {
383                 fase= F_START;
384                 dupob= NULL;
385         }
386         else {
387
388                 /* run_again is set when a duplilist has been ended */
389                 while(run_again) {
390                         run_again= 0;
391
392                         /* the first base */
393                         if(fase==F_START) {
394                                 *base= G.scene->base.first;
395                                 if(*base) {
396                                         *ob= (*base)->object;
397                                         fase= F_SCENE;
398                                 }
399                                 else {
400                                     /* exception: empty scene */
401                                         if(G.scene->set && G.scene->set->base.first) {
402                                                 *base= G.scene->set->base.first;
403                                                 *ob= (*base)->object;
404                                                 fase= F_SET;
405                                         }
406                                 }
407                         }
408                         else {
409                                 if(*base && fase!=F_DUPLI) {
410                                         *base= (*base)->next;
411                                         if(*base) *ob= (*base)->object;
412                                         else {
413                                                 if(fase==F_SCENE) {
414                                                         /* scene is finished, now do the set */
415                                                         if(G.scene->set && G.scene->set->base.first) {
416                                                                 *base= G.scene->set->base.first;
417                                                                 *ob= (*base)->object;
418                                                                 fase= F_SET;
419                                                         }
420                                                 }
421                                         }
422                                 }
423                         }
424                         
425                         if(*base == NULL) fase= F_START;
426                         else {
427                                 if(fase!=F_DUPLI) {
428                                         if( (*base)->object->transflag & OB_DUPLI) {
429                                                 /* groups cannot be duplicated for mballs yet, 
430                                                 this enters eternal loop because of 
431                                                 makeDispListMBall getting called inside of group_duplilist */
432                                                 if((*base)->object->dup_group == NULL) {
433                                                         duplilist= object_duplilist(G.scene, (*base)->object);
434                                                         
435                                                         dupob= duplilist->first;
436
437                                                         if(!dupob)
438                                                                 free_object_duplilist(duplilist);
439                                                 }
440                                         }
441                                 }
442                                 /* handle dupli's */
443                                 if(dupob) {
444                                         
445                                         Mat4CpyMat4(dupob->ob->obmat, dupob->mat);
446                                         
447                                         (*base)->flag |= OB_FROMDUPLI;
448                                         *ob= dupob->ob;
449                                         fase= F_DUPLI;
450                                         
451                                         dupob= dupob->next;
452                                 }
453                                 else if(fase==F_DUPLI) {
454                                         fase= F_SCENE;
455                                         (*base)->flag &= ~OB_FROMDUPLI;
456                                         
457                                         for(dupob= duplilist->first; dupob; dupob= dupob->next) {
458                                                 Mat4CpyMat4(dupob->ob->obmat, dupob->omat);
459                                         }
460                                         
461                                         free_object_duplilist(duplilist);
462                                         duplilist= NULL;
463                                         run_again= 1;
464                                 }
465                         }
466                 }
467         }
468         
469         return fase;
470 }
471
472 Object *scene_find_camera(Scene *sc)
473 {
474         Base *base;
475         
476         for (base= sc->base.first; base; base= base->next)
477                 if (base->object->type==OB_CAMERA)
478                         return base->object;
479
480         return NULL;
481 }
482
483
484 Base *scene_add_base(Scene *sce, Object *ob)
485 {
486         Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
487         BLI_addhead(&sce->base, b);
488
489         b->object= ob;
490         b->flag= ob->flag;
491         b->lay= ob->lay;
492
493         return b;
494 }
495
496 void scene_deselect_all(Scene *sce)
497 {
498         Base *b;
499
500         for (b= sce->base.first; b; b= b->next) {
501                 b->flag&= ~SELECT;
502                 b->object->flag= b->flag;
503         }
504 }
505
506 void scene_select_base(Scene *sce, Base *selbase)
507 {
508         scene_deselect_all(sce);
509
510         selbase->flag |= SELECT;
511         selbase->object->flag= selbase->flag;
512
513         sce->basact= selbase;
514 }
515
516 /* checks for cycle, returns 1 if it's all OK */
517 int scene_check_setscene(Scene *sce)
518 {
519         Scene *scene;
520         int a, totscene;
521         
522         if(sce->set==NULL) return 1;
523         
524         totscene= 0;
525         for(scene= G.main->scene.first; scene; scene= scene->id.next)
526                 totscene++;
527         
528         for(a=0, scene=sce; scene->set; scene=scene->set, a++) {
529                 /* more iterations than scenes means we have a cycle */
530                 if(a > totscene) {
531                         /* the tested scene gets zero'ed, that's typically current scene */
532                         sce->set= NULL;
533                         return 0;
534                 }
535         }
536
537         return 1;
538 }
539
540 static void scene_update(Scene *sce, unsigned int lay)
541 {
542         Base *base;
543         Object *ob;
544         
545         if(sce->theDag==NULL)
546                 DAG_scene_sort(sce);
547         
548         DAG_scene_update_flags(sce, lay);   // only stuff that moves or needs display still
549         
550         for(base= sce->base.first; base; base= base->next) {
551                 ob= base->object;
552                 
553                 object_handle_update(ob);   // bke_object.h
554                 
555                 /* only update layer when an ipo */
556                 if(ob->ipo && has_ipo_code(ob->ipo, OB_LAY) ) {
557                         base->lay= ob->lay;
558                 }
559         }
560 }
561
562 /* applies changes right away, does all sets too */
563 void scene_update_for_newframe(Scene *sce, unsigned int lay)
564 {
565         Scene *scene= sce;
566         
567         /* clears all BONE_UNKEYED flags for every pose's pchans */
568         framechange_poses_clear_unkeyed();
569         
570         /* object ipos are calculated in where_is_object */
571         do_all_data_ipos();
572         
573         if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
574         
575         /* sets first, we allow per definition current scene to have dependencies on sets */
576         for(sce= sce->set; sce; sce= sce->set)
577                 scene_update(sce, lay);
578
579         scene_update(scene, lay);
580 }
581
582 /* return default layer, also used to patch old files */
583 void scene_add_render_layer(Scene *sce)
584 {
585         SceneRenderLayer *srl;
586         int tot= 1 + BLI_countlist(&sce->r.layers);
587         
588         srl= MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
589         sprintf(srl->name, "%d RenderLayer", tot);
590         BLI_addtail(&sce->r.layers, srl);
591
592         /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */
593         srl->lay= (1<<20) -1;
594         srl->layflag= 0x7FFF;   /* solid ztra halo edge strand */
595         srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z;
596 }
597
598 /* Initialize 'permanent' sculpt data that is saved with file kept after
599    switching out of sculptmode. */
600 void sculptdata_init(Scene *sce)
601 {
602         SculptData *sd;
603
604         if(!sce)
605                 return;
606
607         sd= &sce->sculptdata;
608
609         if(sd->cumap) {
610                 curvemapping_free(sd->cumap);
611                 sd->cumap = NULL;
612         }
613
614         memset(sd, 0, sizeof(SculptData));
615
616         sd->drawbrush.size = sd->smoothbrush.size = sd->pinchbrush.size =
617                 sd->inflatebrush.size = sd->grabbrush.size =
618                 sd->layerbrush.size = sd->flattenbrush.size = 50;
619         sd->drawbrush.strength = sd->smoothbrush.strength =
620                 sd->pinchbrush.strength = sd->inflatebrush.strength =
621                 sd->grabbrush.strength = sd->layerbrush.strength =
622                 sd->flattenbrush.strength = 25;
623         sd->drawbrush.dir = sd->pinchbrush.dir = sd->inflatebrush.dir = sd->layerbrush.dir= 1;
624         sd->drawbrush.flag = sd->smoothbrush.flag =
625                 sd->pinchbrush.flag = sd->inflatebrush.flag =
626                 sd->layerbrush.flag = sd->flattenbrush.flag = 0;
627         sd->drawbrush.view= 0;
628         sd->brush_type= DRAW_BRUSH;
629         sd->texact= -1;
630         sd->texfade= 1;
631         sd->averaging= 1;
632         sd->texsep= 0;
633         sd->texrept= SCULPTREPT_DRAG;
634         sd->flags= SCULPT_DRAW_BRUSH;
635         sd->tablet_size=3;
636         sd->tablet_strength=10;
637         sd->rake=0;
638         sculpt_reset_curve(sd);
639 }
640
641 void sculptdata_free(Scene *sce)
642 {
643         SculptData *sd= &sce->sculptdata;
644         int a;
645
646         sculptsession_free(sce);
647
648         for(a=0; a<MAX_MTEX; a++) {
649                 MTex *mtex= sd->mtex[a];
650                 if(mtex) {
651                         if(mtex->tex) mtex->tex->id.us--;
652                         MEM_freeN(mtex);
653                 }
654         }
655
656         curvemapping_free(sd->cumap);
657         sd->cumap = NULL;
658 }
659
660 void sculpt_vertexusers_free(SculptSession *ss)
661 {
662         if(ss && ss->vertex_users){
663                 MEM_freeN(ss->vertex_users);
664                 MEM_freeN(ss->vertex_users_mem);
665                 ss->vertex_users= NULL;
666                 ss->vertex_users_mem= NULL;
667                 ss->vertex_users_size= 0;
668         }
669 }
670
671 void sculptsession_free(Scene *sce)
672 {
673         SculptSession *ss= sce->sculptdata.session;
674         if(ss) {
675                 if(ss->projverts)
676                         MEM_freeN(ss->projverts);
677                 if(ss->mats)
678                         MEM_freeN(ss->mats);
679
680                 if(ss->radialcontrol)
681                         MEM_freeN(ss->radialcontrol);
682
683                 sculpt_vertexusers_free(ss);
684                 if(ss->texcache)
685                         MEM_freeN(ss->texcache);
686                 MEM_freeN(ss);
687                 sce->sculptdata.session= NULL;
688         }
689 }
690
691 /*  Default curve approximates 0.5 * (cos(pi * x) + 1), with 0 <= x <= 1 */
692 void sculpt_reset_curve(SculptData *sd)
693 {
694         CurveMap *cm = NULL;
695
696         if(!sd->cumap)
697                 sd->cumap = curvemapping_add(1, 0, 0, 1, 1);
698
699         cm = sd->cumap->cm;
700
701         if(cm->curve)
702                 MEM_freeN(cm->curve);
703         cm->curve= MEM_callocN(6*sizeof(CurveMapPoint), "curve points");
704         cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
705         cm->totpoint= 6;
706         cm->curve[0].x= 0;
707         cm->curve[0].y= 1;
708         cm->curve[1].x= 0.1;
709         cm->curve[1].y= 0.97553;
710         cm->curve[2].x= 0.3;
711         cm->curve[2].y= 0.79389;
712         cm->curve[3].x= 0.9;
713         cm->curve[3].y= 0.02447;
714         cm->curve[4].x= 0.7;
715         cm->curve[4].y= 0.20611;
716         cm->curve[5].x= 1;
717         cm->curve[5].y= 0;
718
719         curvemapping_changed(sd->cumap, 0);
720 }
721
722 /* render simplification */
723
724 int get_render_subsurf_level(RenderData *r, int lvl)
725 {
726         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
727                 return MIN2(r->simplify_subsurf, lvl);
728         else
729                 return lvl;
730 }
731
732 int get_render_child_particle_number(RenderData *r, int num)
733 {
734         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
735                 return (int)(r->simplify_particles*num);
736         else
737                 return num;
738 }
739
740 int get_render_shadow_samples(RenderData *r, int samples)
741 {
742         if(G.rt == 1 && (r->mode & R_SIMPLIFY) && samples > 0)
743                 return MIN2(r->simplify_shadowsamples, samples);
744         else
745                 return samples;
746 }
747
748 float get_render_aosss_error(RenderData *r, float error)
749 {
750         if(G.rt == 1 && (r->mode & R_SIMPLIFY))
751                 return ((1.0f-r->simplify_aosss)*10.0f + 1.0f)*error;
752         else
753                 return error;
754 }
755