[Bf-blender-cvs] [ffc3c82] gooseberry_farm: Cycles: Merge density and color volume attributes if they both requested

Sergey Sharybin noreply at git.blender.org
Wed Jun 10 11:27:35 CEST 2015


Commit: ffc3c829738ecb7376217aaf6852084a6aa0b19b
Author: Sergey Sharybin
Date:   Mon Jun 8 15:48:11 2015 +0200
Branches: gooseberry_farm
https://developer.blender.org/rBffc3c829738ecb7376217aaf6852084a6aa0b19b

Cycles: Merge density and color volume attributes if they both requested

This way we store quite reasonable amount of memory (density is stored as RGBA
textures, which ends up in gigabytes of RAM for hires smoke sims).

It's not really pretty implementation and we'll really need to support textures
with 1 and 3 channels instead of doing such packing, but we need to be able to
render some files here.

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

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/kernel/geom/geom_volume.h
M	intern/cycles/render/attribute.h
M	intern/cycles/render/mesh.cpp

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

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index bfd91a2..3fa80a8 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -229,7 +229,13 @@ static void mikk_compute_tangents(BL::Mesh b_mesh, BL::MeshTextureFaceLayer *b_l
 
 /* Create Volume Attribute */
 
-static void create_mesh_volume_attribute(BL::Object b_ob, Mesh *mesh, ImageManager *image_manager, AttributeStandard std, float frame)
+static void create_mesh_volume_attribute(BL::Object b_ob,
+                                         Mesh *mesh,
+                                         ImageManager *image_manager,
+                                         AttributeStandard std,
+                                         float frame,
+                                         AttributeStandard special_std = ATTR_STD_NONE,
+                                         bool from_alpha = false)
 {
 	BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
 
@@ -240,17 +246,35 @@ static void create_mesh_volume_attribute(BL::Object b_ob, Mesh *mesh, ImageManag
 	VoxelAttribute *volume_data = attr->data_voxel();
 	bool is_float, is_linear;
 	bool animated = false;
+	AttributeStandard data_attr = (special_std == ATTR_STD_NONE) ? std : special_std;
 
 	volume_data->manager = image_manager;
-	volume_data->slot = image_manager->add_image(Attribute::standard_name(std),
+	volume_data->slot = image_manager->add_image(Attribute::standard_name(data_attr),
 		b_ob.ptr.data, animated, frame, is_float, is_linear, INTERPOLATION_LINEAR, true);
+	volume_data->from_alpha = from_alpha;
 }
 
 static void create_mesh_volume_attributes(Scene *scene, 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_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_DENSITY, frame);
+	if(mesh->need_attribute(scene, ATTR_STD_VOLUME_DENSITY)) {
+		/* Special case: we re-map density to A channel of Color texture
+		 * if both attributes are requested.
+		 */
+		AttributeStandard special_std = ATTR_STD_VOLUME_DENSITY;
+		bool from_alpha = false;
+		if(mesh->need_attribute(scene, ATTR_STD_VOLUME_COLOR)) {
+			special_std = ATTR_STD_VOLUME_COLOR;
+			from_alpha = true;
+		}
+		create_mesh_volume_attribute(b_ob,
+		                             mesh,
+		                             scene->image_manager,
+		                             ATTR_STD_VOLUME_DENSITY,
+		                             frame,
+		                             special_std,
+		                             from_alpha);
+	}
 	if(mesh->need_attribute(scene, ATTR_STD_VOLUME_COLOR))
 		create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_COLOR, frame);
 	if(mesh->need_attribute(scene, ATTR_STD_VOLUME_FLAME))
diff --git a/intern/cycles/kernel/geom/geom_volume.h b/intern/cycles/kernel/geom/geom_volume.h
index c72afa2..24430dd 100644
--- a/intern/cycles/kernel/geom/geom_volume.h
+++ b/intern/cycles/kernel/geom/geom_volume.h
@@ -53,17 +53,21 @@ ccl_device float volume_attribute_float(KernelGlobals *kg, const ShaderData *sd,
 	float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
 #else
 	float4 r;
+	int slot = id >> 1;
 	if(sd->flag & SD_VOLUME_CUBIC)
-		r = kernel_tex_image_interp_3d_ex(id, P.x, P.y, P.z, INTERPOLATION_CUBIC);
+		r = kernel_tex_image_interp_3d_ex(slot, P.x, P.y, P.z, INTERPOLATION_CUBIC);
 	else
-		r = kernel_tex_image_interp_3d(id, P.x, P.y, P.z);
+		r = kernel_tex_image_interp_3d(slot, P.x, P.y, P.z);
 #endif
 
 	if(dx) *dx = 0.0f;
 	if(dy) *dy = 0.0f;
 
 	/* todo: support float textures to lower memory usage for single floats */
-	return average(float4_to_float3(r));
+	if(id & 1)
+		return r.w;
+	else
+		return average(float4_to_float3(r));
 }
 
 ccl_device float3 volume_attribute_float3(KernelGlobals *kg, const ShaderData *sd, AttributeElement elem, int id, float3 *dx, float3 *dy)
@@ -73,16 +77,20 @@ ccl_device float3 volume_attribute_float3(KernelGlobals *kg, const ShaderData *s
 	float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
 #else
 	float4 r;
+	int slot = id >> 1;
 	if(sd->flag & SD_VOLUME_CUBIC)
-		r = kernel_tex_image_interp_3d_ex(id, P.x, P.y, P.z, INTERPOLATION_CUBIC);
+		r = kernel_tex_image_interp_3d_ex(slot, P.x, P.y, P.z, INTERPOLATION_CUBIC);
 	else
-		r = kernel_tex_image_interp_3d(id, P.x, P.y, P.z);
+		r = kernel_tex_image_interp_3d(slot, P.x, P.y, P.z);
 #endif
 
 	if(dx) *dx = make_float3(0.0f, 0.0f, 0.0f);
 	if(dy) *dy = make_float3(0.0f, 0.0f, 0.0f);
 
-	return float4_to_float3(r);
+	if(id & 1)
+		return make_float3(r.w, r.w, r.w);
+	else
+		return float4_to_float3(r);
 }
 
 #endif
diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h
index bbc6cf7..b49f0ff 100644
--- a/intern/cycles/render/attribute.h
+++ b/intern/cycles/render/attribute.h
@@ -39,6 +39,7 @@ struct Transform;
 struct VoxelAttribute {
 	ImageManager *manager;
 	int slot;
+	int from_alpha;
 };
 
 /* Attribute
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 4f99bfc..fdd1e3e 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -818,7 +818,10 @@ static void update_attribute_element_offset(Mesh *mesh,
 		if(mattr->element == ATTR_ELEMENT_VOXEL) {
 			/* store slot in offset value */
 			VoxelAttribute *voxel_data = mattr->data_voxel();
-			offset = voxel_data->slot;
+			offset = voxel_data->slot << 1;
+			if(voxel_data->from_alpha) {
+				++offset;
+			}
 		}
 		else if(mattr->element == ATTR_ELEMENT_CORNER_BYTE) {
 			uchar4 *data = mattr->data_uchar4();




More information about the Bf-blender-cvs mailing list