diff options
Diffstat (limited to 'source/blender')
3 files changed, 16 insertions, 22 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl index d4f7866b206..e8487fb5d42 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl @@ -93,11 +93,6 @@ vec3 c_mod(vec3 a, vec3 b) return vec3(c_mod(a.x, b.x), c_mod(a.y, b.y), c_mod(a.z, b.z)); } -void vector_mix(float strength, vec3 a, vec3 b, out vec3 outVector) -{ - outVector = strength * a + (1 - strength) * b; -} - void invert_z(vec3 v, out vec3 outv) { v.z = -v.z; diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl index a9be6bfa0ff..2b4a0204d97 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_normal_map.glsl @@ -20,3 +20,8 @@ void color_to_blender_normal_new_shading(vec3 color, out vec3 normal) { normal = vec3(2.0, -2.0, -2.0) * color - vec3(1.0); } + +void node_normal_map_mix(float strength, vec3 newnormal, vec3 oldnormal, out vec3 outnormal) +{ + outnormal = normalize(mix(oldnormal, newnormal, max(strength, 0.0))); +} 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 18015d94f03..006f15f40a1 100644 --- a/source/blender/nodes/shader/nodes/node_shader_normal_map.c +++ b/source/blender/nodes/shader/nodes/node_shader_normal_map.c @@ -54,12 +54,8 @@ static int gpu_shader_normal_map(GPUMaterial *mat, GPUNodeStack *out) { NodeShaderNormalMap *nm = node->storage; - GPUNodeLink *negnorm; - GPUNodeLink *realnorm; - GPUNodeLink *strength; - - float strength_min[4] = {0, 0, 0, 0}; + GPUNodeLink *strength; if (in[0].link) { strength = in[0].link; } @@ -72,27 +68,25 @@ static int gpu_shader_normal_map(GPUMaterial *mat, strength = GPU_constant(in[0].vec); } + GPUNodeLink *newnormal; if (in[1].link) { - realnorm = in[1].link; + newnormal = 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); + newnormal = GPU_uniform(socket_data->value); } else { - realnorm = GPU_constant(in[1].vec); + newnormal = GPU_constant(in[1].vec); } - negnorm = GPU_builtin(GPU_WORLD_NORMAL); - GPU_link(mat, "math_maximum", strength, GPU_constant(strength_min), &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"; } - GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); + GPU_link(mat, color_to_normal_fnc_name, newnormal, &newnormal); switch (nm->space) { case SHD_SPACE_TANGENT: GPU_link(mat, @@ -100,13 +94,13 @@ static int gpu_shader_normal_map(GPUMaterial *mat, GPU_builtin(GPU_OBJECT_INFO), GPU_attribute(CD_TANGENT, nm->uv_map), GPU_builtin(GPU_WORLD_NORMAL), - realnorm, - &realnorm); + newnormal, + &newnormal); break; case SHD_SPACE_OBJECT: case SHD_SPACE_BLENDER_OBJECT: GPU_link( - mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm); + mat, "direction_transform_m4v3", newnormal, GPU_builtin(GPU_OBJECT_MATRIX), &newnormal); break; case SHD_SPACE_WORLD: case SHD_SPACE_BLENDER_WORLD: @@ -114,8 +108,8 @@ static int gpu_shader_normal_map(GPUMaterial *mat, break; } - GPU_link(mat, "vector_mix", strength, realnorm, negnorm, &out[0].link); - GPU_link(mat, "vector_normalize", out[0].link, &out[0].link); + GPUNodeLink *oldnormal = GPU_builtin(GPU_WORLD_NORMAL); + GPU_link(mat, "node_normal_map_mix", strength, newnormal, oldnormal, &out[0].link); return true; } |