From 6b91fb706d60033af9d2a1b09015d99ffc7e3bbc Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 11 Mar 2016 21:41:16 +0500 Subject: Cycles: Optimize derivatives calculation by using pre-calculated dx/dy We've got pixel-wide world-space derivatives which we can use in the perspective camera sampling. This allows to get rid of two calls to transform_direction() function. In theory we can save two transform_perspective() calls if we'll also save pre-calculated camera-space dx/dy. --- intern/cycles/kernel/kernel_camera.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index db2f45ce096..31a578e0b44 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -114,18 +114,20 @@ ccl_device void camera_sample_perspective(KernelGlobals *kg, float raster_x, flo /* ray differential */ ray->dP = differential3_zero(); - tD = transform_direction(&cameratoworld, Pcamera); - float3 Pdiff = spherical_stereo_position(kg, tD, Pcamera); - float3 Ddiff = spherical_stereo_direction(kg, tD, Pcamera, Pdiff); + float3 tD_diff = transform_direction(&cameratoworld, Pcamera); + float3 Pdiff = spherical_stereo_position(kg, tD_diff, Pcamera); + float3 Ddiff = spherical_stereo_direction(kg, tD_diff, Pcamera, Pdiff); - tP = transform_perspective(&rastertocamera, make_float3(raster_x + 1.0f, raster_y, 0.0f)); - tD = transform_direction(&cameratoworld, tP); + tP = transform_perspective(&rastertocamera, + make_float3(raster_x + 1.0f, raster_y, 0.0f)); + tD = tD_diff + float4_to_float3(kernel_data.cam.dx); Pcamera = spherical_stereo_position(kg, tD, tP); ray->dD.dx = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff; ray->dP.dx = Pcamera - Pdiff; - tP = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y + 1.0f, 0.0f)); - tD = transform_direction(&cameratoworld, tP); + tP = transform_perspective(&rastertocamera, + make_float3(raster_x, raster_y + 1.0f, 0.0f)); + tD = tD_diff + float4_to_float3(kernel_data.cam.dy); Pcamera = spherical_stereo_position(kg, tD, tP); ray->dD.dy = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff; /* dP.dy is zero, since the omnidirectional panorama only shift the eyes horizontally */ -- cgit v1.2.3