Top-down zdepth projected to camera


#1

Hi all, I have an interesting little problem and I’m new to working with matrices so I thought I’d ask for help here.

I need to create a depth map. Unfortunately the one made in my camera’s space is not very good… we need the depth as though it were from the top-down and then rendered from the camera.

I imagine there has to be a way to get the zdepth data from the top-down, and then use the camera’s transform or projection matrix to get it “back” into camera space and render from there?

Any help or pointers in the right direction would be greatly appreciated.


#2

falloff map type:distance direction:object.
create dummy somevhere up. set it as object.
put right near far dist.


#3

Better to use direction:World Z-Axis.
Using an object would introduce inaccuracies on a big enough scene.


#4

I’ll definitely try this, thanks guy!

Is there a way to clamp the map? The actual height of the scene isn’t terribly tall and I need good precision.

By default does the map clamp to the lowest and tallest objects in the scene if you use direction:World Z axis?


#5

The values are mapped to the min/max distances you specify. Measure the height of your object/scene and use its lowest point as the min and its highest point as the max.


#6

have you tried rendering the z depth as 32 bit per channel exr file ?

I make the assumption that max does resolve the depth correctly…

1000 meters @ 8 bit should give a resolution of 3.9 meters per level
1000 meters @ 16 bit should give a resolution of 0.015258 meters per level
1000 meters @ 32 bit should give a resolution of 0.000000232 meters per level

suppose is does depend on you ability to access the data in the exr file

or even something along the lines of…

bm = render $camera01 outputHDRbitmap:true  vfb:false channels:#(#zDepth)
 getChannel bm [404,263] #zdepth

might do the trick


#7

seems to give pretty good depth resolution…

fn ScreenToWPostion xy zdepth vp_size =
  (
  	vp_pos = mapScreenToView xy zdepth vp_size; 
  	vp_pos * inverse (viewport.getTM())
  )	
  	
  
  fn PointRenderSceneFromDepthMap w h =
  (
  -- render depth
  	
  	bm = render $camera01 outputHDRbitmap:true  vfb:false channels:#(#zDepth)  outputwidth:w outputheight:h;
  	
  	for i = 0 to w - 1 do
  	(	
  		for  j = 0 to h - 1 do
  		(	
  			zdepth = getChannel bm [i,j] #zdepth
			if zdepth[1] > -100000.0 then
  				 point pos:(ScreenToWPostion [i,j] zdepth[1] [w,h]) size:200
  		)
  	)	
  )	
  
  viewport.setCamera $camera01
  PointRenderSceneFromDepthMap 32 32

kept the width and height low when creating points this will then render points to the scene from the rendered depth map.


#8

this shows it off better though you need to go to vertex subobject level to see the result

fn ScreenToWPostion xy zdepth vp_size =
(
	vp_pos = mapScreenToView xy zdepth vp_size; 
	vp_pos * inverse (viewport.getTM())
)	
	

fn PointRenderSceneFromDepthMap w h =
(
-- render depth
	
	msh = mesh numverts:(w*h) numfaces:0
	
	bm = render $camera01 outputHDRbitmap:true  vfb:false channels:#(#zDepth)  outputwidth:w outputheight:h;
	verti = 1
	for i = 0 to w - 1 do
	(	
		for  j = 0 to h - 1 do
		(	
			zdepth = getChannel bm [i,j] #zdepth
			if zdepth[1] > -100000.0 then
			(	
				setvert msh verti (ScreenToWPostion [i,j] zdepth[1] [w,h])
				verti+=1;
			)	
		)
	)
	
	update msh
	msh;
)	

viewport.setCamera $camera01
PointRenderSceneFromDepthMap 400 400

#9

is anything different than the height map? (see HeightMap : BakeElement)

set projection

apply planar mapping

render heightmap element to the texture

(don’t use cage, use ray offset)


#10

Thanks for the suggestions, guys. I’ll try out these methods and see which yields the best result.

Question about the falloff map parameters: what are near and far distances relative to? I’m assuming it’s from the camera, which is not top-down… but I really need a nice evenly applied map that falls off from the lowest object to the highest object on the World Z axis. I set the direction to be World Z but am getting some weird results still, trying to find the right near and far values.


#11

If you are using the direction of the World Z Axis in the falloff map, the near/far values are the actual world Z values in scene units, unrelated to the camera.


#12

That’s what I was hoping!

Now sorry if this is a dumb question, but shouldn’t I be allowed to input a negative value to account for the objects that are sitting below the XY plane? Going off what you said, a near value of 0 and a far value of 1 means it’ll grab everything between the XY plane and a Z of 1… but what about objects with negative Z?


#13

I’m trying it now and it doesn’t seem to work at all. Perhaps it’s not as I remembered.
I’m pretty sure BerconGradient can do it though.


#14

You can right-click the spinner and via Show in Track View change its value to negative one. That said, it seems to be broken nonetheless: Falloff: Distance Blend: World XYZ-Axis (Broken)


#15

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.