[Bf-blender-cvs] [75bff3c0137] soc-2018-cycles-volumes: Threshold sparse grid with volume mesh isovalue and optimize tile copying during grid generation.

Geraldine Chua noreply at git.blender.org
Thu Jun 7 17:19:00 CEST 2018


Commit: 75bff3c0137e18a00bc9318549e6c3da8b7ae5ac
Author: Geraldine Chua
Date:   Thu Jun 7 23:14:33 2018 +0800
Branches: soc-2018-cycles-volumes
https://developer.blender.org/rB75bff3c0137e18a00bc9318549e6c3da8b7ae5ac

Threshold sparse grid with volume mesh isovalue
and optimize tile copying during grid generation.

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

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/render/image.cpp
M	intern/cycles/render/image.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/util/util_sparse_grid.h

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

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 8bf3f66dff6..f70e859ba8a 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -354,6 +354,7 @@ static void create_mesh_volume_attribute(BL::Object& b_ob,
 	        EXTENSION_CLIP,
 	        use_alpha,
 	        make_sparse,
+	        mesh->volume_isovalue,
 	        metadata);
 }
 
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index bef1419d178..61394700886 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -262,6 +262,7 @@ int ImageManager::add_image(const string& filename,
                             ExtensionType extension,
                             bool use_alpha,
                             bool make_sparse,
+                            float isovalue,
                             ImageMetaData& metadata)
 {
 	Image *img;
@@ -340,6 +341,7 @@ int ImageManager::add_image(const string& filename,
 	img->users = 1;
 	img->use_alpha = use_alpha;
 	img->make_sparse = make_sparse;
+	img->isovalue = isovalue;
 	img->mem = NULL;
 
 	images[type][slot] = img;
@@ -743,6 +745,7 @@ bool ImageManager::file_make_image_sparse(Device *device,
 	                                                 tex_img->data_width,
 	                                                 tex_img->data_height,
 	                                                 tex_img->data_depth,
+	                                                 img->isovalue,
 	                                                 &sparse_grid,
 	                                                 &offsets);
 
diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h
index 7ef9cfb5ba5..7f4810968b2 100644
--- a/intern/cycles/render/image.h
+++ b/intern/cycles/render/image.h
@@ -57,6 +57,7 @@ public:
 	              ExtensionType extension,
 	              bool use_alpha,
 	              bool make_sparse,
+	              float isovalue,
 	              ImageMetaData& metadata);
 	void remove_image(int flat_slot);
 	void remove_image(const string& filename,
@@ -117,6 +118,7 @@ public:
 		bool need_load;
 		bool animated;
 		bool make_sparse;
+		float isovalue;
 		float frame;
 		InterpolationType interpolation;
 		ExtensionType extension;
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 71b1d42b25e..09201421813 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -308,6 +308,7 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
 		                                extension,
 		                                use_alpha,
 		                                false,
+		                                0.0f,
 		                                metadata);
 		is_float = metadata.is_float;
 		is_linear = metadata.is_linear;
@@ -374,6 +375,7 @@ void ImageTextureNode::compile(OSLCompiler& compiler)
 			                                extension,
 			                                use_alpha,
 			                                false,
+			                                0.0f,
 			                                metadata);
 		}
 		is_float = metadata.is_float;
@@ -505,6 +507,7 @@ void EnvironmentTextureNode::compile(SVMCompiler& compiler)
 		                                EXTENSION_REPEAT,
 		                                use_alpha,
 		                                false,
+		                                0.0f,
 		                                metadata);
 		is_float = metadata.is_float;
 		is_linear = metadata.is_linear;
@@ -562,6 +565,7 @@ void EnvironmentTextureNode::compile(OSLCompiler& compiler)
 			                                EXTENSION_REPEAT,
 			                                use_alpha,
 			                                false,
+			                                0.0f,
 			                                metadata);
 		}
 		is_float = metadata.is_float;
@@ -1514,6 +1518,7 @@ void PointDensityTextureNode::compile(SVMCompiler& compiler)
 			                                EXTENSION_CLIP,
 			                                true,
 			                                false,
+			                                0.0f,
 			                                metadata);
 		}
 
@@ -1568,6 +1573,7 @@ void PointDensityTextureNode::compile(OSLCompiler& compiler)
 			                                EXTENSION_CLIP,
 			                                true,
 			                                false,
+											0.0f,
 			                                metadata);
 		}
 
diff --git a/intern/cycles/util/util_sparse_grid.h b/intern/cycles/util/util_sparse_grid.h
index 5e47316ddff..d7d426363a9 100644
--- a/intern/cycles/util/util_sparse_grid.h
+++ b/intern/cycles/util/util_sparse_grid.h
@@ -48,7 +48,6 @@ namespace {
 }
 
 static const int TILE_SIZE = 8;
-static const float THRESHOLD = 0.001f;
 
 const inline int compute_index(const size_t x, const size_t y, const size_t z,
                                const size_t width, const size_t height, const size_t depth)
@@ -130,6 +129,7 @@ const inline int compute_index(const int *offsets, int index,
 template<typename T>
 int create_sparse_grid(const T *dense_grid,
                        int width, int height, int depth,
+                       float isovalue,
                        vector<T> *sparse_grid,
                        vector<int> *offsets)
 {
@@ -138,8 +138,7 @@ int create_sparse_grid(const T *dense_grid,
 	}
 
 	const T empty = cast_from_float<T>(0.0f);
-	const T threshold = cast_from_float<T>(THRESHOLD);
-	T tile[TILE_SIZE * TILE_SIZE * TILE_SIZE];
+	const T threshold = cast_from_float<T>(isovalue);
 
 	/* Total number of active voxels (voxels in active tiles). */
 	int voxel_count = 0;
@@ -168,10 +167,10 @@ int create_sparse_grid(const T *dense_grid,
 							if(index < 0) {
 								/* Out of bounds of original image
 								 * store an empty voxel. */
-								tile[c] = empty;
+								sparse_grid->at(voxel_count + c) = empty;
 							}
 							else {
-								tile[c] = dense_grid[index];
+								sparse_grid->at(voxel_count + c) = dense_grid[index];
 								if(tile_is_empty) {
 									if(gt(dense_grid[index], threshold)) {
 										tile_is_empty = false;
@@ -185,13 +184,10 @@ int create_sparse_grid(const T *dense_grid,
 
 				/* Add tile if active. */
 				if(tile_is_empty) {
-					(*offsets)[tile_count] = -1;
+					offsets->at(tile_count) = -1;
 				}
 				else {
-					(*offsets)[tile_count] = voxel_count;
-					for(int i=0 ; i < c ; ++i) {
-						sparse_grid->at(voxel_count + i) = tile[i];
-					}
+					offsets->at(tile_count) = voxel_count;
 					voxel_count += c;
 				}
 				++tile_count;



More information about the Bf-blender-cvs mailing list