Top-down zdepth projected to camera

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2013
Top-down zdepth projected to camera

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.
 
  03 March 2013
falloff map type:distance direction:object.
create dummy somevhere up. set it as object.
put right near far dist.
__________________
My TEN entry My THU entry
I didn't leave Max/Autodesk...they left me.
 
  03 March 2013
Originally Posted by stefan: falloff map type:distance direction:object.
create dummy somevhere up. set it as object.
put right near far dist.


Better to use direction:World Z-Axis.
Using an object would introduce inaccuracies on a big enough scene.
 
  03 March 2013
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?
 
  03 March 2013
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.
 
  03 March 2013
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

Last edited by Klunk : 03 March 2013 at 02:45 PM.
 
  03 March 2013
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.

Last edited by Klunk : 03 March 2013 at 07:55 PM.
 
  03 March 2013
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
 
  03 March 2013
Originally Posted by solarnoise: 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?

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)
 
  03 March 2013
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.
 
  03 March 2013
Originally Posted by solarnoise: 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.


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.
 
  03 March 2013
Originally Posted by lo: 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.


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?
 
  03 March 2013
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.
 
  03 March 2013
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)
__________________
Scripts :: linkedin
 
  03 March 2013
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:30 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.