Bugfix #25301
authorTon Roosendaal <ton@blender.org>
Mon, 20 Dec 2010 13:02:33 +0000 (13:02 +0000)
committerTon Roosendaal <ton@blender.org>
Mon, 20 Dec 2010 13:02:33 +0000 (13:02 +0000)
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)

source/blender/editors/render/render_preview.c
source/blender/makesrna/intern/rna_object.c
source/blender/render/intern/source/sss.c

index f8c8faffc88290a950c8a568919e1c30bf4b0274..2eac7c203502d3c22466cc2f9d35843a22ba69a7 100644 (file)
@@ -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 */
index 2c5cddca77ffcd31991108fdc748224cb5081d03..6031d3e29d9da775e9ab433ee493f6a358560c5f 100644 (file)
@@ -587,12 +587,29 @@ 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);
 }
 
@@ -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);
index 993e0aeb9c341d31d6809c6fc1989af21533353f..4bccb46d3d855a41e9cc93bedb7b28bc9693bcf9 100644 (file)
@@ -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)