[Bf-blender-cvs] [bdae647] master: Color sources for point density textures based on mesh vertices

Lukas Tönne noreply at git.blender.org
Thu Mar 24 12:07:56 CET 2016


Commit: bdae647670817f4c09d4c871314f237dde1bfaac
Author: Lukas Tönne
Date:   Thu Mar 24 11:41:44 2016 +0100
Branches: master
https://developer.blender.org/rBbdae647670817f4c09d4c871314f237dde1bfaac

Color sources for point density textures based on mesh vertices

This patch adds support for coloring point density textures based on several mesh vertex attributes.

* Vertex Color: Use a vertex color layer for coloring the point density texture
* Vertex Weight: Use a weights from a vertex group as intensity values. (for Blender Render engine the additional color band is used)
* Vertex Normals: Use object-space vertex normals as RGB values.

The vertex color source enum is stored separately from the particle color source, to avoid invalid values when switching.

Note that vertex colors are technically "corner colors" (MLoop), so each vertex can have as many colors as faces it is part of.
For the purpose of point density the mloop colors are simply averaged, which is physically plausible because corners can be viewed
as multiple points in the same location.

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

M	release/scripts/startup/bl_ui/properties_texture.py
M	source/blender/editors/space_node/drawnode.c
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesdna/DNA_texture_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/makesrna/intern/rna_texture.c
M	source/blender/render/intern/source/pointdensity.c

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

diff --git a/release/scripts/startup/bl_ui/properties_texture.py b/release/scripts/startup/bl_ui/properties_texture.py
index 1f0107f..caf19a9 100644
--- a/release/scripts/startup/bl_ui/properties_texture.py
+++ b/release/scripts/startup/bl_ui/properties_texture.py
@@ -830,12 +830,21 @@ class TEXTURE_PT_pointdensity(TextureButtonsPanel, Panel):
 
         col.separator()
 
+        col.label(text="Color Source:")
         if pd.point_source == 'PARTICLE_SYSTEM':
-            col.label(text="Color Source:")
-            col.prop(pd, "color_source", text="")
-            if pd.color_source in {'PARTICLE_SPEED', 'PARTICLE_VELOCITY'}:
+            col.prop(pd, "particle_color_source", text="")
+            if pd.particle_color_source in {'PARTICLE_SPEED', 'PARTICLE_VELOCITY'}:
                 col.prop(pd, "speed_scale")
