POV-Ray / povray

The Persistence of Vision Raytracer (POV-Ray)
https://www.povray.org/
GNU Affero General Public License v3.0
1.37k stars 283 forks source link

Scene depth as (debug?) image output #372

Closed iljah closed 5 years ago

iljah commented 5 years ago

Summary

Is it possible to have povray render a scene but instead (or additionally) output a gray scale image in which each pixel corresponds to the distance from camera to first/closest object visible at that position in regular image? Or could this be emulated with render/scene/lighting/camera/etc settings? If not, how easy would something like this be to add?

For example in below scene center of sphere would be e.g. whitest while background would be black since rays missing the sphere wouldn't really hit anything.

Environment

POV-Ray version: POV-Ray 3.7.0.8.unofficial (Fedora 28)

Scene

#version 3.7;

#include "colors.inc"

global_settings { assumed_gamma 1 }

background { color White }
camera {
    location <0, 2, -3>
    look_at  <0, 1,  2>
}
sphere {
    <0, 1, 2>, 2
    texture {
        pigment { color Yellow }
    }
}
light_source { <2, 4, -3> color White}
c-lipka commented 5 years ago

You can use a pigment that varies with distance to the camera location, and set the finish to "ambient 0 emission 1 diffuse 0".

Make sure to put all objects in a global union and assign the pigment to that one, so you don't ruin the distance-from-camera thing by transformations of the individual objects.

You'll be able to find more support on this and other topics on our newsgroups, at https://news.povray.org or news://news.povray.org.