CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 03-11-2013, 04:57 AM   #1
solarnoise
Veteran
portfolio
Derrick B
Worcester, USA
 
Join Date: Jan 2012
Posts: 30
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.
 
Old 03-11-2013, 09:57 AM   #2
stefan
Expert
 
stefan's Avatar
portfolio
Stefan Gura
bratislava, Slovakia
 
Join Date: Feb 2003
Posts: 615
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
 
Old 03-11-2013, 01:09 PM   #3
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,832
Quote:
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.
 
Old 03-11-2013, 01:49 PM   #4
solarnoise
Veteran
portfolio
Derrick B
Worcester, USA
 
Join Date: Jan 2012
Posts: 30
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?
 
Old 03-11-2013, 01:56 PM   #5
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,832
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.
 
Old 03-11-2013, 01:57 PM   #6
Klunk
Lord of the posts
 
Klunk's Avatar
portfolio
Klunk
United Kingdom
 
Join Date: Sep 2005
Posts: 701
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....

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


might do the trick

Last edited by Klunk : 03-11-2013 at 02:45 PM.
 
Old 03-11-2013, 07:47 PM   #7
Klunk
Lord of the posts
 
Klunk's Avatar
portfolio
Klunk
United Kingdom
 
Join Date: Sep 2005
Posts: 701
seems to give pretty good depth resolution....

Code:
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-11-2013 at 07:55 PM.
 
Old 03-11-2013, 08:27 PM   #8
Klunk
Lord of the posts
 
Klunk's Avatar
portfolio
Klunk
United Kingdom
 
Join Date: Sep 2005
Posts: 701
this shows it off better though you need to go to vertex subobject level to see the result

Code:
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
 
Old 03-11-2013, 09:02 PM   #9
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,421
Send a message via ICQ to denisT
Quote:
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)
 
Old 03-12-2013, 03:24 PM   #10
solarnoise
Veteran
portfolio
Derrick B
Worcester, USA
 
Join Date: Jan 2012
Posts: 30
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.
 
Old 03-12-2013, 03:29 PM   #11
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,832
Quote:
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.
 
Old 03-12-2013, 04:24 PM   #12
solarnoise
Veteran
portfolio
Derrick B
Worcester, USA
 
Join Date: Jan 2012
Posts: 30
Quote:
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?
 
Old 03-12-2013, 04:34 PM   #13
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,832
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.
 
Old 03-12-2013, 04:46 PM   #14
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 364
Send a message via ICQ to Swordslayer
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)
__________________
Blog :: LinkedIn profile
 
Old 03-12-2013, 04:46 PM   #15
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:36 PM.


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