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:
authorSergey Sharybin <sergey.vfx@gmail.com>2015-02-19 10:52:48 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2015-02-19 10:52:48 +0300
commit3e534833e3a83ceecef35aa6c32764971e3b086e (patch)
treea3d56ccf3cc8205aa9b2a129ece3b361817ccd1f /intern/cycles
parent5004b582622144317948262793d5a4199ec90f13 (diff)
Cycles: Make sphere and tube image mapping friendly with OpenCL
OpenCL doesn't let you to get address of vector components, which is kinda annoying. On the other hand, maybe now compiler will have more chances to optimize something out.
Diffstat (limited to 'intern/cycles')
-rw-r--r--intern/cycles/blender/blender_mesh.cpp4
-rw-r--r--intern/cycles/kernel/svm/svm_image.h10
-rw-r--r--intern/cycles/util/util_math.h35
3 files changed, 27 insertions, 22 deletions
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 572d8e89cbc..d71825c4de3 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -106,7 +106,9 @@ static void mikk_get_texture_coordinate(const SMikkTSpaceContext *context, float
int vert_idx = userdata->mesh.tessfaces[face_num].vertices()[vert_num];
float3 orco =
get_float3(userdata->mesh.vertices[vert_idx].undeformed_co());
- map_to_sphere(&uv[0], &uv[1], orco[0], orco[1], orco[2]);
+ float2 tmp = map_to_sphere(make_float3(orco[0], orco[1], orco[2]));
+ uv[0] = tmp.x;
+ uv[1] = tmp.y;
}
}
diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h
index e667fc2033d..4de69479bd9 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -368,16 +368,20 @@ ccl_device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *sta
decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb);
float3 co = stack_load_float3(stack, co_offset);
+ float2 tex_co;
uint use_alpha = stack_valid(alpha_offset);
if(node.w == NODE_IMAGE_PROJ_SPHERE) {
co = texco_remap_square(co);
- map_to_sphere(&co.x, &co.y, co.x, co.y, co.z);
+ tex_co = map_to_sphere(co);
}
else if(node.w == NODE_IMAGE_PROJ_TUBE) {
co = texco_remap_square(co);
- map_to_tube(&co.x, &co.y, co.x, co.y, co.z);
+ tex_co = map_to_tube(co);
}
- float4 f = svm_image_texture(kg, id, co.x, co.y, srgb, use_alpha);
+ else {
+ tex_co = make_float2(co.x, co.y);
+ }
+ float4 f = svm_image_texture(kg, id, tex_co.x, tex_co.y, srgb, use_alpha);
if(stack_valid(out_offset))
stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z));
diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h
index c92b89f1639..a4d49681a38 100644
--- a/intern/cycles/util/util_math.h
+++ b/intern/cycles/util/util_math.h
@@ -1457,38 +1457,37 @@ ccl_device bool ray_quad_intersect(
}
/* projections */
-ccl_device void map_to_tube(float *r_u, float *r_v,
- const float x, const float y, const float z)
+ccl_device_inline float2 map_to_tube(const float3 co)
{
- float len;
- *r_v = (z + 1.0f) * 0.5f;
- len = sqrtf(x * x + y * y);
+ float len, u, v;
+ len = sqrtf(co.x * co.x + co.y * co.y);
if (len > 0.0f) {
- *r_u = (1.0f - (atan2f(x / len, y / len) / M_PI_F)) * 0.5f;
+ u = (1.0f - (atan2f(co.x / len, co.y / len) / M_PI_F)) * 0.5f;
+ v = (co.x + 1.0f) * 0.5f;
}
else {
- *r_v = *r_u = 0.0f; /* To avoid un-initialized variables. */
+ u = v = 0.0f;
}
+ return make_float2(u, v);
}
-ccl_device bool map_to_sphere(float *r_u, float *r_v,
- const float x, const float y, const float z)
+ccl_device_inline float2 map_to_sphere(const float3 co)
{
- float len = sqrtf(x * x + y * y + z * z);
- if(len > 0.0f) {
- if(UNLIKELY(x == 0.0f && y == 0.0f)) {
- *r_u = 0.0f; /* othwise domain error */
+ float l = len(co);
+ float u, v;
+ if(l > 0.0f) {
+ if(UNLIKELY(co.x == 0.0f && co.y == 0.0f)) {
+ u = 0.0f; /* othwise domain error */
}
else {
- *r_u = (1.0f - atan2f(x, y) / M_PI_F) / 2.0f;
+ u = (1.0f - atan2f(co.x, co.y) / M_PI_F) / 2.0f;
}
- *r_v = 1.0f - safe_acosf(z / len) / M_PI_F;
- return true;
+ v = 1.0f - safe_acosf(co.z / l) / M_PI_F;
}
else {
- *r_v = *r_u = 0.0f; /* to avoid un-initialized variables */
- return false;
+ u = v = 0.0f;
}
+ return make_float2(u, v);
}
ccl_device_inline int util_max_axis(float3 vec)