Skip to main content
GameDev.net gamedev.net
🔒 Locked

3D position from depth FOV problem

Started by rubicondev Dec 16, 2009 at 9:00 PM 1 replies 1k views
Original Post
rubicondev
rubicondev
I pulled this out of a necroed thread on the topic: // pnt is still in eye-space float2 ss = ( newPoint.xy / newPoint.z ) * float2( 0.75, 1.0 ); float2 tx = ss * 0.5 + 0.5; float depth = tex2D( depthMap, tx ); I'm doing exactly this above to sample my texture from a reconstructed position, but it only works if the FOV I've setup is 90 degrees. 90 degrees having the magical property that the far distance is the same as the sideways distance so a point in the corner of the screen is going to map to -1,-1 when one is divided by the other. However, if I set up say 60 degrees, then my far corners look like this (reflected for all corners): -71,-54,100 So now when I divide -71 by 100 in the top/left corner, my UV will be 0.71 and this isn't sampling the edge of my texture iyswim. What am I missing here? I've tried just scaling the divide but that didn't work either. Should z in this example range 0-1 and then get multiplied by [71][54] or does this stuff only work with a FOV of 90 or hopefully some other answer that's just not reaching my brain. Many thanks...
------------------------------Great Little War Game
bigneilm3
bigneilm3
To solve for depth given the actual size of an object, the tangent of the field of view angle is factored in.
rubicondev
rubicondev
Yeah, fixed it now. I figured it should be a straight-up rescaling but it didn't work when I first tried to do so as I had another bug elsewhere that wasn't passing the correct values in the first place.

Not exactly my finest hour! Thanks for the help though.
------------------------------Great Little War Game

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.