Search Unity

Resolved Linear Fog Bug on Mobile

Discussion in 'General Graphics' started by ferhandemez, Sep 16, 2020.

  1. ferhandemez

    ferhandemez

    Joined:
    Jul 5, 2018
    Posts:
    11
    I am working with Unity 3D General Graphics and I am using Linear Fog. It is working correctly on Windows Editor but when I build it for Android it doesn't seem same. (I tried different fog modes but result is same). Shaders are Standard Shader btw.

    On Editor:

    onEditor.gif


    On Android:

    onAndroid.gif
     
  2. ferhandemez

    ferhandemez

    Joined:
    Jul 5, 2018
    Posts:
    11
    I fixed. Large meshes with low vertex count causes this (just like large scaled plane). The solution is divide meshes to many small meshes and increase vertex count. For example I divided 4-5 times the road.
     
    XoetziX and marcozakaria like this.
  3. CringeItIn

    CringeItIn

    Joined:
    Jan 24, 2021
    Posts:
    9
    Hey ferhandemez:) I'm working on something very similar and am facing the same/a similar problem. I want a constant linear fog in the camera view. This works fine in the unity editor but in the mobile (android build), the fog seems to "stay" at the initial camera position and my player just moves into the fog. Do you have any idea how I could solve this problem? Happy for any input!
     
  4. ferhandemez

    ferhandemez

    Joined:
    Jul 5, 2018
    Posts:
    11
    Hey! If you want to use fog just like the image titled "On Editor" above, you should divide your mesh to small pieces. Unity doesn't support linear fog for big surfaces on mobile. For example here is my road mesh:



     
    Josep97 and XoetziX like this.
  5. CringeItIn

    CringeItIn

    Joined:
    Jan 24, 2021
    Posts:
    9
    Dear Ferhandemez,
    first of all: Thank you very much for taking your time! I really appreciate that!

    Regarding the problem: I got to admit, I'm really new to unity. I'm not quite sure what "dividing the mesh" means.
    Would this mean I should increase the "size" property of the "floor" objects mesh component? Or should I instantiate multiple objects connected to each other (looking at your second image)?

    Best regards
     
  6. ferhandemez

    ferhandemez

    Joined:
    Jul 5, 2018
    Posts:
    11
    Mesh dividing is 3D Modelling term. If you didn't make your models yourself, you are using an asset or Unity's 3D objects (cube, sphere etc) for ground, right? Can you show me an image of ground object?
     
  7. CringeItIn

    CringeItIn

    Joined:
    Jan 24, 2021
    Posts:
    9
    Yes, I'm using a simple cube as the "floor". Attached are the images of the "floor" and the desired view, which can be seen in the editor.
     

    Attached Files:

  8. ferhandemez

    ferhandemez

    Joined:
    Jul 5, 2018
    Posts:
    11
    The X scale of your cube is very big probably. Could you try to get same road with many cubes that has smaller x scale? For example if x scale (longest axis) of your cube is 100 units, try to create same road with 20 cubes that has 5 units x scale.
     
    Last edited: Mar 14, 2021
  9. CringeItIn

    CringeItIn

    Joined:
    Jan 24, 2021
    Posts:
    9
    Hey ferhandemez! After reading your suggestion, I played around with smaller "floor" sizes, and this indeed resulted in a fog as I wanted it to be! Thank you very much!:)
    If you are willing, could you explain why the object size has effect on the fog? This didn't even come to my mind.
     
  10. ferhandemez

    ferhandemez

    Joined:
    Jul 5, 2018
    Posts:
    11
    You're welcome! I'm glad to it's fixed. :) In my opinion Unity doesn't support the linear fog for big surfaces on mobile. We need to use smaller surfaces to it works correctly. Keep in mind, when you make your models yourself you should divide your surfaces to small pieces.
     
  11. marcozakaria

    marcozakaria

    Joined:
    Sep 17, 2017
    Posts:
    23
    Thanks solved issue
     
  12. XoetziX

    XoetziX

    Joined:
    Mar 16, 2021
    Posts:
    16
    @ferhandemez First of all, thanks for this solution regarding the fog.

    However, creating lot's of smaller ground pieces causes a strange new problem. There seem to be invisible edges now between these ground blocks, which cause my "block car" sometimes but not always (!?) to jump when passing over to another ground piece.

    Obviously, I only changes one axis, expecting that this should lead to no "invisible" edges or something similar.

    Does anyone have an idea what could cause this problem?

    The only idea I have is that something my cause either the "car block" or the ground blocks to slightly change there Y position. But I have not idea what or why this should happen?!
     

    Attached Files:

    Last edited: Feb 24, 2022
  13. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,789
    You don't have to create separate meshes, just have a mesh with enough vertices since on mobile fog is done per vertex.
     
  14. XoetziX

    XoetziX

    Joined:
    Mar 16, 2021
    Posts:
    16
    @AcidArrow Thanks for this hint. I did some google research now and maybe you could give me another advice.

    So far I did not find a simple way to change the vertices of a mesh within the unity editor, but only via scripts.
    SInce I am far away from being a 3D modeling expert, I would prefere the easiest version.
    Is it somehow possible to do it via the editor or will I have to fight my way through some 3D modeling tutorials? :)
     
  15. UzairHassan11

    UzairHassan11

    Joined:
    Sep 3, 2019
    Posts:
    5
    this worked for me
    to male the track large I scaled it up a lot so as a result fog was working weird on the track for all fog modes.