Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/kernel_projection.h
| Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | ccl_device float3 spherical_to_direction(float theta, float phi) | ||||
| return make_float3( | return make_float3( | ||||
| sinf(theta)*cosf(phi), | sinf(theta)*cosf(phi), | ||||
| sinf(theta)*sinf(phi), | sinf(theta)*sinf(phi), | ||||
| cosf(theta)); | cosf(theta)); | ||||
| } | } | ||||
| /* Equirectangular coordinates <-> Cartesian direction */ | /* Equirectangular coordinates <-> Cartesian direction */ | ||||
| ccl_device float2 direction_to_equirectangular(float3 dir) | #define FULL_RANGE make_float4(-M_2_PI_F, M_PI_F, -M_PI_F, M_PI_F) | ||||
sergey: You're too fast with this. What i thought is if there's no speed regressions (because compiler… | |||||
| ccl_device float2 direction_to_equirectangular(float3 dir, float4 range) | |||||
| { | { | ||||
| float u = -atan2f(dir.y, dir.x)/(M_2PI_F) + 0.5f; | float u = (atan2f(dir.y, dir.x) - range.y) / range.x; | ||||
| float v = atan2f(dir.z, hypotf(dir.x, dir.y))/M_PI_F + 0.5f; | float v = (acosf(dir.z / len(dir)) - range.w) / range.z; | ||||
| return make_float2(u, v); | return make_float2(u, v); | ||||
| } | } | ||||
| ccl_device float3 equirectangular_to_direction(float u, float v) | ccl_device float3 equirectangular_to_direction(float u, float v, float4 range) | ||||
| { | { | ||||
| float phi = M_PI_F*(1.0f - 2.0f*u); | float phi = range.x*u + range.y; | ||||
| float theta = M_PI_F*(1.0f - v); | float theta = range.z*v + range.w; | ||||
| return make_float3( | return make_float3( | ||||
| sinf(theta)*cosf(phi), | sinf(theta)*cosf(phi), | ||||
| sinf(theta)*sinf(phi), | sinf(theta)*sinf(phi), | ||||
| cosf(theta)); | cosf(theta)); | ||||
| } | } | ||||
| /* Fisheye <-> Cartesian direction */ | /* Fisheye <-> Cartesian direction */ | ||||
Not Done Inline ActionsPicky: I would just use _range as a suffix name (to avoid camera-specific naming since it might be useful in general). sergey: Picky: I would just use `_range` as a suffix name (to avoid camera-specific naming since it… | |||||
| ccl_device float2 direction_to_fisheye(float3 dir, float fov) | ccl_device float2 direction_to_fisheye(float3 dir, float fov) | ||||
| { | { | ||||
| float r = atan2f(sqrtf(dir.y*dir.y + dir.z*dir.z), dir.x) / fov; | float r = atan2f(sqrtf(dir.y*dir.y + dir.z*dir.z), dir.x) / fov; | ||||
| float phi = atan2f(dir.z, dir.y); | float phi = atan2f(dir.z, dir.y); | ||||
| float u = r * cosf(phi) + 0.5f; | float u = r * cosf(phi) + 0.5f; | ||||
| float v = r * sinf(phi) + 0.5f; | float v = r * sinf(phi) + 0.5f; | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | ccl_device float2 direction_to_mirrorball(float3 dir) | ||||
| return make_float2(u, v); | return make_float2(u, v); | ||||
| } | } | ||||
| ccl_device float3 panorama_to_direction(KernelGlobals *kg, float u, float v) | ccl_device float3 panorama_to_direction(KernelGlobals *kg, float u, float v) | ||||
| { | { | ||||
| switch(kernel_data.cam.panorama_type) { | switch(kernel_data.cam.panorama_type) { | ||||
| case PANORAMA_EQUIRECTANGULAR: | case PANORAMA_EQUIRECTANGULAR: | ||||
| return equirectangular_to_direction(u, v); | return equirectangular_to_direction(u, v, kernel_data.cam.equirectangular_range); | ||||
| case PANORAMA_FISHEYE_EQUIDISTANT: | case PANORAMA_FISHEYE_EQUIDISTANT: | ||||
| return fisheye_to_direction(u, v, kernel_data.cam.fisheye_fov); | return fisheye_to_direction(u, v, kernel_data.cam.fisheye_fov); | ||||
| case PANORAMA_FISHEYE_EQUISOLID: | case PANORAMA_FISHEYE_EQUISOLID: | ||||
| default: | default: | ||||
| return fisheye_equisolid_to_direction(u, v, kernel_data.cam.fisheye_lens, | return fisheye_equisolid_to_direction(u, v, kernel_data.cam.fisheye_lens, | ||||
| kernel_data.cam.fisheye_fov, kernel_data.cam.sensorwidth, kernel_data.cam.sensorheight); | kernel_data.cam.fisheye_fov, kernel_data.cam.sensorwidth, kernel_data.cam.sensorheight); | ||||
| } | } | ||||
| } | } | ||||
| ccl_device float2 direction_to_panorama(KernelGlobals *kg, float3 dir) | ccl_device float2 direction_to_panorama(KernelGlobals *kg, float3 dir) | ||||
| { | { | ||||
| switch(kernel_data.cam.panorama_type) { | switch(kernel_data.cam.panorama_type) { | ||||
| case PANORAMA_EQUIRECTANGULAR: | case PANORAMA_EQUIRECTANGULAR: | ||||
| return direction_to_equirectangular(dir); | return direction_to_equirectangular(dir, kernel_data.cam.equirectangular_range); | ||||
| case PANORAMA_FISHEYE_EQUIDISTANT: | case PANORAMA_FISHEYE_EQUIDISTANT: | ||||
| return direction_to_fisheye(dir, kernel_data.cam.fisheye_fov); | return direction_to_fisheye(dir, kernel_data.cam.fisheye_fov); | ||||
| case PANORAMA_FISHEYE_EQUISOLID: | case PANORAMA_FISHEYE_EQUISOLID: | ||||
| default: | default: | ||||
| return direction_to_fisheye_equisolid(dir, kernel_data.cam.fisheye_lens, | return direction_to_fisheye_equisolid(dir, kernel_data.cam.fisheye_lens, | ||||
| kernel_data.cam.sensorwidth, kernel_data.cam.sensorheight); | kernel_data.cam.sensorwidth, kernel_data.cam.sensorheight); | ||||
| } | } | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
| #endif /* __KERNEL_PROJECTION_CL__ */ | #endif /* __KERNEL_PROJECTION_CL__ */ | ||||
You're too fast with this. What i thought is if there's no speed regressions (because compiler could substitude the constant values to the expression) is to have something more like:
ccl_device_inline float2 direction_to_equirectangular(float3 dir) { return direction_to_equirectangular_range(dir, make_float4(-M_2_PI_F, M_PI_F, -M_PI_F, M_PI_F)) } ccl_device float2 direction_to_equirectangular_range(float3 dir, float4 range) { /* ... */ }