Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / reconstructing World Position from Depth "crytek way"

Author
Message
Kuper
17
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 22nd Dec 2014 08:45 Edited at: 22nd Dec 2014 08:48
Hi guys! I need to reconstruct World Position from depth buffer.I ve find some docs so its like you make it different ways.I prefer the way its used in Crysis. The main idea is to render out normalized view-space z as our depth and then convert it to Wpos. So there is two shaders - one is for all geometry and other is for screen quad.




The reconstruction looks correct only when main camera is in 0,0,0 coordinates.I think there is errors in quad shader.

PS
ViewProjInverse matrix which is used is set up from DBPro :

set current camera Main_Camera
view matrix4 AL_Matrix(1)
projection matrix4 AL_Matrix(2)
multiply matrix4 AL_Matrix(3),AL_Matrix(1),AL_Matrix(2)
null=inverse matrix4(AL_Matrix(4),AL_Matrix(3))
set effect constant matrix QuadEffect,"ViewProjInverse",AL_Matrix(4)

I hope my code and comments are undestandable
Thanks

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Dec 2014 10:38
Now biggie, include the eye position when working out the depth;

float3 eyepos : CameraPosition;

Kuper
17
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 22nd Dec 2014 10:47 Edited at: 22nd Dec 2014 11:10
You mean in object shader?
I get that whole reconstruction in my quad shader is wrong

Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 22nd Dec 2014 12:01 Edited at: 22nd Dec 2014 12:03
Edit: scratch that, I'm too tired to think clearly.
The view matrix (which is part of the view-projection) should contain the camra ("eye") position so I don't see why you would have to offset by that.
Are you sure your inverse view-projection isn't just an inverse projection matrix, because that should cause the results you're having with only working with the default (zero) camera transform?

Kuper
17
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 22nd Dec 2014 12:44 Edited at: 22nd Dec 2014 12:45
I'm not very advanced im matrixes - it is one of the part in hlsl which i understand indifferently.

Quote: " Are you sure your inverse view-projection isn't just an inverse projection matrix "


I have view matrix4 AL_Matrix(1) so I think that it is inverse view-projection.

Depth info is maybe correct but it reconstruction is wrong - when I rotate or move camera depth is changing unpredictable.It is also wrong when I am at 0,0,0 coordiantes.


Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Dec 2014 12:51
Quote: "You mean in object shader?"


Yes, the objects themselves will have to tell the screen shader how far their vertices are.

Unless I have missed anything in the documentation; could one detect Z-Depth any other way in model 3?

Best to follow Rudolpho's advice, he knows more about shaders than I do.

Good luck

Login to post a reply

Server time is: 2025-05-11 10:43:31
Your offset time is: 2025-05-11 10:43:31