Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadow Normal Offset Bias #17260

Closed
Enhex opened this issue Mar 4, 2018 · 9 comments · Fixed by #37678
Closed

Shadow Normal Offset Bias #17260

Enhex opened this issue Mar 4, 2018 · 9 comments · Fixed by #37678

Comments

@Enhex
Copy link
Contributor

Enhex commented Mar 4, 2018

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.

@CptPotato
Copy link
Contributor

CptPotato commented Mar 15, 2019

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.

@CptPotato
Copy link
Contributor

I'll see if I can get this implemented

@CptPotato
Copy link
Contributor

Getting somewhere but still needs a lot of work:

grafik

The PR might take me some time.

@reduz
Copy link
Member

reduz commented Oct 24, 2019

Any progress with this?

@reduz
Copy link
Member

reduz commented Oct 24, 2019

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

@CptPotato
Copy link
Contributor

CptPotato commented Oct 26, 2019

@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).

@Calinou
Copy link
Member

Calinou commented Dec 21, 2019

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

@reduz
Copy link
Member

reduz commented Dec 21, 2019

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

@CptPotato
Copy link
Contributor

@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.

reduz added a commit to reduz/godot that referenced this issue Apr 8, 2020
- Made shadow bias size independent, so it will remain when changing light or camera size.
- Implemented normal offset bias, which greatly enhances quality.
- Added transmission to subsurface scattering
- Reimplemented shadow filter modes

Closes godotengine#17260
@akien-mga akien-mga added this to the 4.0 milestone Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants