POV-Ray : Newsgroups : povray.beta-test : Camera is off by half a pixel : Re: Camera is off by half a pixel Server Time
30 Jul 2024 16:22:01 EDT (-0400)
  Re: Camera is off by half a pixel  
From: Anders K 
Date: 19 Oct 2001 16:17:42
Message: <3bd08a66$1@news.povray.org>
> I would venture to say that the centerpoint of the screen is always
> rounded up or down, instead of being left at, say, (319.5,239.5),
> which is where it should be for a 640x480 screen.

No; looking at the POV-Ray 3.1 source, the problem is that, the x paramater
passed to create_ray() ranges from -0.5 to 639.5, and the y parameter ranges
from -0.5 to 479.5. Also (related), the center of pixel (100, 200) should be
(100.5, 200.5) rather than (100, 200) as it is now.

The easiest fix, although not the most elegant, is in create_ray() itself.
(This is under perspective camera; there are similar lines under every
camera type. Why shouldn't x0 and y0 be computed once, at the beginning of
this function? Then they can be scaled as necessary for some camera types.)
Anyway, the lines

      /* Convert the x coordinate to be a DBL from -0.5 to 0.5. */
      x0 = x / (DBL)Frame.Screen_Width - 0.5;
      /* Convert the y coordinate to be a DBL from -0.5 to 0.5. */
      y0 = ((DBL)(Frame.Screen_Height - 1) - y) / (DBL)Frame.Screen_Height -
0.5;

can be replaced with

      /* Convert the x coordinate to be a DBL from -0.5 to 0.5. */
      x0 = (x + 0.5) / (DBL)Frame.Screen_Width - 0.5;
      /* Convert the y coordinate to be a DBL from -0.5 to 0.5. */
      y0 = 0.5 - (y + 0.5) / (DBL)Frame.Screen_Height;

(similarly for other projections) and the problem goes away.

The better fix, which isn't that much harder, is to rework the code to use x
values in [0, width] and y values in [0, height], and pixels centered at
(mmm.5, nnn.5), as they should be. When antialiasing is not used, and you
are on pixel (i, j) (where i, j are integers from 0 to width-1 and 0 to
height-1), call create_ray with (i+.5, j+.5). When antialiasing is used,
make the values vary from (i, j) to (i+1, j+1). You also have to change each
(Frame.Screen_Height - 1) in create_ray to simply Frame.Screen_Height.

Anders


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.