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