Shaders: add target setting to material output node.
This makes it possible to have a single shading nodetree that contains separate Cycles and Eevee shaders. By default the target is set to All so shaders are shared.
This commit is contained in:
@@ -812,6 +812,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, c
|
||||
struct bNodeTreeExec *ntreeShaderBeginExecTree(struct bNodeTree *ntree);
|
||||
void ntreeShaderEndExecTree(struct bNodeTreeExec *exec);
|
||||
bool ntreeShaderExecTree(struct bNodeTree *ntree, int thread);
|
||||
struct bNode *ntreeShaderOutputNode(struct bNodeTree *ntree, int target);
|
||||
|
||||
void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat,
|
||||
bool *has_surface_output, bool *has_volume_output);
|
||||
|
||||
@@ -1066,6 +1066,11 @@ static void node_shader_buts_script_ex(uiLayout *layout, bContext *C, PointerRNA
|
||||
#endif
|
||||
}
|
||||
|
||||
static void node_buts_output_shader(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
|
||||
{
|
||||
uiItemR(layout, ptr, "target", 0, "", ICON_NONE);
|
||||
}
|
||||
|
||||
static void node_buts_output_linestyle(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
|
||||
{
|
||||
uiLayout *row, *col;
|
||||
@@ -1209,6 +1214,11 @@ static void node_shader_set_butfunc(bNodeType *ntype)
|
||||
case SH_NODE_UVALONGSTROKE:
|
||||
ntype->draw_buttons = node_shader_buts_uvalongstroke;
|
||||
break;
|
||||
case SH_NODE_OUTPUT_MATERIAL:
|
||||
case SH_NODE_OUTPUT_LAMP:
|
||||
case SH_NODE_OUTPUT_WORLD:
|
||||
ntype->draw_buttons = node_buts_output_shader;
|
||||
break;
|
||||
case SH_NODE_OUTPUT_LINESTYLE:
|
||||
ntype->draw_buttons = node_buts_output_linestyle;
|
||||
break;
|
||||
|
||||
@@ -1101,39 +1101,6 @@ enum {
|
||||
|
||||
#define CMP_NODE_MASK_MBLUR_SAMPLES_MAX 64
|
||||
|
||||
/* geometry output socket defines */
|
||||
#define GEOM_OUT_GLOB 0
|
||||
#define GEOM_OUT_LOCAL 1
|
||||
#define GEOM_OUT_VIEW 2
|
||||
#define GEOM_OUT_ORCO 3
|
||||
#define GEOM_OUT_UV 4
|
||||
#define GEOM_OUT_NORMAL 5
|
||||
#define GEOM_OUT_VCOL 6
|
||||
#define GEOM_OUT_VCOL_ALPHA 7
|
||||
#define GEOM_OUT_FRONTBACK 8
|
||||
|
||||
/* material input socket defines */
|
||||
#define MAT_IN_COLOR 0
|
||||
#define MAT_IN_SPEC 1
|
||||
#define MAT_IN_REFL 2
|
||||
#define MAT_IN_NORMAL 3
|
||||
#define MAT_IN_MIR 4
|
||||
#define MAT_IN_AMB 5
|
||||
#define MAT_IN_EMIT 6
|
||||
#define MAT_IN_SPECTRA 7
|
||||
#define MAT_IN_RAY_MIRROR 8
|
||||
#define MAT_IN_ALPHA 9
|
||||
#define MAT_IN_TRANSLUCENCY 10
|
||||
#define NUM_MAT_IN 11 /* for array size */
|
||||
|
||||
/* material output socket defines */
|
||||
#define MAT_OUT_COLOR 0
|
||||
#define MAT_OUT_ALPHA 1
|
||||
#define MAT_OUT_NORMAL 2
|
||||
#define MAT_OUT_DIFFUSE 3
|
||||
#define MAT_OUT_SPEC 4
|
||||
#define MAT_OUT_AO 5
|
||||
|
||||
/* image */
|
||||
#define CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT 1
|
||||
|
||||
@@ -1176,4 +1143,12 @@ enum {
|
||||
SHD_POINTDENSITY_COLOR_VERTNOR = 2,
|
||||
};
|
||||
|
||||
/* Output shader node */
|
||||
|
||||
typedef enum NodeShaderOutputTarget {
|
||||
SHD_OUTPUT_ALL = 0,
|
||||
SHD_OUTPUT_EEVEE = 1,
|
||||
SHD_OUTPUT_CYCLES = 2,
|
||||
} NodeShaderOutputTarget;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -175,6 +175,14 @@ static const EnumPropertyItem node_sampler_type_items[] = {
|
||||
{2, "BICUBIC", 0, "Bicubic", ""},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
static const EnumPropertyItem prop_shader_output_target_items[] = {
|
||||
{SHD_OUTPUT_ALL, "ALL", 0, "All", "Use shaders for all renderers and viewports, unless there exists a more specific output"},
|
||||
{SHD_OUTPUT_EEVEE, "EEVEE", 0, "Eevee", "Use shaders for Eevee renderer"},
|
||||
{SHD_OUTPUT_CYCLES, "CYCLES", 0, "Cycles", "Use shaders for Cycles renderer"},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef RNA_RUNTIME
|
||||
@@ -3536,6 +3544,12 @@ static void def_sh_output(StructRNA *srna)
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", NODE_DO_OUTPUT);
|
||||
RNA_def_property_ui_text(prop, "Active Output", "True if this node is used as the active output");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
|
||||
prop = RNA_def_property(srna, "target", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "custom1");
|
||||
RNA_def_property_enum_items(prop, prop_shader_output_target_items);
|
||||
RNA_def_property_ui_text(prop, "Target", "Which renderer and viewport shading types to use the shaders for");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
}
|
||||
|
||||
static void def_sh_output_linestyle(StructRNA *srna)
|
||||
@@ -8377,12 +8391,21 @@ static void rna_def_composite_nodetree(BlenderRNA *brna)
|
||||
static void rna_def_shader_nodetree(BlenderRNA *brna)
|
||||
{
|
||||
StructRNA *srna;
|
||||
FunctionRNA *func;
|
||||
PropertyRNA *parm;
|
||||
|
||||
srna = RNA_def_struct(brna, "ShaderNodeTree", "NodeTree");
|
||||
RNA_def_struct_ui_text(srna, "Shader Node Tree",
|
||||
"Node tree consisting of linked nodes used for materials (and other shading data-blocks)");
|
||||
RNA_def_struct_sdna(srna, "bNodeTree");
|
||||
RNA_def_struct_ui_icon(srna, ICON_MATERIAL);
|
||||
|
||||
func = RNA_def_function(srna, "get_output_node", "ntreeShaderOutputNode");
|
||||
RNA_def_function_ui_description(func, "Return active shader output node for the specified target");
|
||||
parm = RNA_def_enum(func, "target", prop_shader_output_target_items, SHD_OUTPUT_ALL, "Target", "");
|
||||
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
|
||||
parm = RNA_def_pointer(func, "node", "ShaderNode", "Node", "");
|
||||
RNA_def_function_return(func, parm);
|
||||
}
|
||||
|
||||
static void rna_def_texture_nodetree(BlenderRNA *brna)
|
||||
|
||||
@@ -209,20 +209,52 @@ static void ntree_shader_link_builtin_normal(bNodeTree *ntree,
|
||||
* render engines works but it's how the GPU shader compilation works. This we
|
||||
* can change in the future and make it a generic function, but for now it stays
|
||||
* private here.
|
||||
*
|
||||
* It also does not yet take into account render engine specific output nodes,
|
||||
* it should give priority to e.g. the Eevee material output node for Eevee.
|
||||
*/
|
||||
static bNode *ntree_shader_output_node(bNodeTree *ntree)
|
||||
bNode *ntreeShaderOutputNode(bNodeTree *ntree, int target)
|
||||
{
|
||||
/* Make sure we only have single node tagged as output. */
|
||||
ntreeSetOutput(ntree);
|
||||
for (bNode *node = ntree->nodes.first; node != NULL; node = node->next) {
|
||||
if (node->flag & NODE_DO_OUTPUT) {
|
||||
return node;
|
||||
|
||||
/* Find output node that matches type and target. If there are
|
||||
* multiple, we prefer exact target match and active nodes. */
|
||||
bNode *output_node = NULL;
|
||||
|
||||
for (bNode *node = ntree->nodes.first; node; node = node->next) {
|
||||
if (!ELEM(node->type, SH_NODE_OUTPUT_MATERIAL,
|
||||
SH_NODE_OUTPUT_WORLD,
|
||||
SH_NODE_OUTPUT_LAMP))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node->custom1 == SHD_OUTPUT_ALL) {
|
||||
if (output_node == NULL) {
|
||||
output_node = node;
|
||||
}
|
||||
else if (output_node->custom1 == SHD_OUTPUT_ALL) {
|
||||
if ((node->flag & NODE_DO_OUTPUT) &&
|
||||
!(output_node->flag & NODE_DO_OUTPUT))
|
||||
{
|
||||
output_node = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node->custom1 == target) {
|
||||
if (output_node == NULL) {
|
||||
output_node = node;
|
||||
}
|
||||
else if(output_node->custom1 == SHD_OUTPUT_ALL) {
|
||||
output_node = node;
|
||||
}
|
||||
else if ((node->flag & NODE_DO_OUTPUT) &&
|
||||
!(output_node->flag & NODE_DO_OUTPUT))
|
||||
{
|
||||
output_node = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
return output_node;
|
||||
}
|
||||
|
||||
/* Find socket with a specified identifier. */
|
||||
@@ -555,7 +587,7 @@ void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, bool *has_surface
|
||||
{
|
||||
/* localize tree to create links for reroute and mute */
|
||||
bNodeTree *localtree = ntreeLocalize(ntree);
|
||||
bNode *output = ntree_shader_output_node(localtree);
|
||||
bNode *output = ntreeShaderOutputNode(localtree, SHD_OUTPUT_EEVEE);
|
||||
bNodeTreeExec *exec;
|
||||
|
||||
/* Perform all needed modifications on the tree in order to support
|
||||
|
||||
Reference in New Issue
Block a user