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.
This commit is contained in:
Sergey Sharybin 2016-03-11 21:41:16 +05:00
parent a8c87bad22
commit 6b91fb706d
1 changed files with 9 additions and 7 deletions

View File

@ -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 */