engine icon indicating copy to clipboard operation
engine copied to clipboard

Toksvig specular doesn't work

Open slimbuck opened this issue 3 years ago • 7 comments

Toksvig specular antialiasing has been broken in the engine for the last two years.

This was unintentionally broken when detail normal maps were added to the engine (see https://github.com/playcanvas/engine/pull/1968/files#diff-dc5bc7097c897bc531ef1e99641a4b3dbd3f70b96fd0c906e264c6f540771414R5).

Toksvig factor is based on the length of the dNormalMap vector as read from the texture/mipmap. The normalise call on this line results in length always being 1.0, effectively disabling toksvig.

We must decide how to proceed: either we re-enable toksvig support in the engine or we remote it.

Keep
Advantages
  • less specular aliasing, simple implementation
  • works with most gltf assets
  • essentially "free" since we've always executed the shader math
    Disadvantage
    • re-introducing toksvig has the potential to change lighting/specular in existing projects
    • looks significantly different to vanilla/non-toksvig specular
    • only works with blinn-phong anyway and we'll likely move to GGX in future
    • toksvig only works in some cases:
      • doesn't work with XY/basis normals maps (which is required for high-quality compressed normals)
      • only impacts punctual lights, doesn't address geometric-based aliasing
      • requires valid normals maps (containing normalised normals)
    Remove
    Advantages
    • no impact to existing projects
    • shaders will be smaller, faster
    • simplify chunks
    Disadvantages
    • continue to live with more aliasing

    slimbuck avatar May 19 '22 14:05 slimbuck

    Would be great to show some 1:1 examples, which highlight issues of aliasing, and how Toksvig handles them.

    Maksims avatar May 19 '22 15:05 Maksims

    Hi @Maksims ,

    Here's a contrived example from a test in the model viewer. I've set pixel scale to 8 so we can see the differences easily.

    Sphere on the left has "modified toksvig" and on the right is none. The two spheres are identical otherwise.

    https://user-images.githubusercontent.com/11276292/169382445-40ccd01d-9cfe-4da6-9229-83c2680d0542.mov

    As you can see, the toksvig highlights are better behaved, but also much brighter.

    slimbuck avatar May 19 '22 19:05 slimbuck

    See possible solution here: https://www.dropbox.com/s/89pvx9obhv6m0pk/High%20Quality,%20High%20Performance%20Graphics%20in%20Filament%20(Handout).pdf?dl=0 page 29

    mvaligursky avatar May 27 '22 08:05 mvaligursky

    See possible solution here: https://www.dropbox.com/s/89pvx9obhv6m0pk/High%20Quality,%20High%20Performance%20Graphics%20in%20Filament%20(Handout).pdf?dl=0 page 29

    Yes! We need to move to ggx for this.

    slimbuck avatar May 27 '22 15:05 slimbuck

    Any updates on this? We're running into issues with specular aliasing on almost every project we make. We've even had customers point it out, saying it looks bad. On high-end projects good anti aliasing is super important, so we'd really appreciate if this was fixed.

    animech-sijo avatar Aug 15 '22 08:08 animech-sijo

    Hi @animech-sijo - this makes perfect sense, and we'll try to allocate some resources to this in the not too distant future. Thanks!

    mvaligursky avatar Aug 15 '22 08:08 mvaligursky

    Is there any status on this? Do you have an estimate on when you think it will be released?

    Carblo avatar Sep 01 '22 06:09 Carblo

    @animech-sijo Would you be able to post or send us some projects/scenes that have these issues please?

    yaustar avatar Oct 04 '22 11:10 yaustar

    @yaustar You might've already gotten this, but here's a project showing specular aliasing. It's a private project, hope that works.

    animech-sijo avatar Oct 04 '22 13:10 animech-sijo