POV-Ray : Newsgroups : povray.general : Output image based on distance to camera? Server Time
26 Nov 2024 22:54:59 EST (-0500)
  Output image based on distance to camera? (Message 1 to 5 of 5)  
From: Paco
Subject: Output image based on distance to camera?
Date: 14 Sep 2009 00:05:03
Message: <web.4aadc07b57c09743f211c3700@news.povray.org>
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?


Post a reply to this message

From: Reactor
Subject: Re: Output image based on distance to camera?
Date: 14 Sep 2009 02:00:16
Message: <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:

#declare CamLocationX =  0;
#declare CamLocationY =  5;
#declare CamLocationZ = -5;

#declare fn_CamDist = function{
sqrt(
      (x - CamLocationX)*(x - CamLocationX)
    + (y - CamLocationY)*(y - CamLocationY)
    + (z - CamLocationZ)*(z - CamLocationZ)
  )
}

That gives you the straight line distance from any point to the camera.  To
properly use it with a color_map or other map, you'll need to normalize or
clamp the values between 0 and 1.  The way you'll want to depends on your scene
- you could set a distance at which all objects beyond (or in front of) have a
certain map entry, or apply a different function that allows very distant
objects to approach a max map entry at infinity.

HTH

-Reactor


Post a reply to this message

From: Chris B
Subject: Re: Output image based on distance to camera?
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

From: Paco
Subject: Re: Output image based on distance to camera?
Date: 14 Sep 2009 05:30:01
Message: <web.4aae0cb4280b0babea2377910@news.povray.org>
Is there a way to override all the textures in the scene and replace it with one
of these? It's a fairly complex scene and doing it all by hand would take
forever...


Post a reply to this message

From: Paco
Subject: Re: Output image based on distance to camera?
Date: 14 Sep 2009 07:15:00
Message: <web.4aae254b280b0babea2377910@news.povray.org>
Thanks for your help!

Ended up using the depth function in megapov. Much easier to this to the global
section than edit all of the textures by hand:

post_process { PP_Depth(1,15)
        save_file "dist.png"
}


Post a reply to this message

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