Implemented a basic framework for node-based shaders.
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Fri, 11 Jul 2014 07:51:04 +0000 (16:51 +0900)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Tue, 12 Aug 2014 01:10:14 +0000 (10:10 +0900)
Shader nodes will be used to define materials for stroke rendering, so as to
allow users to interactively configure textures.

release/scripts/startup/bl_ui/space_node.py
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/space_node.c
source/blender/makesdna/DNA_space_types.h
source/blender/makesrna/intern/rna_linestyle.c
source/blender/makesrna/intern/rna_space.c
source/blender/nodes/CMakeLists.txt
source/blender/nodes/SConscript
source/blender/nodes/shader/node_shader_tree.c

index 959043f7931bd0b4a65b5ec8fe2384d29330d93b..e8914a3e9b023b9fa8ab7edf548c566ad530d37a 100644 (file)
@@ -67,6 +67,16 @@ class NODE_HT_header(Header):
                 if snode_id:
                     row.prop(snode_id, "use_nodes")
 
+            if scene.render.use_shading_nodes and snode.shader_type == 'LINESTYLE':
+                rl = context.scene.render.layers.active
+                lineset = rl.freestyle_settings.linesets.active
+                if lineset is not None:
+                    row = layout.row()
+                    row.enabled = not snode.pin
+                    row.template_ID(lineset, "linestyle", new="scene.freestyle_linestyle_new")
+                    if snode_id:
+                        row.prop(snode_id, "use_nodes")
+
         elif snode.tree_type == 'TextureNodeTree':
             layout.prop(snode, "texture_type", text="", expand=True)
 
index 8422df35063d35daf50a58308eb06d9d9150e50b..9616d01efb0079afc308e1b23ed39180e32d84f9 100644 (file)
@@ -434,6 +434,19 @@ void ED_node_shader_default(const bContext *C, ID *id)
                                strength = 1.0f;
                        break;
                }
+               case ID_LS:
+               {
+                       FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
+                       linestyle->nodetree = ntree;
+
+                       /* TODO use appropriate output_type & shader_type */
+                       output_type = SH_NODE_OUTPUT_MATERIAL;
+                       shader_type = SH_NODE_BSDF_DIFFUSE;
+
+                       copy_v3_v3(color, &linestyle->r);
+                       strength = 1.0f;
+                       break;
+               }
                default:
                        printf("ED_node_shader_default called on wrong ID type.\n");
                        return;
index ddfbe3bebf2fbb0b8ed1861402100e43cfdaff3a..9eaee60bfce80cd627000a8efa687295a6834df4 100644 (file)
@@ -501,6 +501,12 @@ static void node_area_listener(bScreen *sc, ScrArea *sa, wmNotifier *wmn)
                                }
                        }
                        break;
+
+               case NC_LINESTYLE:
+                       if (ED_node_is_shader(snode) && shader_type == SNODE_SHADER_LINESTYLE) {
+                               ED_area_tag_refresh(sa);
+                       }
+                       break;
        }
 }
 
@@ -740,6 +746,7 @@ static void node_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegi
                case NC_TEXTURE:
                case NC_WORLD:
                case NC_NODE:
+               case NC_LINESTYLE:
                        ED_region_tag_redraw(ar);
                        break;
                case NC_OBJECT:
