Merged changes in the trunk up to revision 39896.
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sat, 3 Sep 2011 21:30:40 +0000 (21:30 +0000)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sat, 3 Sep 2011 21:30:40 +0000 (21:30 +0000)
1  2 
source/blender/editors/animation/anim_filter.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/shadeoutput.c

index 3cfe3f6094cd876ae158b74da02b18828c0988a8,bb710a3279420bef13fb01152246db120960f81b..1ecf4259d6bb6fc73edb5bdb0cc0316805029b43
@@@ -55,7 -55,6 +55,7 @@@
  #include "DNA_camera_types.h"
  #include "DNA_lamp_types.h"
  #include "DNA_lattice_types.h"
 +#include "DNA_linestyle_types.h"
  #include "DNA_key_types.h"
  #include "DNA_material_types.h"
  #include "DNA_mesh_types.h"
@@@ -696,19 -695,6 +696,19 @@@ static bAnimListElem *make_new_animlist
                                ale->key_data= (adt) ? adt->action : NULL;
                                ale->datatype= ALE_ACT;
                                
 +                              ale->adt= BKE_animdata_from_id(data);
 +                      }
 +                              break;
 +                      case ANIMTYPE_DSLINESTYLE:
 +                      {
 +                              FreestyleLineStyle *linestyle= (FreestyleLineStyle *)data;
 +                              AnimData *adt= linestyle->adt;
 +                              
 +                              ale->flag= FILTER_LS_SCED(linestyle); 
 +                              
 +                              ale->key_data= (adt) ? adt->action : NULL;
 +                              ale->datatype= ALE_ACT;
 +                              
                                ale->adt= BKE_animdata_from_id(data);
                        }
                                break;
@@@ -1191,29 -1177,34 +1191,34 @@@ static size_t animfilter_nla (bAnimCont
  /* determine what animation data from AnimData block should get displayed */
  static size_t animfilter_block_data (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *id, int filter_mode)
  {
-       IdAdtTemplate *iat = (IdAdtTemplate*)id;
        AnimData *adt = BKE_animdata_from_id(id);
        size_t items = 0;
-       
-       /* NOTE: this macro is used instead of inlining the logic here, since this sort of filtering is still needed 
-        * in a few places in he rest of the code still - notably for the few cases where special mode-based 
-        * different types of data expanders are required.
-        */
-       ANIMDATA_FILTER_CASES(iat,
-               { /* AnimData */
-                       /* specifically filter animdata block */
-                       ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_ANIMDATA, id);
-               },
-               { /* NLA */
-                       items += animfilter_nla(ac, anim_data, ads, adt, filter_mode, id); 
-               },
-               { /* Drivers */
-                       items += animfilter_fcurves(anim_data, ads, adt->drivers.first, NULL, filter_mode, id);
-               },
-               { /* Keyframes */
-                       items += animfilter_action(ac, anim_data, ads, adt->action, filter_mode, id);
-               });
-       
+       /* image object datablocks have no anim-data so check for NULL */
+       if(adt) {
+               IdAdtTemplate *iat = (IdAdtTemplate*)id;
+               /* NOTE: this macro is used instead of inlining the logic here, since this sort of filtering is still needed
+                * in a few places in he rest of the code still - notably for the few cases where special mode-based
+                * different types of data expanders are required.
+                */
+               ANIMDATA_FILTER_CASES(iat,
+                       { /* AnimData */
+                               /* specifically filter animdata block */
+                               ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_ANIMDATA, id);
+                       },
+                       { /* NLA */
+                               items += animfilter_nla(ac, anim_data, ads, adt, filter_mode, id);
+                       },
+                       { /* Drivers */
+                               items += animfilter_fcurves(anim_data, ads, adt->drivers.first, NULL, filter_mode, id);
+                       },
+                       { /* Keyframes */
+                               items += animfilter_action(ac, anim_data, ads, adt->action, filter_mode, id);
+                       }
+               );
+       }
        return items;
  }
  
