[Bf-blender-cvs] [606f8b25762] hair_guides_grooming: Move material_index property from hair to groom.
Lukas Tönne
noreply at git.blender.org
Mon Jun 4 12:09:06 CEST 2018
Commit: 606f8b25762cc0738faf077a1c1c2ae9f9d9cf1f
Author: Lukas Tönne
Date: Mon Jun 4 11:07:37 2018 +0100
Branches: hair_guides_grooming
https://developer.blender.org/rB606f8b25762cc0738faf077a1c1c2ae9f9d9cf1f
Move material_index property from hair to groom.
This refers to a material slot in an object, so for pure hair system
would have to use the scalp object slots, which is confusing.
===================================================================
M intern/cycles/blender/blender_curves.cpp
M release/scripts/startup/bl_ui/properties_data_groom.py
M source/blender/blenkernel/intern/groom.c
M source/blender/blenkernel/intern/hair.c
M source/blender/draw/engines/eevee/eevee_materials.c
M source/blender/makesdna/DNA_groom_types.h
M source/blender/makesdna/DNA_hair_types.h
M source/blender/makesrna/intern/rna_groom.c
M source/blender/makesrna/intern/rna_hair.c
===================================================================
diff --git a/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp
index 417d845537c..ce881258225 100644
--- a/intern/cycles/blender/blender_curves.cpp
+++ b/intern/cycles/blender/blender_curves.cpp
@@ -298,11 +298,11 @@ static void ObtainCacheVColFromParticleSystem(BL::Mesh *b_mesh,
}
}
-static void ObtainCacheDataFromHairSystem(Mesh *mesh,
- BL::Object *b_ob,
+static void ObtainCacheDataFromHairSystem(BL::Object *b_ob,
BL::HairSystem *b_hsys,
+ int shader,
+ bool /*background*/,
ParticleCurveData *CData,
- bool background,
int *curvenum,
int *keyno)
{
@@ -325,11 +325,8 @@ static void ObtainCacheDataFromHairSystem(Mesh *mesh,
CData->psys_firstcurve.push_back_slow(*curvenum);
CData->psys_curvenum.push_back_slow(totcurves);
- {
- // Material
- int shader = clamp(b_hsys->material_index()-1, 0, mesh->used_shaders.size()-1);
- CData->psys_shader.push_back_slow(shader);
- }
+ // Material
+ CData->psys_shader.push_back_slow(shader);
{
// Cycles settings
@@ -438,11 +435,15 @@ static bool ObtainCacheDataFromObject(Mesh *mesh,
if((b_mod->type() == b_mod->type_FUR)) {
BL::FurModifier b_fmd((const PointerRNA)b_mod->ptr);
BL::HairSystem b_hsys = b_fmd.hair_system();
- ObtainCacheDataFromHairSystem(mesh,
- b_ob,
+
+ const int material_index = 1; /* TODO */
+ int shader = clamp(material_index - 1, 0, mesh->used_shaders.size()-1);
+
+ ObtainCacheDataFromHairSystem(b_ob,
&b_hsys,
- CData,
+ shader,
background,
+ CData,
&curvenum,
&keyno);
}
diff --git a/release/scripts/startup/bl_ui/properties_data_groom.py b/release/scripts/startup/bl_ui/properties_data_groom.py
index 9d96bed500b..cb799874e00 100644
--- a/release/scripts/startup/bl_ui/properties_data_groom.py
+++ b/release/scripts/startup/bl_ui/properties_data_groom.py
@@ -125,6 +125,8 @@ class DATA_PT_groom_draw_settings(DataButtonsPanel, Panel):
groom = context.groom
ds = groom.hair_draw_settings
+ layout.prop(groom, "material_slot")
+
split = layout.split()
col = split.column()
diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index 4972649d444..c9e39537bfc 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -78,6 +78,8 @@ void BKE_groom_init(Groom *groom)
groom->hair_system = BKE_hair_new();
groom->hair_draw_settings = BKE_hair_draw_settings_new();
+
+ groom->material_index = 1;
}
void *BKE_groom_add(Main *bmain, const char *name)
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 979c799810f..61e714a521f 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -60,8 +60,6 @@ HairSystem* BKE_hair_new(void)
hair->pattern = MEM_callocN(sizeof(HairPattern), "hair pattern");
- hair->material_index = 1;
-
return hair;
}
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index b4f31e72f96..9c4e4246086 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -1457,6 +1457,7 @@ static void material_hair(
EEVEE_ViewLayerData *sldata,
Object *ob,
HairSystem *hsys,
+ Material *material,
struct Mesh *scalp)
{
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
@@ -1483,9 +1484,8 @@ static void material_hair(
}
GPUTexture **fiber_texture = (GPUTexture **)(&hsys->draw_texture_cache);
- Material *ma = give_current_material(ob, hsys->material_index);
- if (ma == NULL) {
- ma = &defmaterial;
+ if (material == NULL) {
+ material = &defmaterial;
}
DRW_shgroup_call_add(stl->g_data->hair_fibers_depth_shgrp, hair_geom, mat);
@@ -1496,20 +1496,20 @@ static void material_hair(
DRW_hair_shader_uniforms(stl->g_data->hair_fibers_depth_shgrp_clip, scene,
fiber_texture, fiber_buffer);
- DRWShadingGroup *shgrp = BLI_ghash_lookup(material_hash, (const void *)ma);
+ DRWShadingGroup *shgrp = BLI_ghash_lookup(material_hash, (const void *)material);
if (!shgrp) {
- float *color_p = &ma->r;
- float *metal_p = &ma->ray_mirror;
- float *spec_p = &ma->spec;
- float *rough_p = &ma->gloss_mir;
+ float *color_p = &material->r;
+ float *metal_p = &material->ray_mirror;
+ float *spec_p = &material->spec;
+ float *rough_p = &material->gloss_mir;
- if (ma->use_nodes && ma->nodetree) {
- struct GPUMaterial *gpumat = EEVEE_material_hair_get(scene, ma, sldata->lamps->shadow_method, true);
+ if (material->use_nodes && material->nodetree) {
+ struct GPUMaterial *gpumat = EEVEE_material_hair_get(scene, material, sldata->lamps->shadow_method, true);
shgrp = DRW_shgroup_material_create(gpumat, psl->material_pass);
if (shgrp) {
add_standard_uniforms(shgrp, sldata, vedata, NULL, NULL, false, false);
- BLI_ghash_insert(material_hash, ma, shgrp);
+ BLI_ghash_insert(material_hash, material, shgrp);
}
else {
/* Shader failed : pink color */
@@ -1531,7 +1531,7 @@ static void material_hair(
DRW_shgroup_uniform_float(shgrp, "specular", spec_p, 1);
DRW_shgroup_uniform_float(shgrp, "roughness", rough_p, 1);
- BLI_ghash_insert(material_hash, ma, shgrp);
+ BLI_ghash_insert(material_hash, material, shgrp);
}
}
@@ -1737,14 +1737,21 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sld
}
else if (md->type == eModifierType_Fur) {
FurModifierData *fmd = (FurModifierData *)md;
- material_hair(vedata, sldata, ob, fmd->hair_system, ob->data);
+
+ const int material_index = 1; /* TODO */
+ Material *material = give_current_material(ob, material_index);
+
+ material_hair(vedata, sldata, ob, fmd->hair_system, material, ob->data);
}
}
}
}
else if (ob->type == OB_GROOM) {
Groom *groom = ob->data;
- material_hair(vedata, sldata, ob, groom->hair_system, BKE_groom_get_scalp(groom));
+
+ Material *material = give_current_material(ob, groom->material_index);
+
+ material_hair(vedata, sldata, ob, groom->hair_system, material, BKE_groom_get_scalp(groom));
}
}
diff --git a/source/blender/makesdna/DNA_groom_types.h b/source/blender/makesdna/DNA_groom_types.h
index 2832efb363e..7a0713c69a3 100644
--- a/source/blender/makesdna/DNA_groom_types.h
+++ b/source/blender/makesdna/DNA_groom_types.h
@@ -138,7 +138,11 @@ typedef struct Groom {
struct Material **mat; /* Material slots */
short totcol; /* Number of material slots */
short pad3;
- int pad4;
+
+ /* Material used for drawing and rendering hair fibers
+ * TODO make this a per-region setting (requires separate shader group for each region)
+ */
+ int material_index;
struct BoundBox *bb;
diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h
index ecf55eb9248..9aa254d5c83 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -91,10 +91,6 @@ typedef struct HairSystem {
/* Guide curve data */
HairGuideData guides;
- /* Material used for drawing and rendering hair fibers */
- int material_index;
- int pad2;
-
/* Data buffers for drawing */
void *draw_batch_cache;
/* Texture buffer for drawing */
diff --git a/source/blender/makesrna/intern/rna_groom.c b/source/blender/makesrna/intern/rna_groom.c
index 904761ce835..d2341f1bbb5 100644
--- a/source/blender/makesrna/intern/rna_groom.c
+++ b/source/blender/makesrna/intern/rna_groom.c
@@ -58,6 +58,7 @@
#include "WM_api.h"
#include "BKE_groom.h"
+#include "BKE_material.h"
#include "BKE_object_facemap.h"
#include "DEG_depsgraph.h"
@@ -133,6 +134,49 @@ static void rna_Groom_active_bundle_index_range(
*max = max_ii(0, BLI_listbase_count(&groom->bundles) - 1);
}
+static const EnumPropertyItem *rna_Groom_material_slot_itemf(
+ bContext *C,
+ PointerRNA *UNUSED(ptr),
+ PropertyRNA *UNUSED(prop),
+ bool *r_free)
+{
+ Object *ob = CTX_data_pointer_get(C, "object").data;
+ Material *ma;
+ EnumPropertyItem *item = NULL;
+ EnumPropertyItem tmp = {0, "", 0, "", ""};
+ int totitem = 0;
+ int i;
+
+ if (ob && ob->totcol > 0) {
+ for (i = 1; i <= ob->totcol; i++) {
+ ma = give_current_material(ob, i);
+ tmp.value = i;
+ tmp.icon = ICON_MATERIAL_DATA;
+ if (ma) {
+ tmp.name = ma->id.name + 2;
+ tmp.identifier = tmp.name;
+ }
+ else {
+ tmp.name = "Default Material";
+ tmp.identifier = tmp.name;
+ }
+ RNA_enum_item_add(&item, &totitem, &tmp);
+ }
+ }
+ else {
+ tmp.value = 1;
+ tmp.icon = ICON_MATERIAL_DATA;
+ tmp.name = "Default Material";
+ tmp.identifier = tmp.name;
+ RNA_enum_item_add(&item, &totitem, &tmp);
+ }
+
+ RNA_enum_item_end(&item, &totitem);
+ *r_free = true;
+
+ return item;
+}
+
#else
static void rna_def_groom_bundle(BlenderRNA *brna)
@@ -195,6 +239,11 @@ static void rna_def_groom(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
+ static const EnumPropertyItem material_slot_items[] = {
+ {0, "DUMMY", 0, "Dummy", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
srna = RNA_def_struct(brna, "Groom", "ID");
RNA_def_struct_sdna(srna, "Groom");
RNA_def_struct_ui_text(srna, "Groom", "Guide curve geometry for hair");
@@ -230,6 +279,19 @@ static void rna_def_groom(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_update(prop, 0, "rna_Groom_update_data");
+ prop = RNA_def_property(srna, "material_i
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list