| 301 | } |
| 302 | |
| 303 | Ray Camera::computeRayPinhole(uint2 pixel, uint2 frameDim, bool applyJitter) const |
| 304 | { |
| 305 | Ray ray; |
| 306 | ray.origin = mData.posW; |
| 307 | |
| 308 | // Compute the normalized ray direction assuming a pinhole camera. |
| 309 | // Compute sample position in screen space in [0,1] with origin at the top-left corner. |
| 310 | // The camera jitter offsets the sample by +-0.5 pixels from the pixel center. |
| 311 | float2 p = (float2(pixel) + float2(0.5f, 0.5f)) / float2(frameDim); |
| 312 | if (applyJitter) p += float2(-mData.jitterX, mData.jitterY); |
| 313 | |
| 314 | float2 ndc = float2(2.0f, -2.0f) * p + float2(-1.0f, 1.0f); |
| 315 | |
| 316 | // Compute the normalized ray direction assuming a pinhole camera. |
| 317 | ray.dir = normalize(ndc.x * mData.cameraU + ndc.y * mData.cameraV + mData.cameraW); |
| 318 | |
| 319 | float invCos = 1.f / dot(normalize(mData.cameraW), ray.dir); |
| 320 | ray.tMin = mData.nearZ * invCos; |
| 321 | ray.tMax = mData.farZ * invCos; |
| 322 | |
| 323 | return ray; |
| 324 | } |
| 325 | |
| 326 | void Camera::updateFromAnimation(const float4x4& transform) |
| 327 | { |
no test coverage detected