Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2016-03-24 13:41:44 +0300
committerLukas Tönne <lukas.toenne@gmail.com>2016-03-24 14:07:03 +0300
commitbdae647670817f4c09d4c871314f237dde1bfaac (patch)
tree59907fb1b268a3023e43b3b4568798a5e4c3f7e2 /source/blender/makesrna/intern/rna_nodetree.c
parent8e9a55f1e51daaadf92cd4f8236e3214b8db7c85 (diff)
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.
Diffstat (limited to 'source/blender/makesrna/intern/rna_nodetree.c')
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c56
1 files changed, 48 insertions, 8 deletions
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index a701cf6182d..ccbabb2b238 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", PROP_ENUM, PROP_NONE);
+ prop = RNA_def_property(srna, "particle_color_source", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "color_source");
- RNA_def_property_enum_items(prop, color_source_items);
+ RNA_def_property_enum_items(prop, particle_color_source_items);
RNA_def_property_ui_text(prop, "Color Source", "Data to derive color results from");
RNA_def_property_update(prop, 0, "rna_Node_update");
+ prop = RNA_def_property(srna, "vertex_color_source", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "ob_color_source");
+ RNA_def_property_enum_items(prop, vertex_color_source_items);
+ RNA_def_property_ui_text(prop, "Color Source", "Data to derive color results from");
+ RNA_def_property_update(prop, 0, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "vertex_attribute_name", PROP_STRING, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Vertex Attribute Name", "Vertex attribute to use for color");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
func = RNA_def_function(srna, "cache_point_density", "rna_ShaderNodePointDensity_density_cache");
RNA_def_function_ui_description(func, "Cache point density data for later calculation");
RNA_def_pointer(func, "scene", "Scene", "", "");