diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-07-29 14:07:05 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-07-29 14:08:47 +0400 |
commit | 946f291c46b5f7f481b42de1ecf1186608809fd8 (patch) | |
tree | 0873323eb89ebe64cfff0dcbed57b7d826dbec92 /intern/cycles/util | |
parent | a9c8a117a267e1feec7471309107c8ef67dc5dc3 (diff) |
Fix T41174: Tangent space required UV map in Cycles
Now Cycles behaves in the same way as BI in terms of using
sphere projection of orco coordinates if there's no UV map
when calculating tangent space.
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_math.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h index fc6827573f8..5ea82c65a92 100644 --- a/intern/cycles/util/util_math.h +++ b/intern/cycles/util/util_math.h @@ -1425,6 +1425,23 @@ ccl_device bool ray_quad_intersect( return false; } +/* projections */ +ccl_device bool map_to_sphere(float *r_u, float *r_v, + const float x, const float y, const float z) +{ + float len = sqrtf(x * x + y * y + z * z); + if (len > 0.0f) { + if (x == 0.0f && y == 0.0f) *r_u = 0.0f; /* othwise domain error */ + else *r_u = (1.0f - atan2f(x, y) / (float)M_PI) / 2.0f; + *r_v = 1.0f - safe_acosf(z / len) / (float)M_PI; + return true; + } + else { + *r_v = *r_u = 0.0f; /* to avoid un-initialized variables */ + return false; + } +} + CCL_NAMESPACE_END #endif /* __UTIL_MATH_H__ */ |