Godot: Shadow Normal Offset Bias

Created on 4 Mar 2018  路  9Comments  路  Source: godotengine/godot

Normal Offset is a better way to eliminate self-shadowing with much less to virtually no peter panning:
gdc_poster_normaloffset

video explanation: https://web.archive.org/web/20160602213857/https://www.dissidentlogic.com/old/video/Techniques/NormalOffsetShadows_0001.wmv

Note: Godot's "Normal bias" seems to be slope bias, and it introduces a lot of peter panning.

feature proposal rendering

Most helpful comment

Getting somewhere but still needs a lot of work:

grafik

The PR might take me some time.

All 9 comments

I just came across this when messing around with shadows and from my experience, depth bias plus a normal offset as described above can give very good results with almost zero peter-panning.

It should be fairly easy to implement as it's really just about adding the normal vector onto the 3D position of the fragment which is shaded (with some form of weighting the length of the offset).

Also, this type of offset should be included in all light types, not just directional light sources.

I'll see if I can get this implemented

Getting somewhere but still needs a lot of work:

grafik

The PR might take me some time.

Any progress with this?

At this point I think it may be better to work in the 4.0 branch, btw.

@reduz I ran into some trouble with calculating the offset distance and haven't had much time to work on it since then.

But the implementation should basically work like this:

  • tone down the depth bias (it's still useful but doesn't have to be as high)
  • offset the sampled position into the direction of the surface normal.
    Theoretically the amount should be the shadowmap pixel size at the sampled position in world space or at least proportional to it.

It's mostly just a few lines of code in the shader and maybe a small adjustment on the c++ side (shader inputs).

@CptPotato Could you upload your work in a branch somewhere? Thanks in advance :slightly_smiling_face:

I don' t understand, does not Godot do this already with the normal bias?

@reduz as far as I know it doesn't. Godot seems to only uses a depth bias (also based on the surface angle) but it only offsets the depth.

The proposed method changes the sampling position by offsetting it away from the sufface (in 3d) before reading from the shadow depth map. The big difference is that you can eliminate self-shadowing even at very shallow angles.

Was this page helpful?
0 / 5 - 0 ratings