diff options
-rw-r--r-- | intern/cycles/kernel/kernel_camera.h | 15 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_passes.h | 4 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_texture_coordinate.osl | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_tex_coord.h | 17 |
4 files changed, 29 insertions, 9 deletions
diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index 1b2fe8c56ee..abc63d99c74 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -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 diff --git a/intern/cycles/kernel/kernel_passes.h b/intern/cycles/kernel/kernel_passes.h index 42733d691e0..7f8b611ba14 100644 --- a/intern/cycles/kernel/kernel_passes.h +++ b/intern/cycles/kernel/kernel_passes.h @@ -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) { diff --git a/intern/cycles/kernel/shaders/node_texture_coordinate.osl b/intern/cycles/kernel/shaders/node_texture_coordinate.osl index 791838dfffe..099116c33c0 100644 --- a/intern/cycles/kernel/shaders/node_texture_coordinate.osl +++ b/intern/cycles/kernel/shaders/node_texture_coordinate.osl @@ -77,5 +77,7 @@ shader node_texture_coordinate( Camera += Dy(Camera); Window += Dy(Window); } + + Window[2] = 0.0; } diff --git a/intern/cycles/kernel/svm/svm_tex_coord.h b/intern/cycles/kernel/svm/svm_tex_coord.h index 8ca7dff3970..f817c00dc8a 100644 --- a/intern/cycles/kernel/svm/svm_tex_coord.h +++ b/intern/cycles/kernel/svm/svm_tex_coord.h @@ -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: { |