diff options
Diffstat (limited to 'source/blender/nodes/shader')
15 files changed, 113 insertions, 80 deletions
diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index d92d0c98a05..7bc8dde3312 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -41,16 +41,13 @@ #include "DNA_linestyle_types.h" #include "BLI_listbase.h" -#include "BLI_math.h" #include "BLI_threads.h" #include "BLI_utildefines.h" #include "BLF_translation.h" #include "BKE_context.h" -#include "BKE_global.h" #include "BKE_linestyle.h" -#include "BKE_main.h" #include "BKE_node.h" #include "BKE_scene.h" @@ -70,9 +67,9 @@ static int shader_tree_poll(const bContext *C, bNodeTreeType *UNUSED(treetype)) Scene *scene = CTX_data_scene(C); /* 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, "BLENDER_RENDER") || - STREQ(scene->r.engine, "BLENDER_GAME") || - STREQ(scene->r.engine, "CYCLES")); + 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)); } static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from) diff --git a/source/blender/nodes/shader/nodes/node_shader_background.c b/source/blender/nodes/shader/nodes/node_shader_background.c index 2478fb4d38c..b387529e456 100644 --- a/source/blender/nodes/shader/nodes/node_shader_background.c +++ b/source/blender/nodes/shader/nodes/node_shader_background.c @@ -40,6 +40,11 @@ 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) +{ + return GPU_stack_link(mat, "node_background", in, out, GPU_builtin(GPU_VIEW_NORMAL)); +} + /* node type definition */ void register_node_type_sh_background(void) { @@ -50,6 +55,7 @@ void register_node_type_sh_background(void) node_type_socket_templates(&ntype, sh_node_background_in, sh_node_background_out); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, node_shader_gpu_background); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/shader/nodes/node_shader_bump.c b/source/blender/nodes/shader/nodes/node_shader_bump.c index 3ce01ce03bf..de152ee45d1 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bump.c +++ b/source/blender/nodes/shader/nodes/node_shader_bump.c @@ -29,11 +29,8 @@ * \ingroup shdnodes */ - - #include "node_shader_util.h" - /* **************** BUMP ******************** */ static bNodeSocketTemplate sh_node_bump_in[] = { { SOCK_FLOAT, 1, N_("Strength"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, diff --git a/source/blender/nodes/shader/nodes/node_shader_material.c b/source/blender/nodes/shader/nodes/node_shader_material.c index 79d66495ad7..b7e10c7e9df 100644 --- a/source/blender/nodes/shader/nodes/node_shader_material.c +++ b/source/blender/nodes/shader/nodes/node_shader_material.c @@ -267,6 +267,8 @@ static int gpu_shader_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNU shi.amb = gpu_get_input_link(&in[MAT_IN_AMB]); if (hasinput[MAT_IN_EMIT]) shi.emit = gpu_get_input_link(&in[MAT_IN_EMIT]); + if (hasinput[MAT_IN_SPECTRA]) + shi.spectra = gpu_get_input_link(&in[MAT_IN_SPECTRA]); if (hasinput[MAT_IN_ALPHA]) shi.alpha = gpu_get_input_link(&in[MAT_IN_ALPHA]); } diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c index dc5971909d2..be2e3dcd311 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_math.c @@ -54,16 +54,16 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode switch (node->custom1) { - case 0: /* Add */ + case NODE_MATH_ADD: r = a + b; break; - case 1: /* Subtract */ + case NODE_MATH_SUB: r = a - b; break; - case 2: /* Multiply */ + case NODE_MATH_MUL: r = a * b; break; - case 3: /* Divide */ + case NODE_MATH_DIVIDE: { if (b == 0) /* We don't want to divide by zero. */ r = 0.0; @@ -71,7 +71,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = a / b; break; } - case 4: /* Sine */ + case NODE_MATH_SIN: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ r = sinf(a); @@ -79,7 +79,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = sinf(b); break; } - case 5: /* Cosine */ + case NODE_MATH_COS: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ r = cosf(a); @@ -87,7 +87,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = cosf(b); break; } - case 6: /* Tangent */ + case NODE_MATH_TAN: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ r = tanf(a); @@ -95,7 +95,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = tanf(b); break; } - case 7: /* Arc-Sine */ + case NODE_MATH_ASIN: { if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ /* Can't do the impossible... */ @@ -113,7 +113,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode } break; } - case 8: /* Arc-Cosine */ + case NODE_MATH_ACOS: { if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ /* Can't do the impossible... */ @@ -131,7 +131,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode } break; } - case 9: /* Arc-Tangent */ + case NODE_MATH_ATAN: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ r = atan(a); @@ -139,7 +139,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = atan(b); break; } - case 10: /* Power */ + case NODE_MATH_POW: { /* Only raise negative numbers by full integers */ if (a >= 0) { @@ -159,7 +159,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode break; } - case 11: /* Logarithm */ + case NODE_MATH_LOG: { /* Don't want any imaginary numbers... */ if (a > 0 && b > 0) @@ -168,7 +168,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = 0.0; break; } - case 12: /* Minimum */ + case NODE_MATH_MIN: { if (a < b) r = a; @@ -176,7 +176,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = b; break; } - case 13: /* Maximum */ + case NODE_MATH_MAX: { if (a > b) r = a; @@ -184,7 +184,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = b; break; } - case 14: /* Round */ + case NODE_MATH_ROUND: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ r = (a < 0) ? (int)(a - 0.5f) : (int)(a + 0.5f); @@ -192,7 +192,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = (b < 0) ? (int)(b - 0.5f) : (int)(b + 0.5f); break; } - case 15: /* Less Than */ + case NODE_MATH_LESS: { if (a < b) r = 1.0f; @@ -200,7 +200,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = 0.0f; break; } - case 16: /* Greater Than */ + case NODE_MATH_GREATER: { if (a > b) r = 1.0f; @@ -208,7 +208,7 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = 0.0f; break; } - case 17: /* Modulo */ + case NODE_MATH_MOD: { if (b == 0.0f) r = 0.0f; @@ -216,13 +216,15 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = fmod(a, b); break; } - case 18: /* Absolute */ + case NODE_MATH_ABS: { r = fabsf(a); break; } } - + if (node->custom2 & SHD_MATH_CLAMP) { + CLAMP(r, 0.0f, 1.0f); + } out[0]->vec[0] = r; } @@ -231,29 +233,30 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED( static const char *names[] = {"math_add", "math_subtract", "math_multiply", "math_divide", "math_sine", "math_cosine", "math_tangent", "math_asin", "math_acos", "math_atan", "math_pow", "math_log", "math_min", "math_max", - "math_round", "math_less_than", "math_greater_than", "math_modulo", "math_absolute"}; + "math_round", "math_less_than", "math_greater_than", "math_modulo", "math_abs"}; switch (node->custom1) { - case 0: - case 1: - case 2: - case 3: - case 10: - case 11: - case 12: - case 13: - case 15: - case 16: - case 17: + case NODE_MATH_ADD: + case NODE_MATH_SUB: + case NODE_MATH_MUL: + case NODE_MATH_DIVIDE: + case NODE_MATH_POW: + case NODE_MATH_LOG: + case NODE_MATH_MIN: + case NODE_MATH_MAX: + case NODE_MATH_LESS: + case NODE_MATH_GREATER: + case NODE_MATH_MOD: GPU_stack_link(mat, names[node->custom1], in, out); break; - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 14: + case NODE_MATH_SIN: + case NODE_MATH_COS: + case NODE_MATH_TAN: + case NODE_MATH_ASIN: + case NODE_MATH_ACOS: + case NODE_MATH_ATAN: + case NODE_MATH_ROUND: + case NODE_MATH_ABS: if (in[0].hasinput || !in[1].hasinput) { /* use only first item and terminator */ GPUNodeStack tmp_in[2]; @@ -272,7 +275,13 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED( default: return 0; } - + + 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); + } + return 1; } diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c index 2da51c19ef8..f911fa058dc 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c @@ -59,6 +59,9 @@ static void node_shader_exec_mix_rgb(void *UNUSED(data), int UNUSED(thread), bNo nodestack_get_vec(vec, SOCK_VECTOR, in[2]); ramp_blend(node->custom1, col, fac, vec); + if (node->custom2 & SHD_MIXRGB_CLAMP) { + CLAMP3(col, 0.0f, 1.0f); + } copy_v3_v3(out[0]->vec, col); } @@ -68,8 +71,13 @@ 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"}; - - return GPU_stack_link(mat, names[node->custom1], in, out); + int ret = GPU_stack_link(mat, 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); + } + return ret; } diff --git a/source/blender/nodes/shader/nodes/node_shader_normal.c b/source/blender/nodes/shader/nodes/node_shader_normal.c index fcd738f0b15..092fc201aa7 100644 --- a/source/blender/nodes/shader/nodes/node_shader_normal.c +++ b/source/blender/nodes/shader/nodes/node_shader_normal.c @@ -61,12 +61,12 @@ static void node_shader_exec_normal(void *UNUSED(data), int UNUSED(thread), bNod static int gpu_shader_normal(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { GPUNodeLink *vec = GPU_uniform(out[0].vec); - int ret = GPU_stack_link(mat, "normal", in, out, vec); - if (ret && GPU_material_use_new_shading_nodes(mat)) { - float fac[3] = {1.0f, 0.0f, 0.0f}; - GPU_link(mat, "invert", GPU_uniform(fac), out[1].link, &out[1].link); + 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); } - return ret; } void register_node_type_sh_normal(void) 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 c8e47c47c5f..ad7389fd56e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_world.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_world.c @@ -35,6 +35,16 @@ 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) +{ + GPUNodeLink *outlink; + + GPU_stack_link(mat, "node_output_world", in, out, &outlink); + GPU_material_output_link(mat, outlink); + + return 1; +} + /* node type definition */ void register_node_type_sh_output_world(void) { @@ -45,7 +55,8 @@ void register_node_type_sh_output_world(void) node_type_socket_templates(&ntype, sh_node_output_world_in, NULL); node_type_init(&ntype, NULL); node_type_storage(&ntype, "", NULL, NULL); - + node_type_gpu(&ntype, node_shader_gpu_output_world); + /* Do not allow muting output node. */ node_type_internal_links(&ntype, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_script.c b/source/blender/nodes/shader/nodes/node_shader_script.c index d5ed38297da..f640dd5ea13 100644 --- a/source/blender/nodes/shader/nodes/node_shader_script.c +++ b/source/blender/nodes/shader/nodes/node_shader_script.c @@ -31,8 +31,6 @@ #include "node_shader_util.h" -#include "BKE_idprop.h" - /* **************** Script ******************** */ static void init(bNodeTree *UNUSED(ntree), bNode *node) 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 781b1bb5a93..85eca6ae990 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c @@ -46,10 +46,18 @@ static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), bNod { GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ""); - - return GPU_stack_link(mat, "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), orco, 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_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), + GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), orco, mtface); + } + else { + return GPU_stack_link(mat, "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), orco, mtface); + } } /* node type definition */ 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 dcb3ef3c8a0..8d6a77455bb 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c @@ -27,8 +27,6 @@ #include "../node_shader_util.h" -#include "IMB_colormanagement.h" - /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_environment_in[] = { @@ -67,13 +65,22 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE if (!ima) return GPU_stack_link(mat, "node_tex_environment_empty", in, out); - if (!in[0].link) - in[0].link = GPU_builtin(GPU_VIEW_POSITION); - + if (!in[0].link) { + GPUMatType type = GPU_Material_get_type(mat); + + if (type == GPU_MATERIAL_TYPE_MESH) + in[0].link = GPU_builtin(GPU_VIEW_POSITION); + else + GPU_link(mat, "background_transform_to_world", GPU_builtin(GPU_VIEW_POSITION), &in[0].link); + } + node_shader_gpu_tex_mapping(mat, node, in, out); - ret = GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser, isdata)); - + if (tex->projection == SHD_PROJ_EQUIRECTANGULAR) + ret = GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata)); + else + ret = GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata)); + if (ret) { ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && 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 0a11ee4a9b6..62db5b70891 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c @@ -27,8 +27,6 @@ #include "../node_shader_util.h" -#include "IMB_colormanagement.h" - /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_tex_image_in[] = { diff --git a/source/blender/nodes/shader/nodes/node_shader_texture.c b/source/blender/nodes/shader/nodes/node_shader_texture.c index d02d72563ba..5cdbaf444f8 100644 --- a/source/blender/nodes/shader/nodes/node_shader_texture.c +++ b/source/blender/nodes/shader/nodes/node_shader_texture.c @@ -29,11 +29,8 @@ * \ingroup shdnodes */ - #include "DNA_texture_types.h" -#include "IMB_colormanagement.h" - #include "node_shader_util.h" /* **************** TEXTURE ******************** */ diff --git a/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c b/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c index 48eb4cadba4..67342e1e836 100644 --- a/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c +++ b/source/blender/nodes/shader/nodes/node_shader_uvAlongStroke.c @@ -27,8 +27,6 @@ #include "../node_shader_util.h" -#include "DNA_customdata_types.h" - /* **************** OUTPUT ******************** */ static bNodeSocketTemplate sh_node_uvalongstroke_out[] = { diff --git a/source/blender/nodes/shader/nodes/node_shader_vectMath.c b/source/blender/nodes/shader/nodes/node_shader_vectMath.c index f2ea2faa5a7..9e75d915d44 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vectMath.c +++ b/source/blender/nodes/shader/nodes/node_shader_vectMath.c @@ -29,11 +29,8 @@ * \ingroup shdnodes */ - - #include "node_shader_util.h" - /* **************** VECTOR MATH ******************** */ static bNodeSocketTemplate sh_node_vect_math_in[] = { { SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, |