Fix T41783: Cycles baking ignores displacement

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
This commit is contained in:
Dalai Felinto
2014-11-11 18:21:56 -02:00
parent 2beb940365
commit 8c227adb8c
3 changed files with 14 additions and 7 deletions

View 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;

View 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|

View 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;