-            if pd.color_source in {'PARTICLE_SPEED', 'PARTICLE_AGE'}:
+            if pd.particle_color_source in {'PARTICLE_SPEED', 'PARTICLE_AGE'}:
+                layout.template_color_ramp(pd, "color_ramp", expand=True)
+        else:
+            col.prop(pd, "vertex_color_source", text="")
+            if pd.vertex_color_source == 'VERTEX_COLOR':
+                if pd.object and pd.object.data:
+                    col.prop_search(pd, "vertex_attribute_name", pd.object.data, "vertex_colors", text="")
+            if pd.vertex_color_source == 'VERTEX_WEIGHT':
+                if pd.object:
+                    col.prop_search(pd, "vertex_attribute_name", pd.object, "vertex_groups", text="")
                 layout.template_color_ramp(pd, "color_ramp", expand=True)
 
         col = split.column()
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 1460a3a..b2f3306 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -961,6 +961,11 @@ static void node_shader_buts_tex_pointdensity(uiLayout *layout, bContext *UNUSED
 {
 	bNode *node = ptr->data;
 	NodeShaderTexPointDensity *shader_point_density = node->storage;
+	Object *ob = (Object *)node->id;
+	PointerRNA ob_ptr, obdata_ptr;
+
+	RNA_id_pointer_create((ID *)ob, &ob_ptr);
+	RNA_id_pointer_create(ob ? (ID *)ob->data : NULL, &obdata_ptr);
 
 	uiItemR(layout, ptr, "point_source", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
 	uiItemR(layout, ptr, "object", 0, NULL, ICON_NONE);
@@ -976,7 +981,18 @@ static void node_shader_buts_tex_pointdensity(uiLayout *layout, bContext *UNUSED
 	uiItemR(layout, ptr, "interpolation", 0, NULL, ICON_NONE);
 	uiItemR(layout, ptr, "resolution", 0, NULL, ICON_NONE);
 	if (shader_point_density->point_source == SHD_POINTDENSITY_SOURCE_PSYS) {
-		uiItemR(layout, ptr, "color_source", 0, NULL, ICON_NONE);
+		uiItemR(layout, ptr, "particle_color_source", 0, NULL, ICON_NONE);
+	}
+	else {
+		uiItemR(layout, ptr, "vertex_color_source", 0, NULL, ICON_NONE);
+		if (shader_point_density->ob_color_source == SHD_POINTDENSITY_COLOR_VERTWEIGHT) {
+			if (ob_ptr.data)
+				uiItemPointerR(layout, ptr, "vertex_attribute_name", &ob_ptr, "vertex_groups", "", ICON_NONE);
+		}
+		if (shader_point_density->ob_color_source == SHD_POINTDENSITY_COLOR_VERTCOL) {
+			if (obdata_ptr.data)
+				uiItemPointerR(layout, ptr, "vertex_attribute_name", &obdata_ptr, "vertex_colors", "", ICON_NONE);
+		}
 	}
 }
 
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index cf5d2df..c75a019 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -807,7 +807,8 @@ typedef struct NodeShaderTexPointDensity {
 	short space;
 	short interpolation;
 	short color_source;
-	short pad2;
+	short ob_color_source;
+	char vertex_attribute_name[64]; /* vertex attribute layer for color source, MAX_CUSTOMDATA_LAYER_NAME */
 	PointDensity pd;
 } NodeShaderTexPointDensity;
 
@@ -1142,4 +1143,10 @@ enum {
 	SHD_POINTDENSITY_COLOR_PARTVEL   = 3,
 };
 
+enum {
+	SHD_POINTDENSITY_COLOR_VERTCOL      = 0,
+	SHD_POINTDENSITY_COLOR_VERTWEIGHT   = 1,
+	SHD_POINTDENSITY_COLOR_VERTNOR      = 2,
+};
+
 #endif
diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h
index 2843d01..995d764 100644
--- a/source/blender/makesdna/DNA_texture_types.h
+++ b/source/blender/makesdna/DNA_texture_types.h
@@ -143,15 +143,18 @@ typedef struct PointDensity {
 	float falloff_softness;
 	float radius;
 	short source;
-	short color_source;
-	int totpoints;
+	short pad0;
+	
+	short color_source; /* psys_color_source */
+	short ob_color_source;
 	
-	int pdpad;
+	int totpoints;
 
 	struct Object *object;	/* for 'Object' or 'Particle system' type - source object */
 	int psys;				/* index+1 in ob.particlesystem, non-ID pointer not allowed */
 	short psys_cache_space;		/* cache points in worldspace, object space, ... ? */
 	short ob_cache_space;		/* cache points in worldspace, object space, ... ? */
+	char vertex_attribute_name[64]; /* vertex attribute layer for color source, MAX_CUSTOMDATA_LAYER_NAME */
 	
 	void *point_tree;		/* the acceleration tree containing points */
 	float *point_data;		/* dynamically allocated extra for extra information, like particle age */
@@ -160,10 +163,10 @@ typedef struct PointDensity {
 	short noise_depth;
 	short noise_influence;
 	short noise_basis;
-	short pdpad3[3];
+	short pad1[3];
 	float noise_fac;
 	
-	float speed_scale, falloff_speed_scale, pdpad2;
+	float speed_scale, falloff_speed_scale, pad2;
 	struct ColorBand *coba;	/* for time -> color */
 	
 	struct CurveMapping *falloff_curve; /* falloff density curve */
@@ -594,13 +597,21 @@ enum {
 #define TEX_PD_NOISE_TIME		3
 
 /* color_source */
-#define TEX_PD_COLOR_CONSTANT	0
-#define TEX_PD_COLOR_PARTAGE	1
-#define TEX_PD_COLOR_PARTSPEED	2
-#define TEX_PD_COLOR_PARTVEL	3
+enum {
+	TEX_PD_COLOR_CONSTANT	= 0,
+	/* color_source: particles */
+	TEX_PD_COLOR_PARTAGE	= 1,
+	TEX_PD_COLOR_PARTSPEED	= 2,
+	TEX_PD_COLOR_PARTVEL	= 3,
+	/* color_source: vertices */
+	TEX_PD_COLOR_VERTCOL	= 1,
+	TEX_PD_COLOR_VERTWEIGHT	= 2,
+	TEX_PD_COLOR_VERTNOR	= 3,
+};
 
 #define POINT_DATA_VEL		1
 #define POINT_DATA_LIFE		2
+#define POINT_DATA_COLOR	4
 
 /******************** Voxel Data *****************************/
 /* flag */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index a701cf6..ccbabb2 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -3030,12 +3030,30 @@ static void rna_ShaderNodePointDensity_psys_set(PointerRNA *ptr, PointerRNA valu
 	}
 }
 
-static int point_density_color_source_from_shader(NodeShaderTexPointDensity *shader_point_density)
+static int point_density_particle_color_source_from_shader(NodeShaderTexPointDensity *shader_point_density)
 {
 	switch (shader_point_density->color_source) {
-		case SHD_POINTDENSITY_COLOR_PARTAGE: return TEX_PD_COLOR_PARTAGE;
-		case SHD_POINTDENSITY_COLOR_PARTSPEED: return TEX_PD_COLOR_PARTSPEED;
-		case SHD_POINTDENSITY_COLOR_PARTVEL: return TEX_PD_COLOR_PARTVEL;
+		case SHD_POINTDENSITY_COLOR_PARTAGE:
+			return TEX_PD_COLOR_PARTAGE;
+		case SHD_POINTDENSITY_COLOR_PARTSPEED:
+			return TEX_PD_COLOR_PARTSPEED;
+		case SHD_POINTDENSITY_COLOR_PARTVEL:
+			return TEX_PD_COLOR_PARTVEL;
+		default:
+			BLI_assert(!"Unknown color source");
+			return TEX_PD_COLOR_CONSTANT;
+	}
+}
+
+static int point_density_vertex_color_source_from_shader(NodeShaderTexPointDensity *shader_point_density)
+{
+	switch (shader_point_density->ob_color_source) {
+		case SHD_POINTDENSITY_COLOR_VERTCOL:
+			return TEX_PD_COLOR_VERTCOL;
+		case SHD_POINTDENSITY_COLOR_VERTWEIGHT:
+			return TEX_PD_COLOR_VERTWEIGHT;
+		case SHD_POINTDENSITY_COLOR_VERTNOR:
+			return TEX_PD_COLOR_VERTNOR;
 		default:
 			BLI_assert(!"Unknown color source");
 			return TEX_PD_COLOR_CONSTANT;
@@ -3064,13 +3082,17 @@ void rna_ShaderNodePointDensity_density_cache(bNode *self,
 		pd->source = TEX_PD_PSYS;
 		pd->psys = shader_point_density->particle_system;
 		pd->psys_cache_space = TEX_PD_OBJECTSPACE;
+		pd->color_source = point_density_particle_color_source_from_shader(shader_point_density);
 	}
 	else {
 		BLI_assert(shader_point_density->point_source == SHD_POINTDENSITY_SOURCE_OBJECT);
 		pd->source = TEX_PD_OBJECT;
 		pd->ob_cache_space = TEX_PD_OBJECTSPACE;
+		pd->ob_color_source = point_density_vertex_color_source_from_shader(shader_point_density);
+		BLI_strncpy(pd->vertex_attribute_name,
+		            shader_point_density->vertex_attribute_name,
+		            sizeof(pd->vertex_attribute_name));
 	}
-	pd->color_source = point_density_color_source_from_shader(shader_point_density);
 
 	/* Single-threaded sampling of the voxel domain. */
 	RE_point_density_cache(scene,
@@ -4002,7 +4024,7 @@ static void def_sh_tex_pointdensity(StructRNA *srna)
 		{0, NULL, 0, NULL, NULL}
 	};
 
-	static EnumPropertyItem color_source_items[] = {
+	static EnumPropertyItem particle_color_source_items[] = {
 		{SHD_POINTDENSITY_COLOR_PARTAGE, "PARTICLE_AGE", 0, "Particle Age",
 		                                 "Lifetime mapped as 0.0 - 1.0 intensity"},
 		{SHD_POINTDENSITY_COLOR_PARTSPEED, "PARTICLE_SPEED", 0, "Particle Speed",
@@ -4012,6 +4034,14 @@ static void def_sh_tex_pointdensity(StructRNA *srna)
 		{0, NULL, 0, NULL, NULL}
 	};
 
+	static EnumPropertyItem vertex_color_source_items[] = {
+	    {SHD_POINTDENSITY_COLOR_VERTCOL, "VERTEX_COLOR", 0, "Vertex Color", "Vertex color layer"},
+	    {SHD_POINTDENSITY_COLOR_VERTWEIGHT, "VERTEX_WEIGHT", 0, "Vertex Weight", "Vertex group weight"},
+	    {SHD_POINTDENSITY_COLOR_VERTNOR, "VERTEX_NORMAL", 0, "Vertex Normal",
+	                                     "XYZ normal vector mapped to RGB colors"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	/* TODO(sergey): Use some mnemonic names for the hardcoded values here. */
 	static EnumPropertyItem calc_mode_items[] = {
 		{0, "VIEWPORT", 0, "Viewport", "Canculate density using viewport settings"},
@@ -4062,12 +4092,22 @@ static void def_sh_tex_pointdensity(StructRNA *srna)
 	RNA_def_property_ui_text(prop, "Interpolation", "Texture interpolation");
 	RNA_def_property_update(prop, 0, "rna_Node_update");
 
-	prop = RNA_def_property(srna, "color_source

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list