diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-05 23:44:35 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-05 23:44:35 +0400 |
commit | c0331cfc090f218537937294fab0abfecc89e2aa (patch) | |
tree | 17d76a2ad39ad0e9dc4993991deadc185c93c8cc /intern/cycles | |
parent | 8103381ded923a097eae5a0ba012ae41847a83ad (diff) |
Cycles: minor refactoring of fisheye code to fit code style.
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/kernel/kernel_camera.h | 33 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_montecarlo.h | 36 |
2 files changed, 34 insertions, 35 deletions
diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index 6d49fd96dd7..220ebec13ce 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -134,19 +134,16 @@ __device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, floa /* Panorama Camera */ -__device float3 panorama_to_direction(KernelGlobals *kg, float u, float v, Ray *ray) +__device float3 panorama_to_direction(KernelGlobals *kg, float u, float v) { - switch (kernel_data.cam.panorama_type) { - case PANORAMA_EQUIRECTANGULAR: - return equirectangular_to_direction(u, v); - break; - case PANORAMA_FISHEYE_EQUIDISTANT: - return fisheye_to_direction(u, v, kernel_data.cam.fisheye_fov, ray); - break; - case PANORAMA_FISHEYE_EQUISOLID: - default: - 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, ray); - break; + switch(kernel_data.cam.panorama_type) { + case PANORAMA_EQUIRECTANGULAR: + return equirectangular_to_direction(u, v); + case PANORAMA_FISHEYE_EQUIDISTANT: + return fisheye_to_direction(u, v, kernel_data.cam.fisheye_fov); + case PANORAMA_FISHEYE_EQUISOLID: + default: + 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); } } @@ -165,7 +162,13 @@ __device void camera_sample_panorama(KernelGlobals *kg, float raster_x, float ra ray->t = FLT_MAX; #endif - ray->D = panorama_to_direction(kg, Pcamera.x, Pcamera.y, ray); + ray->D = panorama_to_direction(kg, Pcamera.x, Pcamera.y); + + /* indicates ray should not receive any light, outside of the lens */ + if(len_squared(ray->D) == 0.0f) { + ray->t = 0.0f; + return; + } /* transform ray from camera to world */ Transform cameratoworld = kernel_data.cam.cameratoworld; @@ -185,10 +188,10 @@ __device void camera_sample_panorama(KernelGlobals *kg, float raster_x, float ra ray->dP.dy = make_float3(0.0f, 0.0f, 0.0f); Pcamera = transform_perspective(&rastertocamera, make_float3(raster_x + 1.0f, raster_y, 0.0f)); - ray->dD.dx = normalize(transform_direction(&cameratoworld, panorama_to_direction(kg, Pcamera.x, Pcamera.y, ray))) - ray->D; + ray->dD.dx = normalize(transform_direction(&cameratoworld, panorama_to_direction(kg, Pcamera.x, Pcamera.y))) - ray->D; Pcamera = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y + 1.0f, 0.0f)); - ray->dD.dy = normalize(transform_direction(&cameratoworld, panorama_to_direction(kg, Pcamera.x, Pcamera.y, ray))) - ray->D; + ray->dD.dy = normalize(transform_direction(&cameratoworld, panorama_to_direction(kg, Pcamera.x, Pcamera.y))) - ray->D; #endif } diff --git a/intern/cycles/kernel/kernel_montecarlo.h b/intern/cycles/kernel/kernel_montecarlo.h index ba24c2ea402..f51ce263ea2 100644 --- a/intern/cycles/kernel/kernel_montecarlo.h +++ b/intern/cycles/kernel/kernel_montecarlo.h @@ -91,8 +91,8 @@ __device_inline void sample_uniform_hemisphere(const float3 N, float3 *omega_in, float *pdf) { float z = randu; - float r = sqrtf(max(0.f, 1.f - z*z)); - float phi = 2.f * M_PI_F * randv; + float r = sqrtf(max(0.0f, 1.0f - z*z)); + float phi = 2.0f * M_PI_F * randv; float x = r * cosf(phi); float y = r * sinf(phi); @@ -226,22 +226,20 @@ __device float3 equirectangular_to_direction(float u, float v) /* Fisheye <- Cartesian direction */ -__device float3 fisheye_to_direction(float u, float v, float fov, Ray *ray) +__device float3 fisheye_to_direction(float u, float v, float fov) { - u = (u - 0.5f) * 2.f; - v = (v - 0.5f) * 2.f; + u = (u - 0.5f) * 2.0f; + v = (v - 0.5f) * 2.0f; float r = sqrt(u*u + v*v); - if (r > 1.0) { - ray->t = 0.f; - return make_float3(0.f,0.f,0.f); - } + if(r > 1.0f) + return make_float3(0.0f, 0.0f, 0.0f); - float phi = acosf((r!=0.f)?u/r:0.f); + float phi = acosf((r != 0.0f)? u/r: 0.0f); float theta = asinf(r) * (fov / M_PI_F); - if (v < 0.f) phi = -phi; + if(v < 0.0f) phi = -phi; return make_float3( cosf(theta), @@ -250,23 +248,21 @@ __device float3 fisheye_to_direction(float u, float v, float fov, Ray *ray) ); } -__device float3 fisheye_equisolid_to_direction(float u, float v, float lens, float fov, float width, float height, Ray *ray) +__device float3 fisheye_equisolid_to_direction(float u, float v, float lens, float fov, float width, float height) { u = (u - 0.5f) * width; v = (v - 0.5f) * height; - float rmax = 2.f * lens * sinf(fov * 0.25f); + float rmax = 2.0f * lens * sinf(fov * 0.25f); float r = sqrt(u*u + v*v); - if (r > rmax) { - ray->t = 0.f; - return make_float3(0.f,0.f,0.f); - } + if(r > rmax) + return make_float3(0.0f, 0.0f, 0.0f); - float phi = acosf((r!=0.f)?u/r:0.f); - float theta = 2.f * asinf(r/(2.f * lens)); + float phi = acosf((r != 0.0f)? u/r: 0.0f); + float theta = 2.0f * asinf(r/(2.0f * lens)); - if (v < 0.f) phi = -phi; + if(v < 0.0f) phi = -phi; return make_float3( cosf(theta), |