Fix T61103: Cycles bevel wrong on objects with negative scale.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 11 Mar 2019 09:20:31 +0000 (10:20 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 11 Mar 2019 13:26:06 +0000 (14:26 +0100)
intern/cycles/kernel/kernel_shader.h
intern/cycles/kernel/svm/svm_bevel.h

index d573270..afb9ff1 100644 (file)
@@ -56,7 +56,7 @@ ccl_device_noinline void shader_setup_from_ray(KernelGlobals *kg,
        PROFILING_INIT(kg, PROFILING_SHADER_SETUP);
 
 #ifdef __INSTANCING__
-       sd->object = (isect->object == PRIM_NONE)? kernel_tex_fetch(__prim_object, isect->prim): isect->object;
+       sd->object = (isect->object == OBJECT_NONE)? kernel_tex_fetch(__prim_object, isect->prim): isect->object;
 #endif
        sd->lamp = LAMP_NONE;
 
@@ -411,7 +411,7 @@ ccl_device_inline void shader_setup_from_background(KernelGlobals *kg, ShaderDat
        sd->ray_length = 0.0f;
 
 #ifdef __INSTANCING__
-       sd->object = PRIM_NONE;
+       sd->object = OBJECT_NONE;
 #endif
        sd->lamp = LAMP_NONE;
        sd->prim = PRIM_NONE;
@@ -457,7 +457,7 @@ ccl_device_inline void shader_setup_from_volume(KernelGlobals *kg, ShaderData *s
        sd->ray_length = 0.0f; /* todo: can we set this to some useful value? */
 
 #  ifdef __INSTANCING__
-       sd->object = PRIM_NONE; /* todo: fill this for texture coordinates */
+       sd->object = OBJECT_NONE; /* todo: fill this for texture coordinates */
 #  endif
        sd->lamp = LAMP_NONE;
        sd->prim = PRIM_NONE;
index 96d132a..b5bb9df 100644 (file)
@@ -146,7 +146,13 @@ ccl_device_noinline float3 svm_bevel(
                        }
 #endif  /* __OBJECT_MOTION__ */
 
+                       /* Get geometric normal. */
                        float3 hit_Ng = isect.Ng[hit];
+                       int object = (isect.hits[hit].object == OBJECT_NONE)? kernel_tex_fetch(__prim_object, isect.hits[hit].prim): isect.hits[hit].object;
+                       int object_flag = kernel_tex_fetch(__object_flag, object);
+                       if(object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) {
+                               hit_Ng = -hit_Ng;
+                       }
 
                        /* Compute smooth normal. */
                        float3 N = hit_Ng;
@@ -168,7 +174,7 @@ ccl_device_noinline float3 svm_bevel(
                        }
 
                        /* Transform normals to world space. */
-                       if(isect.hits[hit].object != OBJECT_NONE) {
+                       if(!(object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
                                object_normal_transform(kg, sd, &N);
                                object_normal_transform(kg, sd, &hit_Ng);
                        }