POV-Ray : Newsgroups : povray.general : Output image based on distance to camera? : Re: Output image based on distance to camera? Server Time
30 Jul 2024 04:23:54 EDT (-0400)
  Re: Output image based on distance to camera?  
From: Chris B
Date: 14 Sep 2009 02:47:46
Message: <4aade712$1@news.povray.org>
"Reactor" <rea### [at] hotmailcom> wrote in message 
news:web.4aaddb72280b0bab74fac1dc0@news.povray.org...
> "Paco" <nomail@nomail> wrote:
>> I was hoping to create an image where the colour of each pixel is 
>> proportional
>> to the distance from the camera to the intersecting object.
>>
>> I figure I can use the trace function to get the intersection distance, 
>> but how
>> about outputting the image? Is there some flag or something to do this?
>
> If I am understanding you correctly, couldn't it be done with a pigment
> function?  You could pre-declare the camera coordinates and make a 
> distance
> function:
>

I think there may be an even simpler way, which is to use a 'spherical' 
pattern centred on the camera and scaled so that the 1-unit radius spherical 
pattern reaches the most distant objects in your scene.

By applying this pigment to all of the objects in the scene (with a high 
ambient setting and with no lights in the scene), you get an image where the 
color of each pixel represents the distance from the camera.

The default pigment_map goes from Black on the outside to White in the 
middle, but you can adjust the pigment_map to control the color that 
represents each distance. The following example uses Red for the most 
distant points, Green for the middle distance and Blue for objects close to 
the camera. The pattern is scaled to reach the most distant object at 50 
units, with the closest part of the furthest plane being at 45 units.


#declare MyCameraLocation = <0,0,>;
//#declare MyCameraLocation = <30,0,25>;
camera {location MyCameraLocation look_at 25*z}

union {
  plane {x,-10}
  plane {-z,-45}
  sphere{<5,0,10>,1}
  sphere{<5,0,20>,1}
  sphere{<5,0,30>,1}
  sphere{<5,0,40>,1}
  pigment {
    spherical
    pigment_map {
      [0   rgb <1,0,0>]
      [0.5 rgb <0,1,0>]
      [1   rgb <0,0,1>]
    }
    scale 50
    translate MyCameraLocation
  }
  finish {ambient 1}
}


Regards,
Chris B.


Post a reply to this message

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