POV-Ray : Newsgroups : povray.newusers : Sky external Image? : Re: Sky external Image? Server Time
5 May 2024 14:00:02 EDT (-0400)
  Re: Sky external Image?  
From: Reactor
Date: 15 Jul 2009 19:00:01
Message: <web.4a5e5e8141a4106c6a9471340@news.povray.org>
"Chrisir" <nomail@nomail> wrote:
> Hello,
>
> Here is my code, but the image bit doesn't work...
>
>
> #macro BigSkyBox ()


One thing I noticed with just quick look at your code is that the box is scaled
and translated before the texture is applied.  Since the image maps from
<0,0,0>, <1,1,0> (and extends infinitely along the z-axis), you should apply it
first, then remove that extra scaling statement from the texture block.
Furthermore, if you only want the image to display and do not want use
generated patterns, you should be using the image_map pigment, not
material_map.  The finish should also be set to
finish{ ambient 1 diffuse 0 } which makes the image fully lit and tells it to
ignore scene lights.

In any case, the method clipka recommended is a good general purpose way of
having the sky map always be more or less in the correct place.  However, it
may be fairly difficult to implement, depending on your math (trigonometry)
ability.  If you already know exactly where you want the camera to be, the
sky_sphere method is easier to implement:

sky_sphere
{
     pigment {
      image_map{
        jpeg "sky02.jpg" // the file to read (iff/tga/gif/png/jpeg/tiff/sys)
        map_type 0        // 0=planar, 1=spherical, 2=cylindrical, 5=torus
        interpolate 2     // 0=none, 1=linear, 2=bilinear, 4=normalized distance
        once            // for no repetitive tiling
         }
     translate <-0.5,-0.5,0>
     scale 4/3 // the aspect ratio of the image
     }
}


There are some important limitations, though.  If your camera's aspect ratio is
significantly different than the aspect ratio of the image, you will see a
black area where the image ends.  To counteract this, you can comment out the
once keyword so that the image tiles.  Alternatively, you can specify a
background color, which will show wherever the image doesn't cover.

Furthermore, since the above code is using planar mapping, the image only looks
correct if viewing angle is parallel or close to parallel with the z-axis.  If
the camera isn't, then the image will look distorted.  Alternatives include
using cylindrical mapping or rotating the image so that it faces the camera.

If you do want the background image to auto-magically be rotated to face the
camera, here is some starter code:

#declare camLocation  = <10, 5, -5>;
#declare camLookAt    = < 0, 5, 0>;

camera
{
    location camLocation
    look_at  camLookAt
}

background{ color rgb <1,0,1> } // color of any parts not covered by image

sky_sphere
{
     pigment {
         image_map{
        jpeg "sky02.jpg" // the file to read (iff/tga/gif/png/jpeg/tiff/sys)
        map_type 0       // 0=planar, 1=spherical, 2=cylindrical, 5=torus
        interpolate 2    // 0=none, 1=linear, 2=bilinear, 4=normalized distance
        once            // for no repetitive tiling
            }
     translate <-0.5,-0.5,0>
     rotate y*degrees(atan((camLocation - camLookAt).x/(camLocation -
camLookAt).z))
     // rotates image about the y axis so that it is facing the camera
     scale 4/3
     }
}


This will correctly rotate the image into view assuming that the viewing axis of
the camera is roughly parallel to the xz plane.  If you are looking up or down,
you will need another rotate statement to make the image rotate about the x
axis.


-Reactor


Post a reply to this message

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