Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Depth to World Position


In a post process material, what would be the best way to get the World Position of a pixel rendered in the CustomDepth GBuffer?

I tried CameraPosition - (CameraVector * CustomDepth.r), but the result is obviously wrong.


Product Version: Not Selected
more ▼

asked Apr 22 '15 at 02:25 PM in Rendering

avatar image

106 3 3 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

That doesn't seem far off. You probably just need to divide the CustomDepth value by the dotproduct of cameravector and cameraforwardvector.

Remember that depth is actually from an orthographic perspective, whereas real distance is shaped like a circle around the camera (ie, the side of the frame actually is further from the camera for a given 'depth').

more ▼

answered Apr 22 '15 at 04:17 PM

avatar image

2k 56 24 118

avatar image pylb Apr 22 '15 at 04:38 PM

Thanks! That was exactly it.

For others who might be interested in the answer, the code I'm using is:

WorldPosition = CameraPosition + CameraVector * CustomDepth.r / dot(CameraVector, CameraDirectionVector)

avatar image duke22 Jan 25 '18 at 09:42 PM

Excuse me for being a muppet, but what's the difference between CameraVector and CameraDirectionVector?

avatar image Deathrey Jan 25 '18 at 10:28 PM

Camera vector is a vector, that points from pixel to camera position. CameraDirectionVector, is a vector, that corresponds to direction, where camera is pointing in worldspace.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question