Hopefully a working merge with trunk (could be one error left in raytrace.c - will...
[blender.git] / source / blender / render / intern / source / convertblender.c
index 06ba8f16a3b3f9caccedd99ae0841aca09d7b393..cd245b3f7783c8c2f28008130cf7173c8ef60ab8 100644 (file)
@@ -41,6 +41,7 @@
 #include "BLI_rand.h"
 #include "BLI_memarena.h"
 #include "BLI_ghash.h"
+#include "BLI_kdtree.h"
 
 #include "DNA_armature_types.h"
 #include "DNA_camera_types.h"
 #include "envmap.h"
 #include "multires.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"
@@ -921,6 +925,28 @@ static void flag_render_node_material(Render *re, bNodeTree *ntree)
        }
 }
 
+static void check_material_is_textured(Material *ma)
+{
+       MTex *mtex;
+       Tex *tex;
+       int tex_nr;
+       
+       for(tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) {
+               if(ma->septex & (1<<tex_nr))
+                       continue;
+               
+               if(ma->mtex[tex_nr]) {
+                       mtex= ma->mtex[tex_nr];
+                       tex= mtex->tex;
+                       if(tex==NULL)
+                               continue;
+                       else
+                               ma->flag |= MA_IS_TEXTURED;
+                               return;
+               }
+       }
+}
+
 static Material *give_render_material(Render *re, Object *ob, int nr)
 {
        extern Material defmaterial;    /* material.c */
@@ -941,6 +967,8 @@ static Material *give_render_material(Render *re, Object *ob, int nr)
        if(ma->nodetree && ma->use_nodes)
                flag_render_node_material(re, ma->nodetree);
        
+       check_material_is_textured(ma);
+       
        return ma;
 }
 
@@ -1951,6 +1979,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                strandbuf->surface= cache_strand_surface(re, obr, psmd->dm, mat, timeoffset);
 
 /* 4. clean up */
+
        if(ma) do_mat_ipo(ma);
 
        if(orco1)
@@ -2928,6 +2957,53 @@ 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;
+                                       
+                                       BLI_addtail(&(re->render_volumes_inside), mi);
+                               }
+                       }
+               }
+       }
+       
+       {
+       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;
@@ -2982,6 +3058,9 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
                        if(re->r.mode & R_RADIO)
                                if(ma->mode & MA_RADIO) 
                                        do_autosmooth= 1;
+                       
+                       if (ma->material_type == MA_VOLUME)
+                               add_volume(re, obr, ma);
                }
        }
 
@@ -4315,6 +4394,8 @@ void RE_Database_Free(Render *re)
        
        BLI_freelistN(&re->lampren);
        BLI_freelistN(&re->lights);
+       
+       free_volume_precache(re);
 
        free_renderdata_tables(re);
        
@@ -4338,6 +4419,11 @@ 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;
@@ -4725,6 +4811,8 @@ 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()) {
                int tothalo;
@@ -4772,6 +4860,13 @@ void RE_Database_FromScene(Render *re, Scene *scene, int use_camera_view)
                        /* ENVIRONMENT MAPS */
                        if(!re->test_break())
                                make_envmaps(re);
+                               
+                       /* point density texture */
+                       if(!re->test_break())
+                               make_pointdensities(re);
+                       /* voxel data texture */
+                       if(!re->test_break())
+                               make_voxeldata(re);//Volumetrics
                }
                
                if(!re->test_break())
@@ -4788,6 +4883,10 @@ void RE_Database_FromScene(Render *re, Scene *scene, int use_camera_view)
                if((re->r.mode & R_SSS) && !re->test_break())
                        if(re->r.renderer==R_INTERN)
                                make_sss_tree(re);
+               
+               if(!re->test_break())
+                       if(re->r.mode & R_RAYTRACE)
+                               volume_precache(re);
        }
        
        if(re->test_break())