Fix #33256: cycles Z pass for orthographic camera was not right, now is more
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 21 Nov 2012 13:00:57 +0000 (13:00 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 21 Nov 2012 13:00:57 +0000 (13:00 +0000)
useful for e.g. fog in compositing.

intern/cycles/kernel/kernel_camera.h
intern/cycles/kernel/kernel_passes.h
intern/cycles/kernel/shaders/node_texture_coordinate.osl
intern/cycles/kernel/svm/svm_tex_coord.h

index 1b2fe8c56ee4889f70179df854edb5b63e605b68..abc63d99c74ae7de04ae324abfe43c3fb365f5f4 100644 (file)
@@ -229,5 +229,20 @@ __device void camera_sample(KernelGlobals *kg, int x, int y, float filter_u, flo
                camera_sample_panorama(kg, raster_x, raster_y, lens_u, lens_v, ray);
 }
 
+/* Utilities */
+
+__device_inline float camera_distance(KernelGlobals *kg, float3 P)
+{
+       Transform cameratoworld = kernel_data.cam.cameratoworld;
+       float3 camP = make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w);
+
+       if(kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
+               float3 camD = make_float3(cameratoworld.x.z, cameratoworld.y.z, cameratoworld.z.z);
+               return fabsf(dot((P - camP), camD));
+       }
+       else
+               return len(P - camP);
+}
+
 CCL_NAMESPACE_END
 
index 42733d691e0a1d1772d41e9254174237fc78d7dd..7f8b611ba14baa74955777982333aeca10b3fff5 100644 (file)
@@ -52,9 +52,7 @@ __device_inline void kernel_write_data_passes(KernelGlobals *kg, __global float
        if(!(path_flag & PATH_RAY_TRANSPARENT)) {
                if(sample == 0) {
                        if(flag & PASS_DEPTH) {
-                               Transform tfm = kernel_data.cam.worldtocamera;
-                               float depth = len(transform_point(&tfm, sd->P));
-
+                               float depth = camera_distance(kg, sd->P);
                                kernel_write_pass_float(buffer + kernel_data.film.pass_depth, sample, depth);
                        }
                        if(flag & PASS_OBJECT_ID) {
index 791838dfffec9d8224799f705d95f61478cf08e8..099116c33c0139203abf71138bef5a38147beb85 100644 (file)
@@ -77,5 +77,7 @@ shader node_texture_coordinate(
                Camera += Dy(Camera);
                Window += Dy(Window);
        }
+
+       Window[2] = 0.0;
 }
 
index 8ca7dff3970766ebef3ad660c406ed339e079533..f817c00dc8ac4d98bb4cae2b239aa6357d304ee7 100644 (file)
@@ -20,17 +20,19 @@ CCL_NAMESPACE_BEGIN
 
 /* Texture Coordinate Node */
 
-__device_inline float3 svm_background_offset(KernelGlobals *kg)
+__device_inline float3 svm_background_position(KernelGlobals *kg, float3 P)
 {
        Transform cameratoworld = kernel_data.cam.cameratoworld;
-       return make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w);
+       float3 camP = make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w);
+
+       return camP + P;
 }
 
 __device_inline float3 svm_world_to_ndc(KernelGlobals *kg, ShaderData *sd, float3 P)
 {
        if(kernel_data.cam.type != CAMERA_PANORAMA) {
                if(sd->object == ~0)
-                       P += svm_background_offset(kg);
+                       P = svm_background_position(kg, P);
 
                Transform tfm = kernel_data.cam.worldtondc;
                return transform_perspective(&tfm, P);
@@ -78,11 +80,12 @@ __device void svm_node_tex_coord(KernelGlobals *kg, ShaderData *sd, float *stack
                        if(sd->object != ~0)
                                data = transform_point(&tfm, sd->P);
                        else
-                               data = transform_point(&tfm, sd->P + svm_background_offset(kg));
+                               data = transform_point(&tfm, svm_background_position(kg, sd->P));
                        break;
                }
                case NODE_TEXCO_WINDOW: {
                        data = svm_world_to_ndc(kg, sd, sd->P);
+                       data.z = 0.0f;
                        break;
                }
                case NODE_TEXCO_REFLECTION: {
@@ -135,11 +138,12 @@ __device void svm_node_tex_coord_bump_dx(KernelGlobals *kg, ShaderData *sd, floa
                        if(sd->object != ~0)
                                data = transform_point(&tfm, sd->P + sd->dP.dx);
                        else
-                               data = transform_point(&tfm, sd->P + sd->dP.dx + svm_background_offset(kg));
+                               data = transform_point(&tfm, svm_background_position(kg, sd->P + sd->dP.dx));
                        break;
                }
                case NODE_TEXCO_WINDOW: {
                        data = svm_world_to_ndc(kg, sd, sd->P + sd->dP.dx);
+                       data.z = 0.0f;
                        break;
                }
                case NODE_TEXCO_REFLECTION: {
@@ -195,11 +199,12 @@ __device void svm_node_tex_coord_bump_dy(KernelGlobals *kg, ShaderData *sd, floa
                        if(sd->object != ~0)
                                data = transform_point(&tfm, sd->P + sd->dP.dy);
                        else
-                               data = transform_point(&tfm, sd->P + sd->dP.dy + svm_background_offset(kg));
+                               data = transform_point(&tfm, svm_background_position(kg, sd->P + sd->dP.dy));
                        break;
                }
                case NODE_TEXCO_WINDOW: {
                        data = svm_world_to_ndc(kg, sd, sd->P + sd->dP.dy);
+                       data.z = 0.0f;
                        break;
                }
                case NODE_TEXCO_REFLECTION: {