Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / render / intern / source / convertblender.c
index 99825c0..2c264ce 100644 (file)
@@ -31,7 +31,7 @@
 #include <string.h>
 #include <limits.h>
 
-
+#include "MTC_matrixops.h"
 
 #include "MEM_guardedalloc.h"
 
 
 #include "envmap.h"
 #include "occlusion.h"
-#include "pointdensity.h"
-#include "voxeldata.h"
 #include "render_types.h"
 #include "rendercore.h"
 #include "renderdatabase.h"
 #include "shading.h"
 #include "strand.h"
 #include "texture.h"
-#include "volume_precache.h"
 #include "sss.h"
 #include "strand.h"
 #include "zbuf.h"
@@ -191,8 +188,8 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void),
        if (re) re->flag |= R_HALO;
        else stargrid *= 1.0;                           /* then it draws fewer */
        
-       if(re) Mat4Invert(mat, re->viewmat);
-       else Mat4One(mat);
+       if(re) MTC_Mat4Invert(mat, re->viewmat);
+       else MTC_Mat4One(mat);
        
        /* BOUNDING BOX CALCULATION
                * bbox goes from z = loc_near_var | loc_far_var,
@@ -240,7 +237,7 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void),
                                        done++;
                                }
                                else {
-                                       Mat4MulVecfl(re->viewmat, vec);
+                                       MTC_Mat4MulVecfl(re->viewmat, vec);
                                        
                                        /* in vec are global coordinates
                                        * calculate distance to camera
@@ -829,7 +826,7 @@ static void autosmooth(Render *re, ObjectRen *obr, float mat[][4], int degr)
        /* rotate vertices and calculate normal of faces */
        for(a=0; a<obr->totvert; a++) {
                ver= RE_findOrAddVert(obr, a);
-               Mat4MulVecfl(mat, ver->co);
+               MTC_Mat4MulVecfl(mat, ver->co);
        }
        for(a=0; a<obr->totvlak; a++) {
                vlr= RE_findOrAddVlak(obr, a);
@@ -920,7 +917,6 @@ static Material *give_render_material(Render *re, Object *ob, int nr)
        
        if(re->r.mode & R_SPEED) ma->texco |= NEED_UV;
        
-       if(ma->material_type == MA_TYPE_VOLUME) ma->mode |= MA_TRANSP;
        if((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP))
                re->flag |= R_ZTRA;
        
@@ -1280,19 +1276,19 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl
 
        VECADD(vlr->v1->co, bb_center, xvec);
        VECADD(vlr->v1->co, vlr->v1->co, yvec);
-       Mat4MulVecfl(re->viewmat, vlr->v1->co);
+       MTC_Mat4MulVecfl(re->viewmat, vlr->v1->co);
 
        VECSUB(vlr->v2->co, bb_center, xvec);
        VECADD(vlr->v2->co, vlr->v2->co, yvec);
-       Mat4MulVecfl(re->viewmat, vlr->v2->co);
+       MTC_Mat4MulVecfl(re->viewmat, vlr->v2->co);
 
        VECSUB(vlr->v3->co, bb_center, xvec);
        VECSUB(vlr->v3->co, vlr->v3->co, yvec);
-       Mat4MulVecfl(re->viewmat, vlr->v3->co);
+       MTC_Mat4MulVecfl(re->viewmat, vlr->v3->co);
 
        VECADD(vlr->v4->co, bb_center, xvec);
        VECSUB(vlr->v4->co, vlr->v4->co, yvec);
-       Mat4MulVecfl(re->viewmat, vlr->v4->co);
+       MTC_Mat4MulVecfl(re->viewmat, vlr->v4->co);
 
        CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n);
        VECCOPY(vlr->v1->n,vlr->n);
@@ -1392,7 +1388,7 @@ static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re
        VECCOPY(loc, state->co);
 
        if(ren_as != PART_DRAW_BB)
