diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2016-04-20 17:45:29 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2016-04-20 17:45:29 +0300 |
commit | aae0598aa233d43d0ffc81a070b2ce20d6871c1d (patch) | |
tree | 378100f45cf1db972c671a6886496a5604f7ab29 /intern/cycles/kernel/kernel_projection.h | |
parent | 95d7d3c2a6aa91f1dcb33ff0cdfc751e2886d8cd (diff) | |
parent | d7e4f920fd93a4ae5679e0eb6b228a349ab3b082 (diff) |
Merge branch 'master' into temp_depsgraph_split_ubereval
Diffstat (limited to 'intern/cycles/kernel/kernel_projection.h')
-rw-r--r-- | intern/cycles/kernel/kernel_projection.h | 62 |
1 files changed, 51 insertions, 11 deletions
diff --git a/intern/cycles/kernel/kernel_projection.h b/intern/cycles/kernel/kernel_projection.h index 62922df3286..c1a359e9269 100644 --- a/intern/cycles/kernel/kernel_projection.h +++ b/intern/cycles/kernel/kernel_projection.h @@ -47,10 +47,10 @@ ccl_device float2 direction_to_spherical(float3 dir) ccl_device float3 spherical_to_direction(float theta, float phi) { - return make_float3( - sinf(theta)*cosf(phi), - sinf(theta)*sinf(phi), - cosf(theta)); + float sin_theta = sinf(theta); + return make_float3(sin_theta*cosf(phi), + sin_theta*sinf(phi), + cosf(theta)); } /* Equirectangular coordinates <-> Cartesian direction */ @@ -67,11 +67,10 @@ ccl_device float3 equirectangular_range_to_direction(float u, float v, float4 ra { float phi = range.x*u + range.y; float theta = range.z*v + range.w; - - return make_float3( - sinf(theta)*cosf(phi), - sinf(theta)*sinf(phi), - cosf(theta)); + float sin_theta = sinf(theta); + return make_float3(sin_theta*cosf(phi), + sin_theta*sinf(phi), + cosf(theta)); } ccl_device float2 direction_to_equirectangular(float3 dir) @@ -222,7 +221,48 @@ ccl_device float2 direction_to_panorama(KernelGlobals *kg, float3 dir) } } -CCL_NAMESPACE_END +ccl_device float3 spherical_stereo_position(KernelGlobals *kg, + float3 dir, + float3 pos) +{ + const float interocular_offset = kernel_data.cam.interocular_offset; + + /* Interocular offset of zero means either non stereo, or stereo without + * spherical stereo. + */ + if(interocular_offset == 0.0f) { + return pos; + } + + float3 up = make_float3(0.0f, 0.0f, 1.0f); + float3 side = normalize(cross(dir, up)); -#endif /* __KERNEL_PROJECTION_CL__ */ + return pos + (side * interocular_offset); +} + +/* NOTE: Ensures direction is normalized. */ +ccl_device float3 spherical_stereo_direction(KernelGlobals *kg, + float3 dir, + float3 pos, + float3 newpos) +{ + const float convergence_distance = kernel_data.cam.convergence_distance; + const float3 normalized_dir = normalize(dir); + /* Interocular offset of zero means either no stereo, or stereo without + * spherical stereo. + * Convergence distance is FLT_MAX in the case of parallel convergence mode, + * no need to mdify direction in this case either. + */ + if(kernel_data.cam.interocular_offset == 0.0f || + convergence_distance == FLT_MAX) + { + return normalized_dir; + } + + float3 screenpos = pos + (normalized_dir * convergence_distance); + return normalize(screenpos - newpos); +} + +CCL_NAMESPACE_END +#endif /* __KERNEL_PROJECTION_CL__ */ |