diff options
Diffstat (limited to 'source/blender/nodes')
110 files changed, 906 insertions, 1689 deletions
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index 7ef41b25de8..8df114afa24 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -32,6 +32,7 @@ set(INC ../blenkernel ../blenlib ../blentranslation + ../depsgraph ../gpu ../imbuf ../makesdna @@ -135,22 +136,17 @@ set(SRC shader/nodes/node_shader_curves.c shader/nodes/node_shader_gamma.c shader/nodes/node_shader_brightness.c - shader/nodes/node_shader_geom.c shader/nodes/node_shader_hueSatVal.c shader/nodes/node_shader_invert.c - shader/nodes/node_shader_lamp.c shader/nodes/node_shader_mapping.c - shader/nodes/node_shader_material.c shader/nodes/node_shader_math.c shader/nodes/node_shader_mixRgb.c shader/nodes/node_shader_normal.c - shader/nodes/node_shader_output.c shader/nodes/node_shader_rgb.c shader/nodes/node_shader_sepcombRGB.c shader/nodes/node_shader_sepcombHSV.c shader/nodes/node_shader_sepcombXYZ.c shader/nodes/node_shader_squeeze.c - shader/nodes/node_shader_texture.c shader/nodes/node_shader_valToRgb.c shader/nodes/node_shader_value.c shader/nodes/node_shader_wireframe.c @@ -184,9 +180,11 @@ set(SRC shader/nodes/node_shader_light_falloff.c shader/nodes/node_shader_light_path.c shader/nodes/node_shader_mix_shader.c + shader/nodes/node_shader_shaderToRgb.c shader/nodes/node_shader_normal_map.c shader/nodes/node_shader_object_info.c shader/nodes/node_shader_hair_info.c + shader/nodes/node_shader_eevee_specular.c shader/nodes/node_shader_output_lamp.c shader/nodes/node_shader_output_material.c shader/nodes/node_shader_output_world.c diff --git a/source/blender/nodes/NOD_composite.h b/source/blender/nodes/NOD_composite.h index 2a82b706de5..a728d1e228d 100644 --- a/source/blender/nodes/NOD_composite.h +++ b/source/blender/nodes/NOD_composite.h @@ -141,7 +141,7 @@ void register_node_type_cmp_planetrackdeform(void); void register_node_type_cmp_cornerpin(void); void node_cmp_rlayers_outputs(struct bNodeTree *ntree, struct bNode *node); -void node_cmp_rlayers_register_pass(struct bNodeTree *ntree, struct bNode *node, struct Scene *scene, struct SceneRenderLayer *srl, const char *name, int type); +void node_cmp_rlayers_register_pass(struct bNodeTree *ntree, struct bNode *node, struct Scene *scene, struct ViewLayer *view_layer, const char *name, int type); const char *node_cmp_rlayers_sock_to_pass(int sock_index); #endif diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index d4134f09597..2f466b0296c 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -44,20 +44,16 @@ void register_node_tree_type_sh(void); void register_node_type_sh_group(void); -void register_node_type_sh_output(void); -void register_node_type_sh_material(void); void register_node_type_sh_camera(void); -void register_node_type_sh_lamp(void); void register_node_type_sh_value(void); void register_node_type_sh_rgb(void); void register_node_type_sh_mix_rgb(void); void register_node_type_sh_valtorgb(void); void register_node_type_sh_rgbtobw(void); -void register_node_type_sh_texture(void); +void register_node_type_sh_shadertorgb(void); void register_node_type_sh_normal(void); void register_node_type_sh_gamma(void); void register_node_type_sh_brightcontrast(void); -void register_node_type_sh_geom(void); void register_node_type_sh_mapping(void); void register_node_type_sh_curve_vec(void); void register_node_type_sh_curve_rgb(void); @@ -65,7 +61,6 @@ void register_node_type_sh_math(void); void register_node_type_sh_vect_math(void); void register_node_type_sh_squeeze(void); void register_node_type_sh_dynamic(void); -void register_node_type_sh_material_ext(void); void register_node_type_sh_invert(void); void register_node_type_sh_seprgb(void); void register_node_type_sh_combrgb(void); @@ -122,9 +117,12 @@ void register_node_type_sh_mix_shader(void); void register_node_type_sh_add_shader(void); void register_node_type_sh_uvmap(void); void register_node_type_sh_uvalongstroke(void); +void register_node_type_sh_eevee_metallic(void); +void register_node_type_sh_eevee_specular(void); void register_node_type_sh_output_lamp(void); void register_node_type_sh_output_material(void); +void register_node_type_sh_output_eevee_material(void); void register_node_type_sh_output_world(void); void register_node_type_sh_output_linestyle(void); diff --git a/source/blender/nodes/NOD_socket.h b/source/blender/nodes/NOD_socket.h index 42735b21e03..3ff65ce4fd9 100644 --- a/source/blender/nodes/NOD_socket.h +++ b/source/blender/nodes/NOD_socket.h @@ -49,7 +49,7 @@ struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree, struc void node_verify_socket_templates(struct bNodeTree *ntree, struct bNode *node); void node_socket_init_default_value(struct bNodeSocket *sock); -void node_socket_copy_default_value(struct bNodeSocket *to, struct bNodeSocket *from); +void node_socket_copy_default_value(struct bNodeSocket *to, const struct bNodeSocket *from); void register_standard_node_socket_types(void); #endif diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index 2fa8cda56a5..22c2afcc466 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -40,34 +40,30 @@ DefNode( Node, NODE_GROUP_INPUT, def_group_input, "GROUP DefNode( Node, NODE_GROUP_OUTPUT, def_group_output, "GROUP_OUTPUT", GroupOutput, "Group Output", "" ) DefNode( Node, NODE_REROUTE, 0, "REROUTE", Reroute, "Reroute", "" ) -DefNode( ShaderNode, SH_NODE_OUTPUT, def_sh_output, "OUTPUT", Output, "Output", "" ) -DefNode( ShaderNode, SH_NODE_MATERIAL, def_sh_material, "MATERIAL", Material, "Material", "" ) DefNode( ShaderNode, SH_NODE_RGB, 0, "RGB", RGB, "RGB", "" ) DefNode( ShaderNode, SH_NODE_VALUE, 0, "VALUE", Value, "Value", "" ) DefNode( ShaderNode, SH_NODE_MIX_RGB, def_mix_rgb, "MIX_RGB", MixRGB, "MixRGB", "" ) DefNode( ShaderNode, SH_NODE_VALTORGB, def_colorramp, "VALTORGB", ValToRGB, "ColorRamp", "" ) DefNode( ShaderNode, SH_NODE_RGBTOBW, 0, "RGBTOBW", RGBToBW, "RGB to BW", "" ) -DefNode( ShaderNode, SH_NODE_TEXTURE, def_texture, "TEXTURE", Texture, "Texture", "" ) +DefNode( ShaderNode, SH_NODE_SHADERTORGB, 0, "SHADERTORGB", ShaderToRGB, "Shader to RGB", "" ) DefNode( ShaderNode, SH_NODE_NORMAL, 0, "NORMAL", Normal, "Normal", "" ) DefNode( ShaderNode, SH_NODE_GAMMA, 0, "GAMMA", Gamma, "Gamma", "" ) DefNode( ShaderNode, SH_NODE_BRIGHTCONTRAST, 0, "BRIGHTCONTRAST", BrightContrast, "Bright Contrast", "" ) -DefNode( ShaderNode, SH_NODE_GEOMETRY, def_sh_geometry, "GEOMETRY", Geometry, "Geometry", "" ) DefNode( ShaderNode, SH_NODE_MAPPING, def_sh_mapping, "MAPPING", Mapping, "Mapping", "" ) DefNode( ShaderNode, SH_NODE_CURVE_VEC, def_vector_curve, "CURVE_VEC", VectorCurve, "Vector Curves", "" ) DefNode( ShaderNode, SH_NODE_CURVE_RGB, def_rgb_curve, "CURVE_RGB", RGBCurve, "RGB Curves", "" ) DefNode( ShaderNode, SH_NODE_CAMERA, 0, "CAMERA", CameraData, "Camera Data", "" ) -DefNode( ShaderNode, SH_NODE_LAMP, def_sh_lamp, "LAMP", LampData, "Lamp Data", "" ) DefNode( ShaderNode, SH_NODE_MATH, def_math, "MATH", Math, "Math", "" ) DefNode( ShaderNode, SH_NODE_VECT_MATH, def_vector_math, "VECT_MATH", VectorMath, "Vector Math", "" ) DefNode( ShaderNode, SH_NODE_SQUEEZE, 0, "SQUEEZE", Squeeze, "Squeeze Value", "" ) -DefNode( ShaderNode, SH_NODE_MATERIAL_EXT, def_sh_material, "MATERIAL_EXT", ExtendedMaterial, "Extended Material", "" ) DefNode( ShaderNode, SH_NODE_INVERT, 0, "INVERT", Invert, "Invert", "" ) DefNode( ShaderNode, SH_NODE_SEPRGB, 0, "SEPRGB", SeparateRGB, "Separate RGB", "" ) DefNode( ShaderNode, SH_NODE_COMBRGB, 0, "COMBRGB", CombineRGB, "Combine RGB", "" ) DefNode( ShaderNode, SH_NODE_HUE_SAT, 0, "HUE_SAT", HueSaturation, "Hue/Saturation", "" ) DefNode( ShaderNode, SH_NODE_OUTPUT_MATERIAL, def_sh_output, "OUTPUT_MATERIAL", OutputMaterial, "Material Output", "" ) -DefNode( ShaderNode, SH_NODE_OUTPUT_LAMP, def_sh_output, "OUTPUT_LAMP", OutputLamp, "Lamp Output", "" ) +DefNode( ShaderNode, SH_NODE_EEVEE_SPECULAR, 0, "EEVEE_SPECULAR", EeveeSpecular, "Specular", "" ) +DefNode( ShaderNode, SH_NODE_OUTPUT_LIGHT, def_sh_output, "OUTPUT_LIGHT", OutputLight, "Light Output", "" ) DefNode( ShaderNode, SH_NODE_OUTPUT_WORLD, def_sh_output, "OUTPUT_WORLD", OutputWorld, "World Output", "" ) DefNode( ShaderNode, SH_NODE_OUTPUT_LINESTYLE, def_sh_output_linestyle,"OUTPUT_LINESTYLE", OutputLineStyle, "Line Style Output", "" ) DefNode( ShaderNode, SH_NODE_FRESNEL, 0, "FRESNEL", Fresnel, "Fresnel", "" ) diff --git a/source/blender/nodes/composite/node_composite_tree.c b/source/blender/nodes/composite/node_composite_tree.c index 1312b764546..4f796da58dc 100644 --- a/source/blender/nodes/composite/node_composite_tree.c +++ b/source/blender/nodes/composite/node_composite_tree.c @@ -261,7 +261,7 @@ void ntreeCompositUpdateRLayers(bNodeTree *ntree) } -void ntreeCompositRegisterPass(bNodeTree *ntree, Scene *scene, SceneRenderLayer *srl, const char *name, int type) +void ntreeCompositRegisterPass(bNodeTree *ntree, Scene *scene, ViewLayer *view_layer, const char *name, int type) { bNode *node; @@ -269,7 +269,7 @@ void ntreeCompositRegisterPass(bNodeTree *ntree, Scene *scene, SceneRenderLayer for (node = ntree->nodes.first; node; node = node->next) { if (node->type == CMP_NODE_R_LAYERS) - node_cmp_rlayers_register_pass(ntree, node, scene, srl, name, type); + node_cmp_rlayers_register_pass(ntree, node, scene, view_layer, name, type); } } diff --git a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c index bf9ab4a5064..af988c0df39 100644 --- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c @@ -37,7 +37,7 @@ /* this is taken from the cryptomatte specification 1.0 */ -static inline float hash_to_float(uint32_t hash) +BLI_INLINE float hash_to_float(uint32_t hash) { uint32_t mantissa = hash & ((1 << 23) - 1); uint32_t exponent = (hash >> 23) & ((1 << 8) - 1); diff --git a/source/blender/nodes/composite/nodes/node_composite_image.c b/source/blender/nodes/composite/nodes/node_composite_image.c index eb48d332f19..3ee4e512d76 100644 --- a/source/blender/nodes/composite/nodes/node_composite_image.c +++ b/source/blender/nodes/composite/nodes/node_composite_image.c @@ -41,6 +41,7 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_main.h" +#include "BKE_scene.h" /* **************** IMAGE (and RenderResult, multilayer image) ******************** */ @@ -190,16 +191,16 @@ typedef struct RLayerUpdateData { int prev_index; } RLayerUpdateData; -void node_cmp_rlayers_register_pass(bNodeTree *ntree, bNode *node, Scene *scene, SceneRenderLayer *srl, const char *name, int type) +void node_cmp_rlayers_register_pass(bNodeTree *ntree, bNode *node, Scene *scene, ViewLayer *view_layer, const char *name, int type) { RLayerUpdateData *data = node->storage; - if (scene == NULL || srl == NULL || data == NULL || node->id != (ID *)scene) { + if (scene == NULL || view_layer == NULL || data == NULL || node->id != (ID *)scene) { return; } - SceneRenderLayer *node_srl = BLI_findlink(&scene->r.layers, node->custom1); - if (node_srl != srl) { + ViewLayer *node_view_layer = BLI_findlink(&scene->view_layers, node->custom1); + if (node_view_layer != view_layer) { return; } @@ -220,15 +221,15 @@ static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, bNode *node, LinkNo if (scene) { RenderEngineType *engine_type = RE_engines_find(scene->r.engine); if (engine_type && engine_type->update_render_passes) { - SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, node->custom1); - if (srl) { + ViewLayer *view_layer = BLI_findlink(&scene->view_layers, node->custom1); + if (view_layer) { RLayerUpdateData *data = MEM_mallocN(sizeof(RLayerUpdateData), "render layer update data"); data->available_sockets = available_sockets; data->prev_index = -1; node->storage = data; RenderEngine *engine = RE_engine_create(engine_type); - engine_type->update_render_passes(engine, scene, srl); + engine_type->update_render_passes(engine, scene, view_layer); RE_engine_free(engine); MEM_freeN(data); @@ -305,8 +306,8 @@ static void node_composit_init_image(bNodeTree *ntree, bNode *node) node->storage = iuser; iuser->frames = 1; iuser->sfra = 1; - iuser->fie_ima = 2; iuser->ok = 1; + iuser->flag |= IMA_ANIM_ALWAYS; /* setup initial outputs */ cmp_node_image_verify_outputs(ntree, node, false); @@ -444,6 +445,7 @@ void register_node_type_cmp_rlayers(void) node_type_storage(&ntype, NULL, node_composit_free_rlayers, node_composit_copy_rlayers); node_type_update(&ntype, cmp_node_rlayers_update, NULL); node_type_init(&ntype, node_cmp_rlayers_outputs); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_splitViewer.c b/source/blender/nodes/composite/nodes/node_composite_splitViewer.c index f7008bc9ae4..863c8af66bb 100644 --- a/source/blender/nodes/composite/nodes/node_composite_splitViewer.c +++ b/source/blender/nodes/composite/nodes/node_composite_splitViewer.c @@ -47,7 +47,6 @@ static void node_composit_init_splitviewer(bNodeTree *UNUSED(ntree), bNode *node ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); node->storage = iuser; iuser->sfra = 1; - iuser->fie_ima = 2; iuser->ok = 1; node->custom1 = 50; /* default 50% split */ diff --git a/source/blender/nodes/composite/nodes/node_composite_viewer.c b/source/blender/nodes/composite/nodes/node_composite_viewer.c index f82b0d7206a..6221202398a 100644 --- a/source/blender/nodes/composite/nodes/node_composite_viewer.c +++ b/source/blender/nodes/composite/nodes/node_composite_viewer.c @@ -49,7 +49,6 @@ static void node_composit_init_viewer(bNodeTree *UNUSED(ntree), bNode *node) ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); node->storage = iuser; iuser->sfra = 1; - iuser->fie_ima = 2; iuser->ok = 1; node->custom3 = 0.5f; node->custom4 = 0.5f; diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index cb04b341c26..2dbb573f305 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -210,7 +210,6 @@ void register_node_type_frame(void) node_type_init(ntype, node_frame_init); node_type_storage(ntype, "NodeFrame", node_free_standard_storage, node_copy_standard_storage); node_type_size(ntype, 150, 100, 0); - node_type_compatibility(ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); ntype->needs_free = 1; nodeRegisterType(ntype); @@ -484,7 +483,6 @@ void register_node_type_group_input(void) node_type_size(ntype, 140, 80, 400); node_type_init(ntype, node_group_input_init); node_type_update(ntype, node_group_input_update, node_group_input_verify); - node_type_compatibility(ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); ntype->needs_free = 1; nodeRegisterType(ntype); @@ -583,7 +581,6 @@ void register_node_type_group_output(void) node_type_size(ntype, 140, 80, 400); node_type_init(ntype, node_group_output_init); node_type_update(ntype, node_group_output_update, node_group_output_verify); - node_type_compatibility(ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); ntype->needs_free = 1; nodeRegisterType(ntype); diff --git a/source/blender/nodes/intern/node_exec.c b/source/blender/nodes/intern/node_exec.c index 4f7f5b5ab1c..09c06e00382 100644 --- a/source/blender/nodes/intern/node_exec.c +++ b/source/blender/nodes/intern/node_exec.c @@ -306,8 +306,6 @@ bool ntreeExecThreadNodes(bNodeTreeExec *exec, bNodeThreadStack *nts, void *call * If the mute func is not set, assume the node should never be muted, * and hence execute it! */ -// if (node->typeinfo->compatibility == NODE_NEW_SHADING) -// return false; if (node->typeinfo->execfunc && !(node->flag & NODE_MUTED)) node->typeinfo->execfunc(callerdata, thread, node, &nodeexec->data, nsin, nsout); } diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c index d1903a53334..23ba51bbe10 100644 --- a/source/blender/nodes/intern/node_socket.c +++ b/source/blender/nodes/intern/node_socket.c @@ -267,7 +267,7 @@ void node_socket_init_default_value(bNodeSocket *sock) } } -void node_socket_copy_default_value(bNodeSocket *to, bNodeSocket *from) +void node_socket_copy_default_value(bNodeSocket *to, const bNodeSocket *from) { /* sanity check */ if (to->type != from->type) diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index 16fda773040..6f2c7835a3c 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -39,6 +39,7 @@ #include "DNA_space_types.h" #include "DNA_world_types.h" #include "DNA_linestyle_types.h" +#include "DNA_workspace_types.h" #include "BLI_listbase.h" #include "BLI_threads.h" @@ -67,11 +68,11 @@ static bool shader_tree_poll(const bContext *C, bNodeTreeType *UNUSED(treetype)) { Scene *scene = CTX_data_scene(C); + const char *engine_id = scene->r.engine; + /* allow empty engine string too, this is from older versions that didn't have registerable engines yet */ - return (scene->r.engine[0] == '\0' || - STREQ(scene->r.engine, RE_engine_id_BLENDER_RENDER) || - STREQ(scene->r.engine, RE_engine_id_BLENDER_GAME) || - STREQ(scene->r.engine, RE_engine_id_CYCLES) || + return (engine_id[0] == '\0' || + STREQ(engine_id, RE_engine_id_CYCLES) || !BKE_scene_use_shading_nodes_custom(scene)); } @@ -79,11 +80,10 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre { SpaceNode *snode = CTX_wm_space_node(C); Scene *scene = CTX_data_scene(C); - Object *ob = OBACT; + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = OBACT(view_layer); - if ((snode->shaderfrom == SNODE_SHADER_OBJECT) || - (BKE_scene_use_new_shading_nodes(scene) == false)) - { + if (snode->shaderfrom == SNODE_SHADER_OBJECT) { if (ob) { *r_from = &ob->id; if (ob->type == OB_LAMP) { @@ -101,7 +101,7 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre } #ifdef WITH_FREESTYLE else if (snode->shaderfrom == SNODE_SHADER_LINESTYLE) { - FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene); + FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer); if (linestyle) { *r_from = NULL; *r_id = &linestyle->id; @@ -118,16 +118,12 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre } } -static void foreach_nodeclass(Scene *scene, void *calldata, bNodeClassCallback func) +static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCallback func) { func(calldata, NODE_CLASS_INPUT, N_("Input")); func(calldata, NODE_CLASS_OUTPUT, N_("Output")); - - if (BKE_scene_use_new_shading_nodes(scene)) { - func(calldata, NODE_CLASS_SHADER, N_("Shader")); - func(calldata, NODE_CLASS_TEXTURE, N_("Texture")); - } - + func(calldata, NODE_CLASS_SHADER, N_("Shader")); + func(calldata, NODE_CLASS_TEXTURE, N_("Texture")); func(calldata, NODE_CLASS_OP_COLOR, N_("Color")); func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector")); func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor")); @@ -182,7 +178,7 @@ void register_node_tree_type_sh(void) tt->type = NTREE_SHADER; strcpy(tt->idname, "ShaderNodeTree"); - strcpy(tt->ui_name, "Shader"); + strcpy(tt->ui_name, "Shader Editor"); tt->ui_icon = 0; /* defined in drawnode.c */ strcpy(tt->ui_description, "Shader nodes"); @@ -214,16 +210,51 @@ static void ntree_shader_link_builtin_normal(bNodeTree *ntree, * can change in the future and make it a generic function, but for now it stays * private here. */ -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_LIGHT)) + { + 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. */ @@ -259,11 +290,11 @@ static bNodeSocket *ntree_shader_node_find_output(bNode *node, * also returned. */ static bool ntree_shader_has_displacement(bNodeTree *ntree, + bNode *output_node, bNode **r_node, bNodeSocket **r_socket, bNodeLink **r_link) { - bNode *output_node = ntree_shader_output_node(ntree); if (output_node == NULL) { /* We can't have displacement without output node, apparently. */ return false; @@ -427,17 +458,13 @@ static void ntree_shader_link_builtin_normal(bNodeTree *ntree, /* Re-link displacement output to unconnected normal sockets via bump node. * This way material with have proper displacement in the viewport. */ -static void ntree_shader_relink_displacement(bNodeTree *ntree, - short compatibility) +static void ntree_shader_relink_displacement(bNodeTree *ntree, bNode *output_node) { - if (compatibility != NODE_NEW_SHADING) { - /* We can only deal with new shading system here. */ - return; - } bNode *displacement_node; bNodeSocket *displacement_socket; bNodeLink *displacement_link; if (!ntree_shader_has_displacement(ntree, + output_node, &displacement_node, &displacement_socket, &displacement_link)) @@ -491,35 +518,107 @@ static void ntree_shader_relink_displacement(bNodeTree *ntree, ntreeUpdateTree(G.main, ntree); } -void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibility) +static bool ntree_tag_ssr_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *userdata, const bool UNUSED(reversed)) +{ + switch (fromnode->type) { + case SH_NODE_BSDF_ANISOTROPIC: + case SH_NODE_EEVEE_SPECULAR: + case SH_NODE_BSDF_PRINCIPLED: + case SH_NODE_BSDF_GLOSSY: + case SH_NODE_BSDF_GLASS: + fromnode->ssr_id = (*(float *)userdata); + (*(float *)userdata) += 1; + break; + default: + /* We could return false here but since we (will) + * allow the use of Closure as RGBA, we can have + * Bsdf nodes linked to other Bsdf nodes. */ + break; + } + + return true; +} + +/* EEVEE: Scan the ntree to set the Screen Space Reflection + * layer id of every specular node. + */ +static void ntree_shader_tag_ssr_node(bNodeTree *ntree, bNode *output_node) +{ + if (output_node == NULL) { + return; + } + /* Make sure sockets links pointers are correct. */ + ntreeUpdateTree(G.main, ntree); + + float lobe_id = 1; + nodeChainIter(ntree, output_node, ntree_tag_ssr_bsdf_cb, &lobe_id, true); +} + +static bool ntree_tag_sss_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *userdata, const bool UNUSED(reversed)) { - /* localize tree to create links for reroute and mute */ - bNodeTree *localtree = ntreeLocalize(ntree); + switch (fromnode->type) { + case SH_NODE_BSDF_PRINCIPLED: + case SH_NODE_SUBSURFACE_SCATTERING: + fromnode->sss_id = (*(float *)userdata); + (*(float *)userdata) += 1; + break; + default: + break; + } + + return true; +} + +/* EEVEE: Scan the ntree to set the Subsurface Scattering id of every SSS node. + */ +static void ntree_shader_tag_sss_node(bNodeTree *ntree, bNode *output_node) +{ + if (output_node == NULL) { + return; + } + /* Make sure sockets links pointers are correct. */ + ntreeUpdateTree(G.main, ntree); + + float sss_id = 1; + nodeChainIter(ntree, output_node, ntree_tag_sss_bsdf_cb, &sss_id, true); +} + +/* This one needs to work on a local tree. */ +void ntreeGPUMaterialNodes(bNodeTree *localtree, GPUMaterial *mat, bool *has_surface_output, bool *has_volume_output) +{ + bNode *output = ntreeShaderOutputNode(localtree, SHD_OUTPUT_EEVEE); bNodeTreeExec *exec; /* Perform all needed modifications on the tree in order to support * displacement/bump mapping. */ - ntree_shader_relink_displacement(localtree, compatibility); + ntree_shader_relink_displacement(localtree, output); + + ntree_shader_tag_ssr_node(localtree, output); + ntree_shader_tag_sss_node(localtree, output); exec = ntreeShaderBeginExecTree(localtree); - ntreeExecGPUNodes(exec, mat, 1, compatibility); + ntreeExecGPUNodes(exec, mat, 1); ntreeShaderEndExecTree(exec); - ntreeFreeTree(localtree); - MEM_freeN(localtree); -} + /* EEVEE: Find which material domain was used (volume, surface ...). */ + *has_surface_output = false; + *has_volume_output = false; -/* **************** call to switch lamploop for material node ************ */ + if (output != NULL) { + bNodeSocket *surface_sock = ntree_shader_node_find_input(output, "Surface"); + bNodeSocket *volume_sock = ntree_shader_node_find_input(output, "Volume"); -void (*node_shader_lamp_loop)(struct ShadeInput *, struct ShadeResult *); + if (surface_sock != NULL) { + *has_surface_output = (nodeCountSocketLinks(localtree, surface_sock) > 0); + } -void set_node_shader_lamp_loop(void (*lamp_loop_func)(ShadeInput *, ShadeResult *)) -{ - node_shader_lamp_loop = lamp_loop_func; + if (volume_sock != NULL) { + *has_volume_output = (nodeCountSocketLinks(localtree, volume_sock) > 0); + } + } } - bNodeTreeExec *ntreeShaderBeginExecTree_internal(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key) { bNodeTreeExec *exec; @@ -594,26 +693,14 @@ void ntreeShaderEndExecTree(bNodeTreeExec *exec) } } -/* only for Blender internal */ -bool ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) +/* TODO: left over from Blender Internal, could reuse for new texture nodes. */ +bool ntreeShaderExecTree(bNodeTree *ntree, int thread) { ShaderCallData scd; - /** - * \note: preserve material from ShadeInput for material id, nodetree execs change it - * fix for bug "[#28012] Mat ID messy with shader nodes" - */ - Material *mat = shi->mat; bNodeThreadStack *nts = NULL; bNodeTreeExec *exec = ntree->execdata; int compat; - /* convert caller data to struct */ - scd.shi = shi; - scd.shr = shr; - - /* each material node has own local shaderesult, with optional copying */ - memset(shr, 0, sizeof(ShadeResult)); - /* ensure execdata is only initialized once */ if (!exec) { BLI_thread_lock(LOCK_NODES); @@ -624,18 +711,10 @@ bool ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr) exec = ntree->execdata; } - nts = ntreeGetThreadStack(exec, shi->thread); - compat = ntreeExecThreadNodes(exec, nts, &scd, shi->thread); + nts = ntreeGetThreadStack(exec, thread); + compat = ntreeExecThreadNodes(exec, nts, &scd, thread); ntreeReleaseThreadStack(nts); - // \note: set material back to preserved material - shi->mat = mat; - - /* better not allow negative for now */ - if (shr->combined[0] < 0.0f) shr->combined[0] = 0.0f; - if (shr->combined[1] < 0.0f) shr->combined[1] = 0.0f; - if (shr->combined[2] < 0.0f) shr->combined[2] = 0.0f; - /* if compat is zero, it has been using non-compatible nodes */ return compat; } diff --git a/source/blender/nodes/shader/node_shader_util.c b/source/blender/nodes/shader/node_shader_util.c index 90b230a280d..ca8286f1772 100644 --- a/source/blender/nodes/shader/node_shader_util.c +++ b/source/blender/nodes/shader/node_shader_util.c @@ -91,53 +91,6 @@ void nodestack_get_vec(float *in, short type_in, bNodeStack *ns) } -/* go over all used Geometry and Texture nodes, and return a texco flag */ -/* no group inside needed, this function is called for groups too */ -void ntreeShaderGetTexcoMode(bNodeTree *ntree, int r_mode, short *texco, int *mode) -{ - bNode *node; - bNodeSocket *sock; - int a; - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == SH_NODE_TEXTURE) { - if ((r_mode & R_OSA) && node->id) { - Tex *tex = (Tex *)node->id; - if (ELEM(tex->type, TEX_IMAGE, TEX_ENVMAP)) { - *texco |= TEXCO_OSA | NEED_UV; - } - } - /* usability exception... without input we still give the node orcos */ - sock = node->inputs.first; - if (sock == NULL || sock->link == NULL) - *texco |= TEXCO_ORCO | NEED_UV; - } - else if (node->type == SH_NODE_GEOMETRY) { - /* note; sockets always exist for the given type! */ - for (a = 0, sock = node->outputs.first; sock; sock = sock->next, a++) { - if (sock->flag & SOCK_IN_USE) { - switch (a) { - case GEOM_OUT_GLOB: - *texco |= TEXCO_GLOB | NEED_UV; break; - case GEOM_OUT_VIEW: - *texco |= TEXCO_VIEW | NEED_UV; break; - case GEOM_OUT_ORCO: - *texco |= TEXCO_ORCO | NEED_UV; break; - case GEOM_OUT_UV: - *texco |= TEXCO_UV | NEED_UV; break; - case GEOM_OUT_NORMAL: - *texco |= TEXCO_NORM | NEED_UV; break; - case GEOM_OUT_VCOL: - *texco |= NEED_UV; *mode |= MA_VERTEXCOL; break; - case GEOM_OUT_VCOL_ALPHA: - *texco |= NEED_UV; *mode |= MA_VERTEXCOL; break; - } - } - } - } - } -} - void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns) { memset(gs, 0, sizeof(*gs)); @@ -147,7 +100,6 @@ void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns) zero_v4(gs->vec); gs->link = NULL; gs->type = GPU_NONE; - gs->name = ""; gs->hasinput = false; gs->hasoutput = false; gs->sockettype = type; @@ -163,11 +115,10 @@ void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns) else if (type == SOCK_RGBA) gs->type = GPU_VEC4; else if (type == SOCK_SHADER) - gs->type = GPU_VEC4; + gs->type = GPU_CLOSURE; else gs->type = GPU_NONE; - gs->name = ""; gs->hasinput = ns->hasinput && ns->data; /* XXX Commented out the ns->data check here, as it seems it's not always set, * even though there *is* a valid connection/output... But that might need @@ -193,7 +144,7 @@ static void gpu_stack_from_data_list(GPUNodeStack *gs, ListBase *sockets, bNodeS for (sock = sockets->first, i = 0; sock; sock = sock->next, i++) node_gpu_stack_from_data(&gs[i], sock->type, ns[i]); - gs[i].type = GPU_NONE; + gs[i].end = true; } static void data_from_gpu_stack_list(ListBase *sockets, bNodeStack **ns, GPUNodeStack *gs) @@ -256,7 +207,7 @@ bNode *nodeGetActiveTexture(bNodeTree *ntree) return inactivenode; } -void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, int do_outputs, short compatibility) +void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, int do_outputs) { bNodeExec *nodeexec; bNode *node; @@ -275,9 +226,8 @@ void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, int do_outputs, sh do_it = false; /* for groups, only execute outputs for edited group */ if (node->typeinfo->nclass == NODE_CLASS_OUTPUT) { - if (node->typeinfo->compatibility & compatibility) - if (do_outputs && (node->flag & NODE_DO_OUTPUT)) - do_it = true; + if (do_outputs && (node->flag & NODE_DO_OUTPUT)) + do_it = true; } else { do_it = true; @@ -303,13 +253,18 @@ void node_shader_gpu_tex_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in float domax = (texmap->flag & TEXMAP_CLIP_MAX) != 0; if (domin || domax || !(texmap->flag & TEXMAP_UNIT_MATRIX)) { - GPUNodeLink *tmat = GPU_uniform((float *)texmap->mat); - GPUNodeLink *tmin = GPU_uniform(texmap->min); - GPUNodeLink *tmax = GPU_uniform(texmap->max); - GPUNodeLink *tdomin = GPU_uniform(&domin); - GPUNodeLink *tdomax = GPU_uniform(&domax); - - GPU_link(mat, "mapping", in[0].link, tmat, tmin, tmax, tdomin, tdomax, &in[0].link); + static float max[3] = { FLT_MAX, FLT_MAX, FLT_MAX}; + static float min[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; + GPUNodeLink *tmin, *tmax, *tmat0, *tmat1, *tmat2, *tmat3; + + tmin = GPU_uniform((domin) ? texmap->min : min); + tmax = GPU_uniform((domax) ? texmap->max : max); + tmat0 = GPU_uniform((float *)texmap->mat[0]); + tmat1 = GPU_uniform((float *)texmap->mat[1]); + tmat2 = GPU_uniform((float *)texmap->mat[2]); + tmat3 = GPU_uniform((float *)texmap->mat[3]); + + GPU_link(mat, "mapping", in[0].link, tmat0, tmat1, tmat2, tmat3, tmin, tmax, &in[0].link); if (texmap->type == TEXMAP_TYPE_NORMAL) GPU_link(mat, "texco_norm", in[0].link, &in[0].link); diff --git a/source/blender/nodes/shader/node_shader_util.h b/source/blender/nodes/shader/node_shader_util.h index e2c1fe7897b..7fce5ed9927 100644 --- a/source/blender/nodes/shader/node_shader_util.h +++ b/source/blender/nodes/shader/node_shader_util.h @@ -78,6 +78,7 @@ #include "RE_shader_ext.h" #include "GPU_material.h" +#include "GPU_uniformbuffer.h" bool sh_node_poll_default(struct bNodeType *ntype, struct bNodeTree *ntree); @@ -87,17 +88,16 @@ void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, shor /* ********* exec data struct, remains internal *********** */ typedef struct ShaderCallData { - ShadeInput *shi; /* from render pipe */ - ShadeResult *shr; /* from render pipe */ + /* Empty for now, may be reused if we convert shader to texture nodes. */ + int dummy; } ShaderCallData; - void nodestack_get_vec(float *in, short type_in, bNodeStack *ns); void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, struct bNodeStack *ns); void node_data_from_gpu_stack(struct bNodeStack *ns, struct GPUNodeStack *gs); void node_shader_gpu_tex_mapping(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out); -void ntreeExecGPUNodes(struct bNodeTreeExec *exec, struct GPUMaterial *mat, int do_outputs, short compatibility); +void ntreeExecGPUNodes(struct bNodeTreeExec *exec, struct GPUMaterial *mat, int do_outputs); #endif diff --git a/source/blender/nodes/shader/nodes/node_shader_add_shader.c b/source/blender/nodes/shader/nodes/node_shader_add_shader.c index 1edac62438e..0661ab59434 100644 --- a/source/blender/nodes/shader/nodes/node_shader_add_shader.c +++ b/source/blender/nodes/shader/nodes/node_shader_add_shader.c @@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_add_shader_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_add_shader(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_add_shader(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_add_shader", in, out); + return GPU_stack_link(mat, node, "node_add_shader", in, out); } /* node type definition */ @@ -51,7 +51,6 @@ void register_node_type_sh_add_shader(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_ADD_SHADER, "Add Shader", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_add_shader_in, sh_node_add_shader_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c index 995ff0cfd40..76ef257f8a3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c +++ b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c @@ -42,9 +42,12 @@ static bNodeSocketTemplate sh_node_ambient_occlusion_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_ambient_occlusion", in, out, GPU_builtin(GPU_VIEW_NORMAL)); + if (!in[2].link) + GPU_link(mat, "world_normals_get", &in[2].link); + + return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out); } static void node_shader_init_ambient_occlusion(bNodeTree *UNUSED(ntree), bNode *node) @@ -59,7 +62,6 @@ void register_node_type_sh_ambient_occlusion(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_AMBIENT_OCCLUSION, "Ambient Occlusion", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_ambient_occlusion_in, sh_node_ambient_occlusion_out); node_type_init(&ntype, node_shader_init_ambient_occlusion); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_attribute.c b/source/blender/nodes/shader/nodes/node_shader_attribute.c index ba5fa131d3e..aca72ac27cc 100644 --- a/source/blender/nodes/shader/nodes/node_shader_attribute.c +++ b/source/blender/nodes/shader/nodes/node_shader_attribute.c @@ -45,9 +45,29 @@ static void node_shader_init_attribute(bNodeTree *UNUSED(ntree), bNode *node) static int node_shader_gpu_attribute(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { NodeShaderAttribute *attr = node->storage; - GPUNodeLink *cd_attr = GPU_attribute(CD_AUTO_FROM_NAME, attr->name); - return GPU_stack_link(mat, "node_attribute", in, out, cd_attr); + /* FIXME : if an attribute layer (like vertex color) has one of theses name, it will not work as expected. */ + if (strcmp(attr->name, "density") == 0) { + return GPU_stack_link(mat, node, "node_attribute_volume_density", in, out, + GPU_builtin(GPU_VOLUME_DENSITY)); + } + else if (strcmp(attr->name, "color") == 0) { + return GPU_stack_link(mat, node, "node_attribute_volume_color", in, out, + GPU_builtin(GPU_VOLUME_DENSITY)); + } + else if (strcmp(attr->name, "flame") == 0) { + return GPU_stack_link(mat, node, "node_attribute_volume_flame", in, out, + GPU_builtin(GPU_VOLUME_FLAME)); + } + else if (strcmp(attr->name, "temperature") == 0) { + return GPU_stack_link(mat, node, "node_attribute_volume_temperature", in, out, + GPU_builtin(GPU_VOLUME_FLAME), + GPU_builtin(GPU_VOLUME_TEMPERATURE)); + } + else { + GPUNodeLink *cd_attr = GPU_attribute(CD_AUTO_FROM_NAME, attr->name); + return GPU_stack_link(mat, node, "node_attribute", in, out, cd_attr); + } } /* node type definition */ @@ -56,7 +76,6 @@ void register_node_type_sh_attribute(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_ATTRIBUTE, "Attribute", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_attribute_out); node_type_init(&ntype, node_shader_init_attribute); node_type_storage(&ntype, "NodeShaderAttribute", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_background.c b/source/blender/nodes/shader/nodes/node_shader_background.c index b387529e456..38b5883bc1e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_background.c +++ b/source/blender/nodes/shader/nodes/node_shader_background.c @@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_background_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_background(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_background(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_background", in, out, GPU_builtin(GPU_VIEW_NORMAL)); + return GPU_stack_link(mat, node, "node_background", in, out); } /* node type definition */ @@ -51,7 +51,6 @@ void register_node_type_sh_background(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BACKGROUND, "Background", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_background_in, sh_node_background_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_bevel.c b/source/blender/nodes/shader/nodes/node_shader_bevel.c index e2e4da21ef3..05161bd453a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bevel.c +++ b/source/blender/nodes/shader/nodes/node_shader_bevel.c @@ -45,13 +45,13 @@ static void node_shader_init_bevel(bNodeTree *UNUSED(ntree), bNode *node) node->custom1 = 4; /* samples */ } -static int gpu_shader_bevel(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_bevel(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[1].link) { GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &in[1].link); } - return GPU_stack_link(mat, "node_bevel", in, out); + return GPU_stack_link(mat, node, "node_bevel", in, out); } /* node type definition */ @@ -60,7 +60,6 @@ void register_node_type_sh_bevel(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BEVEL, "Bevel", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bevel_in, sh_node_bevel_out); node_type_init(&ntype, node_shader_init_bevel); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_blackbody.c b/source/blender/nodes/shader/nodes/node_shader_blackbody.c index 2006ef890f6..28ba3d2c5c8 100644 --- a/source/blender/nodes/shader/nodes/node_shader_blackbody.c +++ b/source/blender/nodes/shader/nodes/node_shader_blackbody.c @@ -38,17 +38,30 @@ static bNodeSocketTemplate sh_node_blackbody_out[] = { { -1, 0, "" } }; +static int node_shader_gpu_blackbody(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +{ + const int size = CM_TABLE + 1; + float *data = MEM_mallocN(sizeof(float) * size * 4, "blackbody texture"); + + blackbody_temperature_to_rgb_table(data, size, 965.0f, 12000.0f); + + float layer; + GPUNodeLink *ramp_texture = GPU_color_band(mat, size, data, &layer); + + return GPU_stack_link(mat, node, "node_blackbody", in, out, ramp_texture, GPU_constant(&layer)); +} + /* node type definition */ void register_node_type_sh_blackbody(void) { static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BLACKBODY, "Blackbody", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_socket_templates(&ntype, sh_node_blackbody_in, sh_node_blackbody_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_blackbody); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_brightness.c b/source/blender/nodes/shader/nodes/node_shader_brightness.c index 75e258bd27d..d17a5b9ba6e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_brightness.c +++ b/source/blender/nodes/shader/nodes/node_shader_brightness.c @@ -42,9 +42,9 @@ static bNodeSocketTemplate sh_node_brightcontrast_out[] = { { -1, 0, "" } }; -static int gpu_shader_brightcontrast(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_brightcontrast(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "brightness_contrast", in, out); + return GPU_stack_link(mat, node, "brightness_contrast", in, out); } void register_node_type_sh_brightcontrast(void) @@ -52,7 +52,6 @@ void register_node_type_sh_brightcontrast(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BRIGHTCONTRAST, "Bright/Contrast", NODE_CLASS_OP_COLOR, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_brightcontrast_in, sh_node_brightcontrast_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c index 6410441797a..6551b20a375 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c @@ -49,14 +49,14 @@ static void node_shader_init_anisotropic(bNodeTree *UNUSED(ntree), bNode *node) node->custom1 = SHD_GLOSSY_GGX; } -static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[4].link) - in[4].link = GPU_builtin(GPU_VIEW_NORMAL); - else - GPU_link(mat, "direction_transform_m4v3", in[4].link, GPU_builtin(GPU_VIEW_MATRIX), &in[4].link); + GPU_link(mat, "world_normals_get", &in[4].link); - return GPU_stack_link(mat, "node_bsdf_anisotropic", in, out); + GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY); + + return GPU_stack_link(mat, node, "node_bsdf_anisotropic", in, out); } /* node type definition */ @@ -65,7 +65,6 @@ void register_node_type_sh_bsdf_anisotropic(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_ANISOTROPIC, "Anisotropic BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_anisotropic_in, sh_node_bsdf_anisotropic_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_anisotropic); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c index e86d2677a61..c1b8c748657 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c @@ -41,14 +41,14 @@ static bNodeSocketTemplate sh_node_bsdf_diffuse_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[2].link) - in[2].link = GPU_builtin(GPU_VIEW_NORMAL); - else - GPU_link(mat, "direction_transform_m4v3", in[2].link, GPU_builtin(GPU_VIEW_MATRIX), &in[2].link); + GPU_link(mat, "world_normals_get", &in[2].link); - return GPU_stack_link(mat, "node_bsdf_diffuse", in, out); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); + + return GPU_stack_link(mat, node, "node_bsdf_diffuse", in, out); } /* node type definition */ @@ -57,7 +57,6 @@ void register_node_type_sh_bsdf_diffuse(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_DIFFUSE, "Diffuse BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_diffuse_in, sh_node_bsdf_diffuse_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c index 529dfbc3df4..b18dcacb98f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c @@ -47,14 +47,14 @@ static void node_shader_init_glass(bNodeTree *UNUSED(ntree), bNode *node) node->custom1 = SHD_GLOSSY_BECKMANN; } -static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[3].link) - in[3].link = GPU_builtin(GPU_VIEW_NORMAL); - else - GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link); + GPU_link(mat, "world_normals_get", &in[3].link); - return GPU_stack_link(mat, "node_bsdf_glass", in, out); + GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY | GPU_MATFLAG_REFRACT); + + return GPU_stack_link(mat, node, "node_bsdf_glass", in, out, GPU_constant(&node->ssr_id)); } /* node type definition */ @@ -63,7 +63,6 @@ void register_node_type_sh_bsdf_glass(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_GLASS, "Glass BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_glass_in, sh_node_bsdf_glass_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_glass); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c index fd55ab0ce17..342b3a67ffb 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c @@ -46,14 +46,14 @@ static void node_shader_init_glossy(bNodeTree *UNUSED(ntree), bNode *node) node->custom1 = SHD_GLOSSY_GGX; } -static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[2].link) - in[2].link = GPU_builtin(GPU_VIEW_NORMAL); - else - GPU_link(mat, "direction_transform_m4v3", in[2].link, GPU_builtin(GPU_VIEW_MATRIX), &in[2].link); + GPU_link(mat, "world_normals_get", &in[2].link); - return GPU_stack_link(mat, "node_bsdf_glossy", in, out); + GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY); + + return GPU_stack_link(mat, node, "node_bsdf_glossy", in, out, GPU_constant(&node->ssr_id)); } /* node type definition */ @@ -62,7 +62,6 @@ void register_node_type_sh_bsdf_glossy(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_GLOSSY, "Glossy BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_glossy_in, sh_node_bsdf_glossy_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_glossy); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c index 7842f1d6b15..d97344ad6a7 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c @@ -43,9 +43,9 @@ static bNodeSocketTemplate sh_node_bsdf_hair_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_bsdf_hair(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_hair(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_bsdf_hair", in, out); + return GPU_stack_link(mat, node, "node_bsdf_hair", in, out); } /* node type definition */ @@ -54,7 +54,6 @@ void register_node_type_sh_bsdf_hair(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_HAIR, "Hair BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_hair_in, sh_node_bsdf_hair_out); node_type_size(&ntype, 150, 60, 200); node_type_init(&ntype, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.c index aeeb262a5a6..83e4bf1731b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair_principled.c @@ -122,7 +122,6 @@ void register_node_type_sh_bsdf_hair_principled(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_HAIR_PRINCIPLED, "Principled Hair BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_hair_principled_in, sh_node_bsdf_hair_principled_out); node_type_size_preset(&ntype, NODE_SIZE_LARGE); node_type_init(&ntype, node_shader_init_hair_principled); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c index e3b3f0fc9a6..16d35c7003a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c @@ -64,21 +64,92 @@ static void node_shader_init_principled(bNodeTree *UNUSED(ntree), bNode *node) node->custom2 = SHD_SUBSURFACE_BURLEY; } -static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +#define socket_not_zero(sock) (in[sock].link || (clamp_f(in[sock].vec[0], 0.0f, 1.0f) > 1e-5f)) +#define socket_not_one(sock) (in[sock].link || (clamp_f(in[sock].vec[0], 0.0f, 1.0f) < 1.0f - 1e-5f)) + +static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - // normal - if (!in[17].link) - in[17].link = GPU_builtin(GPU_VIEW_NORMAL); - else - GPU_link(mat, "direction_transform_m4v3", in[17].link, GPU_builtin(GPU_VIEW_MATRIX), &in[17].link); - - // clearcoat normal - if (!in[18].link) - in[18].link = GPU_builtin(GPU_VIEW_NORMAL); - else - GPU_link(mat, "direction_transform_m4v3", in[18].link, GPU_builtin(GPU_VIEW_MATRIX), &in[18].link); - - return GPU_stack_link(mat, "node_bsdf_principled", in, out, GPU_builtin(GPU_VIEW_POSITION)); + GPUNodeLink *sss_scale; + + /* Normals */ + if (!in[17].link) { + GPU_link(mat, "world_normals_get", &in[17].link); + } + + /* Clearcoat Normals */ + if (!in[18].link) { + GPU_link(mat, "world_normals_get", &in[18].link); + } + + /* Tangents */ + if (!in[19].link) { + GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "tangent_orco_z", orco, &in[19].link); + GPU_link(mat, "node_tangent", + GPU_builtin(GPU_VIEW_NORMAL), in[19].link, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), + &in[19].link); + } + + /* SSS Profile */ + if (node->sss_id == 1) { + static short profile = SHD_SUBSURFACE_BURLEY; + bNodeSocket *socket = BLI_findlink(&node->original->inputs, 2); + bNodeSocketValueRGBA *socket_data = socket->default_value; + /* For some reason it seems that the socket value is in ARGB format. */ + GPU_material_sss_profile_create(mat, &socket_data->value[1], &profile, NULL); + } + + if (in[2].link) { + sss_scale = in[2].link; + } + else { + float one[3] = {1.0f, 1.0f, 1.0f}; + GPU_link(mat, "set_rgb", GPU_constant((float *)one), &sss_scale); + } + + bool use_diffuse = socket_not_one(4) && socket_not_one(15); + bool use_subsurf = socket_not_zero(1) && use_diffuse; + bool use_refract = socket_not_one(4) && socket_not_zero(15); + bool use_clear = socket_not_zero(12); + + /* Due to the manual effort done per config, we only optimize the most common permutations. */ + char *node_name; + uint flag = 0; + if (!use_subsurf && use_diffuse && !use_refract && !use_clear) { + static char name[] = "node_bsdf_principled_dielectric"; + node_name = name; + flag = GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY; + } + else if (!use_subsurf && !use_diffuse && !use_refract && !use_clear) { + static char name[] = "node_bsdf_principled_metallic"; + node_name = name; + flag = GPU_MATFLAG_GLOSSY; + } + else if (!use_subsurf && !use_diffuse && !use_refract && use_clear) { + static char name[] = "node_bsdf_principled_clearcoat"; + node_name = name; + flag = GPU_MATFLAG_GLOSSY; + } + else if (use_subsurf && use_diffuse && !use_refract && !use_clear) { + static char name[] = "node_bsdf_principled_subsurface"; + node_name = name; + flag = GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_SSS | GPU_MATFLAG_GLOSSY; + } + else if (!use_subsurf && !use_diffuse && use_refract && !use_clear && !socket_not_zero(4)) { + static char name[] = "node_bsdf_principled_glass"; + node_name = name; + flag = GPU_MATFLAG_GLOSSY | GPU_MATFLAG_REFRACT; + } + else { + static char name[] = "node_bsdf_principled"; + node_name = name; + flag = GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY | GPU_MATFLAG_SSS | GPU_MATFLAG_REFRACT; + } + + GPU_material_flag_set(mat, flag); + + return GPU_stack_link(mat, node, node_name, in, out, GPU_builtin(GPU_VIEW_POSITION), + GPU_constant(&node->ssr_id), GPU_constant(&node->sss_id), sss_scale); } static void node_shader_update_principled(bNodeTree *UNUSED(ntree), bNode *node) @@ -103,7 +174,6 @@ void register_node_type_sh_bsdf_principled(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_PRINCIPLED, "Principled BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_principled_in, sh_node_bsdf_principled_out); node_type_size_preset(&ntype, NODE_SIZE_LARGE); node_type_init(&ntype, node_shader_init_principled); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c index 4b16fcab081..b59f1c80342 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c @@ -47,14 +47,14 @@ static void node_shader_init_refraction(bNodeTree *UNUSED(ntree), bNode *node) node->custom1 = SHD_GLOSSY_BECKMANN; } -static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[3].link) - in[3].link = GPU_builtin(GPU_VIEW_NORMAL); - else - GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link); + GPU_link(mat, "world_normals_get", &in[3].link); - return GPU_stack_link(mat, "node_bsdf_refraction", in, out); + GPU_material_flag_set(mat, GPU_MATFLAG_REFRACT); + + return GPU_stack_link(mat, node, "node_bsdf_refraction", in, out); } /* node type definition */ @@ -63,7 +63,6 @@ void register_node_type_sh_bsdf_refraction(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_REFRACTION, "Refraction BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_refraction_in, sh_node_bsdf_refraction_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_refraction); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c index b268779d6bb..0754a7e5a3b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c @@ -42,14 +42,14 @@ static bNodeSocketTemplate sh_node_bsdf_toon_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[3].link) in[3].link = GPU_builtin(GPU_VIEW_NORMAL); else GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link); - return GPU_stack_link(mat, "node_bsdf_toon", in, out); + return GPU_stack_link(mat, node, "node_bsdf_toon", in, out); } /* node type definition */ @@ -58,7 +58,6 @@ void register_node_type_sh_bsdf_toon(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_TOON, "Toon BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_toon_in, sh_node_bsdf_toon_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c index 3eee8a08fa2..349db30af14 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c @@ -40,14 +40,14 @@ static bNodeSocketTemplate sh_node_bsdf_translucent_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[1].link) - in[1].link = GPU_builtin(GPU_VIEW_NORMAL); - else - GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link); + GPU_link(mat, "world_normals_get", &in[1].link); - return GPU_stack_link(mat, "node_bsdf_translucent", in, out); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); + + return GPU_stack_link(mat, node, "node_bsdf_translucent", in, out); } /* node type definition */ @@ -56,7 +56,6 @@ void register_node_type_sh_bsdf_translucent(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_TRANSLUCENT, "Translucent BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_translucent_in, sh_node_bsdf_translucent_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c index 00aac45e4c8..08ddf221804 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c @@ -39,9 +39,9 @@ static bNodeSocketTemplate sh_node_bsdf_transparent_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_bsdf_transparent", in, out); + return GPU_stack_link(mat, node, "node_bsdf_transparent", in, out); } /* node type definition */ @@ -50,7 +50,6 @@ void register_node_type_sh_bsdf_transparent(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_TRANSPARENT, "Transparent BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_transparent_in, sh_node_bsdf_transparent_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c index 69bc74793e7..59b831c0dab 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c @@ -41,14 +41,14 @@ static bNodeSocketTemplate sh_node_bsdf_velvet_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[2].link) - in[2].link = GPU_builtin(GPU_VIEW_NORMAL); - else - GPU_link(mat, "direction_transform_m4v3", in[2].link, GPU_builtin(GPU_VIEW_MATRIX), &in[2].link); + GPU_link(mat, "world_normals_get", &in[2].link); - return GPU_stack_link(mat, "node_bsdf_velvet", in, out); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); + + return GPU_stack_link(mat, node, "node_bsdf_velvet", in, out); } /* node type definition */ @@ -57,7 +57,6 @@ void register_node_type_sh_bsdf_velvet(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BSDF_VELVET, "Velvet BSDF", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bsdf_velvet_in, sh_node_bsdf_velvet_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_bump.c b/source/blender/nodes/shader/nodes/node_shader_bump.c index 41df17cef67..b71a59d8c11 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bump.c +++ b/source/blender/nodes/shader/nodes/node_shader_bump.c @@ -52,7 +52,7 @@ static int gpu_shader_bump(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED( else GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link); float invert = node->custom1; - GPU_stack_link(mat, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&invert)); + GPU_stack_link(mat, node, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_constant(&invert)); /* Other nodes are applying view matrix if the input Normal has a link. * We don't want normal to have view matrix applied twice, so we cancel it here. * @@ -68,7 +68,6 @@ void register_node_type_sh_bump(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_BUMP, "Bump", NODE_CLASS_OP_VECTOR, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_bump_in, sh_node_bump_out); node_type_storage(&ntype, "", NULL, NULL); node_type_gpu(&ntype, gpu_shader_bump); diff --git a/source/blender/nodes/shader/nodes/node_shader_camera.c b/source/blender/nodes/shader/nodes/node_shader_camera.c index b1c3a817b84..9089d415759 100644 --- a/source/blender/nodes/shader/nodes/node_shader_camera.c +++ b/source/blender/nodes/shader/nodes/node_shader_camera.c @@ -40,29 +40,13 @@ static bNodeSocketTemplate sh_node_camera_out[] = { { -1, 0, "" } }; - -static void node_shader_exec_camera(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out) -{ - if (data) { - ShadeInput *shi = ((ShaderCallData *)data)->shi; /* Data we need for shading. */ - - copy_v3_v3(out[0]->vec, shi->co); /* get view vector */ - out[1]->vec[0] = fabsf(shi->co[2]); /* get view z-depth */ - out[2]->vec[0] = normalize_v3(out[0]->vec); /* get view distance */ - } -} - -static int gpu_shader_camera(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_camera(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { GPUNodeLink *viewvec; viewvec = GPU_builtin(GPU_VIEW_POSITION); - - /* Blender has negative Z, Cycles positive Z convention */ - if (GPU_material_use_new_shading_nodes(mat)) - GPU_link(mat, "invert_z", viewvec, &viewvec); - - return GPU_stack_link(mat, "camera", in, out, viewvec); + GPU_link(mat, "invert_z", viewvec, &viewvec); + return GPU_stack_link(mat, node, "camera", in, out, viewvec); } void register_node_type_sh_camera(void) @@ -70,10 +54,8 @@ void register_node_type_sh_camera(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_CAMERA, "Camera Data", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_camera_out); node_type_storage(&ntype, "", NULL, NULL); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_camera); node_type_gpu(&ntype, gpu_shader_camera); nodeRegisterType(&ntype); diff --git a/source/blender/nodes/shader/nodes/node_shader_common.c b/source/blender/nodes/shader/nodes/node_shader_common.c index 24de03dbda4..23b27fc5008 100644 --- a/source/blender/nodes/shader/nodes/node_shader_common.c +++ b/source/blender/nodes/shader/nodes/node_shader_common.c @@ -215,11 +215,7 @@ static int gpu_group_execute(GPUMaterial *mat, bNode *node, bNodeExecData *execd return 0; group_gpu_copy_inputs(node, in, exec->stack); -#if 0 /* XXX NODE_GROUP_EDIT is deprecated, depends on node space */ - ntreeExecGPUNodes(exec, mat, (node->flag & NODE_GROUP_EDIT)); -#else - ntreeExecGPUNodes(exec, mat, 0, NODE_NEW_SHADING | NODE_OLD_SHADING); -#endif + ntreeExecGPUNodes(exec, mat, 0); group_gpu_move_outputs(node, out, exec->stack); return 1; @@ -242,7 +238,6 @@ void register_node_type_sh_group(void) BLI_assert(ntype.ext.srna != NULL); RNA_struct_blender_type_set(ntype.ext.srna, &ntype); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, NULL); node_type_size(&ntype, 140, 60, 400); node_type_label(&ntype, node_group_label); diff --git a/source/blender/nodes/shader/nodes/node_shader_curves.c b/source/blender/nodes/shader/nodes/node_shader_curves.c index 0c583ced75f..243d57339ea 100644 --- a/source/blender/nodes/shader/nodes/node_shader_curves.c +++ b/source/blender/nodes/shader/nodes/node_shader_curves.c @@ -62,11 +62,13 @@ static void node_shader_init_curve_vec(bNodeTree *UNUSED(ntree), bNode *node) static int gpu_shader_curve_vec(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - float *array; + float *array, layer; int size; curvemapping_table_RGBA(node->storage, &array, &size); - return GPU_stack_link(mat, "curves_vec", in, out, GPU_texture(size, array)); + GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); + + return GPU_stack_link(mat, node, "curves_vec", in, out, tex, GPU_constant(&layer)); } void register_node_type_sh_curve_vec(void) @@ -74,7 +76,6 @@ void register_node_type_sh_curve_vec(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_curve_vec_in, sh_node_curve_vec_out); node_type_init(&ntype, node_shader_init_curve_vec); node_type_size_preset(&ntype, NODE_SIZE_LARGE); @@ -120,12 +121,14 @@ static void node_shader_init_curve_rgb(bNodeTree *UNUSED(ntree), bNode *node) static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - float *array; + float *array, layer; int size; curvemapping_initialize(node->storage); curvemapping_table_RGBA(node->storage, &array, &size); - return GPU_stack_link(mat, "curves_rgb", in, out, GPU_texture(size, array)); + GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); + + return GPU_stack_link(mat, node, "curves_rgb", in, out, tex, GPU_constant(&layer)); } void register_node_type_sh_curve_rgb(void) @@ -133,7 +136,6 @@ void register_node_type_sh_curve_rgb(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_curve_rgb_in, sh_node_curve_rgb_out); node_type_init(&ntype, node_shader_init_curve_rgb); node_type_size_preset(&ntype, NODE_SIZE_LARGE); diff --git a/source/blender/nodes/shader/nodes/node_shader_displacement.c b/source/blender/nodes/shader/nodes/node_shader_displacement.c index e259a9e3f6d..4480cbdf56b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_displacement.c +++ b/source/blender/nodes/shader/nodes/node_shader_displacement.c @@ -61,10 +61,10 @@ static int gpu_shader_displacement(GPUMaterial *mat, bNode *node, bNodeExecData } if (node->custom1 == SHD_SPACE_OBJECT) { - return GPU_stack_link(mat, "node_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); + return GPU_stack_link(mat, node, "node_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); } else { - return GPU_stack_link(mat, "node_displacement_world", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); + return GPU_stack_link(mat, node, "node_displacement_world", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); } } @@ -74,7 +74,6 @@ void register_node_type_sh_displacement(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_DISPLACEMENT, "Displacement", NODE_CLASS_OP_VECTOR, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_displacement_in, sh_node_displacement_out); node_type_storage(&ntype, "", NULL, NULL); node_type_init(&ntype, node_shader_init_displacement); diff --git a/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c b/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c new file mode 100644 index 00000000000..939cd9f79a2 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c @@ -0,0 +1,88 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Clément Foucault. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "../node_shader_util.h" + +/* **************** OUTPUT ******************** */ + +static bNodeSocketTemplate sh_node_eevee_specular_in[] = { + { SOCK_RGBA, 1, N_("Base Color"), 0.8f, 0.8f, 0.8f, 1.0f}, + { SOCK_RGBA, 1, N_("Specular"), 0.03f, 0.03f, 0.03f, 1.0f}, + { SOCK_FLOAT, 1, N_("Roughness"), 0.2f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + { SOCK_RGBA, 1, N_("Emissive Color"), 0.0f, 0.0f, 0.0f, 1.0f}, + { SOCK_FLOAT, 1, N_("Transparency"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { SOCK_FLOAT, 1, N_("Clear Coat"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + { SOCK_FLOAT, 1, N_("Clear Coat Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, + { SOCK_VECTOR, 1, N_("Clear Coat Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { SOCK_FLOAT, 1, N_("Ambient Occlusion"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { -1, 0, "" } +}; + +static bNodeSocketTemplate sh_node_eevee_specular_out[] = { + { SOCK_SHADER, 0, N_("BSDF")}, + { -1, 0, "" } +}; + +static int node_shader_gpu_eevee_specular(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +{ + static float one = 1.0f; + + /* Normals */ + if (!in[5].link) { + GPU_link(mat, "world_normals_get", &in[5].link); + } + + /* Clearcoat Normals */ + if (!in[8].link) { + GPU_link(mat, "world_normals_get", &in[8].link); + } + + /* Occlusion */ + if (!in[9].link) { + GPU_link(mat, "set_value", GPU_constant(&one), &in[9].link); + } + + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_GLOSSY); + + return GPU_stack_link(mat, node, "node_eevee_specular", in, out, GPU_constant(&node->ssr_id)); +} + + +/* node type definition */ +void register_node_type_sh_eevee_specular(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_EEVEE_SPECULAR, "Specular", NODE_CLASS_SHADER, 0); + node_type_socket_templates(&ntype, sh_node_eevee_specular_in, sh_node_eevee_specular_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_eevee_specular); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_emission.c b/source/blender/nodes/shader/nodes/node_shader_emission.c index 2838e9dc54d..25194c23d0a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_emission.c +++ b/source/blender/nodes/shader/nodes/node_shader_emission.c @@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_emission_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_emission(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_emission(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_emission", in, out, GPU_builtin(GPU_VIEW_NORMAL)); + return GPU_stack_link(mat, node, "node_emission", in, out, GPU_builtin(GPU_VIEW_NORMAL)); } /* node type definition */ @@ -51,7 +51,6 @@ void register_node_type_sh_emission(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_EMISSION, "Emission", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_emission_in, sh_node_emission_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_fresnel.c b/source/blender/nodes/shader/nodes/node_shader_fresnel.c index 393d2c5fee0..cb6b35ac4a7 100644 --- a/source/blender/nodes/shader/nodes/node_shader_fresnel.c +++ b/source/blender/nodes/shader/nodes/node_shader_fresnel.c @@ -39,45 +39,20 @@ static bNodeSocketTemplate sh_node_fresnel_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[1].link) { in[1].link = GPU_builtin(GPU_VIEW_NORMAL); } - else if (GPU_material_use_world_space_shading(mat)) { + else { GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link); } - return GPU_stack_link(mat, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION)); + return GPU_stack_link(mat, node, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION)); } -static void node_shader_exec_fresnel(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_fresnel(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) { - ShadeInput *shi = ((ShaderCallData *)data)->shi; - - /* Compute IOR. */ - float eta; - nodestack_get_vec(&eta, SOCK_FLOAT, in[0]); - eta = max_ff(eta, 0.00001); - eta = shi->flippednor ? 1 / eta : eta; - - /* Get normal from socket, but only if linked. */ - bNodeSocket *sock_normal = node->inputs.first; - sock_normal = sock_normal->next; - - float n[3]; - if (sock_normal->link) { - nodestack_get_vec(n, SOCK_VECTOR, in[1]); - } - else { - copy_v3_v3(n, shi->vn); - } - - if (shi->use_world_space_shading) { - mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), n); - } - - out[0]->vec[0] = RE_fresnel_dielectric(shi->view, n, eta); } /* node type definition */ @@ -86,7 +61,6 @@ void register_node_type_sh_fresnel(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_FRESNEL, "Fresnel", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING | NODE_OLD_SHADING); node_type_socket_templates(&ntype, sh_node_fresnel_in, sh_node_fresnel_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_gamma.c b/source/blender/nodes/shader/nodes/node_shader_gamma.c index 8bf58682ef3..4a946e92778 100644 --- a/source/blender/nodes/shader/nodes/node_shader_gamma.c +++ b/source/blender/nodes/shader/nodes/node_shader_gamma.c @@ -52,9 +52,9 @@ static void node_shader_exec_gamma(void *UNUSED(data), int UNUSED(thread), bNode out[0]->vec[2] = col[2] > 0.0f ? powf(col[2], gamma) : col[2]; } -static int node_shader_gpu_gamma(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_gamma(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_gamma", in, out); + return GPU_stack_link(mat, node, "node_gamma", in, out); } void register_node_type_sh_gamma(void) @@ -62,7 +62,6 @@ void register_node_type_sh_gamma(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_GAMMA, "Gamma", NODE_CLASS_OP_COLOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_gamma_in, sh_node_gamma_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_geom.c b/source/blender/nodes/shader/nodes/node_shader_geom.c deleted file mode 100644 index 0a51ee8dc68..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_geom.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/shader/nodes/node_shader_geom.c - * \ingroup shdnodes - */ - - -#include "node_shader_util.h" - -#include "DNA_customdata_types.h" - -/* **************** GEOMETRY ******************** */ - -/* output socket type definition */ -static bNodeSocketTemplate sh_node_geom_out[] = { - { SOCK_VECTOR, 0, N_("Global")}, - { SOCK_VECTOR, 0, N_("Local")}, - { SOCK_VECTOR, 0, N_("View")}, - { SOCK_VECTOR, 0, N_("Orco")}, - { SOCK_VECTOR, 0, N_("UV")}, - { SOCK_VECTOR, 0, N_("Normal")}, - { SOCK_RGBA, 0, N_("Vertex Color")}, - { SOCK_FLOAT, 0, N_("Vertex Alpha")}, - { SOCK_FLOAT, 0, N_("Front/Back")}, - { -1, 0, "" } -}; - -/* node execute callback */ -static void node_shader_exec_geom(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out) -{ - if (data) { - ShadeInput *shi = ((ShaderCallData *)data)->shi; - NodeGeometry *ngeo = (NodeGeometry *)node->storage; - ShadeInputUV *suv = &shi->uv[shi->actuv]; - static float defaultvcol[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - int i; - - if (ngeo->uvname[0]) { - /* find uv map by name */ - for (i = 0; i < shi->totuv; i++) { - if (STREQ(shi->uv[i].name, ngeo->uvname)) { - suv = &shi->uv[i]; - break; - } - } - } - - /* out: global, local, view, orco, uv, normal, vertex color */ - copy_v3_v3(out[GEOM_OUT_GLOB]->vec, shi->gl); - copy_v3_v3(out[GEOM_OUT_LOCAL]->vec, shi->co); - copy_v3_v3(out[GEOM_OUT_VIEW]->vec, shi->view); - copy_v3_v3(out[GEOM_OUT_ORCO]->vec, shi->lo); - copy_v3_v3(out[GEOM_OUT_UV]->vec, suv->uv); - copy_v3_v3(out[GEOM_OUT_NORMAL]->vec, shi->vno); - - if (shi->use_world_space_shading) { - negate_v3(out[GEOM_OUT_NORMAL]->vec); - mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), out[GEOM_OUT_NORMAL]->vec); - } - if (shi->totcol) { - /* find vertex color layer by name */ - ShadeInputCol *scol = &shi->col[0]; - - if (ngeo->colname[0]) { - for (i = 0; i < shi->totcol; i++) { - if (STREQ(shi->col[i].name, ngeo->colname)) { - scol = &shi->col[i]; - break; - } - } - } - - srgb_to_linearrgb_v3_v3(out[GEOM_OUT_VCOL]->vec, scol->col); - out[GEOM_OUT_VCOL]->vec[3] = scol->col[3]; - out[GEOM_OUT_VCOL_ALPHA]->vec[0] = scol->col[3]; - } - else { - memcpy(out[GEOM_OUT_VCOL]->vec, defaultvcol, sizeof(defaultvcol)); - out[GEOM_OUT_VCOL_ALPHA]->vec[0] = 1.0f; - } - - if (shi->osatex) { - out[GEOM_OUT_GLOB]->data = shi->dxgl; - out[GEOM_OUT_GLOB]->datatype = NS_OSA_VECTORS; - out[GEOM_OUT_LOCAL]->data = shi->dxco; - out[GEOM_OUT_LOCAL]->datatype = NS_OSA_VECTORS; - out[GEOM_OUT_VIEW]->data = &shi->dxview; - out[GEOM_OUT_VIEW]->datatype = NS_OSA_VALUES; - out[GEOM_OUT_ORCO]->data = shi->dxlo; - out[GEOM_OUT_ORCO]->datatype = NS_OSA_VECTORS; - out[GEOM_OUT_UV]->data = suv->dxuv; - out[GEOM_OUT_UV]->datatype = NS_OSA_VECTORS; - out[GEOM_OUT_NORMAL]->data = shi->dxno; - out[GEOM_OUT_NORMAL]->datatype = NS_OSA_VECTORS; - } - - /* front/back, normal flipping was stored */ - out[GEOM_OUT_FRONTBACK]->vec[0] = (shi->flippednor) ? 0.0f : 1.0f; - } -} - -static void node_shader_init_geometry(bNodeTree *UNUSED(ntree), bNode *node) -{ - node->storage = MEM_callocN(sizeof(NodeGeometry), "NodeGeometry"); -} - -static int gpu_shader_geom(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) -{ - NodeGeometry *ngeo = (NodeGeometry *)node->storage; - GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); - GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ngeo->uvname); - GPUNodeLink *mcol = GPU_attribute(CD_MCOL, ngeo->colname); - - bool ret = GPU_stack_link(mat, "geom", in, out, - GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), - GPU_builtin(GPU_INVERSE_VIEW_MATRIX), orco, mtface, mcol); - if (GPU_material_use_world_space_shading(mat)) { - GPU_link(mat, "vec_math_negate", out[5].link, &out[5].link); - ret &= GPU_link(mat, "direction_transform_m4v3", out[5].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[5].link); - } - return ret; -} - -/* node type definition */ -void register_node_type_sh_geom(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_GEOMETRY, "Geometry", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING); - node_type_socket_templates(&ntype, NULL, sh_node_geom_out); - node_type_init(&ntype, node_shader_init_geometry); - node_type_storage(&ntype, "NodeGeometry", node_free_standard_storage, node_copy_standard_storage); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_geom); - node_type_gpu(&ntype, gpu_shader_geom); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_geometry.c b/source/blender/nodes/shader/nodes/node_shader_geometry.c index d73628ebd67..d004e0e80a1 100644 --- a/source/blender/nodes/shader/nodes/node_shader_geometry.c +++ b/source/blender/nodes/shader/nodes/node_shader_geometry.c @@ -41,11 +41,12 @@ static bNodeSocketTemplate sh_node_geometry_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_geometry", in, out, + return GPU_stack_link(mat, node, "node_geometry", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), - GPU_builtin(GPU_INVERSE_VIEW_MATRIX)); + GPU_attribute(CD_ORCO, ""), GPU_builtin(GPU_OBJECT_MATRIX), + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_BARYCENTRIC_TEXCO)); } /* node type definition */ @@ -54,7 +55,6 @@ void register_node_type_sh_geometry(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_NEW_GEOMETRY, "Geometry", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_geometry_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_hair_info.c b/source/blender/nodes/shader/nodes/node_shader_hair_info.c index 6a15c59aa5b..8b2f4b479ad 100644 --- a/source/blender/nodes/shader/nodes/node_shader_hair_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_hair_info.c @@ -37,16 +37,21 @@ static bNodeSocketTemplate outputs[] = { { -1, 0, "" } }; +static int node_shader_gpu_hair_info(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +{ + return GPU_stack_link(mat, node, "node_hair_info", in, out); +} + /* node type definition */ void register_node_type_sh_hair_info(void) { static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_HAIR_INFO, "Hair Info", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, outputs); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_hair_info); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_holdout.c b/source/blender/nodes/shader/nodes/node_shader_holdout.c index 42563f2bfa8..6109022fddf 100644 --- a/source/blender/nodes/shader/nodes/node_shader_holdout.c +++ b/source/blender/nodes/shader/nodes/node_shader_holdout.c @@ -45,7 +45,6 @@ void register_node_type_sh_holdout(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_HOLDOUT, "Holdout", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_holdout_in, sh_node_holdout_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c b/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c index 548b3970a89..c017765c8e2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c +++ b/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c @@ -82,9 +82,9 @@ static void node_shader_exec_hue_sat(void *UNUSED(data), int UNUSED(thread), bNo } -static int gpu_shader_hue_sat(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_hue_sat(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "hue_sat", in, out); + return GPU_stack_link(mat, node, "hue_sat", in, out); } void register_node_type_sh_hue_sat(void) @@ -92,7 +92,6 @@ void register_node_type_sh_hue_sat(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_hue_sat_in, sh_node_hue_sat_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_exec(&ntype, NULL, NULL, node_shader_exec_hue_sat); diff --git a/source/blender/nodes/shader/nodes/node_shader_ies_light.c b/source/blender/nodes/shader/nodes/node_shader_ies_light.c index 8084f445e34..2714d560862 100644 --- a/source/blender/nodes/shader/nodes/node_shader_ies_light.c +++ b/source/blender/nodes/shader/nodes/node_shader_ies_light.c @@ -52,7 +52,6 @@ void register_node_type_sh_tex_ies(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_IES, "IES Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_ies_in, sh_node_tex_ies_out); node_type_init(&ntype, node_shader_init_tex_ies); node_type_storage(&ntype, "NodeShaderTexIES", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_invert.c b/source/blender/nodes/shader/nodes/node_shader_invert.c index dc0817782e5..448d305b44e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_invert.c +++ b/source/blender/nodes/shader/nodes/node_shader_invert.c @@ -65,9 +65,9 @@ static void node_shader_exec_invert(void *UNUSED(data), int UNUSED(thread), bNod copy_v3_v3(out[0]->vec, icol); } -static int gpu_shader_invert(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_invert(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "invert", in, out); + return GPU_stack_link(mat, node, "invert", in, out); } void register_node_type_sh_invert(void) @@ -75,7 +75,6 @@ void register_node_type_sh_invert(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_invert_in, sh_node_invert_out); node_type_exec(&ntype, NULL, NULL, node_shader_exec_invert); node_type_gpu(&ntype, gpu_shader_invert); diff --git a/source/blender/nodes/shader/nodes/node_shader_lamp.c b/source/blender/nodes/shader/nodes/node_shader_lamp.c deleted file mode 100644 index 5dd3a9cd507..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_lamp.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2013 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/shader/nodes/node_shader_lamp.c - * \ingroup shdnodes - */ - - -#include "node_shader_util.h" - -/* **************** LAMP INFO ******************** */ -static bNodeSocketTemplate sh_node_lamp_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { SOCK_VECTOR, 0, N_("Light Vector")}, - { SOCK_FLOAT, 0, N_("Distance")}, - { SOCK_RGBA, 0, N_("Shadow")}, - { SOCK_FLOAT, 0, N_("Visibility Factor")}, - { -1, 0, "" } -}; - - -static void node_shader_exec_lamp(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out) -{ - if (data) { - Object *ob = (Object *)node->id; - - if (ob) { - ShadeInput *shi = ((ShaderCallData *)data)->shi; - - shi->nodes = 1; /* temp hack to prevent trashadow recursion */ - out[4]->vec[0] = RE_lamp_get_data(shi, ob, out[0]->vec, out[1]->vec, out[2]->vec, out[3]->vec); - shi->nodes = 0; - if (shi->use_world_space_shading) - mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), out[1]->vec); - } - } -} - -static int gpu_shader_lamp(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) -{ - if (node->id) { - GPULamp *lamp = GPU_lamp_from_blender(GPU_material_scene(mat), (Object *)node->id, NULL); - GPUNodeLink *col, *lv, *dist, *visifac, *shadow, *energy; - - visifac = GPU_lamp_get_data(mat, lamp, &col, &lv, &dist, &shadow, &energy); - - bool ret = GPU_stack_link(mat, "lamp", in, out, col, energy, lv, dist, shadow, visifac); - if (GPU_material_use_world_space_shading(mat)) - ret &= GPU_link(mat, "direction_transform_m4v3", out[1].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[1].link); - return ret; - } - - return false; -} - -void register_node_type_sh_lamp(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_LAMP, "Lamp Data", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING); - node_type_socket_templates(&ntype, NULL, sh_node_lamp_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_lamp); - node_type_gpu(&ntype, gpu_shader_lamp); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_layer_weight.c b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c index 3d27d6bef7f..9c0b0a2f5f6 100644 --- a/source/blender/nodes/shader/nodes/node_shader_layer_weight.c +++ b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c @@ -41,52 +41,20 @@ static bNodeSocketTemplate sh_node_layer_weight_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - if (!in[1].link) + if (!in[1].link) { in[1].link = GPU_builtin(GPU_VIEW_NORMAL); - else if (GPU_material_use_world_space_shading(mat)) { + } + else { GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link); } - return GPU_stack_link(mat, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION)); + return GPU_stack_link(mat, node, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION)); } -static void node_shader_exec_layer_weight(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_layer_weight(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) { - ShadeInput *shi = ((ShaderCallData *)data)->shi; - - /* Compute IOR. */ - float blend; - nodestack_get_vec(&blend, SOCK_FLOAT, in[0]); - float eta = max_ff(1 - blend, 0.00001); - eta = shi->flippednor ? eta : 1 / eta; - - /* Get normal from socket, but only if linked. */ - bNodeSocket *sock_normal = node->inputs.first; - sock_normal = sock_normal->next; - - float n[3]; - if (sock_normal->link) { - nodestack_get_vec(n, SOCK_VECTOR, in[1]); - } - else { - copy_v3_v3(n, shi->vn); - } - - - if (shi->use_world_space_shading) - mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), n); - - out[0]->vec[0] = RE_fresnel_dielectric(shi->view, n, eta); - - float facing = fabs(dot_v3v3(shi->view, n)); - if (blend != 0.5) { - CLAMP(blend, 0.0, 0.99999); - blend = (blend < 0.5) ? 2.0 * blend : 0.5 / (1.0 - blend); - facing = pow(facing, blend); - } - out[1]->vec[0] = 1.0 - facing; } /* node type definition */ @@ -95,7 +63,6 @@ void register_node_type_sh_layer_weight(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_LAYER_WEIGHT, "Layer Weight", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING | NODE_OLD_SHADING); node_type_socket_templates(&ntype, sh_node_layer_weight_in, sh_node_layer_weight_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_light_falloff.c b/source/blender/nodes/shader/nodes/node_shader_light_falloff.c index e28920d6f6e..f32570eaeaa 100644 --- a/source/blender/nodes/shader/nodes/node_shader_light_falloff.c +++ b/source/blender/nodes/shader/nodes/node_shader_light_falloff.c @@ -44,9 +44,9 @@ static bNodeSocketTemplate sh_node_light_falloff_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_light_falloff(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_light_falloff(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_light_falloff", in, out); + return GPU_stack_link(mat, node, "node_light_falloff", in, out); } /* node type definition */ @@ -55,7 +55,6 @@ void register_node_type_sh_light_falloff(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_LIGHT_FALLOFF, "Light Falloff", NODE_CLASS_OP_COLOR, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_light_falloff_in, sh_node_light_falloff_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_light_path.c b/source/blender/nodes/shader/nodes/node_shader_light_path.c index 3d4d76a96b3..23d01ad4417 100644 --- a/source/blender/nodes/shader/nodes/node_shader_light_path.c +++ b/source/blender/nodes/shader/nodes/node_shader_light_path.c @@ -46,9 +46,9 @@ static bNodeSocketTemplate sh_node_light_path_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_light_path(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_light_path(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_light_path", in, out); + return GPU_stack_link(mat, node, "node_light_path", in, out); } /* node type definition */ @@ -57,7 +57,6 @@ void register_node_type_sh_light_path(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_LIGHT_PATH, "Light Path", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_light_path_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.c b/source/blender/nodes/shader/nodes/node_shader_mapping.c index 95d0fa5c951..282c6a4f147 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mapping.c +++ b/source/blender/nodes/shader/nodes/node_shader_mapping.c @@ -88,13 +88,18 @@ static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS TexMapping *texmap = node->storage; float domin = (texmap->flag & TEXMAP_CLIP_MIN) != 0; float domax = (texmap->flag & TEXMAP_CLIP_MAX) != 0; - GPUNodeLink *tmat = GPU_uniform((float *)texmap->mat); - GPUNodeLink *tmin = GPU_uniform(texmap->min); - GPUNodeLink *tmax = GPU_uniform(texmap->max); - GPUNodeLink *tdomin = GPU_uniform(&domin); - GPUNodeLink *tdomax = GPU_uniform(&domax); + static float max[3] = { FLT_MAX, FLT_MAX, FLT_MAX}; + static float min[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX}; + GPUNodeLink *tmin, *tmax, *tmat0, *tmat1, *tmat2, *tmat3; - GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax); + tmin = GPU_uniform((domin) ? texmap->min : min); + tmax = GPU_uniform((domax) ? texmap->max : max); + tmat0 = GPU_uniform((float *)texmap->mat[0]); + tmat1 = GPU_uniform((float *)texmap->mat[1]); + tmat2 = GPU_uniform((float *)texmap->mat[2]); + tmat3 = GPU_uniform((float *)texmap->mat[3]); + + GPU_stack_link(mat, node, "mapping", in, out, tmat0, tmat1, tmat2, tmat3, tmin, tmax); if (texmap->type == TEXMAP_TYPE_NORMAL) GPU_link(mat, "texco_norm", out[0].link, &out[0].link); @@ -107,7 +112,6 @@ void register_node_type_sh_mapping(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_MAPPING, "Mapping", NODE_CLASS_OP_VECTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_mapping_in, sh_node_mapping_out); node_type_size(&ntype, 320, 160, 360); node_type_init(&ntype, node_shader_init_mapping); diff --git a/source/blender/nodes/shader/nodes/node_shader_material.c b/source/blender/nodes/shader/nodes/node_shader_material.c deleted file mode 100644 index 8a73ddc1194..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_material.c +++ /dev/null @@ -1,374 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/shader/nodes/node_shader_material.c - * \ingroup shdnodes - */ - -#include "node_shader_util.h" - -/* **************** MATERIAL ******************** */ - -static bNodeSocketTemplate sh_node_material_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Spec"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("DiffuseIntensity"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_DIRECTION}, - { -1, 0, "" } -}; - -static bNodeSocketTemplate sh_node_material_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { SOCK_FLOAT, 0, N_("Alpha")}, - { SOCK_VECTOR, 0, N_("Normal")}, - { -1, 0, "" } -}; - -/* **************** EXTENDED MATERIAL ******************** */ - -static bNodeSocketTemplate sh_node_material_ext_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, N_("Spec"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("DiffuseIntensity"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_DIRECTION}, - { SOCK_RGBA, 1, N_("Mirror"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Ambient"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Emit"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - { SOCK_FLOAT, 1, N_("SpecTra"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Reflectivity"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { SOCK_FLOAT, 1, N_("Alpha"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED}, - { SOCK_FLOAT, 1, N_("Translucency"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" } -}; - -static bNodeSocketTemplate sh_node_material_ext_out[] = { - { SOCK_RGBA, 0, N_("Color")}, - { SOCK_FLOAT, 0, N_("Alpha")}, - { SOCK_VECTOR, 0, N_("Normal")}, - { SOCK_RGBA, 0, N_("Diffuse")}, - { SOCK_RGBA, 0, N_("Spec")}, - { SOCK_RGBA, 0, N_("AO")}, - { -1, 0, "" } -}; - -static void node_shader_exec_material(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) -{ - if (data && node->id) { - ShadeResult shrnode; - ShadeInput *shi; - ShaderCallData *shcd = data; - float col[4]; - bNodeSocket *sock; - char hasinput[NUM_MAT_IN] = {'\0'}; - int i, mode; - - /* note: cannot use the in[]->hasinput flags directly, as these are not necessarily - * the constant input stack values (e.g. in case material node is inside a group). - * we just want to know if a node input uses external data or the material setting. - * this is an ugly hack, but so is this node as a whole. - */ - for (sock = node->inputs.first, i = 0; sock; sock = sock->next, ++i) - hasinput[i] = (sock->link != NULL); - - shi = shcd->shi; - shi->mat = (Material *)node->id; - - /* copy all relevant material vars, note, keep this synced with render_types.h */ - memcpy(&shi->r, &shi->mat->r, 23 * sizeof(float)); - shi->har = shi->mat->har; - - /* write values */ - if (hasinput[MAT_IN_COLOR]) - nodestack_get_vec(&shi->r, SOCK_VECTOR, in[MAT_IN_COLOR]); - - if (hasinput[MAT_IN_SPEC]) - nodestack_get_vec(&shi->specr, SOCK_VECTOR, in[MAT_IN_SPEC]); - - if (hasinput[MAT_IN_REFL]) - nodestack_get_vec(&shi->refl, SOCK_FLOAT, in[MAT_IN_REFL]); - - /* retrieve normal */ - if (hasinput[MAT_IN_NORMAL]) { - nodestack_get_vec(shi->vn, SOCK_VECTOR, in[MAT_IN_NORMAL]); - if (shi->use_world_space_shading) { - negate_v3(shi->vn); - mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), shi->vn); - } - normalize_v3(shi->vn); - } - else - copy_v3_v3(shi->vn, shi->vno); - - /* custom option to flip normal */ - if (node->custom1 & SH_NODE_MAT_NEG) { - negate_v3(shi->vn); - } - - if (node->type == SH_NODE_MATERIAL_EXT) { - if (hasinput[MAT_IN_MIR]) - nodestack_get_vec(&shi->mirr, SOCK_VECTOR, in[MAT_IN_MIR]); - if (hasinput[MAT_IN_AMB]) - nodestack_get_vec(&shi->amb, SOCK_FLOAT, in[MAT_IN_AMB]); - if (hasinput[MAT_IN_EMIT]) - nodestack_get_vec(&shi->emit, SOCK_FLOAT, in[MAT_IN_EMIT]); - if (hasinput[MAT_IN_SPECTRA]) - nodestack_get_vec(&shi->spectra, SOCK_FLOAT, in[MAT_IN_SPECTRA]); - if (hasinput[MAT_IN_RAY_MIRROR]) - nodestack_get_vec(&shi->ray_mirror, SOCK_FLOAT, in[MAT_IN_RAY_MIRROR]); - if (hasinput[MAT_IN_ALPHA]) - nodestack_get_vec(&shi->alpha, SOCK_FLOAT, in[MAT_IN_ALPHA]); - if (hasinput[MAT_IN_TRANSLUCENCY]) - nodestack_get_vec(&shi->translucency, SOCK_FLOAT, in[MAT_IN_TRANSLUCENCY]); - } - - /* make alpha output give results even if transparency is only enabled on - * the material linked in this not and not on the parent material */ - mode = shi->mode; - if (shi->mat->mode & MA_TRANSP) - shi->mode |= MA_TRANSP; - - shi->nodes = 1; /* temp hack to prevent trashadow recursion */ - node_shader_lamp_loop(shi, &shrnode); /* clears shrnode */ - shi->nodes = 0; - - shi->mode = mode; - - /* write to outputs */ - if (node->custom1 & SH_NODE_MAT_DIFF) { - copy_v3_v3(col, shrnode.combined); - if (!(node->custom1 & SH_NODE_MAT_SPEC)) { - sub_v3_v3(col, shrnode.spec); - } - } - else if (node->custom1 & SH_NODE_MAT_SPEC) { - copy_v3_v3(col, shrnode.spec); - } - else - col[0] = col[1] = col[2] = 0.0f; - - col[3] = shrnode.alpha; - - if (shi->do_preview) - BKE_node_preview_set_pixel(execdata->preview, col, shi->xs, shi->ys, shi->do_manage); - - copy_v3_v3(out[MAT_OUT_COLOR]->vec, col); - out[MAT_OUT_ALPHA]->vec[0] = shrnode.alpha; - - if (node->custom1 & SH_NODE_MAT_NEG) { - shi->vn[0] = -shi->vn[0]; - shi->vn[1] = -shi->vn[1]; - shi->vn[2] = -shi->vn[2]; - } - - copy_v3_v3(out[MAT_OUT_NORMAL]->vec, shi->vn); - - if (shi->use_world_space_shading) { - negate_v3(out[MAT_OUT_NORMAL]->vec); - mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), out[MAT_OUT_NORMAL]->vec); - } - /* Extended material options */ - if (node->type == SH_NODE_MATERIAL_EXT) { - /* Shadow, Reflect, Refract, Radiosity, Speed seem to cause problems inside - * a node tree :( */ - copy_v3_v3(out[MAT_OUT_DIFFUSE]->vec, shrnode.diffshad); - copy_v3_v3(out[MAT_OUT_SPEC]->vec, shrnode.spec); - copy_v3_v3(out[MAT_OUT_AO]->vec, shrnode.ao); - } - - /* copy passes, now just active node */ - if (node->flag & NODE_ACTIVE_ID) { - float combined[4], alpha; - - copy_v4_v4(combined, shcd->shr->combined); - alpha = shcd->shr->alpha; - - *(shcd->shr) = shrnode; - - copy_v4_v4(shcd->shr->combined, combined); - shcd->shr->alpha = alpha; - } - } -} - - -static void node_shader_init_material(bNodeTree *UNUSED(ntree), bNode *node) -{ - node->custom1 = SH_NODE_MAT_DIFF | SH_NODE_MAT_SPEC; -} - -/* XXX this is also done as a local static function in gpu_codegen.c, - * but we need this to hack around the crappy material node. - */ -static GPUNodeLink *gpu_get_input_link(GPUMaterial *mat, GPUNodeStack *in) -{ - if (in->link) { - return in->link; - } - else { - GPUNodeLink *result = NULL; - - /* note GPU_uniform() is only intended to be used as a parameter to - * GPU_link(), returning it directly results in leaks or double frees */ - if (in->type == GPU_FLOAT) - GPU_link(mat, "set_value", GPU_uniform(in->vec), &result); - else if (in->type == GPU_VEC3) - GPU_link(mat, "set_rgb", GPU_uniform(in->vec), &result); - else if (in->type == GPU_VEC4) - GPU_link(mat, "set_rgba", GPU_uniform(in->vec), &result); - else - BLI_assert(0); - - return result; - } -} - -static int gpu_shader_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) -{ - if (node->id) { - GPUShadeInput shi; - GPUShadeResult shr; - bNodeSocket *sock; - char hasinput[NUM_MAT_IN] = {'\0'}; - int i; - - /* note: cannot use the in[]->hasinput flags directly, as these are not necessarily - * the constant input stack values (e.g. in case material node is inside a group). - * we just want to know if a node input uses external data or the material setting. - */ - for (sock = node->inputs.first, i = 0; sock; sock = sock->next, ++i) - hasinput[i] = (sock->link != NULL); - - GPU_shadeinput_set(mat, (Material *)node->id, &shi); - - /* write values */ - if (hasinput[MAT_IN_COLOR]) - shi.rgb = gpu_get_input_link(mat, &in[MAT_IN_COLOR]); - - if (hasinput[MAT_IN_SPEC]) - shi.specrgb = gpu_get_input_link(mat, &in[MAT_IN_SPEC]); - - if (hasinput[MAT_IN_REFL]) - shi.refl = gpu_get_input_link(mat, &in[MAT_IN_REFL]); - - /* retrieve normal */ - if (hasinput[MAT_IN_NORMAL]) { - GPUNodeLink *tmp; - shi.vn = gpu_get_input_link(mat, &in[MAT_IN_NORMAL]); - if (GPU_material_use_world_space_shading(mat)) { - GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn); - GPU_link(mat, "direction_transform_m4v3", shi.vn, GPU_builtin(GPU_VIEW_MATRIX), &shi.vn); - } - GPU_link(mat, "vec_math_normalize", shi.vn, &shi.vn, &tmp); - } - - /* custom option to flip normal */ - if (node->custom1 & SH_NODE_MAT_NEG) - GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn); - - if (node->type == SH_NODE_MATERIAL_EXT) { - if (hasinput[MAT_IN_MIR]) - shi.mir = gpu_get_input_link(mat, &in[MAT_IN_MIR]); - if (hasinput[MAT_IN_AMB]) - shi.amb = gpu_get_input_link(mat, &in[MAT_IN_AMB]); - if (hasinput[MAT_IN_EMIT]) - shi.emit = gpu_get_input_link(mat, &in[MAT_IN_EMIT]); - if (hasinput[MAT_IN_SPECTRA]) - shi.spectra = gpu_get_input_link(mat, &in[MAT_IN_SPECTRA]); - if (hasinput[MAT_IN_ALPHA]) - shi.alpha = gpu_get_input_link(mat, &in[MAT_IN_ALPHA]); - } - - GPU_shaderesult_set(&shi, &shr); /* clears shr */ - - /* write to outputs */ - if (node->custom1 & SH_NODE_MAT_DIFF) { - out[MAT_OUT_COLOR].link = shr.combined; - - if (!(node->custom1 & SH_NODE_MAT_SPEC)) { - GPUNodeLink *link; - GPU_link(mat, "vec_math_sub", shr.combined, shr.spec, &out[MAT_OUT_COLOR].link, &link); - } - } - else if (node->custom1 & SH_NODE_MAT_SPEC) { - out[MAT_OUT_COLOR].link = shr.spec; - } - else - GPU_link(mat, "set_rgb_zero", &out[MAT_OUT_COLOR].link); - - GPU_link(mat, "mtex_alpha_to_col", out[MAT_OUT_COLOR].link, shr.alpha, &out[MAT_OUT_COLOR].link); - - out[MAT_OUT_ALPHA].link = shr.alpha; // - - if (node->custom1 & SH_NODE_MAT_NEG) - GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn); - out[MAT_OUT_NORMAL].link = shi.vn; - if (GPU_material_use_world_space_shading(mat)) { - GPU_link(mat, "vec_math_negate", out[MAT_OUT_NORMAL].link, &out[MAT_OUT_NORMAL].link); - GPU_link(mat, "direction_transform_m4v3", out[MAT_OUT_NORMAL].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[MAT_OUT_NORMAL].link); - } - - if (node->type == SH_NODE_MATERIAL_EXT) { - out[MAT_OUT_DIFFUSE].link = shr.diff; - out[MAT_OUT_SPEC].link = shr.spec; - GPU_link(mat, "set_rgb_one", &out[MAT_OUT_AO].link); - } - - return 1; - } - - return 0; -} - -void register_node_type_sh_material(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_MATERIAL, "Material", NODE_CLASS_INPUT, NODE_PREVIEW); - node_type_compatibility(&ntype, NODE_OLD_SHADING); - node_type_socket_templates(&ntype, sh_node_material_in, sh_node_material_out); - node_type_init(&ntype, node_shader_init_material); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_material); - node_type_gpu(&ntype, gpu_shader_material); - - nodeRegisterType(&ntype); -} - - -void register_node_type_sh_material_ext(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_MATERIAL_EXT, "Extended Material", NODE_CLASS_INPUT, NODE_PREVIEW); - node_type_compatibility(&ntype, NODE_OLD_SHADING); - node_type_socket_templates(&ntype, sh_node_material_ext_in, sh_node_material_ext_out); - node_type_init(&ntype, node_shader_init_material); - node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_material); - node_type_gpu(&ntype, gpu_shader_material); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c index 605c869099a..a072c686686 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_math.c @@ -296,7 +296,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED( case NODE_MATH_GREATER: case NODE_MATH_MOD: case NODE_MATH_ATAN2: - GPU_stack_link(mat, names[node->custom1], in, out); + GPU_stack_link(mat, node, names[node->custom1], in, out); break; case NODE_MATH_SIN: case NODE_MATH_COS: @@ -315,14 +315,14 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED( GPUNodeStack tmp_in[2]; memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack)); memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); - GPU_stack_link(mat, names[node->custom1], tmp_in, out); + GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); } else { /* use only second item and terminator */ GPUNodeStack tmp_in[2]; memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack)); memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); - GPU_stack_link(mat, names[node->custom1], tmp_in, out); + GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); } break; default: @@ -332,7 +332,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED( if (node->custom2 & SHD_MATH_CLAMP) { float min[3] = {0.0f, 0.0f, 0.0f}; float max[3] = {1.0f, 1.0f, 1.0f}; - GPU_link(mat, "clamp_val", out[0].link, GPU_uniform(min), GPU_uniform(max), &out[0].link); + GPU_link(mat, "clamp_val", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); } return 1; @@ -343,7 +343,6 @@ void register_node_type_sh_math(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_math_in, sh_node_math_out); node_type_label(&ntype, node_math_label); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c index 14a9f2c5ea5..5bf5ce69261 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c @@ -71,11 +71,12 @@ static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS "mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light", "mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat", "mix_val", "mix_color", "mix_soft", "mix_linear"}; - int ret = GPU_stack_link(mat, names[node->custom1], in, out); + + int ret = GPU_stack_link(mat, node, names[node->custom1], in, out); if (ret && node->custom2 & SHD_MIXRGB_CLAMP) { float min[3] = {0.0f, 0.0f, 0.0f}; float max[3] = {1.0f, 1.0f, 1.0f}; - GPU_link(mat, "clamp_vec3", out[0].link, GPU_uniform(min), GPU_uniform(max), &out[0].link); + GPU_link(mat, "clamp_vec3", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); } return ret; } @@ -86,7 +87,6 @@ void register_node_type_sh_mix_rgb(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_mix_rgb_in, sh_node_mix_rgb_out); node_type_label(&ntype, node_blend_label); node_type_exec(&ntype, NULL, NULL, node_shader_exec_mix_rgb); diff --git a/source/blender/nodes/shader/nodes/node_shader_mix_shader.c b/source/blender/nodes/shader/nodes/node_shader_mix_shader.c index 0e4d6c9cda6..1d6c76766b3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mix_shader.c +++ b/source/blender/nodes/shader/nodes/node_shader_mix_shader.c @@ -41,9 +41,9 @@ static bNodeSocketTemplate sh_node_mix_shader_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_mix_shader(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_mix_shader(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_mix_shader", in, out); + return GPU_stack_link(mat, node, "node_mix_shader", in, out); } /* node type definition */ @@ -52,7 +52,6 @@ void register_node_type_sh_mix_shader(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_MIX_SHADER, "Mix Shader", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_mix_shader_in, sh_node_mix_shader_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_normal.c b/source/blender/nodes/shader/nodes/node_shader_normal.c index 84d250eed7b..13335c86382 100644 --- a/source/blender/nodes/shader/nodes/node_shader_normal.c +++ b/source/blender/nodes/shader/nodes/node_shader_normal.c @@ -58,15 +58,10 @@ static void node_shader_exec_normal(void *UNUSED(data), int UNUSED(thread), bNod out[1]->vec[0] = -dot_v3v3(vec, out[0]->vec); } -static int gpu_shader_normal(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_normal(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - GPUNodeLink *vec = GPU_uniform(out[0].vec); - if (GPU_material_use_new_shading_nodes(mat)) { - return GPU_stack_link(mat, "normal_new_shading", in, out, vec); - } - else { - return GPU_stack_link(mat, "normal", in, out, vec); - } + GPUNodeLink *vec = GPU_constant(out[0].vec); + return GPU_stack_link(mat, node, "normal_new_shading", in, out, vec); } void register_node_type_sh_normal(void) @@ -74,7 +69,6 @@ void register_node_type_sh_normal(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_normal_in, sh_node_normal_out); node_type_exec(&ntype, NULL, NULL, node_shader_exec_normal); node_type_gpu(&ntype, gpu_shader_normal); diff --git a/source/blender/nodes/shader/nodes/node_shader_normal_map.c b/source/blender/nodes/shader/nodes/node_shader_normal_map.c index 7584b5eba4d..c066fea81ad 100644 --- a/source/blender/nodes/shader/nodes/node_shader_normal_map.c +++ b/source/blender/nodes/shader/nodes/node_shader_normal_map.c @@ -47,80 +47,9 @@ static void node_shader_init_normal_map(bNodeTree *UNUSED(ntree), bNode *node) } static void node_shader_exec_normal_map( - void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), - bNodeStack **in, bNodeStack **out) + void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), + bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) { - if (data) { - ShadeInput *shi = ((ShaderCallData *)data)->shi; - - NodeShaderNormalMap *nm = node->storage; - - float strength, vecIn[3]; - nodestack_get_vec(&strength, SOCK_FLOAT, in[0]); - nodestack_get_vec(vecIn, SOCK_VECTOR, in[1]); - - vecIn[0] = -2 * (vecIn[0] - 0.5f); - vecIn[1] = 2 * (vecIn[1] - 0.5f); - vecIn[2] = 2 * (vecIn[2] - 0.5f); - - CLAMP_MIN(strength, 0.0f); - - float *N = shi->nmapnorm; - int uv_index = 0; - switch (nm->space) { - case SHD_SPACE_TANGENT: - if (nm->uv_map[0]) { - /* find uv map by name */ - for (int i = 0; i < shi->totuv; i++) { - if (STREQ(shi->uv[i].name, nm->uv_map)) { - uv_index = i; - break; - } - } - } - else { - uv_index = shi->actuv; - } - - float *T = shi->tangents[uv_index]; - - float B[3]; - cross_v3_v3v3(B, N, T); - mul_v3_fl(B, T[3]); - - for (int j = 0; j < 3; j++) - out[0]->vec[j] = vecIn[0] * T[j] + vecIn[1] * B[j] + vecIn[2] * N[j]; - interp_v3_v3v3(out[0]->vec, N, out[0]->vec, strength); - if (shi->use_world_space_shading) { - mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), out[0]->vec); - } - break; - - case SHD_SPACE_OBJECT: - case SHD_SPACE_BLENDER_OBJECT: - if (shi->use_world_space_shading) { - mul_mat3_m4_v3((float (*)[4])RE_object_instance_get_matrix(shi->obi, RE_OBJECT_INSTANCE_MATRIX_OB), vecIn); - mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), N); - } - else - mul_mat3_m4_v3((float (*)[4])RE_object_instance_get_matrix(shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW), vecIn); - interp_v3_v3v3(out[0]->vec, N, vecIn, strength); - break; - - case SHD_SPACE_WORLD: - case SHD_SPACE_BLENDER_WORLD: - if (shi->use_world_space_shading) - mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), N); - else - mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), vecIn); - interp_v3_v3v3(out[0]->vec, N, vecIn, strength); - break; - } - if (shi->use_world_space_shading) { - negate_v3(out[0]->vec); - } - normalize_v3(out[0]->vec); - } } static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) @@ -134,68 +63,50 @@ static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *U if (in[0].link) strength = in[0].link; + else if (node->original) { + bNodeSocket *socket = BLI_findlink(&node->original->inputs, 0); + bNodeSocketValueFloat *socket_data = socket->default_value; + strength = GPU_uniform(&socket_data->value); + } else - strength = GPU_uniform(in[0].vec); + strength = GPU_constant(in[0].vec); if (in[1].link) realnorm = in[1].link; + else if (node->original) { + bNodeSocket *socket = BLI_findlink(&node->original->inputs, 1); + bNodeSocketValueRGBA *socket_data = socket->default_value; + realnorm = GPU_uniform(socket_data->value); + } else - realnorm = GPU_uniform(in[1].vec); + realnorm = GPU_constant(in[1].vec); negnorm = GPU_builtin(GPU_VIEW_NORMAL); - GPU_link(mat, "math_max", strength, GPU_uniform(d), &strength); - - if (GPU_material_use_world_space_shading(mat)) { - - /* ******* CYCLES or BLENDER INTERNAL with world space shading flag ******* */ - - const char *color_to_normal_fnc_name = "color_to_normal_new_shading"; - if (nm->space == SHD_SPACE_BLENDER_OBJECT || nm->space == SHD_SPACE_BLENDER_WORLD || !GPU_material_use_new_shading_nodes(mat)) - color_to_normal_fnc_name = "color_to_blender_normal_new_shading"; - switch (nm->space) { - case SHD_SPACE_TANGENT: - GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm); - GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm); - GPU_link(mat, "vec_math_mix", strength, realnorm, GPU_builtin(GPU_VIEW_NORMAL), &out[0].link); - /* for uniform scale this is sufficient to match Cycles */ - GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link); - GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); - return true; - case SHD_SPACE_OBJECT: - case SHD_SPACE_BLENDER_OBJECT: - GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); - GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); - GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm); - break; - case SHD_SPACE_WORLD: - case SHD_SPACE_BLENDER_WORLD: - GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); - GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); - break; - } - - } - else { - - /* ************** BLENDER INTERNAL without world space shading flag ******* */ - - GPU_link(mat, "color_to_normal", realnorm, &realnorm); - GPU_link(mat, "mtex_negate_texnormal", realnorm, &realnorm); - GPU_link(mat, "vec_math_negate", negnorm, &negnorm); - - switch (nm->space) { - case SHD_SPACE_TANGENT: - GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm); - break; - case SHD_SPACE_OBJECT: - case SHD_SPACE_BLENDER_OBJECT: - GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_LOC_TO_VIEW_MATRIX), &realnorm); - break; - case SHD_SPACE_WORLD: - case SHD_SPACE_BLENDER_WORLD: - GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_VIEW_MATRIX), &realnorm); - break; - } + GPU_link(mat, "math_max", strength, GPU_constant(d), &strength); + + const char *color_to_normal_fnc_name = "color_to_normal_new_shading"; + if (nm->space == SHD_SPACE_BLENDER_OBJECT || nm->space == SHD_SPACE_BLENDER_WORLD) + color_to_normal_fnc_name = "color_to_blender_normal_new_shading"; + switch (nm->space) { + case SHD_SPACE_TANGENT: + GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm); + GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm); + GPU_link(mat, "vec_math_mix", strength, realnorm, GPU_builtin(GPU_VIEW_NORMAL), &out[0].link); + /* for uniform scale this is sufficient to match Cycles */ + GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link); + GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); + return true; + case SHD_SPACE_OBJECT: + case SHD_SPACE_BLENDER_OBJECT: + GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); + GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); + GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm); + break; + case SHD_SPACE_WORLD: + case SHD_SPACE_BLENDER_WORLD: + GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); + GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); + break; } GPU_link(mat, "vec_math_mix", strength, realnorm, negnorm, &out[0].link); @@ -210,7 +121,6 @@ void register_node_type_sh_normal_map(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_NORMAL_MAP, "Normal Map", NODE_CLASS_OP_VECTOR, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING | NODE_OLD_SHADING); node_type_socket_templates(&ntype, sh_node_normal_map_in, sh_node_normal_map_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_normal_map); diff --git a/source/blender/nodes/shader/nodes/node_shader_object_info.c b/source/blender/nodes/shader/nodes/node_shader_object_info.c index 9c7ea549ea5..713e2f749f7 100644 --- a/source/blender/nodes/shader/nodes/node_shader_object_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_object_info.c @@ -37,18 +37,13 @@ static bNodeSocketTemplate sh_node_object_info_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_object_info(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_object_info(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "node_object_info", in, out, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_OBJECT_INFO)); + return GPU_stack_link(mat, node, "node_object_info", in, out, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_OBJECT_INFO)); } -static void node_shader_exec_object_info(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out) +static void node_shader_exec_object_info(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) { - ShaderCallData *scd = (ShaderCallData *)data; - copy_v4_v4(out[0]->vec, RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_OB)[3]); - out[1]->vec[0] = RE_object_instance_get_object_pass_index(scd->shi->obi); - out[2]->vec[0] = scd->shi->mat->index; - out[3]->vec[0] = RE_object_instance_get_random_id(scd->shi->obi) * (1.0f / (float)0xFFFFFFFF); } /* node type definition */ @@ -57,7 +52,6 @@ void register_node_type_sh_object_info(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_OBJECT_INFO, "Object Info", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_object_info_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_output.c b/source/blender/nodes/shader/nodes/node_shader_output.c deleted file mode 100644 index 5b1a68b4bf9..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_output.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/shader/nodes/node_shader_output.c - * \ingroup shdnodes - */ - - -#include "node_shader_util.h" - -/* **************** OUTPUT ******************** */ -static bNodeSocketTemplate sh_node_output_in[] = { - { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f}, - { SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE}, - { -1, 0, "" } -}; - -static void node_shader_exec_output(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **UNUSED(out)) -{ - if (data) { - ShadeInput *shi = ((ShaderCallData *)data)->shi; - float col[4]; - - /* stack order input sockets: col, alpha, normal */ - nodestack_get_vec(col, SOCK_VECTOR, in[0]); - nodestack_get_vec(col + 3, SOCK_FLOAT, in[1]); - - if (shi->do_preview) { - BKE_node_preview_set_pixel(execdata->preview, col, shi->xs, shi->ys, shi->do_manage); - node->lasty = shi->ys; - } - - if (node->flag & NODE_DO_OUTPUT) { - ShadeResult *shr = ((ShaderCallData *)data)->shr; - - copy_v4_v4(shr->combined, col); - shr->alpha = col[3]; - - // copy_v3_v3(shr->nor, in[3]->vec); - } - } -} - -static int gpu_shader_output(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) -{ - GPUNodeLink *outlink; - -#if 0 - if (in[1].hasinput) - GPU_material_enable_alpha(mat); -#endif - - GPU_stack_link(mat, "output_node", in, out, &outlink); - GPU_material_output_link(mat, outlink); - - return 1; -} - -void register_node_type_sh_output(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW); - node_type_compatibility(&ntype, NODE_OLD_SHADING); - node_type_socket_templates(&ntype, sh_node_output_in, NULL); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_output); - node_type_gpu(&ntype, gpu_shader_output); - - /* Do not allow muting output node. */ - node_type_internal_links(&ntype, NULL); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_output_lamp.c b/source/blender/nodes/shader/nodes/node_shader_output_lamp.c index b08a4b4ff57..f44f5d332cf 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_lamp.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_lamp.c @@ -39,8 +39,7 @@ void register_node_type_sh_output_lamp(void) { static bNodeType ntype; - sh_node_type_base(&ntype, SH_NODE_OUTPUT_LAMP, "Lamp Output", NODE_CLASS_OUTPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); + sh_node_type_base(&ntype, SH_NODE_OUTPUT_LIGHT, "Light Output", NODE_CLASS_OUTPUT, 0); node_type_socket_templates(&ntype, sh_node_output_lamp_in, NULL); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_output_linestyle.c b/source/blender/nodes/shader/nodes/node_shader_output_linestyle.c index 2eb68f23912..b56d6eca44b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_linestyle.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_linestyle.c @@ -43,7 +43,6 @@ void register_node_type_sh_output_linestyle(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_OUTPUT_LINESTYLE, "Line Style Output", NODE_CLASS_OUTPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_output_linestyle_in, NULL); node_type_init(&ntype, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_output_material.c b/source/blender/nodes/shader/nodes/node_shader_output_material.c index 353ab387075..81a89177351 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_material.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_material.c @@ -27,6 +27,8 @@ #include "../node_shader_util.h" +#include "BKE_scene.h" + /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_output_material_in[] = { @@ -36,11 +38,11 @@ static bNodeSocketTemplate sh_node_output_material_in[] = { { -1, 0, "" } }; -static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { GPUNodeLink *outlink; - GPU_stack_link(mat, "node_output_material", in, out, &outlink); + GPU_stack_link(mat, node, "node_output_material", in, out, &outlink); GPU_material_output_link(mat, outlink); return true; @@ -53,7 +55,6 @@ void register_node_type_sh_output_material(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_OUTPUT_MATERIAL, "Material Output", NODE_CLASS_OUTPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_output_material_in, NULL); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_output_world.c b/source/blender/nodes/shader/nodes/node_shader_output_world.c index 9581153538b..1980e6be5a3 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_world.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_world.c @@ -35,11 +35,11 @@ static bNodeSocketTemplate sh_node_output_world_in[] = { { -1, 0, "" } }; -static int node_shader_gpu_output_world(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_output_world(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { GPUNodeLink *outlink; - GPU_stack_link(mat, "node_output_world", in, out, &outlink); + GPU_stack_link(mat, node, "node_output_world", in, out, &outlink); GPU_material_output_link(mat, outlink); return true; @@ -51,7 +51,6 @@ void register_node_type_sh_output_world(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_OUTPUT_WORLD, "World Output", NODE_CLASS_OUTPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_output_world_in, NULL); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_particle_info.c b/source/blender/nodes/shader/nodes/node_shader_particle_info.c index 6dd8fbee3d2..34c4d364fac 100644 --- a/source/blender/nodes/shader/nodes/node_shader_particle_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_particle_info.c @@ -42,17 +42,14 @@ static bNodeSocketTemplate outputs[] = { { SOCK_VECTOR, 0, "Angular Velocity" }, { -1, 0, "" } }; -static void node_shader_exec_particle_info(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out) +static void node_shader_exec_particle_info(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) { - ShadeInput *shi = ((ShaderCallData *)data)->shi; - - RE_instance_get_particle_info(shi->obi, out[0]->vec, out[1]->vec, out[2]->vec, out[3]->vec, out[4]->vec, out[5]->vec, out[6]->vec, out[7]->vec); } -static int gpu_shader_particle_info(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_particle_info(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "particle_info", in, out, + return GPU_stack_link(mat, node, "particle_info", in, out, GPU_builtin(GPU_PARTICLE_SCALAR_PROPS), GPU_builtin(GPU_PARTICLE_LOCATION), GPU_builtin(GPU_PARTICLE_VELOCITY), @@ -65,7 +62,6 @@ void register_node_type_sh_particle_info(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_PARTICLE_INFO, "Particle Info", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING | NODE_OLD_SHADING); node_type_socket_templates(&ntype, NULL, outputs); node_type_exec(&ntype, NULL, NULL, node_shader_exec_particle_info); node_type_gpu(&ntype, gpu_shader_particle_info); diff --git a/source/blender/nodes/shader/nodes/node_shader_rgb.c b/source/blender/nodes/shader/nodes/node_shader_rgb.c index d3ac659c153..0ddad803270 100644 --- a/source/blender/nodes/shader/nodes/node_shader_rgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_rgb.c @@ -38,10 +38,10 @@ static bNodeSocketTemplate sh_node_rgb_out[] = { { -1, 0, "" } }; -static int gpu_shader_rgb(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - GPUNodeLink *vec = GPU_uniform(out[0].vec); - return GPU_stack_link(mat, "set_rgba", in, out, vec); + GPUNodeLink *link = GPU_uniformbuffer_link_out(mat, node, out, 0); + return GPU_stack_link(mat, node, "set_rgba", in, out, link); } void register_node_type_sh_rgb(void) @@ -49,7 +49,6 @@ void register_node_type_sh_rgb(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_RGB, "RGB", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_rgb_out); node_type_gpu(&ntype, gpu_shader_rgb); diff --git a/source/blender/nodes/shader/nodes/node_shader_script.c b/source/blender/nodes/shader/nodes/node_shader_script.c index 888e502a7f6..2d13fc214be 100644 --- a/source/blender/nodes/shader/nodes/node_shader_script.c +++ b/source/blender/nodes/shader/nodes/node_shader_script.c @@ -68,7 +68,6 @@ void register_node_type_sh_script(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_SCRIPT, "Script", NODE_CLASS_SCRIPT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_init(&ntype, init); node_type_storage(&ntype, "NodeShaderScript", node_free_script, node_copy_script); diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c index 0a47978431f..09cd997f86b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c @@ -53,9 +53,9 @@ static void node_shader_exec_sephsv(void *UNUSED(data), int UNUSED(thread), bNod &out[0]->vec[0], &out[1]->vec[0], &out[2]->vec[0]); } -static int gpu_shader_sephsv(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_sephsv(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "separate_hsv", in, out); + return GPU_stack_link(mat, node, "separate_hsv", in, out); } void register_node_type_sh_sephsv(void) @@ -63,7 +63,6 @@ void register_node_type_sh_sephsv(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_SEPHSV, "Separate HSV", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_sephsv_in, sh_node_sephsv_out); node_type_exec(&ntype, NULL, NULL, node_shader_exec_sephsv); node_type_gpu(&ntype, gpu_shader_sephsv); @@ -94,9 +93,9 @@ static void node_shader_exec_combhsv(void *UNUSED(data), int UNUSED(thread), bNo hsv_to_rgb(h, s, v, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2]); } -static int gpu_shader_combhsv(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_combhsv(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "combine_hsv", in, out); + return GPU_stack_link(mat, node, "combine_hsv", in, out); } void register_node_type_sh_combhsv(void) @@ -104,7 +103,6 @@ void register_node_type_sh_combhsv(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_COMBHSV, "Combine HSV", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_combhsv_in, sh_node_combhsv_out); node_type_exec(&ntype, NULL, NULL, node_shader_exec_combhsv); node_type_gpu(&ntype, gpu_shader_combhsv); diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c index 8748abd5eb6..b4810b95d4b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c @@ -54,9 +54,9 @@ static void node_shader_exec_seprgb(void *UNUSED(data), int UNUSED(thread), bNod out[2]->vec[0] = col[2]; } -static int gpu_shader_seprgb(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_seprgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "separate_rgb", in, out); + return GPU_stack_link(mat, node, "separate_rgb", in, out); } void register_node_type_sh_seprgb(void) @@ -64,7 +64,6 @@ void register_node_type_sh_seprgb(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_seprgb_in, sh_node_seprgb_out); node_type_exec(&ntype, NULL, NULL, node_shader_exec_seprgb); node_type_gpu(&ntype, gpu_shader_seprgb); @@ -98,9 +97,9 @@ static void node_shader_exec_combrgb(void *UNUSED(data), int UNUSED(thread), bNo out[0]->vec[2] = b; } -static int gpu_shader_combrgb(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_combrgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "combine_rgb", in, out); + return GPU_stack_link(mat, node, "combine_rgb", in, out); } void register_node_type_sh_combrgb(void) @@ -108,7 +107,6 @@ void register_node_type_sh_combrgb(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_combrgb_in, sh_node_combrgb_out); node_type_exec(&ntype, NULL, NULL, node_shader_exec_combrgb); node_type_gpu(&ntype, gpu_shader_combrgb); diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c index 9394dc7215b..bff8e38b8c8 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c @@ -44,9 +44,9 @@ static bNodeSocketTemplate sh_node_sepxyz_out[] = { { -1, 0, "" } }; -static int gpu_shader_sepxyz(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_sepxyz(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "separate_xyz", in, out); + return GPU_stack_link(mat, node, "separate_xyz", in, out); } void register_node_type_sh_sepxyz(void) @@ -54,7 +54,6 @@ void register_node_type_sh_sepxyz(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_sepxyz_in, sh_node_sepxyz_out); node_type_gpu(&ntype, gpu_shader_sepxyz); @@ -75,9 +74,9 @@ static bNodeSocketTemplate sh_node_combxyz_out[] = { { -1, 0, "" } }; -static int gpu_shader_combxyz(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_combxyz(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "combine_xyz", in, out); + return GPU_stack_link(mat, node, "combine_xyz", in, out); } void register_node_type_sh_combxyz(void) @@ -85,7 +84,6 @@ void register_node_type_sh_combxyz(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_combxyz_in, sh_node_combxyz_out); node_type_gpu(&ntype, gpu_shader_combxyz); diff --git a/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c b/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c new file mode 100644 index 00000000000..8617e3414b5 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_shaderToRgb.c @@ -0,0 +1,60 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Kanzaki Wataru, Kinouti Takahiro + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "../node_shader_util.h" + +/* **************** OUTPUT ******************** */ + +static bNodeSocketTemplate sh_node_shadertorgb_in[] = { + { SOCK_SHADER, 1, N_("Shader")}, + { -1, 0, "" } +}; + +static bNodeSocketTemplate sh_node_shadertorgb_out[] = { + { SOCK_RGBA, 0, N_("Color")}, + { SOCK_FLOAT, 0, N_("Alpha")}, + { -1, 0, "" } +}; + +static int node_shader_gpu_shadertorgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +{ + return GPU_stack_link(mat, node, "node_shader_to_rgba", in, out); +} + +/* node type definition */ +void register_node_type_sh_shadertorgb(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_SHADERTORGB, "Shader to RGB", NODE_CLASS_CONVERTOR, 0); + node_type_socket_templates(&ntype, sh_node_shadertorgb_in, sh_node_shadertorgb_out); + node_type_init(&ntype, NULL); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_shadertorgb); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_squeeze.c b/source/blender/nodes/shader/nodes/node_shader_squeeze.c index bba6a56d9e5..51167db857b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_squeeze.c +++ b/source/blender/nodes/shader/nodes/node_shader_squeeze.c @@ -56,9 +56,9 @@ static void node_shader_exec_squeeze(void *UNUSED(data), int UNUSED(thread), bNo out[0]->vec[0] = 1.0f / (1.0f + powf(M_E, -((vec[0] - vec[2]) * vec[1]))); } -static int gpu_shader_squeeze(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_squeeze(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "squeeze", in, out); + return GPU_stack_link(mat, node, "squeeze", in, out); } void register_node_type_sh_squeeze(void) @@ -66,7 +66,6 @@ void register_node_type_sh_squeeze(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_SQUEEZE, "Squeeze Value", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING); node_type_socket_templates(&ntype, sh_node_squeeze_in, sh_node_squeeze_out); node_type_storage(&ntype, "", NULL, NULL); node_type_exec(&ntype, NULL, NULL, node_shader_exec_squeeze); diff --git a/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c b/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c index 78757782203..7cc80a0c636 100644 --- a/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c +++ b/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c @@ -49,14 +49,25 @@ static void node_shader_init_subsurface_scattering(bNodeTree *UNUSED(ntree), bNo node->custom1 = SHD_SUBSURFACE_BURLEY; } -static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[5].link) - in[5].link = GPU_builtin(GPU_VIEW_NORMAL); - else - GPU_link(mat, "direction_transform_m4v3", in[5].link, GPU_builtin(GPU_VIEW_MATRIX), &in[5].link); + GPU_link(mat, "world_normals_get", &in[5].link); - return GPU_stack_link(mat, "node_subsurface_scattering", in, out); + GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_SSS); + + if (node->sss_id == 1) { + bNodeSocket *socket = BLI_findlink(&node->original->inputs, 2); + bNodeSocketValueRGBA *socket_data = socket->default_value; + bNodeSocket *socket_sharp = BLI_findlink(&node->original->inputs, 3); + bNodeSocketValueFloat *socket_data_sharp = socket_sharp->default_value; + /* For some reason it seems that the socket value is in ARGB format. */ + GPU_material_sss_profile_create(mat, &socket_data->value[1], + &node->original->custom1, + &socket_data_sharp->value); + } + + return GPU_stack_link(mat, node, "node_subsurface_scattering", in, out, GPU_constant(&node->sss_id)); } static void node_shader_update_subsurface_scattering(bNodeTree *UNUSED(ntree), bNode *node) @@ -81,7 +92,6 @@ void register_node_type_sh_subsurface_scattering(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_SUBSURFACE_SCATTERING, "Subsurface Scattering", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_subsurface_scattering_in, sh_node_subsurface_scattering_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_subsurface_scattering); diff --git a/source/blender/nodes/shader/nodes/node_shader_tangent.c b/source/blender/nodes/shader/nodes/node_shader_tangent.c index 7aa7fb43221..da3a8e39ccb 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tangent.c +++ b/source/blender/nodes/shader/nodes/node_shader_tangent.c @@ -41,16 +41,38 @@ static void node_shader_init_tangent(bNodeTree *UNUSED(ntree), bNode *node) node->storage = attr; } +static int node_shader_gpu_tangent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +{ + NodeShaderTangent *attr = node->storage; + + if (attr->direction_type == SHD_TANGENT_UVMAP) { + return GPU_stack_link(mat, node, "node_tangentmap", in, out, GPU_attribute(CD_TANGENT, ""), GPU_builtin(GPU_INVERSE_VIEW_MATRIX)); + } + else { + GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); + + if (attr->axis == SHD_TANGENT_AXIS_X) + GPU_link(mat, "tangent_orco_x", orco, &orco); + else if (attr->axis == SHD_TANGENT_AXIS_Y) + GPU_link(mat, "tangent_orco_y", orco, &orco); + else + GPU_link(mat, "tangent_orco_z", orco, &orco); + + return GPU_stack_link(mat, node, "node_tangent", in, out, GPU_builtin(GPU_VIEW_NORMAL), orco, + GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX)); + } +} + /* node type definition */ void register_node_type_sh_tangent(void) { static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TANGENT, "Tangent", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_tangent_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_tangent); + node_type_gpu(&ntype, node_shader_gpu_tangent); node_type_storage(&ntype, "NodeShaderTangent", node_free_standard_storage, node_copy_standard_storage); nodeRegisterType(&ntype); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c index ebfb3fc29a1..2002e3c14c9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c @@ -80,10 +80,10 @@ static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, bNodeExecDat NodeTexBrick *tex = (NodeTexBrick *)node->storage; float offset_freq = tex->offset_freq; float squash_freq = tex->squash_freq; - return GPU_stack_link(mat, "node_tex_brick", + return GPU_stack_link(mat, node, "node_tex_brick", in, out, - GPU_uniform(&tex->offset), GPU_uniform(&offset_freq), - GPU_uniform(&tex->squash), GPU_uniform(&squash_freq)); + GPU_constant(&tex->offset), GPU_constant(&offset_freq), + GPU_constant(&tex->squash), GPU_constant(&squash_freq)); } /* node type definition */ @@ -92,7 +92,6 @@ void register_node_type_sh_tex_brick(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_BRICK, "Brick Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_brick_in, sh_node_tex_brick_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_tex_brick); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_checker.c b/source/blender/nodes/shader/nodes/node_shader_tex_checker.c index f700faff200..4e065ffde23 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_checker.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_checker.c @@ -61,7 +61,7 @@ static int node_shader_gpu_tex_checker(GPUMaterial *mat, bNode *node, bNodeExecD node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_checker", in, out); + return GPU_stack_link(mat, node, "node_tex_checker", in, out); } /* node type definition */ @@ -70,7 +70,6 @@ void register_node_type_sh_tex_checker(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_CHECKER, "Checker Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_checker_in, sh_node_tex_checker_out); node_type_init(&ntype, node_shader_init_tex_checker); node_type_storage(&ntype, "NodeTexChecker", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c index f1721fe5567..002fdc6d3ae 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c @@ -42,20 +42,22 @@ static bNodeSocketTemplate sh_node_tex_coord_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ""); GPUMatType type = GPU_Material_get_type(mat); - if (type == GPU_MATERIAL_TYPE_MESH) { - return GPU_stack_link(mat, "node_tex_coord", in, out, + GPU_link(mat, "generated_from_orco", orco, &orco); + + if (type == GPU_MATERIAL_TYPE_WORLD) { + return GPU_stack_link(mat, node, "node_tex_coord_background", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface); } else { - return GPU_stack_link(mat, "node_tex_coord_background", in, out, + return GPU_stack_link(mat, node, "node_tex_coord", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface); @@ -68,7 +70,6 @@ void register_node_type_sh_tex_coord(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_COORD, "Texture Coordinate", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_tex_coord_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c index 9b485a30083..41860df5670 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c @@ -48,7 +48,6 @@ static void node_shader_init_tex_environment(bNodeTree *UNUSED(ntree), bNode *no tex->projection = SHD_PROJ_EQUIRECTANGULAR; tex->iuser.frames = 1; tex->iuser.sfra = 1; - tex->iuser.fie_ima = 2; tex->iuser.ok = 1; node->storage = tex; @@ -62,7 +61,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE int isdata = tex->color_space == SHD_COLORSPACE_NONE; if (!ima) - return GPU_stack_link(mat, "node_tex_environment_empty", in, out); + return GPU_stack_link(mat, node, "node_tex_environment_empty", in, out); if (!in[0].link) { GPUMatType type = GPU_Material_get_type(mat); @@ -76,9 +75,9 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE node_shader_gpu_tex_mapping(mat, node, in, out); if (tex->projection == SHD_PROJ_EQUIRECTANGULAR) - GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata)); + GPU_stack_link(mat, node, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata)); else - GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata)); + GPU_stack_link(mat, node, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata)); ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && @@ -97,12 +96,12 @@ void register_node_type_sh_tex_environment(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_ENVIRONMENT, "Environment Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_environment_in, sh_node_tex_environment_out); node_type_init(&ntype, node_shader_init_tex_environment); node_type_storage(&ntype, "NodeTexEnvironment", node_free_standard_storage, node_copy_standard_storage); node_type_gpu(&ntype, node_shader_gpu_tex_environment); node_type_label(&ntype, node_image_label); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c index 9be4f2a719d..750ce60e84d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c @@ -61,7 +61,7 @@ static int node_shader_gpu_tex_gradient(GPUMaterial *mat, bNode *node, bNodeExec NodeTexGradient *tex = (NodeTexGradient *)node->storage; float gradient_type = tex->gradient_type; - return GPU_stack_link(mat, "node_tex_gradient", in, out, GPU_uniform(&gradient_type)); + return GPU_stack_link(mat, node, "node_tex_gradient", in, out, GPU_constant(&gradient_type)); } /* node type definition */ @@ -70,7 +70,6 @@ void register_node_type_sh_tex_gradient(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_GRADIENT, "Gradient Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_gradient_in, sh_node_tex_gradient_out); node_type_init(&ntype, node_shader_init_tex_gradient); node_type_storage(&ntype, "NodeTexGradient", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c index ae9124d0588..0b33b186dd2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c @@ -48,7 +48,6 @@ static void node_shader_init_tex_image(bNodeTree *UNUSED(ntree), bNode *node) tex->color_space = SHD_COLORSPACE_COLOR; tex->iuser.frames = 1; tex->iuser.sfra = 1; - tex->iuser.fie_ima = 2; tex->iuser.ok = 1; node->storage = tex; @@ -56,17 +55,43 @@ static void node_shader_init_tex_image(bNodeTree *UNUSED(ntree), bNode *node) static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { + static const char *names[] = { + "node_tex_image_linear", + "node_tex_image_nearest", + "node_tex_image_cubic", + "node_tex_image_smart" + }; + static const char *names_box[] = { + "tex_box_sample_linear", + "tex_box_sample_nearest", + "tex_box_sample_cubic", + "tex_box_sample_smart" + }; + Image *ima = (Image *)node->id; ImageUser *iuser = NULL; NodeTexImage *tex = node->storage; + const char *gpu_node_name = (tex->projection == SHD_PROJ_BOX) + ? names_box[tex->interpolation] + : names[tex->interpolation]; + bool do_color_correction = false; - GPUNodeLink *norm; + GPUNodeLink *norm, *col1, *col2, *col3; int isdata = tex->color_space == SHD_COLORSPACE_NONE; float blend = tex->projection_blend; if (!ima) - return GPU_stack_link(mat, "node_tex_image_empty", in, out); + return GPU_stack_link(mat, node, "node_tex_image_empty", in, out); + + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); + if ((tex->color_space == SHD_COLORSPACE_COLOR) && + ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && + GPU_material_do_color_management(mat)) + { + do_color_correction = true; + } + BKE_image_release_ibuf(ima, ibuf, NULL); if (!in[0].link) in[0].link = GPU_attribute(CD_MTFACE, ""); @@ -75,7 +100,7 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat switch (tex->projection) { case SHD_PROJ_FLAT: - GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata)); + GPU_stack_link(mat, node, gpu_node_name, in, out, GPU_image(ima, iuser, isdata)); break; case SHD_PROJ_BOX: GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL), @@ -84,33 +109,40 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat GPU_link(mat, "direction_transform_m4v3", norm, GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), &norm); + GPU_link(mat, gpu_node_name, in[0].link, + norm, + GPU_image(ima, iuser, isdata), + &col1, + &col2, + &col3); + if (do_color_correction) { + GPU_link(mat, "srgb_to_linearrgb", col1, &col1); + GPU_link(mat, "srgb_to_linearrgb", col2, &col2); + GPU_link(mat, "srgb_to_linearrgb", col3, &col3); + } GPU_link(mat, "node_tex_image_box", in[0].link, norm, + col1, col2, col3, GPU_image(ima, iuser, isdata), - GPU_uniform(&blend), + GPU_constant(&blend), &out[0].link, &out[1].link); break; case SHD_PROJ_SPHERE: GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link); GPU_link(mat, "point_map_to_sphere", in[0].link, &in[0].link); - GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata)); + GPU_stack_link(mat, node, gpu_node_name, in, out, GPU_image(ima, iuser, isdata)); break; case SHD_PROJ_TUBE: GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link); GPU_link(mat, "point_map_to_tube", in[0].link, &in[0].link); - GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata)); + GPU_stack_link(mat, node, gpu_node_name, in, out, GPU_image(ima, iuser, isdata)); break; } - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); - if ((tex->color_space == SHD_COLORSPACE_COLOR) && - ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && - GPU_material_do_color_management(mat)) - { + if (do_color_correction && (tex->projection != SHD_PROJ_BOX)) { GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link); } - BKE_image_release_ibuf(ima, ibuf, NULL); return true; } @@ -121,12 +153,12 @@ void register_node_type_sh_tex_image(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_IMAGE, "Image Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_image_in, sh_node_tex_image_out); node_type_init(&ntype, node_shader_init_tex_image); node_type_storage(&ntype, "NodeTexImage", node_free_standard_storage, node_copy_standard_storage); node_type_gpu(&ntype, node_shader_gpu_tex_image); node_type_label(&ntype, node_image_label); + node_type_size_preset(&ntype, NODE_SIZE_LARGE); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_magic.c b/source/blender/nodes/shader/nodes/node_shader_tex_magic.c index 8ab2651e014..fb3012e1d2b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_magic.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_magic.c @@ -64,7 +64,7 @@ static int node_shader_gpu_tex_magic(GPUMaterial *mat, bNode *node, bNodeExecDat node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_magic", in, out, GPU_uniform(&depth)); + return GPU_stack_link(mat, node, "node_tex_magic", in, out, GPU_constant(&depth)); } /* node type definition */ @@ -73,7 +73,6 @@ void register_node_type_sh_tex_magic(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_MAGIC, "Magic Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_magic_in, sh_node_tex_magic_out); node_type_init(&ntype, node_shader_init_tex_magic); node_type_storage(&ntype, "NodeTexMagic", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c index c0584214269..30171eea9e2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c @@ -68,7 +68,7 @@ static int node_shader_gpu_tex_musgrave(GPUMaterial *mat, bNode *node, bNodeExec NodeTexMusgrave *tex = (NodeTexMusgrave *)node->storage; float type = tex->musgrave_type; - return GPU_stack_link(mat, "node_tex_musgrave", in, out, GPU_uniform(&type)); + return GPU_stack_link(mat, node, "node_tex_musgrave", in, out, GPU_constant(&type)); } /* node type definition */ @@ -77,7 +77,6 @@ void register_node_type_sh_tex_musgrave(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_MUSGRAVE, "Musgrave Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_musgrave_in, sh_node_tex_musgrave_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_tex_musgrave); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.c b/source/blender/nodes/shader/nodes/node_shader_tex_noise.c index 2b8291ba8bb..e2879528a5f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.c @@ -61,7 +61,7 @@ static int node_shader_gpu_tex_noise(GPUMaterial *mat, bNode *node, bNodeExecDat node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_noise", in, out); + return GPU_stack_link(mat, node, "node_tex_noise", in, out); } /* node type definition */ @@ -70,7 +70,6 @@ void register_node_type_sh_tex_noise(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_NOISE, "Noise Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_noise_in, sh_node_tex_noise_out); node_type_init(&ntype, node_shader_init_tex_noise); node_type_storage(&ntype, "NodeTexNoise", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c index 436eeeefb4a..1c5f53132bd 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c @@ -85,7 +85,6 @@ void register_node_type_sh_tex_pointdensity(void) "Point Density", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_pointdensity_in, sh_node_tex_pointdensity_out); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_sky.c b/source/blender/nodes/shader/nodes/node_shader_tex_sky.c index 4221c10fe50..821d4b41d09 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_sky.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_sky.c @@ -61,7 +61,7 @@ static int node_shader_gpu_tex_sky(GPUMaterial *mat, bNode *node, bNodeExecData node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_sky", in, out); + return GPU_stack_link(mat, node, "node_tex_sky", in, out); } /* node type definition */ @@ -70,7 +70,6 @@ void register_node_type_sh_tex_sky(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_SKY, "Sky Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_sky_in, sh_node_tex_sky_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_tex_sky); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c index e5bf8f49717..a4145a350d2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c @@ -65,8 +65,10 @@ static int node_shader_gpu_tex_voronoi(GPUMaterial *mat, bNode *node, bNodeExecD NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage; float coloring = tex->coloring; + float metric = tex->distance; + float feature = tex->feature; - return GPU_stack_link(mat, "node_tex_voronoi", in, out, GPU_uniform(&coloring)); + return GPU_stack_link(mat, node, "node_tex_voronoi", in, out, GPU_constant(&coloring), GPU_constant(&metric), GPU_constant(&feature)); } static void node_shader_update_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node) @@ -92,7 +94,6 @@ void register_node_type_sh_tex_voronoi(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_VORONOI, "Voronoi Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_voronoi_in, sh_node_tex_voronoi_out); node_type_init(&ntype, node_shader_init_tex_voronoi); node_type_storage(&ntype, "NodeTexVoronoi", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_wave.c b/source/blender/nodes/shader/nodes/node_shader_tex_wave.c index c88183bd7dd..ac955b29808 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_wave.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_wave.c @@ -67,7 +67,7 @@ static int node_shader_gpu_tex_wave(GPUMaterial *mat, bNode *node, bNodeExecData float wave_type = tex->wave_type; float wave_profile = tex->wave_profile; - return GPU_stack_link(mat, "node_tex_wave", in, out, GPU_uniform(&wave_type), GPU_uniform(&wave_profile)); + return GPU_stack_link(mat, node, "node_tex_wave", in, out, GPU_constant(&wave_type), GPU_constant(&wave_profile)); } /* node type definition */ @@ -76,7 +76,6 @@ void register_node_type_sh_tex_wave(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_TEX_WAVE, "Wave Texture", NODE_CLASS_TEXTURE, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_tex_wave_in, sh_node_tex_wave_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_tex_wave); diff --git a/source/blender/nodes/shader/nodes/node_shader_texture.c b/source/blender/nodes/shader/nodes/node_shader_texture.c deleted file mode 100644 index 737ec7d1c4b..00000000000 --- a/source/blender/nodes/shader/nodes/node_shader_texture.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2005 Blender Foundation. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/nodes/shader/nodes/node_shader_texture.c - * \ingroup shdnodes - */ - -#include "DNA_texture_types.h" - -#include "node_shader_util.h" - -#include "GPU_material.h" - -/* **************** TEXTURE ******************** */ -static bNodeSocketTemplate sh_node_texture_in[] = { - { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, /* no limit */ - { -1, 0, "" } -}; -static bNodeSocketTemplate sh_node_texture_out[] = { - { SOCK_FLOAT, 0, N_("Value"), 0, 0, 0, 0, 0, 0, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_RGBA, 0, N_("Color"), 0, 0, 0, 0, 0, 0, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { SOCK_VECTOR, 0, N_("Normal"), 0, 0, 0, 0, 0, 0, PROP_NONE, SOCK_NO_INTERNAL_LINK}, - { -1, 0, "" } -}; - -static void node_shader_exec_texture(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out) -{ - if (data && node->id) { - ShadeInput *shi = ((ShaderCallData *)data)->shi; - TexResult texres; - bNodeSocket *sock_vector = node->inputs.first; - float vec[3], nor[3] = {0.0f, 0.0f, 0.0f}; - int retval; - short which_output = node->custom1; - - short thread = shi->thread; - - /* out: value, color, normal */ - - /* we should find out if a normal as output is needed, for now we do all */ - texres.nor = nor; - texres.tr = texres.tg = texres.tb = 0.0f; - - /* don't use in[0]->hasinput, see material node for explanation */ - if (sock_vector->link) { - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - - if (in[0]->datatype == NS_OSA_VECTORS) { - float *fp = in[0]->data; - retval = multitex_nodes((Tex *)node->id, vec, fp, fp + 3, shi->osatex, &texres, thread, which_output, NULL, NULL, NULL); - } - else if (in[0]->datatype == NS_OSA_VALUES) { - const float *fp = in[0]->data; - float dxt[3], dyt[3]; - - dxt[0] = fp[0]; dxt[1] = dxt[2] = 0.0f; - dyt[0] = fp[1]; dyt[1] = dyt[2] = 0.0f; - retval = multitex_nodes((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres, thread, which_output, NULL, NULL, NULL); - } - else - retval = multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL, NULL); - } - else { - copy_v3_v3(vec, shi->lo); - retval = multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL, NULL); - } - - /* stupid exception */ - if ( ((Tex *)node->id)->type == TEX_STUCCI) { - texres.tin = 0.5f + 0.7f * texres.nor[0]; - CLAMP(texres.tin, 0.0f, 1.0f); - } - - /* intensity and color need some handling */ - if (texres.talpha) - out[0]->vec[0] = texres.ta; - else - out[0]->vec[0] = texres.tin; - - if ((retval & TEX_RGB) == 0) { - copy_v3_fl(out[1]->vec, out[0]->vec[0]); - out[1]->vec[3] = 1.0f; - } - else { - copy_v3_v3(out[1]->vec, &texres.tr); - out[1]->vec[3] = 1.0f; - } - - copy_v3_v3(out[2]->vec, nor); - - if (shi->do_preview) { - BKE_node_preview_set_pixel(execdata->preview, out[1]->vec, shi->xs, shi->ys, shi->do_manage); - } - - } -} - -static int gpu_shader_texture(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) -{ - Tex *tex = (Tex *)node->id; - - if (tex && tex->ima && (tex->type == TEX_IMAGE || tex->type == TEX_ENVMAP)) { - if (tex->type == TEX_IMAGE) { - GPUNodeLink *texlink = GPU_image(tex->ima, &tex->iuser, false); - GPU_stack_link(mat, "texture_image", in, out, texlink); - } - else { /* TEX_ENVMAP */ - if (!in[0].link) - in[0].link = GPU_uniform(in[0].vec); - if (!GPU_material_use_world_space_shading(mat)) - GPU_link(mat, "direction_transform_m4v3", in[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &in[0].link); - GPU_link(mat, "mtex_cube_map_refl_from_refldir", - GPU_cube_map(tex->ima, &tex->iuser, false), in[0].link, &out[0].link, &out[1].link); - GPU_link(mat, "color_to_normal", out[1].link, &out[2].link); - } - - ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL); - if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && - GPU_material_do_color_management(mat)) - { - GPU_link(mat, "srgb_to_linearrgb", out[1].link, &out[1].link); - } - BKE_image_release_ibuf(tex->ima, ibuf, NULL); - - return true; - } - - return false; -} - -void register_node_type_sh_texture(void) -{ - static bNodeType ntype; - - sh_node_type_base(&ntype, SH_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_PREVIEW); - node_type_compatibility(&ntype, NODE_OLD_SHADING); - node_type_socket_templates(&ntype, sh_node_texture_in, sh_node_texture_out); - node_type_exec(&ntype, NULL, NULL, node_shader_exec_texture); - node_type_gpu(&ntype, gpu_shader_texture); - - nodeRegisterType(&ntype); -} diff --git a/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c b/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c index 67342e1e836..023f5417e22 100644 --- a/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c +++ b/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c @@ -40,7 +40,6 @@ void register_node_type_sh_uvalongstroke(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_UVALONGSTROKE, "UV Along Stroke", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_uvalongstroke_out); node_type_init(&ntype, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_uvmap.c b/source/blender/nodes/shader/nodes/node_shader_uvmap.c index 0f96cb45fe0..9da1056b47f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_uvmap.c +++ b/source/blender/nodes/shader/nodes/node_shader_uvmap.c @@ -47,7 +47,7 @@ static int node_shader_gpu_uvmap(GPUMaterial *mat, bNode *node, bNodeExecData *U NodeShaderUVMap *attr = node->storage; GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, attr->uv_map); - return GPU_stack_link(mat, "node_uvmap", in, out, mtface); + return GPU_stack_link(mat, node, "node_uvmap", in, out, mtface); } /* node type definition */ @@ -56,7 +56,6 @@ void register_node_type_sh_uvmap(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_UVMAP, "UV Map", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_uvmap_out); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_init(&ntype, node_shader_init_uvmap); diff --git a/source/blender/nodes/shader/nodes/node_shader_valToRgb.c b/source/blender/nodes/shader/nodes/node_shader_valToRgb.c index 5a1f0bd472d..4f4462f20bb 100644 --- a/source/blender/nodes/shader/nodes/node_shader_valToRgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_valToRgb.c @@ -65,11 +65,19 @@ static void node_shader_init_valtorgb(bNodeTree *UNUSED(ntree), bNode *node) static int gpu_shader_valtorgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - float *array; + struct ColorBand *coba = node->storage; + float *array, layer; int size; - BKE_colorband_evaluate_table_rgba(node->storage, &array, &size); - return GPU_stack_link(mat, "valtorgb", in, out, GPU_texture(size, array)); + BKE_colorband_evaluate_table_rgba(coba, &array, &size); + GPUNodeLink *tex = GPU_color_band(mat, size, array, &layer); + + if (coba->ipotype == COLBAND_INTERP_CONSTANT) { + return GPU_stack_link(mat, node, "valtorgb_nearest", in, out, tex, GPU_constant(&layer)); + } + else { + return GPU_stack_link(mat, node, "valtorgb", in, out, tex, GPU_constant(&layer)); + } } void register_node_type_sh_valtorgb(void) @@ -77,7 +85,6 @@ void register_node_type_sh_valtorgb(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_valtorgb_in, sh_node_valtorgb_out); node_type_init(&ntype, node_shader_init_valtorgb); node_type_size_preset(&ntype, NODE_SIZE_LARGE); @@ -110,9 +117,9 @@ static void node_shader_exec_rgbtobw(void *UNUSED(data), int UNUSED(thread), bNo out[0]->vec[0] = IMB_colormanagement_get_luminance(col); } -static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return GPU_stack_link(mat, "rgbtobw", in, out); + return GPU_stack_link(mat, node, "rgbtobw", in, out); } void register_node_type_sh_rgbtobw(void) @@ -120,7 +127,6 @@ void register_node_type_sh_rgbtobw(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_rgbtobw_in, sh_node_rgbtobw_out); node_type_exec(&ntype, NULL, NULL, node_shader_exec_rgbtobw); node_type_gpu(&ntype, gpu_shader_rgbtobw); diff --git a/source/blender/nodes/shader/nodes/node_shader_value.c b/source/blender/nodes/shader/nodes/node_shader_value.c index ed57887bdf8..a143b0118e7 100644 --- a/source/blender/nodes/shader/nodes/node_shader_value.c +++ b/source/blender/nodes/shader/nodes/node_shader_value.c @@ -38,10 +38,10 @@ static bNodeSocketTemplate sh_node_value_out[] = { { -1, 0, "" } }; -static int gpu_shader_value(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +static int gpu_shader_value(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - GPUNodeLink *vec = GPU_uniform(out[0].vec); - return GPU_stack_link(mat, "set_value", in, out, vec); + GPUNodeLink *link = GPU_uniformbuffer_link_out(mat, node, out, 0); + return GPU_stack_link(mat, node, "set_value", in, out, link); } void register_node_type_sh_value(void) @@ -49,7 +49,6 @@ void register_node_type_sh_value(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_VALUE, "Value", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, NULL, sh_node_value_out); node_type_gpu(&ntype, gpu_shader_value); diff --git a/source/blender/nodes/shader/nodes/node_shader_vectMath.c b/source/blender/nodes/shader/nodes/node_shader_vectMath.c index 02cff52e1a0..8087e1cab41 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vectMath.c +++ b/source/blender/nodes/shader/nodes/node_shader_vectMath.c @@ -111,7 +111,7 @@ static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UN case 2: case 3: case 4: - GPU_stack_link(mat, names[node->custom1], in, out); + GPU_stack_link(mat, node, names[node->custom1], in, out); break; case 5: if (in[0].hasinput || !in[1].hasinput) { @@ -119,14 +119,14 @@ static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UN GPUNodeStack tmp_in[2]; memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack)); memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); - GPU_stack_link(mat, names[node->custom1], tmp_in, out); + GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); } else { /* use only second item and terminator */ GPUNodeStack tmp_in[2]; memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack)); memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); - GPU_stack_link(mat, names[node->custom1], tmp_in, out); + GPU_stack_link(mat, node, names[node->custom1], tmp_in, out); } break; default: @@ -141,7 +141,6 @@ void register_node_type_sh_vect_math(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_VECT_MATH, "Vector Math", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_vect_math_in, sh_node_vect_math_out); node_type_label(&ntype, node_vect_math_label); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c index af36e7cea22..bce96230403 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c +++ b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c @@ -52,68 +52,8 @@ static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *nod node->storage = vect; } -static const float (* get_matrix_from_to(ShaderCallData *scd, short from, short to))[4] +static void node_shader_exec_vect_transform(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) { - switch (from) { - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - switch (to) { - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - return NULL; - case SHD_VECT_TRANSFORM_SPACE_WORLD: - return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_OB); - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW); - } - break; - case SHD_VECT_TRANSFORM_SPACE_WORLD: - switch (to) { - case SHD_VECT_TRANSFORM_SPACE_WORLD: - return NULL; - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - return RE_render_current_get_matrix(RE_VIEW_MATRIX); - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_OBINV); - } - break; - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - switch (to) { - case SHD_VECT_TRANSFORM_SPACE_CAMERA: - return NULL; - case SHD_VECT_TRANSFORM_SPACE_WORLD: - return RE_render_current_get_matrix(RE_VIEWINV_MATRIX); - case SHD_VECT_TRANSFORM_SPACE_OBJECT: - return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEWINV); - } - break; - } - return NULL; -} - -static void node_shader_exec_vect_transform(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) -{ - float vec[4]; - const float (*mat)[4]; - - if (data) { - NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage; - - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - - if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_POINT) - vec[3] = 1.0f; - else - vec[3] = 0.0f; - - mat = get_matrix_from_to((ShaderCallData *)data, nodeprop->convert_from, nodeprop->convert_to); - if (mat) { - mul_m4_v4((float(*)[4])mat, vec); - } - - if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL) - normalize_v3(vec); - - copy_v4_v4(out[0]->vec, vec); - } } static GPUNodeLink *get_gpulink_matrix_from_to(short from, short to) @@ -161,32 +101,25 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecDat const char *ptransform = "point_transform_m4v3"; const char *func_name = 0; - bool new_shading = GPU_material_use_new_shading_nodes(mat); - NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage; if (in[0].hasinput) inputlink = in[0].link; else - inputlink = GPU_uniform(in[0].vec); + inputlink = GPU_constant(in[0].vec); fromto = get_gpulink_matrix_from_to(nodeprop->convert_from, nodeprop->convert_to); func_name = (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_POINT) ? ptransform : vtransform; if (fromto) { - if (new_shading) { - /* For cycles we have inverted Z */ - /* TODO: pass here the correct matrices */ - if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) { - GPU_link(mat, "invert_z", inputlink, &inputlink); - } - GPU_link(mat, func_name, inputlink, fromto, &out[0].link); - if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) { - GPU_link(mat, "invert_z", out[0].link, &out[0].link); - } + /* For cycles we have inverted Z */ + /* TODO: pass here the correct matrices */ + if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) { + GPU_link(mat, "invert_z", inputlink, &inputlink); } - else { - GPU_link(mat, func_name, inputlink, fromto, &out[0].link); + GPU_link(mat, func_name, inputlink, fromto, &out[0].link); + if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) { + GPU_link(mat, "invert_z", out[0].link, &out[0].link); } } else @@ -203,7 +136,6 @@ void register_node_type_sh_vect_transform(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_VECT_TRANSFORM, "Vector Transform", NODE_CLASS_OP_VECTOR, 0); - node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING); node_type_init(&ntype, node_shader_init_vect_transform); node_type_socket_templates(&ntype, sh_node_vect_transform_in, sh_node_vect_transform_out); node_type_storage(&ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage); diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c b/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c index 073bc3110f6..2a40d98baf9 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c +++ b/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c @@ -50,6 +50,7 @@ static int gpu_shader_vector_displacement(GPUMaterial *mat, bNode *node, bNodeEx { if (node->custom1 == SHD_SPACE_TANGENT) { return GPU_stack_link(mat, + node, "node_vector_displacement_tangent", in, out, @@ -59,10 +60,10 @@ static int gpu_shader_vector_displacement(GPUMaterial *mat, bNode *node, bNodeEx GPU_builtin(GPU_VIEW_MATRIX)); } else if (node->custom1 == SHD_SPACE_OBJECT) { - return GPU_stack_link(mat, "node_vector_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); + return GPU_stack_link(mat, node, "node_vector_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX)); } else { - return GPU_stack_link(mat, "node_vector_displacement_world", in, out); + return GPU_stack_link(mat, node, "node_vector_displacement_world", in, out); } } @@ -72,7 +73,6 @@ void register_node_type_sh_vector_displacement(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_VECTOR_DISPLACEMENT, "Vector Displacement", NODE_CLASS_OP_VECTOR, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_vector_displacement_in, sh_node_vector_displacement_out); node_type_storage(&ntype, "", NULL, NULL); node_type_init(&ntype, node_shader_init_vector_displacement); diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c b/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c index 4861871e8d3..d0ba43d1a15 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c +++ b/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c @@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_volume_absorption_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_volume_absorption(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out)) +static int node_shader_gpu_volume_absorption(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return false; + return GPU_stack_link(mat, node, "node_volume_absorption", in, out); } /* node type definition */ @@ -51,7 +51,6 @@ void register_node_type_sh_volume_absorption(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_VOLUME_ABSORPTION, "Volume Absorption", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_volume_absorption_in, sh_node_volume_absorption_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_principled.c b/source/blender/nodes/shader/nodes/node_shader_volume_principled.c index 8aaf84dc2f0..cf458ac8f51 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_principled.c +++ b/source/blender/nodes/shader/nodes/node_shader_volume_principled.c @@ -62,9 +62,89 @@ static void node_shader_init_volume_principled(bNodeTree *UNUSED(ntree), bNode * } } -static int node_shader_gpu_volume_principled(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out)) +static void node_shader_gpu_volume_attribute(GPUMaterial *mat, const char *name, GPUNodeLink **outcol, GPUNodeLink **outvec, GPUNodeLink **outf) { - return false; + if (strcmp(name, "density") == 0) { + GPU_link(mat, "node_attribute_volume_density", + GPU_builtin(GPU_VOLUME_DENSITY), + outcol, outvec, outf); + } + else if (strcmp(name, "color") == 0) { + GPU_link(mat, "node_attribute_volume_color", + GPU_builtin(GPU_VOLUME_DENSITY), + outcol, outvec, outf); + } + else if (strcmp(name, "flame") == 0) { + GPU_link(mat, "node_attribute_volume_flame", + GPU_builtin(GPU_VOLUME_FLAME), + outcol, outvec, outf); + } + else if (strcmp(name, "temperature") == 0) { + GPU_link(mat, "node_attribute_volume_temperature", + GPU_builtin(GPU_VOLUME_FLAME), + GPU_builtin(GPU_VOLUME_TEMPERATURE), + outcol, outvec, outf); + } + else { + *outcol = *outvec = *outf = NULL; + } +} + +static int node_shader_gpu_volume_principled(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +{ + /* Test if blackbody intensity is enabled. */ + bool use_blackbody = (in[8].link || in[8].vec[0] != 0.0f); + + /* Get volume attributes. */ + GPUNodeLink *density = NULL, *color = NULL, *temperature = NULL; + + for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { + if (sock->typeinfo->type != SOCK_STRING) { + continue; + } + + bNodeSocketValueString *value = sock->default_value; + GPUNodeLink *outcol, *outvec, *outf; + + if (STREQ(sock->name, "Density Attribute")) { + node_shader_gpu_volume_attribute(mat, value->value, &outcol, &outvec, &density); + } + else if (STREQ(sock->name, "Color Attribute")) { + node_shader_gpu_volume_attribute(mat, value->value, &color, &outvec, &outf); + } + else if (use_blackbody && STREQ(sock->name, "Temperature Attribute")) { + node_shader_gpu_volume_attribute(mat, value->value, &outcol, &outvec, &temperature); + } + } + + /* Default values if attributes not found. */ + if (!density) { + static float one = 1.0f; + density = GPU_constant(&one); + } + if (!color) { + static float white[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + color = GPU_constant(white); + } + if (!temperature) { + static float one = 1.0f; + temperature = GPU_constant(&one); + } + + /* Create blackbody spectrum. */ + const int size = CM_TABLE + 1; + float *data, layer; + if (use_blackbody) { + data = MEM_mallocN(sizeof(float) * size * 4, "blackbody texture"); + blackbody_temperature_to_rgb_table(data, size, 965.0f, 12000.0f); + } + else { + data = MEM_callocN(sizeof(float) * size * 4, "blackbody black"); + } + GPUNodeLink *spectrummap = GPU_color_band(mat, size, data, &layer); + + return GPU_stack_link(mat, node, "node_volume_principled", in, out, density, color, temperature, spectrummap, + GPU_constant(&layer)); } /* node type definition */ @@ -73,7 +153,6 @@ void register_node_type_sh_volume_principled(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_VOLUME_PRINCIPLED, "Principled Volume", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_volume_principled_in, sh_node_volume_principled_out); node_type_size_preset(&ntype, NODE_SIZE_LARGE); node_type_init(&ntype, node_shader_init_volume_principled); diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c b/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c index 33180e8ecf1..0f97d08803a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c +++ b/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c @@ -41,9 +41,9 @@ static bNodeSocketTemplate sh_node_volume_scatter_out[] = { { -1, 0, "" } }; -static int node_shader_gpu_volume_scatter(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out)) +static int node_shader_gpu_volume_scatter(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - return false; + return GPU_stack_link(mat, node, "node_volume_scatter", in, out); } /* node type definition */ @@ -52,7 +52,6 @@ void register_node_type_sh_volume_scatter(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_VOLUME_SCATTER, "Volume Scatter", NODE_CLASS_SHADER, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_volume_scatter_in, sh_node_volume_scatter_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_wavelength.c b/source/blender/nodes/shader/nodes/node_shader_wavelength.c index f903e314edf..edc4333c000 100644 --- a/source/blender/nodes/shader/nodes/node_shader_wavelength.c +++ b/source/blender/nodes/shader/nodes/node_shader_wavelength.c @@ -44,7 +44,6 @@ void register_node_type_sh_wavelength(void) static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_WAVELENGTH, "Wavelength", NODE_CLASS_CONVERTOR, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); node_type_socket_templates(&ntype, sh_node_wavelength_in, sh_node_wavelength_out); node_type_init(&ntype, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_wireframe.c b/source/blender/nodes/shader/nodes/node_shader_wireframe.c index 0b9f3ac347a..3592f98d81d 100644 --- a/source/blender/nodes/shader/nodes/node_shader_wireframe.c +++ b/source/blender/nodes/shader/nodes/node_shader_wireframe.c @@ -38,16 +38,27 @@ static bNodeSocketTemplate sh_node_wireframe_out[] = { { -1, 0, "" } }; +static int node_shader_gpu_wireframe(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +{ + /* node->custom1 is use_pixel_size */ + if (node->custom1) { + return GPU_stack_link(mat, node, "node_wireframe_screenspace", in, out, GPU_builtin(GPU_BARYCENTRIC_TEXCO)); + } + else { + return GPU_stack_link(mat, node, "node_wireframe", in, out, GPU_builtin(GPU_BARYCENTRIC_TEXCO), GPU_builtin(GPU_BARYCENTRIC_DIST)); + } +} + /* node type definition */ void register_node_type_sh_wireframe(void) { static bNodeType ntype; sh_node_type_base(&ntype, SH_NODE_WIREFRAME, "Wireframe", NODE_CLASS_INPUT, 0); - node_type_compatibility(&ntype, NODE_NEW_SHADING); node_type_socket_templates(&ntype, sh_node_wireframe_in, sh_node_wireframe_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_wireframe); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c index abaaf338ed7..551d955c70f 100644 --- a/source/blender/nodes/texture/node_texture_tree.c +++ b/source/blender/nodes/texture/node_texture_tree.c @@ -53,44 +53,22 @@ #include "NOD_texture.h" #include "node_texture_util.h" +#include "DEG_depsgraph.h" + #include "RNA_access.h" #include "RE_shader_ext.h" - -static void texture_get_from_context(const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from) +static void texture_get_from_context( + const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from) { SpaceNode *snode = CTX_wm_space_node(C); Scene *scene = CTX_data_scene(C); - Object *ob = OBACT; + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = OBACT(view_layer); Tex *tx = NULL; - if (snode->texfrom == SNODE_TEX_OBJECT) { - if (ob) { - tx = give_current_object_texture(ob); - if (tx) { - if (ob->type == OB_LAMP) - *r_from = (ID *)ob->data; - else - *r_from = (ID *)give_current_material(ob, ob->actcol); - - /* from is not set fully for material nodes, should be ID + Node then */ - *r_id = &tx->id; - *r_ntree = tx->nodetree; - } - } - } - else if (snode->texfrom == SNODE_TEX_WORLD) { - if (scene->world) { - *r_from = (ID *)scene->world; - tx = give_current_world_texture(scene->world); - if (tx) { - *r_id = &tx->id; - *r_ntree = tx->nodetree; - } - } - } - else if (snode->texfrom == SNODE_TEX_BRUSH) { + if (snode->texfrom == SNODE_TEX_BRUSH) { struct Brush *brush = NULL; if (ob && (ob->mode & OB_MODE_SCULPT)) @@ -108,7 +86,7 @@ static void texture_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tr } } else if (snode->texfrom == SNODE_TEX_LINESTYLE) { - FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene); + FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer); if (linestyle) { *r_from = (ID *)linestyle; tx = give_current_linestyle_texture(linestyle); @@ -186,7 +164,7 @@ void register_node_tree_type_tex(void) tt->type = NTREE_TEXTURE; strcpy(tt->idname, "TextureNodeTree"); - strcpy(tt->ui_name, "Texture"); + strcpy(tt->ui_name, "Texture Editor"); tt->ui_icon = 0; /* defined in drawnode.c */ strcpy(tt->ui_description, "Texture nodes"); @@ -321,7 +299,6 @@ int ntreeTexExecTree( short which_output, int cfra, int preview, - ShadeInput *shi, MTex *mtex) { TexCallData data; @@ -336,12 +313,11 @@ int ntreeTexExecTree( data.osatex = osatex; data.target = texres; data.do_preview = preview; - data.do_manage = (shi) ? shi->do_manage : true; + data.do_manage = true; data.thread = thread; data.which_output = which_output; data.cfra = cfra; data.mtex = mtex; - data.shi = shi; /* ensure execdata is only initialized once */ if (!exec) { diff --git a/source/blender/nodes/texture/node_texture_util.c b/source/blender/nodes/texture/node_texture_util.c index 6b9f29475b5..ff2e3d20155 100644 --- a/source/blender/nodes/texture/node_texture_util.c +++ b/source/blender/nodes/texture/node_texture_util.c @@ -124,7 +124,6 @@ void params_from_cdata(TexParams *out, TexCallData *in) out->previewco = in->co; out->osatex = in->osatex; out->cfra = in->cfra; - out->shi = in->shi; out->mtex = in->mtex; } diff --git a/source/blender/nodes/texture/node_texture_util.h b/source/blender/nodes/texture/node_texture_util.h index 389be543d7e..63418248b71 100644 --- a/source/blender/nodes/texture/node_texture_util.h +++ b/source/blender/nodes/texture/node_texture_util.h @@ -87,7 +87,6 @@ typedef struct TexCallData { short which_output; int cfra; - ShadeInput *shi; MTex *mtex; } TexCallData; @@ -100,7 +99,6 @@ typedef struct TexParams { /* optional. we don't really want these here, but image * textures need to do mapping & color correction */ - ShadeInput *shi; MTex *mtex; } TexParams; diff --git a/source/blender/nodes/texture/nodes/node_texture_image.c b/source/blender/nodes/texture/nodes/node_texture_image.c index d6881ca41f0..4fccab27b24 100644 --- a/source/blender/nodes/texture/nodes/node_texture_image.c +++ b/source/blender/nodes/texture/nodes/node_texture_image.c @@ -93,8 +93,8 @@ static void init(bNodeTree *UNUSED(ntree), bNode *node) ImageUser *iuser = MEM_callocN(sizeof(ImageUser), "node image user"); node->storage = iuser; iuser->sfra = 1; - iuser->fie_ima = 2; iuser->ok = 1; + iuser->flag |= IMA_ANIM_ALWAYS; } void register_node_type_tex_image(void) diff --git a/source/blender/nodes/texture/nodes/node_texture_proc.c b/source/blender/nodes/texture/nodes/node_texture_proc.c index 76f5e7d5c5b..47f4683549f 100644 --- a/source/blender/nodes/texture/nodes/node_texture_proc.c +++ b/source/blender/nodes/texture/nodes/node_texture_proc.c @@ -69,7 +69,7 @@ static void do_proc(float *result, TexParams *p, const float col1[4], const floa texres.nor = NULL; textype = multitex_nodes(tex, p->co, p->dxt, p->dyt, p->osatex, - &texres, thread, 0, p->shi, p->mtex, NULL); + &texres, thread, 0, p->mtex, NULL); if (is_normal) return; diff --git a/source/blender/nodes/texture/nodes/node_texture_texture.c b/source/blender/nodes/texture/nodes/node_texture_texture.c index 57703e3a044..ff405cc9f3e 100644 --- a/source/blender/nodes/texture/nodes/node_texture_texture.c +++ b/source/blender/nodes/texture/nodes/node_texture_texture.c @@ -78,7 +78,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor texres.nor = nor; textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex, - &texres, thread, 0, p->shi, p->mtex, NULL); + &texres, thread, 0, p->mtex, NULL); if (textype & TEX_RGB) { copy_v4_v4(out, &texres.tr); |