index e7a98246eccb5a5e0c3c534052f17b6efdd01648..6f57f549efb918c5da8ae6ae96ad1bd248ef6311 100644 (file)
@@ -991,6 +991,7 @@ typedef enum eSpaceNode_TexFrom {
 typedef enum eSpaceNode_ShaderFrom {
        SNODE_SHADER_OBJECT = 0,
        SNODE_SHADER_WORLD = 1,
+       SNODE_SHADER_LINESTYLE = 2,
 } eSpaceNode_ShaderFrom;
 
 /* Game Logic Editor ===================================== */
index 50b888b02472aa53af42a40bd43002518af61c3c..f6f329e6b4db74f605b45b17e181038498fbc5ea 100644 (file)
@@ -87,6 +87,8 @@ EnumPropertyItem linestyle_geometry_modifier_type_items[] = {
 #include "BKE_texture.h"
 #include "BKE_depsgraph.h"
 
+#include "ED_node.h"
+
 #include "RNA_access.h"
 
 static StructRNA *rna_LineStyle_color_modifier_refine(struct PointerRNA *ptr)
@@ -283,6 +285,16 @@ static void rna_LineStyle_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poin
        WM_main_add_notifier(NC_LINESTYLE, linestyle);
 }
 
+static void rna_LineStyle_use_nodes_update(bContext *C, PointerRNA *ptr)
+{
+       FreestyleLineStyle *linestyle = (FreestyleLineStyle *)ptr->data;
+
+       if (linestyle->use_nodes && linestyle->nodetree == NULL)
+               ED_node_shader_default(C, &linestyle->id);
+
+       rna_LineStyle_update(CTX_data_main(C), CTX_data_scene(C), ptr);
+}
+
 static LineStyleModifier *rna_LineStyle_color_modifier_add(FreestyleLineStyle *linestyle, ReportList *reports,
                                                            const char *name, int type)
 {
@@ -1606,14 +1618,14 @@ static void rna_def_linestyle(BlenderRNA *brna)
        /* nodes */
        prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
        RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
-       RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based textures");
+       RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node-based shaders");
 
        prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "use_nodes", 1);
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
        RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
-       RNA_def_property_ui_text(prop, "Use Nodes", "Use texture nodes for the line style");
-       RNA_def_property_update(prop, NC_LINESTYLE, "rna_LineStyle_update");
+       RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes for the line style");
+       RNA_def_property_update(prop, NC_LINESTYLE, "rna_LineStyle_use_nodes_update");
 }
 
 void RNA_def_linestyle(BlenderRNA *brna)
index 7dc77814ad5d51cc4db756aed445a6d935a35217..201428a0a435e67d17dfbe2caa0815081fc7c2ed 100644 (file)
@@ -3418,6 +3418,7 @@ static void rna_def_space_node(BlenderRNA *brna)
        static EnumPropertyItem shader_type_items[] = {
                {SNODE_SHADER_OBJECT, "OBJECT", ICON_OBJECT_DATA, "Object", "Edit shader nodes from Object"},
                {SNODE_SHADER_WORLD, "WORLD", ICON_WORLD_DATA, "World", "Edit shader nodes from World"},
+               {SNODE_SHADER_LINESTYLE, "LINESTYLE", ICON_LINE_DATA, "Line Style", "Edit shader nodes from Line Style"},
                {0, NULL, 0, NULL, NULL}
        };
 
index e09a0892370dfb5de6130679960912c336796c66..b485d7d86d2e5b9edc473fbc802651ace319c95d 100644 (file)
@@ -277,4 +277,8 @@ if(WITH_COMPOSITOR)
        add_definitions(-DWITH_COMPOSITOR)
 endif()
 
+if(WITH_FREESTYLE)
+       add_definitions(-DWITH_FREESTYLE)
+endif()
+
 blender_add_lib(bf_nodes "${SRC}" "${INC}" "${INC_SYS}")
index 683a1c475e4d89959b2691616271fdf4bef703db..becf6e79d448754b5ac6be10f75cf1a320539d5f 100644 (file)
@@ -72,6 +72,9 @@ if env['WITH_BF_COMPOSITOR']:
     incs += ' ../compositor '
     defs.append("WITH_COMPOSITOR")
 
+if env['WITH_BF_FREESTYLE']:
+    defs.append('WITH_FREESTYLE')
+
 env.BlenderLib ( libname = 'bf_nodes', sources = sources, includes = Split(incs), defines = defs, libtype=['core','player'], priority = [190,105] )
 env.BlenderLib ( libname = 'bf_cmpnodes', sources = cmpsources, includes = Split(incs), defines = defs, libtype=['core','player'], priority = [175,101] )
 env.BlenderLib ( libname = 'bf_shdnodes', sources = shdsources, includes = Split(incs), defines = defs, libtype=['core','player'], priority = [175,101] )
index 4288b8fbcdcf0c973fb4371af8b94b841442dd5b..629bd7eeea6bc715674dad9e61618b2d45b8c7af 100644 (file)
@@ -38,6 +38,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_space_types.h"
 #include "DNA_world_types.h"
+#include "DNA_linestyle_types.h"
 
 #include "BLI_listbase.h"
 #include "BLI_math.h"
@@ -97,6 +98,16 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre
                        }
                }
        }
+#ifdef WITH_FREESTYLE
+       else if (snode->shaderfrom == SNODE_SHADER_LINESTYLE) {
+               FreestyleLineStyle *linestyle = CTX_data_linestyle_from_scene(scene);
+               if (linestyle) {
+                       *r_from = NULL;
+                       *r_id = &linestyle->id;
+                       *r_ntree = linestyle->nodetree;
+               }
+       }
+#endif
        else { /* SNODE_SHADER_WORLD */
                if (scene->world) {
                        *r_from = NULL;