Search Unity

Fireflies/Anti Aliasing

Discussion in 'Editor & General Support' started by lakru, Mar 23, 2011.

  1. lakru

    lakru

    Joined:
    Feb 19, 2008
    Posts:
    116
    Hi

    We have a big problem with our specular materials after switching from 2.6 to 3.2.

    The problem is that the models has these fireflies or really bad anti aliasing.

    You can see an example here: http://lovemyhome.net/clients/hjortknudsen/customizer/ucreate/

    If you click on a furniture and then apply a leather material you should see the problem. (Leather is the last materials: semi aniline and madras)

    Does any of you guys know a solution to this problem?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I don't see any problems; maybe you should post a screenshot of what you see.

    --Eric
     
  3. lakru

    lakru

    Joined:
    Feb 19, 2008
    Posts:
    116
    Here is a picture where you can see all the white dots.

     
  4. Frank Oz

    Frank Oz

    Joined:
    Oct 13, 2010
    Posts:
    1,560
    It's something to do with some of the textures, lakru. Either they're not filling the UV's fully, or the mip maps are messing them up, or set to clamp or repeat or ok I dunno, but it's the textures I'm sure.
     
  5. lakru

    lakru

    Joined:
    Feb 19, 2008
    Posts:
    116
    I don't think it is something with our textures. We are using tiling textures on both fabrics and leather, but it is only on the leather that uses specular map it happens. So it must be something in the specular shader.

    It wasn't like this in 2.6 only after we updated to 3.2.

    Pic:

     
    Last edited: Mar 23, 2011
  6. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    ive seen this problem too... in some of my projects.
     
  7. lakru

    lakru

    Joined:
    Feb 19, 2008
    Posts:
    116
    I would like to hear an opinion from one of the Unity guys, because this is a problem in all our projects.
     
  8. kondrup

    kondrup

    Joined:
    Apr 23, 2009
    Posts:
    205
  9. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Are those seams due to not-continuous mesh maybe?
     
  10. kondrup

    kondrup

    Joined:
    Apr 23, 2009
    Posts:
    205
    @megmaltese - No, it has something to do with unity's lighting, Anti-Aliasing or the specular shader.

    In v. 2.6 all our assets worked perfectly using the same shaders and light setup.
     
  11. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Could you send me that model so i can check?
     
  12. 2dfxman1

    2dfxman1

    Joined:
    Oct 6, 2010
    Posts:
    1,065
    Thief!
     
  13. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
  14. Frank Oz

    Frank Oz

    Joined:
    Oct 13, 2010
    Posts:
    1,560
    You mention AA so I take it you're using forward rendering, tried Deferred yet?
     
  15. JetSoap

    JetSoap

    Joined:
    Dec 29, 2010
    Posts:
    107
    Ahh, You Beat me to it! :D

    Also, Why is it that when i tried to click the 'Reply' Button, my cursor disappeared every-time....Weird....
     
  16. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,724
    It looks fine to me (the webplayer I mean), so maybe it's something related to your graphics card/driver?
     
  17. lakru

    lakru

    Joined:
    Feb 19, 2008
    Posts:
    116
  18. lakru

    lakru

    Joined:
    Feb 19, 2008
    Posts:
    116
    @AcidArrow

    Did you change to a leather material?
     
  19. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,724
    I think I did, hang on I'll try again and edit this post.

    EDIT: Ah, stupid me, I didn't. I see it now. I guess we can rule that one out. I think you have a bug here, send a bug report.

    EDIT2: I should also add that I don't see anything really wrong with the model
     
    Last edited: Apr 1, 2011
  20. kondrup

    kondrup

    Joined:
    Apr 23, 2009
    Posts:
    205
    Ye' I also think we can safely send a bugreport - the problem is that we have clients using our products right this minute, which means that we need a solution now.

    We will happily reward a good solution to this problem :)
     
  21. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,724
    Do the leather materials also change the shader? It could be a problem with the shader then.

    EDIT: Also, I see you are using unity 3.2? Maybe upgrade to 3.3 and see if the bug is already fixed?
     
  22. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    Thank you for posting this, we didn't get around to do it.

    We are having the same problem, and I can confirm the behaviour. The following symptoms can be noticed:
    - rendering was fine in 2.6, problem occured in 3.x
    - it is independent from texturing, there are no holes in the model, the meshes are correct
    - the problem is least visible if you DISABLE antialiasing. it is worst with 2x antialiasing, but even 16x antialiasing is much worse than no antialiasing (we're using nvidia GTX's)
    - the problem is invisible if you look at the model from closeup
    - the problem is extremely visible with forward rendering
    - the problem is invisible with the vertexlit rendering path
    - the problem is invisible with deferred lighting - but probably only because there is no antialiasing in deferred lighting! there are already a few "white pixel" artefacts visible with deferred lighting, which are less visible in forward rendering without antialiasing, and which are not present with vertex lighting.
    - the problem is most prominent in the builtin Specular shader (it is independent from the Shininess value, but most noticeable with maximum shininess, since the rest of the model is very dark then), but it is also visible in the VertexLit and Diffuse shaders (although here it might be a different problem related to subpixels)
    - with the Specular shader, the problem is equally prominent if the light source is behind the object, and barely noticeable for Diffuse and VertexLit
    - the problem appears to be connected to long, thin polygons, which are usually present along the edges of detailed models, but I seem to remember having seen this even if the aspect ratio was undistorted, so the important fact is the view of polygons at grazing angles

    I'll post a few snapshots in a moment.

    EDIT: all 3.x version have that problem, tried 3.0-3.3
     
    Last edited: Apr 1, 2011
  23. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    rendering path vs. antialiasing comparison
     

    Attached Files:

  24. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    backlit and closeup behaviour.

    note the problem is not the long, thin polygon itself, but the regular connection between two angled polygons with interpolated normals (there are no deformed polygons involved)
     

    Attached Files:

  25. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,724
    It seems there is something wrong with the way unity calculates normals when smoothing and the specular shading.

    If you switch normals to Calculate and angle to 0 (effectively having a flat shaded result), the artifacts go away.

    Obviously that is not a solution because the shading looks horrible for a couch.
     
  26. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,724
    Okay! Solution! (sort of)

    Switch to Bumped Specular. Put a flat normal map (that effectively does nothing, you can generate one if you go to an image, tick Generate Normal map in the settings of the image and turn down Bumpiness to 0). I think then the effect is greatly reduced or gone. I guess it's because then the shader re-writes the normal calculation, which is where the problem is probably.
     
  27. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    Whoa, nice find!
    I can confirm the problem is mostly gone if you replace "Specular" by "Bumped "Specular", even without assigning a normal map.
    There are only a few artifacts remaining (the ones also visible with Duffuse/VertexLit shaders), but the majority of problems is gone.
    So it's definitely a bug in the normal handling of the Specular shader, as opposed to the Bumped Specular shader.
     
  28. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Here are some ruminations: I guess they introduced this artifact in rendering to gain performance.
    With the computational power of today's GPUs it's not a problem to add a 10% more polys, so they added this to the pipeline.

    You are so probably required to model "round corners" by adding additional geometric detail at the tips.
    If you don't understand what I am talking about just ask and I'll explain more in detail.

    By adding a flat normal mapping to the model you somewhat "flatten" the phong interpolation, thus reducing the artifact.
     
    Last edited: Apr 1, 2011
  29. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,724
    I understand but I think you are making a lot of assumptions.

    And the effect is not limited to hard edges (which you sometimes do want anyway).

    It can appear anywhere at certain angles.
     
  30. kondrup

    kondrup

    Joined:
    Apr 23, 2009
    Posts:
    205
    Yeah this actually seems to work - Wierd!

    The following comment is just what we assume - can anyone tell if this is true or not?

    "The problem is that the "Bumped-Specular-shader" is more expensive than the specular shader - and this actually means alot in our case because we have many assets in our scene at one time."

    We could be wrong - maybe the normal shader is not more expensive as long as you don't use a normal map in it?
     
  31. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,724
    It probably is a bit more expensive, but I'm guessing not enough to make any noticeable difference.
     
  32. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Yes they are ruminations, but it's a fact that the rendering engine changed.
     
  33. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,724
    Yes, but I'm not sure this is a calculated side-effect of some design decision they took when they changed the render engine, or simply a bug. You are assuming it is a design decision, but I don't see any hints of that.
     
  34. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Yes sure that's just my speculation, but when you think that Unity people are not exactly the last on the field, they are probably basing their dev on some factors... one possibly being:
    - Hey but if the engine works like this we'll have those artifacts on tight triangles!
    - Well who cares, anyway there are so many triangles available that you can refine the round corners easily, that's the way you should model nowadays. OR, you can just splat normal maps, that's now happening 90% of the time, right?
     
  35. kondrup

    kondrup

    Joined:
    Apr 23, 2009
    Posts:
    205
    I could not imagine them doing this on purpose - it must be a bug.

    Well, here is another example:


    Unfortunately the "solution" is not perfect for us - due to several reasons but If we end up using it we will make sure to stick by our word and give you a 'donation' AcidArrow :)
     
  36. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
  37. ricardo_arango

    ricardo_arango

    Unity Technologies

    Joined:
    Jun 18, 2009
    Posts:
    64
    The specular shader is not doing vector normalization everywhere which may be causing those erros. This is obviously for speed.

    A workaround for this is to copy the builtin specular shader available here and add a line after o.Specular = _Shininess; with o.Normal = fixed3(0,0,1);
     
  38. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    Ah, thanks! I was looking for this, but I don't speak SurfaceShadish. For example, in the builtin shader, o.Normal is never assigned - which normal is it using then?

    What good is a speed optimization, if it introduces severe artifacts (=the white pixels discussed here, and the facetting discussed in the other thread) and creates results that are mathematically plainly wrong? If this "optimization" is done on purpose, there should be at least a warning/explanation somewhere, or a way to choose between speed and quality. :-(
     
  39. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Have you tried rendering it at a different scale and zooming the camera right out? This can solve issues with different engines. It looks to me the object is really tiny. Try it for a test.
     
  40. kondrup

    kondrup

    Joined:
    Apr 23, 2009
    Posts:
    205
    We at interactive lab production completely agree with you on this point.
    - We have contacted unity support and they confirmed that this was indeed for optimization reasons.

    But why the FU...£@£€# would they want to make an optimization that causes these errors in the shader?
    And also why did they not inform about this """""optimization""""?

    We are working with very large projects and have several deadlines every month so upgrading to unity 3 has not been easy and to top it all off we are now having thousands of assets online that our customers use on a daily basis with horrible looking shaders.

    Now we have to spend at least a week converting everything to the fixed specular shader (the shader we still have to write btw.) and building all our assetbundles.

    yeah... we are pretty frustrated about this - atm. this shader problem has probably already cost us 1-2weeks of extra work, bughunting for the problem, posting on this forum and paying for conversion script.
     
  41. jcarpay

    jcarpay

    Joined:
    Aug 15, 2008
    Posts:
    561
    Did they told you they have the intention to fix this?
     
  42. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    One thing that just occured to me: Both the 2.6 and 3.x Specular shaders show the facetting problem - but only 3.x has the additional white-pixel problems described here. I wonder why.
    Both problems can be solved with the suggested o.Normal assignment (at least in 3.x - haven't tried 2.6, since there are no Surface shaders used).
     
  43. kondrup

    kondrup

    Joined:
    Apr 23, 2009
    Posts:
    205
    @jcarpay - They said it was expected because of the optimization. It was my colleague Lasse who contacted them, so I am not 100% sure on the details but we can post the answer in this thread tomorrow.
     
  44. Dynamike666

    Dynamike666

    Joined:
    May 19, 2011
    Posts:
    2
    Any news about that issue?
     
  45. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    Problem is still persistent in 3.4, both workarounds are still working.
     
  46. felix_berninger

    felix_berninger

    Joined:
    Aug 19, 2011
    Posts:
    30
    will this problem be fixed anytime soon?

    we are using 3.5 and it is still present.

    having this problem with some bought shaders and really need to get rid of these white pixels.
     
  47. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    4.0 problem going strong lol. Using normals anyway, but still, come on guys.
     
  48. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Check your geometry. This kind of gaps are often only worsened by AA but present on the geometry level actually. Basically whenever your model has a 'seam' it results in split vertices and if your modeling exported them even with the slightest offset, this will result in a numeric impression that causes a visual white gap or seam.
    This is not a unity fault but just how graphics cards and their drivers act.

    If it looked right in U2 but not in U3 then chances are very high that the import settings were not adopted to how the split angle etc in U3 work, as thats the only thing I can recall that changed that impacts it (the import settings will impact on where vertices will be dublicated etc in the end to create the desired 'seams' for the splits)
     
  49. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    I had the same issue with my custom shaders. In my opinion the problem is caused by Unity no longer normalizing the normals during per-pixel lighting rendering which of course is faster than what 2.6 did.

    The solution is to add a normalize step to the shader code. If the standard specular shader is used, then it has to be replaced by a custom surface shader which also does normalizing per pixel.

    Just take the SimpleSpecular example surface shader from the unity surface shader lighting tutorial page and change the lighting routine to this and you'll see a lot less fireflies.

    Code (csharp):
    1.  
    2.       half4 LightingSimpleSpecular (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
    3.           half3 n = normalize (s.Normal); // Added line to fix fireflies
    4.           half3 h = normalize (lightDir + viewDir);
    5.  
    6.           half diff = max (0, dot (n, lightDir)); // changed this
    7.  
    8.           float nh = max (0, dot (n, h)); // changed that
    9.           float spec = pow (nh, 48.0);
    10.  
    11.           half4 c;
    12.           c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten * 2);
    13.           c.a = s.Alpha;
    14.           return c;
    15.       }
    16.  
     
  50. topaz7

    topaz7

    Joined:
    Dec 15, 2012
    Posts:
    76
    This problem has also occurred to me. Why is it that everything has a dithering effect on edges making a sluggish look?