@@@ -1365,54 -1356,6 +1370,54 @@@ static size_t animdata_filter_ds_nodetr
        return items;
  }
  
 +static size_t animdata_filter_ds_linestyle (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
 +{
 +      SceneRenderLayer *srl;
 +      size_t items = 0;
 +
 +      for (srl= sce->r.layers.first; srl; srl= srl->next) {
 +              FreestyleLineSet *lineset;
 +
 +              /* skip render layers without Freestyle enabled */
 +              if (!(srl->layflag & SCE_LAY_FRS))
 +                      continue;
 +
 +              /* loop over linesets defined in the render layer */
 +              for (lineset= srl->freestyleConfig.linesets.first; lineset; lineset= lineset->next) {
 +                      FreestyleLineStyle *linestyle = lineset->linestyle;
 +                      ListBase tmp_data = {NULL, NULL};
 +                      size_t tmp_items = 0;
 +
 +                      /* add scene-level animation channels */
 +                      BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_LS_SCED(linestyle))
 +                      {
 +                              /* animation data filtering */
 +                              tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)linestyle, filter_mode);
 +                      }
 +                      END_ANIMFILTER_SUBCHANNELS;
 +
 +                      /* did we find anything? */
 +                      if (tmp_items) {
 +                              /* include anim-expand widget first */
 +                              if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
 +                                      /* check if filtering by active status */
 +                                      if ANIMCHANNEL_ACTIVEOK(linestyle) {
 +                                              ANIMCHANNEL_NEW_CHANNEL(linestyle, ANIMTYPE_DSLINESTYLE, sce);
 +                                      }
 +                              }
 +                              
 +                              /* now add the list of collected channels */
 +                              BLI_movelisttolist(anim_data, &tmp_data);
 +                              BLI_assert((tmp_data.first == tmp_data.last) && (tmp_data.first == NULL));
 +                              items += tmp_items;
 +                      }
 +              }
 +      }
 +      
 +      /* return the number of items added to the list */
 +      return items;
 +}
 +
  /* NOTE: owner_id is either material, lamp, or world block, which is the direct owner of the texture stack in question */
  static size_t animdata_filter_ds_textures (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, int filter_mode)
  {
@@@ -2004,11 -1947,6 +2009,11 @@@ static size_t animdata_filter_dopesheet
                if ((ntree && ntree->adt) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
                        tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)sce, ntree, filter_mode);
                }
 +
 +              /* line styles */
 +              if ((ads->filterflag & ADS_FILTER_NOLINESTYLE) == 0) {
 +                      tmp_items += animdata_filter_ds_linestyle(ac, &tmp_data, ads, sce, filter_mode);
 +              }
                
                // TODO: one day, when sequencer becomes its own datatype, perhaps it should be included here
        }
index ba149efd8d33b0fb2a47c3a618c8f34c06e8dccd,49e5e7b989d4f76f28cf7de89bf3e28662c89ed9..6f1df7fa0b7b169b3f919fb9c878a39d7080f1fd
@@@ -50,7 -50,6 +50,7 @@@
  #include "BKE_animsys.h"      /* <------ should this be here?, needed for sequencer update */
  #include "BKE_global.h"
  #include "BKE_image.h"
 +#include "BKE_library.h"
  #include "BKE_main.h"
  #include "BKE_node.h"
  #include "BKE_object.h"
@@@ -76,9 -75,6 +76,9 @@@
  
  #include "RE_pipeline.h"
  
 +#include "FRS_freestyle.h"
 +#include "FRS_freestyle_config.h"
 +
  /* internal */
  #include "render_types.h"
  #include "renderpipeline.h"
@@@ -178,7 -174,7 +178,7 @@@ static void stats_background(void *UNUS
                        fprintf(stdout, "Sce: %s Ve:%d Fa:%d La:%d", rs->scenename, rs->totvert, rs->totface, rs->totlamp);
        }
  
-       BLI_exec_cb(rs, (ID *)rs, BLI_CB_EVT_RENDER_STATS);
+       BLI_exec_cb(G.main, NULL, BLI_CB_EVT_RENDER_STATS);
  
        fputc('\n', stdout);
        fflush(stdout);
