playcanvas / engine

Powerful web graphics runtime built on WebGL, WebGPU, WebXR and glTF
https://playcanvas.com
MIT License
9.72k stars 1.36k forks source link

Toksvig specular doesn't work #4260

Open slimbuck opened 2 years ago

slimbuck commented 2 years ago

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
    Maksims commented 2 years ago

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

    slimbuck commented 2 years ago

    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.

    mvaligursky commented 2 years ago

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

    slimbuck commented 2 years ago

    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.

    animech-sijo commented 2 years ago

    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.

    mvaligursky commented 2 years ago

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

    Carblo commented 2 years ago

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

    yaustar commented 2 years ago

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

    animech-sijo commented 2 years ago

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