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:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2012-02-28 20:44:54 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2012-02-28 20:44:54 +0400
commit4a903395194aef1cfe97e4d50d73320a72280cf3 (patch)
tree056c15cc54f0d0446aef69c9b7f299023c01a69f /intern/cycles/kernel
parent0052cbed0dadafce44f818d3d2016254c3d914d0 (diff)
Cycles: support for camera rendering an environment map with equirectangular
environment map, by enabling the Panorama option in the camera. http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Camera#Panorama The focal length or sensor settings are not used, the UI can be tweaked still to communicate this, also panorama should probably become a proper camera type like perspective or ortho.
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r--intern/cycles/kernel/kernel_camera.h44
-rw-r--r--intern/cycles/kernel/kernel_displace.h4
-rw-r--r--intern/cycles/kernel/kernel_light.h8
-rw-r--r--intern/cycles/kernel/kernel_montecarlo.h11
-rw-r--r--intern/cycles/kernel/kernel_types.h10
5 files changed, 61 insertions, 16 deletions
diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h
index 2dbdd076891..251b2c280da 100644
--- a/intern/cycles/kernel/kernel_camera.h
+++ b/intern/cycles/kernel/kernel_camera.h
@@ -122,6 +122,44 @@ __device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, floa
#endif
}
+/* Environment Camera */
+
+__device void camera_sample_environment(KernelGlobals *kg, float raster_x, float raster_y, Ray *ray)
+{
+ Transform rastertocamera = kernel_data.cam.rastertocamera;
+ float3 Pcamera = transform(&rastertocamera, make_float3(raster_x, raster_y, 0.0f));
+
+ /* create ray form raster position */
+ ray->P = make_float3(0.0, 0.0f, 0.0f);
+ ray->D = equirectangular_to_direction(Pcamera.x, Pcamera.y);
+
+ /* transform ray from camera to world */
+ Transform cameratoworld = kernel_data.cam.cameratoworld;
+
+ ray->P = transform(&cameratoworld, ray->P);
+ ray->D = transform_direction(&cameratoworld, ray->D);
+ ray->D = normalize(ray->D);
+
+#ifdef __RAY_DIFFERENTIALS__
+ /* ray differential */
+ ray->dP.dx = make_float3(0.0f, 0.0f, 0.0f);
+ ray->dP.dy = make_float3(0.0f, 0.0f, 0.0f);
+
+ Pcamera = transform(&rastertocamera, make_float3(raster_x + 1.0f, raster_y, 0.0f));
+ ray->dD.dx = equirectangular_to_direction(Pcamera.x, Pcamera.y) - ray->D;
+
+ Pcamera = transform(&rastertocamera, make_float3(raster_x, raster_y + 1.0f, 0.0f));
+ ray->dD.dy = equirectangular_to_direction(Pcamera.x, Pcamera.y) - ray->D;
+#endif
+
+#ifdef __CAMERA_CLIPPING__
+ /* clipping */
+ ray->t = kernel_data.cam.cliplength;
+#else
+ ray->t = FLT_MAX;
+#endif
+}
+
/* Common */
__device void camera_sample(KernelGlobals *kg, int x, int y, float filter_u, float filter_v, float lens_u, float lens_v, Ray *ray)
@@ -134,10 +172,12 @@ __device void camera_sample(KernelGlobals *kg, int x, int y, float filter_u, flo
//ray->time = lerp(time_t, kernel_data.cam.shutter_open, kernel_data.cam.shutter_close);
/* sample */
- if(kernel_data.cam.ortho)
+ if(kernel_data.cam.type == CAMERA_PERSPECTIVE)
+ camera_sample_perspective(kg, raster_x, raster_y, lens_u, lens_v, ray);
+ else if(kernel_data.cam.type == CAMERA_ORTHOGRAPHIC)
camera_sample_orthographic(kg, raster_x, raster_y, ray);
else
- camera_sample_perspective(kg, raster_x, raster_y, lens_u, lens_v, ray);
+ camera_sample_environment(kg, raster_x, raster_y, ray);
}
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/kernel_displace.h b/intern/cycles/kernel/kernel_displace.h
index 73666892cf3..f4b33605f5b 100644
--- a/intern/cycles/kernel/kernel_displace.h
+++ b/intern/cycles/kernel/kernel_displace.h
@@ -41,9 +41,11 @@ __device void kernel_shader_evaluate(KernelGlobals *kg, uint4 *input, float4 *ou
else { // SHADER_EVAL_BACKGROUND
/* setup ray */
Ray ray;
+ float u = __int_as_float(in.x);
+ float v = __int_as_float(in.y);
ray.P = make_float3(0.0f, 0.0f, 0.0f);
- ray.D = make_float3(__int_as_float(in.x), __int_as_float(in.y), __int_as_float(in.z));
+ ray.D = equirectangular_to_direction(u, v);
ray.t = 0.0f;
#ifdef __RAY_DIFFERENTIALS__
diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index aa125180a94..42260577069 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -120,13 +120,9 @@ __device float3 background_light_sample(KernelGlobals *kg, float randu, float ra
float du = (randu - cdf_u.y) / (cdf_next_u.y - cdf_u.y);
float u = (index_u + du) / res;
- /* spherical coordinates */
- float theta = v * M_PI_F;
- float phi = u * M_PI_F * 2.0f;
-
/* compute pdf */
float denom = cdf_last_u.x * cdf_last_v.x;
- float sin_theta = sinf(theta);
+ float sin_theta = sinf(M_PI_F * v);
if(sin_theta == 0.0f || denom == 0.0f)
*pdf = 0.0f;
@@ -136,7 +132,7 @@ __device float3 background_light_sample(KernelGlobals *kg, float randu, float ra
*pdf *= kernel_data.integrator.pdf_lights;
/* compute direction */
- return spherical_to_direction(theta, phi);
+ return -equirectangular_to_direction(u, v);
}
__device float background_light_pdf(KernelGlobals *kg, float3 direction)
diff --git a/intern/cycles/kernel/kernel_montecarlo.h b/intern/cycles/kernel/kernel_montecarlo.h
index 9776baf65e4..66bd0ee9998 100644
--- a/intern/cycles/kernel/kernel_montecarlo.h
+++ b/intern/cycles/kernel/kernel_montecarlo.h
@@ -185,7 +185,7 @@ __device float2 regular_polygon_sample(float corners, float rotation, float u, f
return make_float2(cr*p.x - sr*p.y, sr*p.x + cr*p.y);
}
-/* Spherical coordinates <-> Cartesion direction */
+/* Spherical coordinates <-> Cartesian direction */
__device float2 direction_to_spherical(float3 dir)
{
@@ -203,11 +203,11 @@ __device float3 spherical_to_direction(float theta, float phi)
cosf(theta));
}
-/* Equirectangular */
+/* Equirectangular coordinates <-> Cartesian direction */
__device float2 direction_to_equirectangular(float3 dir)
{
- float u = (atan2f(dir.y, dir.x) + M_PI_F)/(2.0f*M_PI_F);
+ float u = -atan2f(dir.y, dir.x)/(2.0f*M_PI_F) + 0.5f;
float v = atan2f(dir.z, hypotf(dir.x, dir.y))/M_PI_F + 0.5f;
return make_float2(u, v);
@@ -215,9 +215,8 @@ __device float2 direction_to_equirectangular(float3 dir)
__device float3 equirectangular_to_direction(float u, float v)
{
- /* XXX check correctness? */
- float theta = M_PI_F*v;
- float phi = 2.0f*M_PI_F*u;
+ float phi = M_PI_F*(1.0f - 2.0f*u);
+ float theta = M_PI_F*(1.0f - v);
return make_float3(
sin(theta)*cos(phi),
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 9f4d5b00e2c..61335d5f9fa 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -240,6 +240,14 @@ typedef enum LightType {
LIGHT_AREA
} LightType;
+/* Camera Type */
+
+enum CameraType {
+ CAMERA_PERSPECTIVE,
+ CAMERA_ORTHOGRAPHIC,
+ CAMERA_ENVIRONMENT
+};
+
/* Differential */
typedef struct differential3 {
@@ -387,7 +395,7 @@ typedef struct ShaderData {
typedef struct KernelCamera {
/* type */
- int ortho;
+ int type;
int pad1, pad2, pad3;
/* matrices */