From c53b20b683cbc6c198f2ec1e78e1b8a16e83d2b3 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 8 Jun 2013 10:51:33 +0000 Subject: Cycles: window texture coordinates now work with orthographic cameras, this was an old issue since the first version. --- intern/cycles/kernel/kernel_camera.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'intern/cycles/kernel/kernel_camera.h') diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index a23586a53a4..4b9ef8893f7 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -245,6 +245,12 @@ __device void camera_sample(KernelGlobals *kg, int x, int y, float filter_u, flo /* Utilities */ +__device_inline float3 camera_position(KernelGlobals *kg) +{ + Transform cameratoworld = kernel_data.cam.cameratoworld; + return make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w); +} + __device_inline float camera_distance(KernelGlobals *kg, float3 P) { Transform cameratoworld = kernel_data.cam.cameratoworld; @@ -258,5 +264,30 @@ __device_inline float camera_distance(KernelGlobals *kg, float3 P) return len(P - camP); } +__device_inline float3 camera_world_to_ndc(KernelGlobals *kg, ShaderData *sd, float3 P) +{ + if(kernel_data.cam.type != CAMERA_PANORAMA) { + /* perspective / ortho */ + if(sd->object == ~0 && kernel_data.cam.type == CAMERA_PERSPECTIVE) + P += camera_position(kg); + + Transform tfm = kernel_data.cam.worldtondc; + return transform_perspective(&tfm, P); + } + else { + /* panorama */ + Transform tfm = kernel_data.cam.worldtocamera; + + if(sd->object != ~0) + P = normalize(transform_point(&tfm, P)); + else + P = normalize(transform_direction(&tfm, P)); + + float2 uv = direction_to_panorama(kg, P); + + return make_float3(uv.x, uv.y, 0.0f); + } +} + CCL_NAMESPACE_END -- cgit v1.2.3