POV-Ray : Newsgroups : povray.general : simulating lens distortion with normal and function in 3.5 : Re: simulating lens distortion with normal and function in 3.5 Server Time
19 Nov 2024 13:28:04 EST (-0500)
  Re: simulating lens distortion with normal and function in 3.5  
From: Bill Brehm
Date: 26 Feb 2002 03:13:03
Message: <3c7b438f@news.povray.org>
Mike,

1. I cannot use square images, but was able to modify the function to give
symmetrical results. I'm curious how you found the Z value experimentally,
if you wouldn't mind explaining. I might have to confirm if it ever changes
for different camera parameters.

3. I was thinking before I read your response that the image plane staying
flat might be a possibility too. Just for fun I think I'll make a test to
confirm it. Some further experiments convinced me that the camera is not
exactly perspective.

My camera looks like this:

#declare HFOV = 5.00;
#declare VFOV = HFOV * 3 / 4;

#declare lens_dist = function(x, y, z, a, b) {
  (HFOV / VFOV) * (x + a * x * sqrt(x*x + y*y) + b * x^3 * sqrt(x*x + y*y) )
^ 2 + (y + a * y * sqrt(x*x + y*y) + b * y^3 * sqrt(x*x + y*y) ) ^ 2
}

#declare a_factor = 0.0;
#declare b_factor = 0.0;

#declare cameraheight = 10.000;

camera {
  orthographic
  location <0, 0, 0>
  right <HFOV, 0, 0>
  up <0, VFOV, 0>
  sky <0, 1, 0>
  direction <0, 0, cameraheight>
  look_at <0, 0, 1>
  translate <0, 0, -cameraheight>

  normal{function {lens_dist(x, y, z, a_factor, b_factor)} }
}

With the normal commented out, changing the camera height does not change
the magnification, whether the direction vector is based on cameraheight or
a constant (<0, 0, 1>). With orthographic also commented out, the
magnification doesn't change if the direction vector is based on
cameraheight, but it does if the direction vector is a constant. But with
the normal and orthographic on, the increasing camera height actually
increases magnification when the direction vector is based on cameraheight,
but decreases it when the direction vector is the constant. Strange.

I think the normal does some kind of approximate calculation. Try rendering
the code below and you'll see that the rendered image is not symmetrical,
even though everything in the code is symmetrical.

#declare lens_dist = function(x, y, a, b) {
   (x + a * x * sqrt(x*x + y*y) + b * x^3 * sqrt(x*x + y*y) ) ^ 2 + (y + a *
y * sqrt(x*x + y*y) + b * y^3 * sqrt(x*x + y*y) ) ^ 2
}

#declare a_factor = 0.69;
#declare b_factor = 0.1;

camera {

  location <0, 0, -100>
  look_at <0, 0, 0>
  right <4/4, 0, 0>

  normal{function {lens_dist(x, y, a_factor, b_factor)} }
}

light_source { <0, 0, -100> color rgb <1, 1, 1> }

plane{-z, -10 pigment{color rgb <0, 0, 1>}}

box{<-25, -25, 0>, <25, 25, 0> pigment {color rgb <1, 0, 0>}}

Thanks,

Bill

"Mike Williams" <mik### [at] nospamplease> wrote in message
news:Grd### [at] econymdemoncouk...
> Wasn't it Bill Brehm who wrote:
> >Thanks Mike.
> >
> >1. Where does the 0.016 for Z come from? Is that a constant built into
> >POVRay?
>
> I haven't a clue. I just did some experiments and that's where it turned
> out to be. It's possible that the camera{} parameters may affect it.
>
> >Do X and Y both vary from -0.5 to +0.5, even though the camera is
> >rectangular (3/4)?
>
> Yes.
>
> > Then I need to consider the camera's aspect ratio in my
> >function, right?
>
> It may be more sensible, in your case, to work with square images.
>
> >2. When would I want to use Z, if it is a constant? Do one or more of the
> >camera types have a variable Z? Is it useful when the camera is
translated
> >in some way?
>
> Probably not in your case.
>
> >3. POVRay help shows an diagram explaining the perspective camera. The
rays
> >emanate from "location", pass through the image plane, then eventually
hit
> >an object. Those rays are not normal to the plane, except at the center.
For
> >the orthographic camera, one could consider that "location" is infinitely
> >far away, so that the rays are normal to the image plane. Or one could
> >consider that the rays emanate from the image plane itself normal to the
> >plane.
> >
> >I'm I correct so far? Assuming yes,
>
> I believe so.
>
> >Can I imagine that the normal function distorts the image plane into a
shape
> >determined by the scalar field and that the rays emanate from that
distorted
> >image "plane" normal to the "plane" at that point?
>
> That's probably not a very helpful way to visualize it. Try thinking of
> something like a freznel lens or a diffraction grating, where the
> surface is flat but it changes the direction of light that passes
> through it.
>
> > Is that still true for a
> >perspective camera with a normal applied to it? I.e., should I sort of
> >forget about "location" and think of a perspective camera as having an
image
> >plane distorted into a piece of a sphere having the rays emanate normal
to
> >that distorted image "plane"? Couldn't  I then simulate any camera type
with
> >the proper normal function?
>
> I guess you could simulate any camera by changing the normal. E.g. if
> you set a_factor and b_factor to zero in your lens_dist() function, then
> you're simulating a perspective camera with angle 20.5 (approximately).
>
> >How does POVRay actually determine the normal at each point? Does it use
the
> >derivative of the function to calculate it exactly or does it look at the
> >surrounding points and calculate a rough approximation? (I'm trying to
> >generate "perfect" images with a known amount of lens distortion to test
a
> >correction algorithm.)
>
> I don't know. I do know that POV normals do work with functions that are
> fiendishly difficult to differentiate analytically, so I guess that it's
> using some sort of numerical approximation method.
>
> --
> Mike Williams
> Gentleman of Leisure


Post a reply to this message

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