POV-Ray : Newsgroups : povray.general : Place light_source based on object bounds Server Time
29 Dec 2024 13:19:03 EST (-0500)
  Place light_source based on object bounds (Message 1 to 2 of 2)  
From: apalabrados
Subject: Place light_source based on object bounds
Date: 2 Oct 2013 17:35:01
Message: <web.524c90c29c0487ff39f63a050@news.povray.org>
Hi,

   I have a script where I load an Object and try to render it. The question is
that every object loaded has its own dimensions. I place it on the center of the
scene but I need to place a light_source at a certain distance.

   My code is:


#declare maxcorner  = 0;
#declare mincorner  = 0;
#declare max_x  = 0;
#declare min_x  = 0;
#declare max_y  = 0;
#declare min_y  = 0;
#declare max_z  = 0;
#declare min_z  = 0;

background {color rgb 0.1}

global_settings {
  assumed_gamma 2
  ambient_light rgb<1, 0, 0>
}

camera {
        orthographic
        location <0,200,0>
        rotate <23,0,-135>
        look_at <0,0,0>
}

sky_sphere
{
 pigment
 {
  gradient y
  color_map
  {
   [0.0 rgb <1.0,1.0,1.0>]  //153, 178.5, 255 //150, 240, 192
   [0.7 rgb <0.9,0.9,0.9>]  //  0,  25.5, 204 //155, 240, 96
  }
  scale 2
  translate 1
 }
}

union {

object {

 {{MODELNAME}}

 Center_Trans({{MODELNAME}}, x+y+z)

 texture {
  pigment { Red }
  finish { ambient 0.1
                 diffuse 0.9
                 phong 1 }
 }

 #declare maxcorner  = max_extent({{MODELNAME}});
 #declare mincorner  = min_extent({{MODELNAME}});
 #declare max_x  = max(maxcorner.x,mincorner.x);
 #declare min_x  = min(maxcorner.x,mincorner.x);
 #declare max_y  = max(maxcorner.y,mincorner.y);
 #declare min_y  = min(maxcorner.y,mincorner.y);
 #declare max_z  = max(maxcorner.z,mincorner.z);
 #declare min_z  = min(maxcorner.z,mincorner.z);

 #debug concat("dX: ", str(max_x-min_x, 0, 2), "\n")
 #debug concat("dY: ", str(max_y-min_y, 0, 2), "\n")
 #debug concat("dZ: ", str(max_z-min_z, 0, 2), "\n")

 scale 140 / max3( max_x-min_x, max_y-min_y, max_z-min_z)

 FindObjectCenter( {{MODELNAME}} )
}

light_source {
        <max_x+100, (max_y-min_y)/2, (max_z-min_z)/2>
        color White
}
light_source {
        <(max_x-min_x)/2, max_y+500, (max_z-min_z)/2>
        color White
}
light_source {
        <(max_x-min_x)/2, (max_y-min_y)/2, max_z+100>
        color White
}

}

    I want to illuminate the three visible planes ( XY, YZ, ZX)  and my issue is
that light_source need to get the bounds of the object to be placed accordingly.

   What's wrong in my code?


Post a reply to this message

From: Le Forgeron
Subject: Re: Place light_source based on object bounds
Date: 3 Oct 2013 02:55:42
Message: <524d14ee@news.povray.org>
Le 02/10/2013 23:31, apalabrados a écrit :
> Hi,
> 
>    I have a script where I load an Object and try to render it. The question is
> that every object loaded has its own dimensions. I place it on the center of the
> scene but I need to place a light_source at a certain distance.
> 

> camera {
>         orthographic
>         location <0,200,0>
>         rotate <23,0,-135>
>         look_at <0,0,0>
> }
> 

> union {
> 
> object {
> 
>  {{MODELNAME}}
> 
>  Center_Trans({{MODELNAME}}, x+y+z)
> 
>  texture {
>   pigment { Red }
>   finish { ambient 0.1
>                  diffuse 0.9
>                  phong 1 }
>  }
> 
>  #declare maxcorner  = max_extent({{MODELNAME}});
>  #declare mincorner  = min_extent({{MODELNAME}});

> 
> light_source {
>         <max_x+100, (max_y-min_y)/2, (max_z-min_z)/2>
>         color White
> }
> light_source {
>         <(max_x-min_x)/2, max_y+500, (max_z-min_z)/2>
>         color White
> }
> light_source {
>         <(max_x-min_x)/2, (max_y-min_y)/2, max_z+100>
>         color White
> }
> 
> }
> 
>     I want to illuminate the three visible planes ( XY, YZ, ZX)  and my issue is
> that light_source need to get the bounds of the object to be placed accordingly.
> 
>    What's wrong in my code?

1. minor: The camera use a rotate to be placed, so it's difficult to
know where it is actually.
2. you used 3 lights sources (good), but with the same intensity. Usual
three-lights settings have a frontal/side/fill approach, with huge
frontal, medium side for a bit of relief and low fill to avoid pitch
black shadows.
3. why does Y get +500 when other get only +100. And it does not scale
smoothly : the effect is not the same if the object is 10 unit wide, or
1000 unit wide (and the camera might then need adjustment too). What
about, instead +100, using +(max_*-min_*) (so light source is mirror of
farest plane by nearest plane)
4. Assuming the object is finite: if it is infinite, the return of
max_extent and min_extent are vectors of big size
5. The center of object is (max_*+min_*)/2 [NOT substraction]

-- 
Just because nobody complains does not mean all parachutes are perfect.


Post a reply to this message

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