-               Mat4MulVecfl(re->viewmat, loc);
+               MTC_Mat4MulVecfl(re->viewmat, loc);
 
        switch(ren_as) {
                case PART_DRAW_LINE:
@@ -1401,7 +1397,7 @@ static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re
                        sd->size = hasize;
 
                        VECCOPY(vel, state->vel);
-                       Mat4Mul3Vecfl(re->viewmat, vel);
+                       MTC_Mat4Mul3Vecfl(re->viewmat, vel);
                        Normalize(vel);
 
                        if(part->draw & PART_DRAW_VEL_LENGTH)
@@ -1621,8 +1617,8 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
        }
        
 /* 2.5 setup matrices */
-       Mat4MulMat4(mat, ob->obmat, re->viewmat);
-       Mat4Invert(ob->imat, mat);      /* need to be that way, for imat texture */
+       MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+       MTC_Mat4Invert(ob->imat, mat);  /* need to be that way, for imat texture */
        Mat3CpyMat4(nmat, ob->imat);
        Mat3Transp(nmat);
 
@@ -1743,10 +1739,8 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
 
                        pa_size = pa->size;
 
-                       BLI_srandom(psys->seed+a);
-
-                       r_tilt = 2.0f*(BLI_frand() - 0.5f);
-                       r_length = BLI_frand();
+                       r_tilt = 1.0f + pa->r_ave[0];
+                       r_length = 0.5f * (1.0f + pa->r_ave[1]);
 
                        if(path_nbr) {
                                cache = psys->pathcache[a];
@@ -1904,7 +1898,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                                time= curlen/strandlen;
 
                                VECCOPY(loc,state.co);
-                               Mat4MulVecfl(re->viewmat,loc);
+                               MTC_Mat4MulVecfl(re->viewmat,loc);
 
                                if(strandbuf) {
                                        VECCOPY(svert->co, loc);
@@ -2046,8 +2040,8 @@ static void make_render_halos(Render *re, ObjectRen *obr, Mesh *me, int totvert,
        float vec[3], hasize, mat[4][4], imat[3][3];
        int a, ok, seed= ma->seed1;
 
-       Mat4MulMat4(mat, ob->obmat, re->viewmat);
-       Mat3CpyMat4(imat, ob->imat);
+       MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+       MTC_Mat3CpyMat4(imat, ob->imat);
 
        re->flag |= R_HALO;
 
@@ -2058,7 +2052,7 @@ static void make_render_halos(Render *re, ObjectRen *obr, Mesh *me, int totvert,
                        hasize= ma->hasize;
 
                        VECCOPY(vec, mvert->co);
-                       Mat4MulVecfl(mat, vec);
+                       MTC_Mat4MulVecfl(mat, vec);
 
                        if(ma->mode & MA_HALOPUNO) {
                                xn= mvert->no[0];
@@ -2191,7 +2185,7 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve
        }
        if (texco & TEXCO_GLOB) {
                VECCOPY(shi->gl, shi->co);
-               Mat4MulVecfl(re->viewinv, shi->gl);
+               MTC_Mat4MulVecfl(re->viewinv, shi->gl);
        }
        if (texco & TEXCO_NORM) {
                VECCOPY(shi->orn, shi->vn);
@@ -2332,9 +2326,9 @@ static void init_render_mball(Render *re, ObjectRen *obr)
        if (ob!=find_basis_mball(re->scene, ob))
                return;
 
-       Mat4MulMat4(mat, ob->obmat, re->viewmat);
-       Mat4Invert(ob->imat, mat);
-       Mat3CpyMat4(imat, ob->imat);
+       MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+       MTC_Mat4Invert(ob->imat, mat);
+       MTC_Mat3CpyMat4(imat, ob->imat);
 
        ma= give_render_material(re, ob, 1);
 
@@ -2355,7 +2349,7 @@ static void init_render_mball(Render *re, ObjectRen *obr)
 
                ver= RE_findOrAddVert(obr, obr->totvert++);
                VECCOPY(ver->co, data);
-               Mat4MulVecfl(mat, ver->co);
+               MTC_Mat4MulVecfl(mat, ver->co);
 
                /* render normals are inverted */
                xn= -nors[0];
@@ -2439,7 +2433,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar,
                if(orco) {
                        v1->orco= orco; orco+= 3; orcoret++;
                }       
-               Mat4MulVecfl(mat, v1->co);
+               MTC_Mat4MulVecfl(mat, v1->co);
                
                for (v = 1; v < sizev; v++) {
                        ver= RE_findOrAddVert(obr, obr->totvert++);
@@ -2447,7 +2441,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar,
                        if(orco) {
                                ver->orco= orco; orco+= 3; orcoret++;
                        }       
-                       Mat4MulVecfl(mat, ver->co);
+                       MTC_Mat4MulVecfl(mat, ver->co);
                }
                /* if V-cyclic, add extra vertices at end of the row */
                if (dl->flag & DL_CYCL_U) {
@@ -2597,8 +2591,8 @@ static void init_render_surf(Render *re, ObjectRen *obr)
        nu= cu->nurb.first;
        if(nu==0) return;
 
-       Mat4MulMat4(mat, ob->obmat, re->viewmat);
-       Mat4Invert(ob->imat, mat);
+       MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+       MTC_Mat4Invert(ob->imat, mat);
 
        /* material array */
        totmat= ob->totcol+1;
@@ -2658,8 +2652,8 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset)
        dl= cu->disp.first;
        if(cu->disp.first==NULL) return;
        
-       Mat4MulMat4(mat, ob->obmat, re->viewmat);
-       Mat4Invert(ob->imat, mat);
+       MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+       MTC_Mat4Invert(ob->imat, mat);
 
        /* material array */
        totmat= ob->totcol+1;
@@ -2701,7 +2695,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset)
                                        ver->flag = 0;
                                }
 
-                               Mat4MulVecfl(mat, ver->co);
+                               MTC_Mat4MulVecfl(mat, ver->co);
                                
                                if (orco) {
                                        ver->orco = orco;
@@ -2753,7 +2747,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset)
                                        ver= RE_findOrAddVert(obr, obr->totvert++);
                                                
                                        VECCOPY(ver->co, fp);
-                                       Mat4MulVecfl(mat, ver->co);
+                                       MTC_Mat4MulVecfl(mat, ver->co);
                                        fp+= 3;
 
                                        if (orco) {
@@ -2982,53 +2976,6 @@ static void use_mesh_edge_lookup(ObjectRen *obr, DerivedMesh *dm, MEdge *medge,
        }
 }
 
-static void free_camera_inside_volumes(Render *re)
-{
-       BLI_freelistN(&re->render_volumes_inside);
-}
-
-static void init_camera_inside_volumes(Render *re)
-{
-       ObjectInstanceRen *obi;
-       VolumeOb *vo;
-       float co[3] = {0.f, 0.f, 0.f};
-
-       for(vo= re->volumes.first; vo; vo= vo->next) {
-               for(obi= re->instancetable.first; obi; obi= obi->next) {
-                       if (obi->obr == vo->obr) {
-                               if (point_inside_volume_objectinstance(obi, co)) {
-                                       MatInside *mi;
-                                       
-                                       mi = MEM_mallocN(sizeof(MatInside), "camera inside material");
-                                       mi->ma = vo->ma;
-                                       mi->obi = obi;
-                                       
-                                       BLI_addtail(&(re->render_volumes_inside), mi);
-                               }
-                       }
-               }
-       }
-       
-       /* debug {
-       MatInside *m;
-       for (m=re->render_volumes_inside.first; m; m=m->next) {
-               printf("matinside: ma: %s \n", m->ma->id.name+2);
-       }
-       }*/
-}
-
-static void add_volume(Render *re, ObjectRen *obr, Material *ma)
-{
-       struct VolumeOb *vo;
-       
-       vo = MEM_mallocN(sizeof(VolumeOb), "volume object");
-       
-       vo->ma = ma;
-       vo->obr = obr;
-       
-       BLI_addtail(&re->volumes, vo);
-}
-
 static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
 {
        Object *ob= obr->ob;
@@ -3050,9 +2997,9 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
 
        me= ob->data;
 
-       Mat4MulMat4(mat, ob->obmat, re->viewmat);
-       Mat4Invert(ob->imat, mat);
-       Mat3CpyMat4(imat, ob->imat);
+       MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+       MTC_Mat4Invert(ob->imat, mat);
+       MTC_Mat3CpyMat4(imat, ob->imat);
 
        if(me->totvert==0)
                return;
@@ -3133,7 +3080,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
                        ver= RE_findOrAddVert(obr, obr->totvert++);
                        VECCOPY(ver->co, mvert->co);
                        if(do_autosmooth==0)    /* autosmooth on original unrotated data to prevent differences between frames */
-                               Mat4MulVecfl(mat, ver->co);
+                               MTC_Mat4MulVecfl(mat, ver->co);
   
                        if(orco) {
                                ver->orco= orco;
@@ -3354,13 +3301,13 @@ static void initshadowbuf(Render *re, LampRen *lar, float mat[][4])
        shb->soft= lar->soft;
        shb->shadhalostep= lar->shadhalostep;
        
-       Mat4Ortho(mat);
-       Mat4Invert(shb->winmat, mat);   /* winmat is temp */
+       MTC_Mat4Ortho(mat);
+       MTC_Mat4Invert(shb->winmat, mat);       /* winmat is temp */
        
        /* matrix: combination of inverse view and lampmat */
        /* calculate again: the ortho-render has no correct viewinv */
-       Mat4Invert(viewinv, re->viewmat);
-       Mat4MulMat4(shb->viewmat, viewinv, shb->winmat);
+       MTC_Mat4Invert(viewinv, re->viewmat);
+       MTC_Mat4MulMat4(shb->viewmat, viewinv, shb->winmat);
        
        /* projection */
        shb->d= lar->clipsta;
@@ -3438,11 +3385,11 @@ static GroupObject *add_render_lamp(Render *re, Object *ob)
        BLI_addtail(&re->lampren, lar);
        go->lampren= lar;
 
-       Mat4MulMat4(mat, ob->obmat, re->viewmat);
-       Mat4Invert(ob->imat, mat);
+       MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+       MTC_Mat4Invert(ob->imat, mat);
 
-       Mat3CpyMat4(lar->mat, mat);
-       Mat3CpyMat4(lar->imat, ob->imat);
+       MTC_Mat3CpyMat4(lar->mat, mat);
+       MTC_Mat3CpyMat4(lar->imat, ob->imat);
 
        lar->bufsize = la->bufsize;
        lar->samp = la->samp;
@@ -3598,7 +3545,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob)
                        lar->sh_invcampos[0]= -lar->co[0];
                        lar->sh_invcampos[1]= -lar->co[1];
                        lar->sh_invcampos[2]= -lar->co[2];
-                       Mat3MulVecfl(lar->imat, lar->sh_invcampos);
+                       MTC_Mat3MulVecfl(lar->imat, lar->sh_invcampos);
 
                        /* z factor, for a normalized volume */
                        angle= saacos(lar->spotsi);
@@ -3862,7 +3809,6 @@ static void set_fullsample_flag(Render *re, ObjectRen *obr)
                        vlr->flag |= R_FULL_OSA;
                else if(trace) {
                        if(mode & MA_SHLESS);
-                       else if(vlr->mat->material_type == MA_TYPE_VOLUME);
                        else if((mode & MA_RAYMIRROR) || ((mode & MA_TRANSP) && (mode & MA_RAYTRANSP)))
                                /* for blurry reflect/refract, better to take more samples 
                                 * inside the raytrace than as OSA samples */
@@ -4222,7 +4168,7 @@ static void set_dupli_tex_mat(Render *re, ObjectInstanceRen *obi, DupliObject *d
 
                obi->duplitexmat= BLI_memarena_alloc(re->memArena, sizeof(float)*4*4);
                Mat4Invert(imat, dob->mat);
-               Mat4MulSerie(obi->duplitexmat, re->viewmat, dob->omat, imat, re->viewinv, 0, 0, 0, 0);
+               MTC_Mat4MulSerie(obi->duplitexmat, re->viewmat, dob->omat, imat, re->viewinv, 0, 0, 0, 0);
        }
 }
 
@@ -4270,7 +4216,7 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject *
        ObjectRen *obr;
        ObjectInstanceRen *obi;
        ParticleSystem *psys;
-       int show_emitter, allow_render= 1, index, psysindex, i;
+       int show_emitter, allow_render= 1, index, psysindex;
 
        index= (dob)? dob->index: 0;
 
@@ -4306,12 +4252,6 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject *
                }
                else
                        find_dupli_instances(re, obr);
-                       
-               for (i=1; i<=ob->totcol; i++) {
-                       Material* ma = give_render_material(re, ob, i);
-                       if (ma && ma->material_type == MA_TYPE_VOLUME)
-                               add_volume(re, obr, ma);
-               }
        }
 
        /* and one render object per particle system */
@@ -4352,8 +4292,8 @@ static void init_render_object(Render *re, Object *ob, Object *par, DupliObject
        else if(render_object_type(ob->type))
                add_render_object(re, ob, par, dob, timeoffset, vectorlay);
        else {
-               Mat4MulMat4(mat, ob->obmat, re->viewmat);
-               Mat4Invert(ob->imat, mat);
+               MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+               MTC_Mat4Invert(ob->imat, mat);
        }
        
        time= PIL_check_seconds_timer();
@@ -4394,8 +4334,6 @@ void RE_Database_Free(Render *re)
                curvemapping_free(lar->curfalloff);
        }
        
-       free_volume_precache(re);
-       
        BLI_freelistN(&re->lampren);
        BLI_freelistN(&re->lights);
 
@@ -4422,11 +4360,6 @@ void RE_Database_Free(Render *re)
        end_render_materials();
        end_render_textures();
        
-       free_pointdensities(re);
-       free_voxeldata(re);
-       
-       free_camera_inside_volumes(re);
-       
        if(re->wrld.aosphere) {
                MEM_freeN(re->wrld.aosphere);
                re->wrld.aosphere= NULL;
@@ -4603,8 +4536,8 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp
        for(SETLOOPER(re->scene, base)) {
                ob= base->object;
                /* imat objects has to be done here, since displace can have texture using Object map-input */
-               Mat4MulMat4(mat, ob->obmat, re->viewmat);
-               Mat4Invert(ob->imat, mat);
+               MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+               MTC_Mat4Invert(ob->imat, mat);
                /* each object should only be rendered once */
                ob->flag &= ~OB_DONE;
                ob->transflag &= ~OB_RENDER_DUPLI;
@@ -4750,8 +4683,8 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp
        if(redoimat) {
                for(SETLOOPER(re->scene, base)) {
                        ob= base->object;
-                       Mat4MulMat4(mat, ob->obmat, re->viewmat);
-                       Mat4Invert(ob->imat, mat);
+                       MTC_Mat4MulMat4(mat, ob->obmat, re->viewmat);
+                       MTC_Mat4Invert(ob->imat, mat);
                }
        }
 
@@ -4819,8 +4752,6 @@ void RE_Database_FromScene(Render *re, Scene *scene, int use_camera_view)
 
        /* MAKE RENDER DATA */
        database_init_objects(re, lay, 0, 0, 0, 0);
-       
-       init_camera_inside_volumes(re);
 
        if(!re->test_break(re->tbh)) {
                int tothalo;
@@ -4869,13 +4800,6 @@ void RE_Database_FromScene(Render *re, Scene *scene, int use_camera_view)
                        /* ENVIRONMENT MAPS */
                        if(!re->test_break(re->tbh))
                                make_envmaps(re);
-                               
-                       /* point density texture */
-                       if(!re->test_break(re->tbh))
-                               make_pointdensities(re);
-                       /* voxel data texture */
-                       if(!re->test_break(re->tbh))
-                               make_voxeldata(re);
                }
                
                if(!re->test_break(re->tbh))
@@ -4892,11 +4816,6 @@ void RE_Database_FromScene(Render *re, Scene *scene, int use_camera_view)
                if((re->r.mode & R_SSS) && !re->test_break(re->tbh))
                        if(re->r.renderer==R_INTERN)
                                make_sss_tree(re);
-               
-               if(!re->test_break(re->tbh))
-                       if(re->r.mode & R_RAYTRACE)
-                               volume_precache(re);
-               
        }
        
        if(re->test_break(re->tbh))
@@ -5177,7 +5096,7 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float *
                return 0;
        
        Mat4CpyMat4(mat, re->viewmat);
-       Mat4Invert(imat, mat);
+       MTC_Mat4Invert(imat, mat);
 
        /* set first vertex OK */
        if(!fss->meshSurfNormals) return 0;