33 #include <optixu/optixu_matrix.h> 35 #include <cugar/linalg/vector.h> 54 #if !defined(OPTIX_COMPILATION) 55 FERMAT_HOST_DEVICE
Camera() :
56 fov(60.0f *
float(M_PI) / 180.0f)
58 eye = make_float3(0, -1, 0);
59 aim = make_float3(0, 0, 0);
60 up = make_float3(0, 0, 1);
61 dx = make_float3(1, 0, 0);
65 FERMAT_HOST_DEVICE Camera rotate(
const float2 rot)
const 68 optix::Matrix<4, 4> rot_X = optix::Matrix<4, 4>::rotate(rot.x, dx);
70 optix::Matrix<4, 4> rot_Y = optix::Matrix<4, 4>::rotate(rot.y, make_float3(0,1,0));
72 const float4 heye = make_float4(eye.x, eye.y, eye.z, 1.0f);
73 const float4 haim = make_float4(aim.x, aim.y, aim.z, 1.0f);
74 const float4 hup = make_float4(up.x, up.y, up.z, 0.0f);
75 const float4 hdx = make_float4(dx.x, dx.y, dx.z, 0.0f);
76 const float4 tdir = rot_Y * rot_X * (heye - haim);
77 const float4 teye = haim + tdir;
78 const float4 tup = rot_Y * rot_X * hup;
79 const float4 tdx = rot_Y * rot_X * hdx;
81 r.eye = make_float3(teye.x, teye.y, teye.z);
83 r.up = make_float3(tup.x, tup.y, tup.z);
84 r.dx = make_float3(tdx.x, tdx.y, tdx.z);
88 FERMAT_HOST_DEVICE Camera walk(
const float delta)
const 91 r.eye = eye + (aim - eye)*delta;
92 r.aim = aim + (aim - eye)*delta;
94 r.dx = normalize(cross(r.aim - r.eye, r.up));
98 FERMAT_HOST_DEVICE Camera pan(
const float2 delta)
const 101 r.eye = eye + up*delta.y - dx * delta.x;
102 r.aim = aim + up*delta.y - dx * delta.x;
108 FERMAT_HOST_DEVICE Camera zoom(
const float delta)
const 115 r.fov = fov * (1.0f + delta);
116 r.fov = fmaxf(fminf(r.fov,
float(M_PI) - 0.1f), 0.05f);
122 float square_pixel_focal_length(
124 const uint32 res_y)
const 126 const float t = tanf(fov / 2);
127 return (
float(res_x * res_y) / 4.0f) / (t*t);
132 float square_screen_focal_length()
const 134 const float t = tanf(fov / 2);
135 return (1.0f / 4.0f) / (t*t);
144 float ulen, vlen, wlen;
145 W.x = lookat.x - eye.x;
146 W.y = lookat.y - eye.y;
147 W.z = lookat.z - eye.z;
149 wlen = sqrtf(cugar::dot(W, W));
151 U = cugar::normalize(cugar::cross(W, up));
152 V = cugar::normalize(cugar::cross(U, W));
154 ulen = wlen * tanf(hfov / 2.0f);
159 vlen = ulen / aspect_ratio;
170 camera_frame(camera.eye, camera.aim, camera.up, camera.fov, aspect_ratio, U, V, W);
184 return d.x*U + d.y*V + W;
197 const float Ix = dot(I, U) / cugar::square_length(U);
198 const float Iy = dot(I, V) / cugar::square_length(V);
213 const float Ix = dot(I, U) / cugar::square_length(U);
214 const float Iy = dot(I, V) / cugar::square_length(V);
216 if (Ix >= -1.0f && Ix <= 1.0f &&
217 Iy >= -1.0f && Iy <= 1.0f)
219 if (out_x) *out_x = Ix;
220 if (out_y) *out_y = Iy;
222 const float cos_theta = dot(out, W) / W_len;
223 return square_focal_length / (cos_theta * cos_theta * cos_theta * cos_theta);
239 const float Ix = dot(I, U) / cugar::square_length(U);
240 const float Iy = dot(I, V) / cugar::square_length(V);
242 if (Ix >= -1.0f && Ix <= 1.0f &&
243 Iy >= -1.0f && Iy <= 1.0f)
245 const float cos_theta = dot(out, W) / W_len;
247 square_focal_length / (cos_theta * cos_theta * cos_theta * cos_theta) :
248 square_focal_length / (cos_theta * cos_theta * cos_theta);
260 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
265 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
272 square_focal_length = camera.square_screen_focal_length();
277 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
285 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
293 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
304 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
315 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
320 if (ndc.x >= 0.0f && ndc.x <= 1.0f &&
321 ndc.y >= 0.0f && ndc.y <= 1.0f)
323 const float cos_theta = dot(out, W) / W_len;
324 *pdf_proj = square_focal_length / (cos_theta * cos_theta * cos_theta * cos_theta);
336 float square_focal_length;
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE float pdf(const cugar::Vector3f out, const bool projected=false) const
Definition: camera.h:286
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE float W_e(const cugar::Vector3f out) const
Definition: camera.h:294
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE cugar::Vector2f invert(const cugar::Vector3f out, float *pdf_proj) const
Definition: camera.h:316
FERMAT_HOST_DEVICE cugar::Vector2f invert_camera_sampler(const cugar::Vector3f &U, const cugar::Vector3f &V, const cugar::Vector3f &W, const float W_len, const cugar::Vector3f out)
Definition: camera.h:190
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE cugar::Vector3f sample_direction(const cugar::Vector2f ndc) const
Definition: camera.h:278
FERMAT_HOST_DEVICE void camera_frame(cugar::Vector3f eye, cugar::Vector3f lookat, cugar::Vector3f up, float hfov, float aspect_ratio, cugar::Vector3f &U, cugar::Vector3f &V, cugar::Vector3f &W)
Definition: camera.h:142
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE CameraSampler(const Camera &camera, const float aspect_ratio)
Definition: camera.h:266
FERMAT_HOST_DEVICE cugar::Vector3f sample_camera_direction(const cugar::Vector2f ndc, const cugar::Vector3f U, const cugar::Vector3f V, const cugar::Vector3f W)
Definition: camera.h:176
FERMAT_HOST_DEVICE float camera_direction_pdf(const cugar::Vector3f &U, const cugar::Vector3f &V, const cugar::Vector3f &W, const float W_len, const float square_focal_length, const cugar::Vector3f out, float *out_x=0, float *out_y=0)
Definition: camera.h:206
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE uint32 length(const vector_view< Iterator > &vec)
Definition: vector_view.h:228
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE cugar::Vector2f invert(const cugar::Vector3f out) const
Definition: camera.h:305
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE CameraSampler()
Definition: camera.h:261