Advertisement

Stuck with restoration Normals from Depth

Started by March 28, 2019 01:11 AM
3 comments, last by ajweeks 5 years, 10 months ago

Hi!

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

http://theorangeduck.com/page/pure-depth-ssao

and also I've tried all these solutions:

http://answers.opencv.org/question/82453/calculate-surface-normals-from-depth-image-using-neighboring-pixels-cross-product/

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.

NormalsError.jpg.7450b11c2f7cd88311bb05ce3d9f1da1.jpg

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

 Depth_.jpg.8dd7a17be5589823eaa4f559626cb889.jpg

 

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.

Advertisement

So this is what I tried.

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

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.

This topic is closed to new replies.

Advertisement