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.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 ===================================== */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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}
|
||||
};
|
||||
|
||||
|
||||
@@ -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}")
|
||||
|
||||
@@ -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] )
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user