Skip to content

Commit c83f8f2

Browse files
authored
defer sqrt computation in fisheye camera ray creation
1 parent 74b3ebe commit c83f8f2

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

source/core/render/tracepixel.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ void TracePixel::operator()(DBL x, DBL y, DBL width, DBL height, RGBTColour& col
341341
bool TracePixel::CreateCameraRay(Ray& ray, DBL x, DBL y, DBL width, DBL height, size_t ray_number)
342342
{
343343
DBL x0 = 0.0, y0 = 0.0;
344-
DBL cx, sx, cy, sy, ty, rad, phi;
344+
DBL cx, sx, cy, sy, ty, rad2, rad, phi;
345345
Vector3d V1;
346346
TRANSFORM Trans;
347347

@@ -402,19 +402,26 @@ bool TracePixel::CreateCameraRay(Ray& ray, DBL x, DBL y, DBL width, DBL height,
402402
x0 *= cameraLengthRight;
403403
y0 *= cameraLengthUp;
404404

405-
rad = sqrt(x0 * x0 + y0 * y0);
406-
405+
rad2 = x0 * x0 + y0 * y0;
407406
// If the pixel lies outside the unit circle no ray is traced.
408-
409-
if(rad > 1.0)
407+
if(rad2 > 1.0)
408+
{
410409
return false;
410+
}
411411

412-
if(rad == 0.0)
412+
if(rad2 == 0.0)
413+
{
414+
rad = 0.0;
413415
phi = 0.0;
414-
else if(x0 < 0.0)
415-
phi = M_PI - asin(y0 / rad);
416+
}
416417
else
417-
phi = asin(y0 / rad);
418+
{
419+
rad = sqrt(rad2);
420+
if(x0 < 0.0)
421+
phi = M_PI - asin(y0 / rad);
422+
else
423+
phi = asin(y0 / rad);
424+
}
418425

419426
// Get spherical coordinates.
420427
x0 = phi;

0 commit comments

Comments
 (0)