@@@ -645,9 -641,9 +645,9 @@@ static RenderResult *new_render_result(
                        render_layer_add_pass(rr, rl, 3, SCE_PASS_REFRACT);
                if(srl->passflag  & SCE_PASS_INDEXOB)
                        render_layer_add_pass(rr, rl, 1, SCE_PASS_INDEXOB);
-                 if(srl->passflag  & SCE_PASS_INDEXMA)
-                         render_layer_add_pass(rr, rl, 1, SCE_PASS_INDEXMA);
-                 if(srl->passflag  & SCE_PASS_MIST)
+               if(srl->passflag  & SCE_PASS_INDEXMA)
+                       render_layer_add_pass(rr, rl, 1, SCE_PASS_INDEXMA);
+               if(srl->passflag  & SCE_PASS_MIST)
                        render_layer_add_pass(rr, rl, 1, SCE_PASS_MIST);
                if(rl->passflag & SCE_PASS_RAYHITS)
                        render_layer_add_pass(rr, rl, 4, SCE_PASS_RAYHITS);
                rl->lay= (1<<20) -1;
                rl->layflag= 0x7FFF;    /* solid ztra halo strand */
                rl->passflag= SCE_PASS_COMBINED;
 +              FRS_add_freestyle_config( srl );
                
                re->r.actlay= 0;
        }
@@@ -1579,7 -1574,7 +1579,7 @@@ static RenderPart *find_next_pano_slice
  
                R.panodxp= (re->winx - (best->disprect.xmin + best->disprect.xmax) )/2;
                R.panodxv= ((viewplane->xmax-viewplane->xmin)*R.panodxp)/(float)(re->winx);
 -
 +              
                /* shift viewplane */
                R.viewplane.xmin = viewplane->xmin + R.panodxv;
                R.viewplane.xmax = viewplane->xmax + R.panodxv;
