Commit: 98a620707f3f57189d96b2b4abdb645c9e179ea5
Author: Geraldine Chua
Date:   Thu Jul 26 21:03:58 2018 +0800
Branches: soc-2018-cycles-volumes
https://developer.blender.org/rB98a620707f3f57189d96b2b4abdb645c9e179ea5

Cleanup; fix some bugs causing crashes.

===================================================================

M       intern/cycles/blender/blender_mesh.cpp
M       intern/cycles/render/image.cpp
M       intern/cycles/render/image.h
M       intern/cycles/render/openvdb.cpp
M       intern/cycles/render/openvdb.h
M       intern/cycles/util/util_image_impl.h
M       intern/cycles/util/util_sparse_grid.h
M       intern/openvdb/openvdb_capi.cc

===================================================================

diff --git a/intern/cycles/blender/blender_mesh.cpp 
b/intern/cycles/blender/blender_mesh.cpp
index d8261d7d86d..8ed0e5232dc 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -324,29 +324,55 @@ static void mikk_compute_tangents(const BL::Mesh& b_mesh,
 
 /* Create Volume Attribute */
 
-static void create_mesh_volume_attribute(BL::BlendData& b_data,
-                                         BL::Object& b_ob,
-                                         Mesh *mesh,
+static void create_mesh_volume_attribute(Mesh *mesh,
                                          ImageManager *image_manager,
                                          AttributeStandard std,
+                                         string filename,
+                                         void *builtin_data,
                                          float frame)
 {
-       BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
-
-       if(!b_domain)
-               return;
+       ImageMetaData metadata;
 
-       mesh->volume_isovalue = b_domain.clipping();
+       if(filename.empty()) {
+               /* Built-in smoke. */
+               filename = Attribute::standard_name(std);
+       }
+       else {
+               /* External VDB. */
+               metadata.grid_name = Attribute::standard_name(std);
+       }
 
        Attribute *attr = mesh->attributes.add(std);
        VoxelAttribute *volume_data = attr->data_voxel();
-       bool animated = false;
-       bool use_alpha = true;
-       bool make_sparse = true;
+
+       volume_data->manager = image_manager;
+       volume_data->slot = image_manager->add_image(
+                       filename,
+                       builtin_data,
+                       false,
+                       frame,
+                       INTERPOLATION_LINEAR,
+                       EXTENSION_CLIP,
+                       true,
+                       true,
+                       mesh->volume_isovalue,
+                       metadata);
+}
+
+static void create_mesh_volume_attributes(Scene *scene,
+                                          BL::BlendData& b_data,
+                                          BL::Object& b_ob,
+                                          Mesh *mesh,
+                                          float frame)
+{
+       /* for smoke volume rendering */
+       BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
+
+       if(!b_domain)
+               return;
 
        string filename;
        void *builtin_data;
-       ImageMetaData metadata;
 
        if(b_domain.is_openvdb()) {
                BL::ID b_id = b_ob.data();
@@ -354,46 +380,25 @@ static void create_mesh_volume_attribute(BL::BlendData& 
b_data,
                                                 b_id,
                                                 b_domain.openvdb_filepath());
                builtin_data = NULL;
-               metadata.grid_name = Attribute::standard_name(std);
        }
        else {
-               filename = Attribute::standard_name(std);
                builtin_data = b_ob.ptr.data;
        }
 
-       volume_data->manager = image_manager;
-       volume_data->slot = image_manager->add_image(
-               filename,
-               builtin_data,
-               animated,
-               frame,
-               INTERPOLATION_LINEAR,
-               EXTENSION_CLIP,
-               use_alpha,
-               make_sparse,
-               mesh->volume_isovalue,
-               metadata);
-}
+       mesh->volume_isovalue = b_domain.clipping();
 
-static void create_mesh_volume_attributes(Scene *scene,
-                                          BL::BlendData& b_data,
-                                          BL::Object& b_ob,
-                                          Mesh *mesh,
-                                          float frame)
-{
-       /* for smoke volume rendering */
        if(mesh->need_attribute(scene, ATTR_STD_VOLUME_DENSITY))
-               create_mesh_volume_attribute(b_data, b_ob, mesh, 
scene->image_manager, ATTR_STD_VOLUME_DENSITY, frame);
+               create_mesh_volume_attribute(mesh, scene->image_manager, 
ATTR_STD_VOLUME_DENSITY, filename, builtin_data, frame);
        if(mesh->need_attribute(scene, ATTR_STD_VOLUME_COLOR))
-               create_mesh_volume_attribute(b_data, b_ob, mesh, 
scene->image_manager, ATTR_STD_VOLUME_COLOR, frame);
+               create_mesh_volume_attribute(mesh, scene->image_manager, 
ATTR_STD_VOLUME_COLOR, filename, builtin_data, frame);
        if(mesh->need_attribute(scene, ATTR_STD_VOLUME_FLAME))
-               create_mesh_volume_attribute(b_data, b_ob, mesh, 
scene->image_manager, ATTR_STD_VOLUME_FLAME, frame);
+               create_mesh_volume_attribute(mesh, scene->image_manager, 
ATTR_STD_VOLUME_FLAME, filename, builtin_data, frame);
        if(mesh->need_attribute(scene, ATTR_STD_VOLUME_HEAT))
-               create_mesh_volume_attribute(b_data, b_ob, mesh, 
scene->image_manager, ATTR_STD_VOLUME_HEAT, frame);
+               create_mesh_volume_attribute(mesh, scene->image_manager, 
ATTR_STD_VOLUME_HEAT, filename, builtin_data, frame);
        if(mesh->need_attribute(scene, ATTR_STD_VOLUME_TEMPERATURE))
-               create_mesh_volume_attribute(b_data, b_ob, mesh, 
scene->image_manager, ATTR_STD_VOLUME_TEMPERATURE, frame);
+               create_mesh_volume_attribute(mesh, scene->image_manager, 
ATTR_STD_VOLUME_TEMPERATURE, filename, builtin_data, frame);
        if(mesh->need_attribute(scene, ATTR_STD_VOLUME_VELOCITY))
-               create_mesh_volume_attribute(b_data, b_ob, mesh, 
scene->image_manager, ATTR_STD_VOLUME_VELOCITY, frame);
+               create_mesh_volume_attribute(mesh, scene->image_manager, 
ATTR_STD_VOLUME_VELOCITY, filename, builtin_data, frame);
 }
 
 /* Create vertex color attributes. */
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 60f2f815c9f..13892db1364 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -275,6 +275,16 @@ string ImageManager::name_from_type(int type)
                return "byte4";
 }
 
+string ImageManager::name_from_grid_type(int type)
+{
+       if(type == IMAGE_GRID_TYPE_SPARSE)
+               return "sparse";
+       else if(type == IMAGE_GRID_TYPE_OPENVDB)
+               return "OpenVDB";
+       else
+               return "default";
+}
+
 static bool image_equals(ImageManager::Image *image,
                          const string& filename,
                          void *builtin_data,
@@ -298,7 +308,7 @@ int ImageManager::add_image(const string& filename,
                             InterpolationType interpolation,
                             ExtensionType extension,
                             bool use_alpha,
-                            bool make_sparse,
+                            bool is_volume,
                             float isovalue,
                             ImageMetaData& metadata)
 {
@@ -379,7 +389,7 @@ int ImageManager::add_image(const string& filename,
        img->extension = extension;
        img->users = 1;
        img->use_alpha = use_alpha;
-       img->make_sparse = make_sparse;
+       img->is_volume = is_volume;
        img->isovalue = isovalue;
        img->mem = NULL;
 
@@ -622,35 +632,51 @@ void ImageManager::file_load_image(Device *device,
                                              MEM_TEXTURE);
        tex_img->grid_type = IMAGE_GRID_TYPE_DEFAULT;
 
-       /* Try to retrieve an ImageInput for reading the image (or just get 
metadata). */
-       const StorageType alpha_one = (FileFormat == TypeDesc::UINT8)? 255 : 1;
+       /* Try to retrieve an ImageInput for reading the image.
+        * Otherwise, retrieve metadata. */
        ImageInput *in = NULL;
        int width, height, depth, components;
        if(!file_load_image_generic(img, &in, width, height, depth, 
components)) {
+               /* Could not retrieve image. */
                file_load_failed<StorageType, DeviceType>(img, type, tex_img);
                return;
        }
 
-       bool is_openvdb = string_endswith(img->filename, ".vdb");
+       size_t max_size = max(max(width, height), depth);
+       size_t num_pixels = ((size_t)width) * height * depth;
+       if(max_size == 0) {
+               /* Don't bother with invalid images. */
+               file_load_failed<StorageType, DeviceType>(img, type, tex_img);
+               return;
+       }
+
+       const bool is_rgba = (type == IMAGE_DATA_TYPE_FLOAT4 ||
+                             type == IMAGE_DATA_TYPE_HALF4 ||
+                             type == IMAGE_DATA_TYPE_BYTE4);
+       const bool is_extern_vdb = string_endswith(img->filename, ".vdb");
 
 #ifdef WITH_OPENVDB
        /* Load pointer to OpenVDB grid into texture if using CPU. */
-       if(is_openvdb && device->info.type == DEVICE_CPU) {
-               VLOG(1) << "Loading " << img->filename << ", Grid: " << 
img->grid_name;
+       if(is_extern_vdb && device->info.type == DEVICE_CPU && 0) {
+               VLOG(1) << "Loading external VDB " << img->filename
+                       << ", Grid: " << img->grid_name;
+
                device_memory *tex_vdb = NULL;
                {
                        thread_scoped_lock device_lock(device_mutex);
-                       tex_vdb = openvdb_load_device(device,
-                                                                               
  img->filename,
-                                                                               
  img->grid_name,
-                                                     img->mem_name,
-                                                                               
  img->interpolation,
-                                                                               
  img->extension,
-                                                     type == 
IMAGE_DATA_TYPE_FLOAT4);
+                       tex_vdb = openvdb_load_device_extern(device,
+                                                            img->filename,
+                                                            img->grid_name,
+                                                            img->mem_name,
+                                                            img->interpolation,
+                                                            img->extension,
+                                                            is_rgba);
                }
+
                if(tex_vdb) {
                        img->mem = tex_vdb;
                        delete tex_img;
+                       tex_img = NULL;
                }
                else {
                        file_load_failed<StorageType, DeviceType>(img, type, 
tex_img);
@@ -661,19 +687,9 @@ void ImageManager::file_load_image(Device *device,
        }
 #endif
 
-       /* Read RGBA pixels. */
-       const size_t max_size = max(max(width, height), depth);
-       if(max_size == 0) {
-               /* Don't bother with invalid images. */
-               file_load_failed<StorageType, DeviceType>(img, type, tex_img);
-               return;
-       }
-
        /* Allocate storage for the image. */
        vector<StorageType> pixels_storage;
        StorageType *pixels;
-       const size_t num_pixels = ((size_t)width) * height * depth;
-
        if(texture_limit > 0 && max_size > texture_limit) {
                pixels_storage.resize(num_pixels * 4);
                pixels = &pixels_storage[0];
@@ -689,8 +705,7 @@ void ImageManager::file_load_image(Device *device,
                return;
        }
 
-       bool cmyk = (in ? strcmp(in->format_name(), "jpeg") == 0 && components 
== 4 : false);
-
+       /* Read RGBA pixels. */
        if(in) {
                StorageType *readpixels = pixels;
                vector<StorageType> tmppixels;
@@ -723,8 +738,9 @@ void ImageManager::file_load_image(Device *device,
                delete in;
        }
 #ifdef WITH_OPENVDB
-       else if(is_openvdb) {
-               VLOG(1) << "Loading " << img->filename << ", Grid: " << 
img->grid_name;
+       else if(is_extern_vdb) {
+               VLOG(1) << "Loading external VDB " << img->filename
+                       << ", Grid: " << img->grid_name;
                openvdb_load_dense(img->filename, img->grid_name, 
(float*)pixels, c

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to