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-03-08 23:52:58 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2012-03-08 23:52:58 +0400
commit9b8dae71a5e0f5cccb4031dbe5f07aae01744c82 (patch)
tree8a575ab4a9e6835eef2175209ee323df883fd0ac /intern/cycles/kernel
parent0f3e1821eae40c7cebfcf199b58370971b57fa35 (diff)
Cycles: support for environment texture "Mirror Ball" projection mode, next to
existing "Equirectangular". This projection is useful to create light probes from a chrome ball placed in a real scene. It expects as input a photograph of the chrome ball, cropped so the ball just fits inside the image boundaries. Example setup with panorama camera and mixing two (poor quality) photographs from different viewpoints to avoid stretching and hide the photographer: http://www.pasteall.org/pic/28036
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r--intern/cycles/kernel/kernel_montecarlo.h32
-rw-r--r--intern/cycles/kernel/svm/svm_image.h11
2 files changed, 42 insertions, 1 deletions
diff --git a/intern/cycles/kernel/kernel_montecarlo.h b/intern/cycles/kernel/kernel_montecarlo.h
index 66bd0ee9998..68f007cfd97 100644
--- a/intern/cycles/kernel/kernel_montecarlo.h
+++ b/intern/cycles/kernel/kernel_montecarlo.h
@@ -224,6 +224,38 @@ __device float3 equirectangular_to_direction(float u, float v)
cos(theta));
}
+/* Mirror Ball <-> Cartesion direction */
+
+__device float3 mirrorball_to_direction(float u, float v)
+{
+ /* point on sphere */
+ float3 dir;
+
+ dir.x = 2.0f*u - 1.0f;
+ dir.z = 2.0f*v - 1.0f;
+ dir.y = -sqrt(max(1.0f - dir.x*dir.x - dir.z*dir.z, 0.0f));
+
+ /* reflection */
+ float3 I = make_float3(0.0f, -1.0f, 0.0f);
+
+ return 2.0f*dot(dir, I)*dir - I;
+}
+
+__device float2 direction_to_mirrorball(float3 dir)
+{
+ /* inverse of mirrorball_to_direction */
+ dir.y -= 1.0f;
+
+ float div = 2.0f*sqrt(max(-0.5f*dir.y, 0.0f));
+ if(div > 0.0f)
+ dir /= div;
+
+ float u = 0.5f*(dir.x + 1.0f);
+ float v = 0.5f*(dir.z + 1.0f);
+
+ return make_float2(u, v);
+}
+
CCL_NAMESPACE_END
#endif /* __KERNEL_MONTECARLO_CL__ */
diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h
index 3d737b483cb..eddd0f7034a 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -171,11 +171,20 @@ __device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float
{
uint id = node.y;
uint co_offset, out_offset, alpha_offset, srgb;
+ uint projection = node.w;
decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb);
float3 co = stack_load_float3(stack, co_offset);
- float2 uv = direction_to_equirectangular(co);
+ float2 uv;
+
+ co = normalize(co);
+
+ if(projection == 0)
+ uv = direction_to_equirectangular(co);
+ else
+ uv = direction_to_mirrorball(co);
+
float4 f = svm_image_texture(kg, id, uv.x, uv.y);
float3 r = make_float3(f.x, f.y, f.z);