Material Node trees:
SSS wasn't displaying in Nodes.

Implementation notes:
- Currently copying local data for preview render, only copies
  the base material. Node materials are re-used.
- This causes data to be in 2 "main" databases... complex.
- To make it work for preview, I had to add another loop in the
  SSS code that checks the original Main dbase. That's marked
  as warning in code to be fixed up.

Another bug:
- Material properties "SSS presets" copied settings to the
  active material, not to the displayed one. Added RNA call 
  to retrieve this from Objects.

(Next commit will fix preset scripts)
This commit is contained in:
Ton Roosendaal 2010-12-20 13:02:33 +00:00
parent 88b2955564
commit 6b1258f5b8
3 changed files with 61 additions and 2 deletions

@ -49,6 +49,7 @@
#include "DNA_world_types.h"
#include "DNA_camera_types.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_lamp_types.h"
#include "DNA_space_types.h"
@ -309,6 +310,32 @@ static Object *find_object(ListBase *lb, const char *name)
return ob;
}
static int preview_mat_has_sss(Material *mat, bNodeTree *ntree)
{
if(mat) {
if(mat->sss_flag & MA_DIFF_SSS)
return 1;
if(mat->nodetree)
if( preview_mat_has_sss(NULL, mat->nodetree))
return 1;
}
else if(ntree) {
bNode *node;
for(node= ntree->nodes.first; node; node= node->next) {
if(node->type==NODE_GROUP && node->id) {
if( preview_mat_has_sss(NULL, (bNodeTree *)node->id))
return 1;
}
else if(node->id && ELEM(node->type, SH_NODE_MATERIAL, SH_NODE_MATERIAL_EXT)) {
mat= (Material *)node->id;
if(mat->sss_flag & MA_DIFF_SSS)
return 1;
}
}
}
return 0;
}
/* call this with a pointer to initialize preview scene */
/* call this with NULL to restore assigned ID pointers in preview scene */
static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPreview *sp)
@ -361,7 +388,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
sce->r.mode |= R_RAYTRACE;
if((mat->mode_l & MA_RAYTRANSP) && (mat->mode_l & MA_TRANSP))
sce->r.mode |= R_RAYTRACE;
if(mat->sss_flag & MA_DIFF_SSS)
if(preview_mat_has_sss(mat, NULL))
sce->r.mode |= R_SSS;
/* turn off fake shadows if needed */

@ -587,15 +587,32 @@ static void rna_Object_active_material_index_range(PointerRNA *ptr, int *min, in
*max= MAX2(ob->totcol-1, 0);
}
/* returns active base material */
static PointerRNA rna_Object_active_material_get(PointerRNA *ptr)
{
Object *ob= (Object*)ptr->id.data;
Material *ma;
ma= (ob->totcol)? give_current_material(ob, ob->actcol): NULL;
return rna_pointer_inherit_refine(ptr, &RNA_Material, ma);
}
/* returns (optional) active node material in base material */
static PointerRNA rna_Object_active_node_material_get(PointerRNA *ptr)
{
Object *ob= (Object*)ptr->id.data;
Material *ma;
ma= (ob->totcol)? give_current_material(ob, ob->actcol): NULL;
if(ma) {
Material *manode= give_node_material(ma);
if(manode)
return rna_pointer_inherit_refine(ptr, &RNA_Material, manode);
}
return rna_pointer_inherit_refine(ptr, &RNA_Material, ma);
}
static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value)
{
Object *ob= (Object*)ptr->id.data;
@ -1777,6 +1794,13 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Active Material", "Active material being displayed");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_MaterialSlot_update");
prop= RNA_def_property(srna, "active_node_material", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Material");
RNA_def_property_pointer_funcs(prop, "rna_Object_active_node_material_get", NULL, NULL, NULL);
RNA_def_property_ui_text(prop, "Active Material", "Active (node) material being displayed");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
prop= RNA_def_property(srna, "active_material_index", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "actcol");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);

@ -997,6 +997,14 @@ void make_sss_tree(Render *re)
if(mat->id.us && (mat->flag & MA_IS_USED) && (mat->sss_flag & MA_DIFF_SSS))
sss_create_tree_mat(re, mat);
/* XXX preview exception */
/* localizing preview render data is not fun for node trees :( */
if(re->main!=G.main) {
for(mat= G.main->mat.first; mat; mat= mat->id.next)
if(mat->id.us && (mat->flag & MA_IS_USED) && (mat->sss_flag & MA_DIFF_SSS))
sss_create_tree_mat(re, mat);
}
}
void free_sss(Render *re)