Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question Problem with thin layer texture appearing very blotchy/broken

Discussion in 'General Graphics' started by james_sg, Feb 3, 2023.

  1. james_sg

    james_sg

    Joined:
    Jun 30, 2020
    Posts:
    10
    I'm having some graphics issues with one of my WebGL builds, using URP. I have some layers in a wall which I want to show and hide. One of them is very thin. When I play the game inside in Unity the texture looks fine, but in the WebGL build, it looks very patchy and glitchy until i zoom in very close to the layer it kind of appears normal.

    I have tried playing with many of the graphics quality, camera and lighting settings but I can't seem to solve it. Any ideas? Screenshot of issue attached :)
     

    Attached Files:

  2. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    Have you tried using a quad instead of a 'thin object'?
    My guess is that WebGL uses less accurate objects for float (such as half or fixed) and thus the bounding box of the renderer is just too small.
     
  3. james_sg

    james_sg

    Joined:
    Jun 30, 2020
    Posts:
    10
    Thanks for the response. I don't have much experience with what you've mentioned. I'm using FBX meshes which were exported from a drawings program. Would there be a way to convert that to a quad?
     
  4. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    Delete all but your front-facing faces.
    Then check if the normals are correct.
     
  5. james_sg

    james_sg

    Joined:
    Jun 30, 2020
    Posts:
    10
    Thanks again. I tried playing around with the front facing render settings, but it didn't really work.

    I'm pretty sure this could work, there are just some settings a miss. I have another similar project with similar layers and thicknesses which work fine in WebGL. I'm going to see if I can compare settings.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,243
    This is a basic example of z fighting.

    WebGL doesn't support reversed Z depth rendering, which significantly improves the accuracy of Z depth sorting, which means your camera's far clip and especially near clip ranges will affect how well the GPU can sort two planes that are very close together.

    The solutions are:
    1. Increase the camera's near clip plane to as high as you can reasonably allow. You can also decrease the far plane, but this will have less immediate impact. Just doubling your near clip plane can have a profound impact on z fighting reduction.
    2. Move the planes further apart. This can be done manually in the content, or with an offset in the shader. For hand written shaders you can use the Offset render state command, but this isn't exposed for Shader Graph. This is unfortunate because the shader Offset exists explicitly to solve this kind of issue. Alternatively you can apply a rough approximation of Offset in the Shader Graph itself, like this:
    https://forum.unity.com/threads/dep...or-something-equivalent.1145399/#post-7354403
    The real way Offset works is significantly more complicated, and cannot be perfectly reproduced by manipulating vertex positions. But one of the key differences between that Shader Graph approximation implementation and the real Offset is how much the surface is pulled towards the camera increases with the surfaces distance from the camera. So that's something you could also add if you were inclined to.
     
  7. james_sg

    james_sg

    Joined:
    Jun 30, 2020
    Posts:
    10
    @bgolus you're completely correct, it was z fighting and the near clip plane was the issue! That's annoying because I thought about this but only focused on the far plane clipping!

    Thanks for saving me much more time and helping to get my show on the road :)