POV-Ray : Newsgroups : povray.unofficial.patches : POV-Ray v3.8 based unix patch for pgm depth maps. Server Time: 27 Jun 2019 04:59:30 GMT
  POV-Ray v3.8 based unix patch for pgm depth maps. (Message 1 to 1 of 1)  
From: William F Pokorny
Subject: POV-Ray v3.8 based unix patch for pgm depth maps.
Date: 16 May 2019 17:03:52
Message: <5cdd97f8$1@news.povray.org>
It recently hit me some of the solver related debug output I was 
creating was not too far from providing a decent depth map output. Given 
depth maps are a frequently requested feature, a *nix only stand alone 
version of POV-Ray specifically modified to create depth map output 
based on the current v3.8 master can be had at:


Download and compile rather than pull probably best. The generated 
povray module should be copied somewhere executable like $HOME/bin and 
renamed pDepth, povrayPGMDepthMap or the like.

No scene modifications are needed, but turnig off photons and radiosity 
will help performance. This version of POV-Ray itself hard coded to run 
a pixel at a time with options creating additional camera rays like AA 
and focal blur hard coded off. Output is always to a file called 
depth.pgm in plain text format and linear values normalized to a range. 
Option SDL variables and defaults are:

DepthMapMin           = 0.0;
DepthMapMax           = 1000.0;
DepthMapPGMDepth      = 65535.0;
DepthMapRangeXVal     = 0.0;
DepthMapComments      = 0.0;   (*) - Float depth from ray origin.
DepthMapIntersections = 0.0;   (*) - Where intersections in range.
DepthMapNormals       = 0.0;   (*) - Raw shape normal at intersection.
DepthMapRayOrigins    = 0.0;
DepthMapRayDirections = 0.0;

These options can be set with the existing Declare=<var_name>=<float> 
command line mechanism. For example, the sample balcony.pov and 
woodbox.pov scenes in the image posted to povray.binaries.images were 
rendered with:

pDepth +W450 +h600 balcony.pov Declare=DepthMapMin=0 Declare=DepthMapMax=800


pDepth +W800 +h600 woodbox.pov Declare=DepthMapMin=10 
Declare=DepthMapMax=50 \

If you turn on comments these get added to the pgm file. 
DepthMapComments must be on (not 0.0) to get other information. So the 

pDepth +W400 +h300 woodbox.pov Declare=DepthMapMin=10 
Declare=DepthMapMax=50 \
        Declare=DepthMapComments=1 \
        Declare=DepthMapIntersections=1 Declare=DepthMapNormals=1

creates an ascii pgm file where the first lines look like:

# DepthMapMin = 10.000  DepthMapMax = 50.000  for mapped range of = 40.000
51196  # 41.2482798167746 I=<-7.6527354,6.4294999e-17,24.929733> N=<0,1,0>
51151  # 41.2204724321481 I=<-7.5807234,-8.7917847e-17,24.905729> N=<0,1,0>
... and so on

There is a significant performance hit given this feature is hanging on 
a debug mechanism. Strongly recommend running on a ramdisk as the file 
I/O opens and closes the file on every string write. Further files can 
get really large depending upon selected output.

---- Performance woodbox.pov with v3.8 master 400 x 300 no AA
Original scene on my 2 core 4 thread i3: 1.22s

---- Performance hit with pDepth
Blocksize 1x1 with 1 thread:             3.98s
Creating depth map pgm no comments       5.82s
Comments on. Ray origins and directions  7.96s

Note. POV-Ray itself fails on image read when the comments are present 
in the output depth.pgm. All the other programs I've tried work OK - 
including netpbm programs. To the netpbm site documents on file formats, 
I think POV-Ray correct. It's just not what netpbm itself actually does 
for the plain ascii format. Run without comments if using the depth.pgm 
directly as input to POV-Ray.

To view pgm bit depths >255 (ie using 16 bit channel) on a srgb-ish 
display environment correctly you may need to use POV-Ray itself. The 
programs I most frequently use for viewing seem to be mapping internally 
to 0-255 channel ranges. I see more banding with 16 bit channel outputs 
than should be. A small scene file which can be used for viewing 16 bit 
pgm output with POV-Ray follows. The view is gamma corrected one of the 
linear depth.pgm. Specifying proportionally matching width and height to 
the depth.pgm file, use your normal version of POV-Ray as in:

povray asPGMViewer.pov +p

Bill P.

//------------- Start asPGMViewer.pov
#version 3.8;
// Scene using POV-Ray as linear pgm file srgb-viewer.
// Use +w +h values which match pgm file's.
global_settings { assumed_gamma 1 }
#declare Grey20 = srgb <0.2,0.2,0.2>;
background { color Grey20 }
#declare VarOrthoMult = 
#declare Camera01z = camera {
     location <0,0,-2>
     direction z
     right VarOrthoMult*x*max(1,image_width/image_height)
     up VarOrthoMult*y*max(1,image_height/image_width)
#declare FileName = "depth.pgm"
#declare ImageMap00_P = pigment { image_map { FileName gamma 1 
interpolate 2 }};
#declare ImageMap00_Range = max_extent(ImageMap00_P);
#declare ImageMap00_NrmScale =
#declare Finish00 = finish { ambient rgb 1 }
#declare Pigment00 = pigment {
     image_map { FileName
         gamma 1
         premultiplied off
         map_type 0
         interpolate 2
#declare Texture00 = texture {
     pigment { Pigment00 }
     finish { Finish00 }
#declare Box00 = box { <0,0,0>,<1,1,1> }
#declare Object00 = object {
     texture { Texture00 }
     translate <-0.5,-0.5,0>
     scale ImageMap00_NrmScale

//--- scene ---
    camera { Camera01z }
    object { Object00 }

//------------- end asPGMViewer.pov

Post a reply to this message

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