Fix T41783: Cycles baking ignores displacement
authorDalai Felinto <dfelinto@gmail.com>
Tue, 11 Nov 2014 20:21:56 +0000 (18:21 -0200)
committerDalai Felinto <dfelinto@gmail.com>
Tue, 11 Nov 2014 20:21:56 +0000 (18:21 -0200)
Create unique flag for output shaders with displacement data and use it
to calculate transformed normal. Implementation suggested by Brecht Van
Lommel.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D890

intern/cycles/kernel/kernel_bake.h
intern/cycles/kernel/kernel_types.h
intern/cycles/render/shader.cpp

index 96be065f5d89d9e3cfb6604414f2f0f261198924..e80bfb32e89cc123abddb07136084f12c652fc4e 100644 (file)
@@ -253,6 +253,10 @@ ccl_device void kernel_bake_evaluate(KernelGlobals *kg, ccl_global uint4 *input,
                /* data passes */
                case SHADER_EVAL_NORMAL:
                {
+                       if ((sd.flag & SD_HAS_BUMP)) {
+                               shader_eval_surface(kg, &sd, 0.f, 0, SHADER_CONTEXT_MAIN);
+                       }
+
                        /* compression: normal = (2 * color) - 1 */
                        out = sd.N * 0.5f + make_float3(0.5f, 0.5f, 0.5f);
                        break;
index a7d269a3e5410c18610c29cfb576ce7f5539635f..65297ecb26746a96701ed03004894c2cc77a6508 100644 (file)
@@ -617,19 +617,20 @@ enum ShaderDataFlag {
        SD_VOLUME_EQUIANGULAR     = (1 << 17),  /* use equiangular sampling */
        SD_VOLUME_MIS             = (1 << 18),  /* use multiple importance sampling */
        SD_VOLUME_CUBIC           = (1 << 19),  /* use cubic interpolation for voxels */
+       SD_HAS_BUMP               = (1 << 20),  /* has data connected to the displacement input */
 
        SD_SHADER_FLAGS = (SD_USE_MIS|SD_HAS_TRANSPARENT_SHADOW|SD_HAS_VOLUME|
                           SD_HAS_ONLY_VOLUME|SD_HETEROGENEOUS_VOLUME|
                           SD_HAS_BSSRDF_BUMP|SD_VOLUME_EQUIANGULAR|SD_VOLUME_MIS|
-                          SD_VOLUME_CUBIC),
+                          SD_VOLUME_CUBIC | SD_HAS_BUMP),
 
        /* object flags */
-       SD_HOLDOUT_MASK             = (1 << 20),  /* holdout for camera rays */
-       SD_OBJECT_MOTION            = (1 << 21),  /* has object motion blur */
-       SD_TRANSFORM_APPLIED        = (1 << 22),  /* vertices have transform applied */
-       SD_NEGATIVE_SCALE_APPLIED   = (1 << 23),  /* vertices have negative scale applied */
-       SD_OBJECT_HAS_VOLUME        = (1 << 24),  /* object has a volume shader */
-       SD_OBJECT_INTERSECTS_VOLUME = (1 << 25),  /* object intersects AABB of an object with volume shader */
+       SD_HOLDOUT_MASK             = (1 << 21),  /* holdout for camera rays */
+       SD_OBJECT_MOTION            = (1 << 22),  /* has object motion blur */
+       SD_TRANSFORM_APPLIED        = (1 << 23),  /* vertices have transform applied */
+       SD_NEGATIVE_SCALE_APPLIED   = (1 << 24),  /* vertices have negative scale applied */
+       SD_OBJECT_HAS_VOLUME        = (1 << 25),  /* object has a volume shader */
+       SD_OBJECT_INTERSECTS_VOLUME = (1 << 26),  /* object intersects AABB of an object with volume shader */
 
        SD_OBJECT_FLAGS = (SD_HOLDOUT_MASK|SD_OBJECT_MOTION|SD_TRANSFORM_APPLIED|
                           SD_NEGATIVE_SCALE_APPLIED|SD_OBJECT_HAS_VOLUME|
index 2a3969b618844b2495e0313fcd0880399c85d75f..5c30d191d344c1e048cf6a00b58f2e37d72f69ef 100644 (file)
@@ -359,6 +359,8 @@ void ShaderManager::device_update_common(Device *device, DeviceScene *dscene, Sc
                        flag |= SD_VOLUME_MIS;
                if(shader->volume_interpolation_method == VOLUME_INTERPOLATION_CUBIC)
                        flag |= SD_VOLUME_CUBIC;
+               if(shader->graph_bump)
+                       flag |= SD_HAS_BUMP;
 
                /* regular shader */
                shader_flag[i++] = flag;