Jump to content
  • Advertisement

3D Stuck with restoration Normals from Depth

Recommended Posts

Posted (edited)


I need normals render in my SSAO so I've decided to restore normals from depth using this articles:


and also I've tried all these solutions:


But I've got problems.In fact all solutions produce incorrect results.

Only one working code is this, but it provides horrible artifacts on edges.

Normal = cross(ddx(WorldPos),ddy(WorldPos));
Normal = normalize(Normal);

All other solutions give something like this strange spot .  Also normal colors change with camera movement/rotation.


Here is my depth render.I use 32 float so here is Depth*0.001



Edited by Just1

Share this post

Link to post
Share on other sites

The reason you're seeing artifacts is that you're attempting to calculate the normals based on what's called the "gradient" of the world position at the current pixel, which is a measure of how quickly it is changing from pixel to pixel. At the edges of objects, the gradient is very steep because the position changes abruptly across two pixels. So rather than calling ddx on the world position, I would sample the depth buffer two more times (like the examples you linked to do) with small offsets up and to the left for example, and calculate the normal from that.

Share this post

Link to post
Share on other sites

So this is what I tried.

But I get strange gradients (picture 1). And normals color is changing on camera movement/rotation.

Share this post

Link to post
Share on other sites

If your normals are changing as your camera moves then your world positions must be in view space. Regardless, I don't think ddx(WorldPos), ddy(WorldPos) will rerturn a valid normal.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!