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 Gavrilov <angavrilov@gmail.com>2016-08-30 12:48:59 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2016-08-30 12:48:59 +0300
commitc376878e5421f4b53ef812f77ab9127effea4505 (patch)
tree3309e80aa4b696cce86a403d3d3246f463e35e17 /intern/cycles/kernel/svm
parent3a0c0c1b5425cd5b050cb742357da57266c70463 (diff)
Fix T49187: inconsistent Normal Map node output for backfacing polygons.
There basically are two issues here: in smooth mode (and all non-tangent normal map types) it doesn't invert the normal for backfacing polys; on the other hand for flat shaded tangent type it is inverted too soon. This fix does a brute force correction by checking the backfacing flag. Reviewers: #cycles, brecht Reviewed By: #cycles, brecht Differential Revision: https://developer.blender.org/D2181
Diffstat (limited to 'intern/cycles/kernel/svm')
-rw-r--r--intern/cycles/kernel/svm/svm_tex_coord.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/intern/cycles/kernel/svm/svm_tex_coord.h b/intern/cycles/kernel/svm/svm_tex_coord.h
index 01dede3fff5..6ea2539c543 100644
--- a/intern/cycles/kernel/svm/svm_tex_coord.h
+++ b/intern/cycles/kernel/svm/svm_tex_coord.h
@@ -277,6 +277,7 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st
float3 color = stack_load_float3(stack, color_offset);
color = 2.0f*make_float3(color.x - 0.5f, color.y - 0.5f, color.z - 0.5f);
+ bool is_backfacing = (ccl_fetch(sd, flag) & SD_BACKFACING) != 0;
float3 N;
if(space == NODE_NORMAL_MAP_TANGENT) {
@@ -306,6 +307,12 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st
}
else {
normal = ccl_fetch(sd, Ng);
+
+ /* the normal is already inverted, which is too soon for the math here */
+ if(is_backfacing) {
+ normal = -normal;
+ }
+
object_inverse_normal_transform(kg, sd, &normal);
}
@@ -332,6 +339,11 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st
N = safe_normalize(N);
}
+ /* invert normal for backfacing polygons */
+ if(is_backfacing) {
+ N = -N;
+ }
+
float strength = stack_load_float(stack, strength_offset);
if(strength != 1.0f) {