Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Romanov <a.romanov@blend4web.com>2016-06-07 10:33:32 +0300
committerAlexander Romanov <a.romanov@blend4web.com>2016-06-07 10:42:29 +0300
commit0da13ad1ebea9e880a0cd7e1d8b32ea567aef174 (patch)
tree53fc3b010e14d615161f908a6b93fdc3b333e284 /source/blender/nodes/shader/nodes/node_shader_normal_map.c
parent441a440cbbb700511d6d1ec01e2f149355adcc02 (diff)
World space switch for BI nodes.
At the moment light shading in Blender is produced in viewspace. Apparently, that's why shader nodes work with normals in camera space. But it is not convenient for artists. The more convenient approach is implemented in Cycles where normals are represented in world space. Blend4Web Team designed the engine keeping in mind shader parameters readability, so normals are interpreted in world space as well. And now our users have to use some tweaks, like empty node group with the name "Replace", which is replacing one input by another on the engine side (replacing working configuration in Blender Viewport by the configuration that has the same behavior in the engine). This patch adds the ability to switch to world space for normals and lamp vector in BI and Viewport. This patch is very important to us and we crave to see this patch in Blender 2.7 because it will significantly simplify Blend4Web material creation workflow. {F315547} {F315548} Reviewers: campbellbarton, brecht Reviewed By: brecht Subscribers: homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov Differential Revision: https://developer.blender.org/D2046
Diffstat (limited to 'source/blender/nodes/shader/nodes/node_shader_normal_map.c')
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_normal_map.c40
1 files changed, 25 insertions, 15 deletions
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 85e2c77662d..57014bdc476 100644
--- a/source/blender/nodes/shader/nodes/node_shader_normal_map.c
+++ b/source/blender/nodes/shader/nodes/node_shader_normal_map.c
@@ -89,20 +89,34 @@ static void node_shader_exec_normal_map(void *data, int UNUSED(thread), bNode *n
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_NORMAL_MAP_OBJECT:
case SHD_NORMAL_MAP_BLENDER_OBJECT:
- mul_mat3_m4_v3((float (*)[4])RE_object_instance_get_matrix(shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW), vecIn);
+ 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_NORMAL_MAP_WORLD:
case SHD_NORMAL_MAP_BLENDER_WORLD:
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), vecIn);
+ 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);
}
}
@@ -129,10 +143,13 @@ static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *U
negnorm = GPU_builtin(GPU_VIEW_NORMAL);
GPU_link(mat, "math_max", strength, GPU_uniform(d), &strength);
- if (GPU_material_use_new_shading_nodes(mat)) {
+ if (GPU_material_use_world_space_shading(mat)) {
- /* **************** CYCLES ******************** */
+ /* ******* 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_NORMAL_MAP_BLENDER_OBJECT || nm->space == SHD_NORMAL_MAP_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_NORMAL_MAP_TANGENT:
GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm);
@@ -143,28 +160,21 @@ static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *U
GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
return true;
case SHD_NORMAL_MAP_OBJECT:
- GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm);
- GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm);
- GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm);
- break;
case SHD_NORMAL_MAP_BLENDER_OBJECT:
GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm);
- GPU_link(mat, "color_to_blender_normal_new_shading", realnorm, &realnorm);
- GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm);
+ 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_NORMAL_MAP_WORLD:
- GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm);
- GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm);
- break;
case SHD_NORMAL_MAP_BLENDER_WORLD:
GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm);
- GPU_link(mat, "color_to_blender_normal_new_shading", realnorm, &realnorm);
+ GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm);
break;
}
} else {
- /* *********** BLENDER INTERNAL *************** */
+ /* ************** BLENDER INTERNAL without world space shading flag ******* */
GPU_link(mat, "color_to_normal", realnorm, &realnorm);
GPU_link(mat, "mtex_negate_texnormal", realnorm, &realnorm);