@@@ -1815,7 -1810,6 +1815,7 @@@ void RE_TileProcessor(Render *re
  /* ************  This part uses API, for rendering Blender scenes ********** */
  
  static int external_render_3d(Render *re, int do_all);
 +static void add_freestyle(Render *re);
  
  static void do_render_3d(Render *re)
  {
                if(!re->test_break(re->tbh))
                        add_halo_flare(re);
        
 +      /* Freestyle  */
 +      if( re->r.mode & R_EDGE_FRS && re->r.renderer==R_INTERN)
 +              if(!re->test_break(re->tbh))
 +                      add_freestyle(re);
 +              
        /* free all render verts etc */
        RE_Database_Free(re);
        
@@@ -2290,66 -2279,6 +2290,66 @@@ static void render_composit_stats(void 
  }
  
  
 +/* invokes Freestyle stroke rendering */
 +static void add_freestyle(Render *re)
 +{
 +      SceneRenderLayer *srl;
 +      LinkData *link;
 +
 +      FRS_init_stroke_rendering(re);
 +
 +      for(srl= (SceneRenderLayer *)re->scene->r.layers.first; srl; srl= srl->next) {
 +
 +              link = (LinkData *)MEM_callocN(sizeof(LinkData), "LinkData to Freestyle render");
 +              BLI_addtail(&re->freestyle_renders, link);
 +
 +              if( FRS_is_freestyle_enabled(srl) ) {
 +                      link->data = (void *)FRS_do_stroke_rendering(re, srl);
 +              }
 +      }
 +
 +      FRS_finish_stroke_rendering(re);
 +}
 +
 +/* merges the results of Freestyle stroke rendering into a given render result */
 +static void composite_freestyle_renders(Render *re, int sample)
 +{
 +      Render *freestyle_render;
 +      SceneRenderLayer *srl;
 +      LinkData *link;
 +
 +      link = (LinkData *)re->freestyle_renders.first;
 +      for(srl= (SceneRenderLayer *)re->scene->r.layers.first; srl; srl= srl->next) {
 +              if( FRS_is_freestyle_enabled(srl) ) {
 +                      freestyle_render = (Render *)link->data;
 +                      read_render_result(freestyle_render, sample);
 +                      FRS_composite_result(re, srl, freestyle_render);
 +                      RE_FreeRenderResult(freestyle_render->result);
 +                      freestyle_render->result = NULL;
 +              }
 +              link = link->next;
 +      }
 +}
 +
 +/* releases temporary scenes and renders for Freestyle stroke rendering */
 +static void free_all_freestyle_renders(void)
 +{
 +      Render *re1, *freestyle_render;
 +      LinkData *link;
 +
 +      for(re1= RenderGlobal.renderlist.first; re1; re1= re1->next) {
 +              for (link = (LinkData *)re1->freestyle_renders.first; link; link = link->next) {
 +                      if (link->data) {
 +                              freestyle_render = (Render *)link->data;
 +                              free_libblock(&G.main->scene, freestyle_render->scene);
 +                              RE_FreeRender(freestyle_render);
 +                      }
 +              }
 +              BLI_freelistN( &re1->freestyle_renders );
 +      }
 +}
 +
 +
  /* reads all buffers, calls optional composite, merges in first result->rectf */
  static void do_merge_fullsample(Render *re, bNodeTree *ntree)
  {
                for(re1= RenderGlobal.renderlist.first; re1; re1= re1->next) {
                        if(re1->scene->id.flag & LIB_DOIT) {
                                if(re1->r.scemode & R_FULL_SAMPLE) {
 -                                      if(sample)
 +                                      if(sample) {
                                                read_render_result(re1, sample);
 +                                              composite_freestyle_renders(re1, sample);
 +                                      }
                                        ntreeCompositTagRender(re1->scene); /* ensure node gets exec to put buffers on stack */
                                }
                        }
@@@ -2575,8 -2502,6 +2575,8 @@@ static void do_render_composite_fields_
                        do_merge_fullsample(re, NULL);
        }
  
 +      free_all_freestyle_renders();
 +
        /* weak... the display callback wants an active renderlayer pointer... */
        re->result->renlay= render_get_active_layer(re, re->result);
        re->display_draw(re->ddh, re->result, NULL);
@@@ -3024,7 -2949,7 +3024,7 @@@ void RE_BlenderFrame(Render *re, Main *
                BLI_exec_cb(re->main, (ID *)scene, BLI_CB_EVT_RENDER_PRE);
  
                do_render_all_options(re);
 -
 +              
                if(write_still && !G.afbreek) {
                        if(BKE_imtype_is_movie(scene->r.imtype)) {
                                /* operator checks this but incase its called from elsewhere */
        G.rendering= 0;
  }
  
 +void RE_RenderFreestyleStrokes(Render *re, Main *bmain, Scene *scene)
 +{
 +      re->result_ok= 0;
 +      if(render_initialize_from_main(re, bmain, scene, NULL, NULL, scene->lay, 0, 0)) {
 +              do_render_fields_blur_3d(re);
 +      }
 +      re->result_ok= 1;
 +}
 +
  static int do_write_image_or_movie(Render *re, Scene *scene, bMovieHandle *mh, const char *name_override)
  {
        char name[FILE_MAX];
index 8b5ae479f641e2fa1322bc799c4e6649b5d70c1f,30632586b04ac608e827f24282a739839ea8b16c..201bec541a8732a3b42bf49233e1ab39dca74633
@@@ -282,10 -282,10 +282,10 @@@ static void spothalo(struct LampRen *la
                else if(ok1==0 || ok2==0) return;
                
                /* at least 1 visible interesction point */
-               if(t1<0.0f && t2<0.0f) return;
+               if(t1<0.0 && t2<0.0) return;
                
-               if(t1<0.0f) t1= 0.0f;
-               if(t2<0.0f) t2= 0.0f;
+               if(t1<0.0) t1= 0.0;
+               if(t2<0.0) t2= 0.0;
                
                if(t1==t2) return;
                
@@@ -423,8 -423,8 +423,8 @@@ float fresnel_fac(float *view, float *v
  
  static double saacos_d(double fac)
  {
-       if(fac<= -1.0f) return M_PI;
-       else if(fac>=1.0f) return 0.0;
+       if(fac<= -1.0) return M_PI;
+       else if(fac>=1.0) return 0.0;
        else return acos(fac);
  }
  
@@@ -590,7 -590,7 +590,7 @@@ static float CookTorr_Spec(float *n, fl
  
        i= spec(nh, hard);
  
-       i= i/(0.1+nv);
+       i= i/(0.1f+nv);
        return i;
  }
  
@@@ -896,7 -896,7 +896,7 @@@ static void ramp_diffuse_result(float *
        if(ma->ramp_col) {
                if(ma->rampin_col==MA_RAMP_IN_RESULT) {
                        
-                       fac= 0.3*diff[0] + 0.58*diff[1] + 0.12*diff[2];
+                       fac= 0.3f*diff[0] + 0.58f*diff[1] + 0.12f*diff[2];
                        do_colorband(ma->ramp_col, fac, col);
                        
                        /* blending method */
@@@ -926,7 -926,7 +926,7 @@@ static void add_to_diffuse(float *diff
                        /* input */
                        switch(ma->rampin_col) {
                        case MA_RAMP_IN_ENERGY:
-                               fac= 0.3*r + 0.58*g + 0.12*b;
+                               fac= 0.3f*r + 0.58f*g + 0.12f*b;
                                break;
                        case MA_RAMP_IN_SHADER:
                                fac= is;
@@@ -966,7 -966,7 +966,7 @@@ static void ramp_spec_result(float *spe
        float fac;
        
        if(ma->ramp_spec && (ma->rampin_spec==MA_RAMP_IN_RESULT)) {
-               fac= 0.3*(*specr) + 0.58*(*specg) + 0.12*(*specb);
+               fac= 0.3f*(*specr) + 0.58f*(*specg) + 0.12f*(*specb);
                do_colorband(ma->ramp_spec, fac, col);
                
                /* blending method */
@@@ -1213,7 -1213,7 +1213,7 @@@ float lamp_get_visibility(LampRen *lar
                                }
                        }
                }
-               if (visifac <= 0.001) visifac = 0.0f;
+               if (visifac <= 0.001f) visifac = 0.0f;
                return visifac;
        }
  }
@@@ -1231,7 -1231,7 +1231,7 @@@ static void shade_one_light(LampRen *la
        view= shi->view;
        
        
-       if (lar->energy == 0.0) return;
+       if (lar->energy == 0.0f) return;
        /* only shadow lamps shouldn't affect shadow-less materials at all */
        if ((lar->mode & LA_ONLYSHADOW) && (!(ma->mode & MA_SHADOW) || !(R.r.mode & R_SHADOW)))
                return;
        
        /* 'is' is diffuse */
        if((ma->shade_flag & MA_CUBIC) && is>0.0f && is<1.0f)
-               is= 3.0*is*is - 2.0*is*is*is;   // nicer termination of shades
+               is= 3.0f*is*is - 2.0f*is*is*is; // nicer termination of shades
  
        i= is*phongcorr;
        
                                                lamp_get_shadow(lar, shi, inp, shadfac, shi->depth);
                                                
                                        /* warning, here it skips the loop */
-                                       if((lar->mode & LA_ONLYSHADOW) && i>0.0) {
+                                       if((lar->mode & LA_ONLYSHADOW) && i>0.0f) {
                                                
                                                shadfac[3]= i*lar->energy*(1.0f-shadfac[3]);
                                                shr->shad[0] -= shadfac[3]*shi->r*(1.0f-lashdw[0]);
                                t= vn[0]*lv[0]+vn[1]*lv[1]+vn[2]*lv[2];
                                
                                if(lar->type==LA_HEMI) {
-                                       t= 0.5*t+0.5;
+                                       t= 0.5f*t+0.5f;
                                }
                                
                                t= shadfac[3]*shi->spec*spec(t, shi->har);
@@@ -1653,7 -1653,7 +1653,7 @@@ void shade_lamp_loop(ShadeInput *shi, S
                        shi->r= shi->vcol[0];
                        shi->g= shi->vcol[1];
                        shi->b= shi->vcol[2];
 -                      if(ma->mode & (MA_FACETEXTURE_ALPHA))
 +                      if((ma->mode & (MA_FACETEXTURE_ALPHA)) || ma->vcol_alpha)
                                shi->alpha= (shi->mode & MA_TRANSP) ? shi->vcol[3] : 1.0f;
                }
                if(ma->texco){