---- DATABASE ERROR ----
Quick And Dirty: Changing Aspect Ratios
by Mike Kost
Introduction
Povray is rather square. Well, the images are. The monitor 640x480,
800x600, or 1024x768 are standard rendering targets. Not all scenes are
their best at these dimentions, though. Sometimes a panorama shot or a
tall and skinny tower better present the scene's contents than the good
old Povray stand-by resolutions. To break outside the boxy world,
aspect ratios must change. This Quick and Dirty tutorial will
demonstrate how to adjust the aspect ratio for a Povray scene using
Povray 3.6.
Quick Reading
To mess with aspect ratios, one must know the camera. To know the
camera, one must do some quick reading:
Aspect Ratios
The aspect ratio refers the screen aspect ratio, which is the screen
width divided by the screen hight of the image. Today, almost all
computer monitors have square pixels [1], which makes it easy to
relate screen resolutions and the aspect ratio. For example, a
full-screen rendering at 1024 x 768 gives an aspect ratio of 1024/768 =
4/3 = 1.33 [2]. Monitors have been 4/3, just like
TVs, for a long time. Povray, by default, assumes that the aspect ratio
will be 4/3 or 1.33.
Enough of this stuff, lets go to some renderings!
The Scene
The scene below is fresh from rendering after careful tweaking of the
shapes
and colors. Please note that this image, like all the others, has the
Povray source linked to the image for downloading.
Rendered to 400x300 pixels, the scene looks a bit cramped. Maybe more
white-space on the sides would open things up a bit. Below is the same
scene rendering at 600x300 pixels.
What just happened? We wanted Povray to give some padding, and instead
there's squished spheres. The squishing results from Povray thinking
that the aspect ratio is still 4/3 = 1.33. Because of this, Povray
generates the image assuming that the screen is shaped funny and the image
will look normal on the funny screen.
Since this is not the case, lets fix the aspect ratio.
Fixing The Aspect Ratio
The new image has an aspect ratio of 600/300 = 200/100 = 2.0, and
Povray needs to
know this. The aspect ratio is altered through the 'up' and
'right' directives inside a camera. Povray understands the
image aspect ratio to be 'right/up'. To change Povray from the default
setting, the camera is altered as follows:
camera {
location <5, -0.8, 0.0>
look_at <0.0, 0.0, 0.0>
up 1*y
right 2*x
angle 33
}
For most aspect ratio changes, it should only be necessary to correct
the 'right' vector, but it's equally valid to change both
right and up. After this change, a new rendered version of the
scene is below:
White space was lost from the top and bottom, not added to the sides.
This is because of the camera angle - it needs to be corrected before
we get the extra space on the sides.
Correcting The Angle
The camera angle tells Povray what the horizontal viewing angle is.
Because the horizontal width was changed without changing the viewing angle,
Povray takes the same scene width and spreads it over the larger sized
image. As a rule of thumb, increase the viewing angle the same percent
that you increased the width [3]. For example, the
width changes from 400 to 600 pixels. 600/400 = 1.5. The angle needs to
be changes by 1.5, giving a new angle of 1.5 * 33 = 48.5. To keep things clean,
the angle was rounded down to 48. The new camera settings are below:
camera {
location <5, -0.8, 0.0>
look_at <0.0, 0.0, 0.0>
up 1*y
right 2*x
angle 48
}
From here, we render one more time:
Ta da!
Want To Know More?
This is another topic that's not well documented for Povray, but there
is some interesting reading on aspect ratios in general:
Notes And Disclaimers
[1] - Not all pixels are square, just almost all of
them. For example,
a typical CRT monitor (4/3 aspect ratio) displaying 1280x1024 (5/4
aspect ratio) results in a 16x15 pixels. Refer to Quite
limited: Device-aspect-ratio for more info.
[2] - You can figure it out all the relationship
between the pixel
aspect ratio (which is generally assumed to be 1/1), the image size,
and the screen aspect ratio by using
pixelAspectRatio * width/height = screenAspectRatio. Driving a
1280x1024 CRT monitor will give a 16x15 pixel aspect ratio. There are
also some flat panel monitors or laptop screens that use wierd pixel
aspect ratios, but these are not normal.
[3] - The rule of thumb works well while the angles are
small, and
gradually breaks from there. The equation to get the exact answer is 'newAngle
= 2 * asin(sin(oldAngle/2) * newWidth/oldWidth)'. In this specific
situation, using the rule of thumb on an old angle of 55 will give a 6%
error versus the mathematically correct version. This should be
acceptable in most applications - just be aware of the limitations.
Published: 08/28/05
Last Edited: 08/28/05
Copyright (C) 2005 Mike
Kost