diff options
author | Lukas Stockner <lukas.stockner@freenet.de> | 2016-11-03 05:08:14 +0300 |
---|---|---|
committer | Lukas Stockner <lukas.stockner@freenet.de> | 2016-11-03 05:08:14 +0300 |
commit | 9847ad977a29685d3400ec222213dfb484ec01f5 (patch) | |
tree | fe3b531f2a4e7a9d5dcb1cff1fb0f6c8c7db6d85 | |
parent | 643c5a24d56f00c45d03b52f4b1211c05a78bf0f (diff) |
Cycles: Fix T49901: OpenCL build error after recent light texture coordinate commit
Basically, the problem here was that the transform that's used to bring texture coordinates
to world space is either fetched while setting up the shader (with Object Motion is enabled) or
fetched when needed (otherwise). That helps to save ShaderData memory on OpenCL when Object Motion isn't needed.
Now, if OM is enabled, the Lamp transform can just be stored inside the ShaderData as well. The original commit just assumed it is.
However, when it's not (on OpenCL by default, for example), there is no easy way to fetch it when needed, since the ShaderData doesn't
store the Lamp index.
So, for now the lamps just don't support local texture coordinates anymore when Object Motion is disabled.
To fix and support this properly, one of the following could be done:
- Just always pre-fetch the transform. Downside: Memory Usage increases when not using OM on OpenCL
- Add a variable to ShaderData that stores the Lamp ID to allow fetching it when needed
- Store the Lamp ID inside prim or object. Problem: Cycles currently checks these for whether an object was hit - these checks would need to be changed.
- Enable OM whenever a Texture Coordinate's Normal output is used. Downside: Might not actually be needed.
-rw-r--r-- | intern/cycles/kernel/geom/geom_object.h | 12 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_shader.h | 7 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_image.h | 3 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_tex_coord.h | 9 |
4 files changed, 14 insertions, 17 deletions
diff --git a/intern/cycles/kernel/geom/geom_object.h b/intern/cycles/kernel/geom/geom_object.h index 6b42f66b0d5..73dc5a0a726 100644 --- a/intern/cycles/kernel/geom/geom_object.h +++ b/intern/cycles/kernel/geom/geom_object.h @@ -161,11 +161,15 @@ ccl_device_inline void object_inverse_position_transform(KernelGlobals *kg, cons ccl_device_inline void object_inverse_normal_transform(KernelGlobals *kg, const ShaderData *sd, float3 *N) { -#ifdef __OBJECT_MOTION__ - *N = normalize(transform_direction_transposed_auto(&ccl_fetch(sd, ob_tfm), *N)); +#ifdef __OBJECT_MOTION_ + if((ccl_fetch(sd, object) != OBJECT_NONE) || (ccl_fetch(sd, type) == PRIMITIVE_LAMP)) { + *N = normalize(transform_direction_transposed_auto(&ccl_fetch(sd, ob_tfm), *N)); + } #else - Transform tfm = object_fetch_transform(kg, ccl_fetch(sd, object), OBJECT_TRANSFORM); - *N = normalize(transform_direction_transposed(&tfm, *N)); + if(ccl_fetch(sd, object) != OBJECT_NONE) { + Transform tfm = object_fetch_transform(kg, ccl_fetch(sd, object), OBJECT_TRANSFORM); + *N = normalize(transform_direction_transposed(&tfm, *N)); + } #endif } diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h index b4b980c4e90..c1b3153d8fe 100644 --- a/intern/cycles/kernel/kernel_shader.h +++ b/intern/cycles/kernel/kernel_shader.h @@ -276,16 +276,13 @@ ccl_device_inline void shader_setup_from_sample(KernelGlobals *kg, #ifdef __OBJECT_MOTION__ shader_setup_object_transforms(kg, sd, time); -#endif + ccl_fetch(sd, time) = time; } else if(lamp != LAMP_NONE) { ccl_fetch(sd, ob_tfm) = lamp_fetch_transform(kg, lamp, false); ccl_fetch(sd, ob_itfm) = lamp_fetch_transform(kg, lamp, true); - } - -#ifdef __OBJECT_MOTION__ - ccl_fetch(sd, time) = time; #endif + } /* transform into world space */ if(object_space) { diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h index 9606064492e..2afdf61b476 100644 --- a/intern/cycles/kernel/svm/svm_image.h +++ b/intern/cycles/kernel/svm/svm_image.h @@ -241,8 +241,7 @@ ccl_device void svm_node_tex_image_box(KernelGlobals *kg, ShaderData *sd, float float3 N = ccl_fetch(sd, N); N = ccl_fetch(sd, N); - if(ccl_fetch(sd, object) != OBJECT_NONE) - object_inverse_normal_transform(kg, sd, &N); + object_inverse_normal_transform(kg, sd, &N); /* project from direction vector to barycentric coordinates in triangles */ N.x = fabsf(N.x); diff --git a/intern/cycles/kernel/svm/svm_tex_coord.h b/intern/cycles/kernel/svm/svm_tex_coord.h index 6c3394adbce..c0b01262212 100644 --- a/intern/cycles/kernel/svm/svm_tex_coord.h +++ b/intern/cycles/kernel/svm/svm_tex_coord.h @@ -49,8 +49,7 @@ ccl_device void svm_node_tex_coord(KernelGlobals *kg, } case NODE_TEXCO_NORMAL: { data = ccl_fetch(sd, N); - if((ccl_fetch(sd, object) != OBJECT_NONE) || (ccl_fetch(sd, type) == PRIMITIVE_LAMP)) - object_inverse_normal_transform(kg, sd, &data); + object_inverse_normal_transform(kg, sd, &data); break; } case NODE_TEXCO_CAMERA: { @@ -131,8 +130,7 @@ ccl_device void svm_node_tex_coord_bump_dx(KernelGlobals *kg, } case NODE_TEXCO_NORMAL: { data = ccl_fetch(sd, N); - if((ccl_fetch(sd, object) != OBJECT_NONE) || (ccl_fetch(sd, type) == PRIMITIVE_LAMP)) - object_inverse_normal_transform(kg, sd, &data); + object_inverse_normal_transform(kg, sd, &data); break; } case NODE_TEXCO_CAMERA: { @@ -216,8 +214,7 @@ ccl_device void svm_node_tex_coord_bump_dy(KernelGlobals *kg, } case NODE_TEXCO_NORMAL: { data = ccl_fetch(sd, N); - if((ccl_fetch(sd, object) != OBJECT_NONE) || (ccl_fetch(sd, type) == PRIMITIVE_LAMP)) - object_inverse_normal_transform(kg, sd, &data); + object_inverse_normal_transform(kg, sd, &data); break; } case NODE_TEXCO_CAMERA: { |