From 87f75299e1b07fd026ecdfa1c993130a60d65280 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Fri, 11 Jul 2014 16:51:04 +0900 Subject: Implemented a basic framework for node-based shaders. Shader nodes will be used to define materials for stroke rendering, so as to allow users to interactively configure textures. --- source/blender/editors/space_node/node_edit.c | 13 +++++++++++++ source/blender/editors/space_node/space_node.c | 7 +++++++ source/blender/makesdna/DNA_space_types.h | 1 + source/blender/makesrna/intern/rna_linestyle.c | 18 +++++++++++++++--- source/blender/makesrna/intern/rna_space.c | 1 + source/blender/nodes/CMakeLists.txt | 4 ++++ source/blender/nodes/SConscript | 3 +++ source/blender/nodes/shader/node_shader_tree.c | 11 +++++++++++ 8 files changed, 55 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 8422df35063..9616d01efb0 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -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; diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index ddfbe3bebf2..9eaee60bfce 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -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: diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index e7a98246ecc..6f57f549efb 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -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 ===================================== */ diff --git a/source/blender/makesrna/intern/rna_linestyle.c b/source/blender/makesrna/intern/rna_linestyle.c index 50b888b0247..f6f329e6b4d 100644 --- a/source/blender/makesrna/intern/rna_linestyle.c +++ b/source/blender/makesrna/intern/rna_linestyle.c @@ -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) diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 7dc77814ad5..201428a0a43 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -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} }; diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index e09a0892370..b485d7d86d2 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -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}") diff --git a/source/blender/nodes/SConscript b/source/blender/nodes/SConscript index 683a1c475e4..becf6e79d44 100644 --- a/source/blender/nodes/SConscript +++ b/source/blender/nodes/SConscript @@ -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] ) diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index 4288b8fbcdc..629bd7eeea6 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -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; -- cgit v1.2.3