Search Unity

Sharp mesh edges

Discussion in 'General Graphics' started by BeautifulFish, Jan 23, 2015.

  1. BeautifulFish

    BeautifulFish

    Joined:
    Sep 25, 2014
    Posts:
    55
    Hi,

    I'm noticing some sharp edges on my door mesh. I tried smooth shading, and this softened them nicely, but added in peculiar looking shading, so I added a edge split in blender, and it fixed the shading issue. But my object still displays harsh edges.

    Wondering what advice you guys could give me to solve it (be it modelling it a different way) or changing settings.

    (The screenshot is 1280x800 on fantastic settings)

    Thanks
     

    Attached Files:

  2. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    You probably need to turn antialiasing in quality settings. Or use a fxaa post shader from the image effects.
     
  3. BeautifulFish

    BeautifulFish

    Joined:
    Sep 25, 2014
    Posts:
    55
    Cheers for the quick reply, i've tried all the antialiasing settings to no avail.

    The fxaa shaders seemed to give the smoothness I want, but then they didn't allow the object to cast or recieve shadows, but I think using shaders is the right path to look down thank you.
     
  4. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Sorry if this is a silly question but are you using the FXAA shaders directly on the mesh or using the FXAA image effect. With sharp edges do you mean the pixel aliasing on the door?

    I think it will look much better with a texture on it and more lights may reduce the hard shadows.
     
  5. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    245
    The FXAA he's talking about is a script you attach to the camera which is an imported asset called Image Effects. It makes the camera anti-alias the whole scene.
     
  6. BeautifulFish

    BeautifulFish

    Joined:
    Sep 25, 2014
    Posts:
    55
    Thanks for the replies guys. I've tried both, and all the anti aliasing shaders available and the antialiasing settings are on and on max, but I still get these jagged edges the mesh. Weirdly if I flick the graphic setting to shader type 2, the objects render perfectly put without shadows.. I don't know if that helps at all?
     

    Attached Files:

  7. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Happen to still have your model? I know my way 'round blender, and can help fix it up for you. Because to me, it appears the problem is not in unity, it's the way you have set up your models normals.

    Reason why I say this is:

    What you told us above is that you put in a couple of vertex splits to "put in hard edges." I would recommend against this, simply because there's a better way of doing this, and doing such a split would be bad for mobiles if you used several doors. Instead, I would have it so that faces that are flat on the door (i.e. not the grooves! ;)) have flat shading, while other surfaces (the previously mentioned grooves... :D) are somewhat curved, so those can be made smooth shaded.

    To do the above... (Assuming you are using blender 2.6 and up)

    First go and make your mesh all-smooth again, then go into edit mode (the tab key's your best shortcut! ;)) and select all the "flat" faces on your mesh. (i.e. the sides of the door, and anything on the front that isn't a groove) Then press the space bar to bring up blender's search box. In the text field, type "shade flat" and hit enter. all the faces selected should all now be flat-shaded!

    Also, remove whatever vertex splits you made after that. this is easily done by again tapping the space bar. but this time, type "remove doubles" into the box and hit ok. it should say up the top "removed xxx vertices" where xxx is the number of verts removed. (should be all the split ones... :D)

    If that sounds too hard for you, just send me your model, and I will fix it up for you! :) I am someone who has often had to deal with shading problems like this before. One thing i have found also is that it often happens on low-poly meshes... :D

    EDIT: Also looked at your screens, that is weird that shader model 2 emulation would fix it as well... :D

    EDIT2: Actually, as Hippocoder pointed out below this post, doing the above splits verts anyway! :D But if one is targeting a PC, it shouldn't matter all that much. Plus, Unity only renders what is visible in the camera view at the time anyway, so unless there's a really LONG corridor with 100 doors down the sides, one shouldn't have a problem at all... :D
     
    Last edited: Jan 24, 2015
  8. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    That actually splits verts. GPUs don't understand smoothing groups, so verts are split regardless :p
     
  9. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    It does? Had no idea. :D

    Does that also mean all flat-shaded cubes do this too? Damn it, not such a simple mesh after all... :D
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yep!

    You can get around it by using normal mapping to harden the appearence but normal mapping is significantly more expensive on mobile. In fact one of mobile's strengths is being able to push large amounts of verts, so you would actually gain significant performance avoiding normal mapping and making things more detailed.

    Having a scene with 100k+ verts and no normal mapping with decent shaders should run 60fps fine opaque on an ipad2 or iPhone 4S class phone from a few years ago.
     
  11. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    :D (Time to update my previous post then!)
     
  12. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah the real weaknesses would be anything in the pixel shader beyond simple MADs and stacked texture reads. You want to shovel everything into the vert shader since most mobile GPUs I've tested (except horrible cheap ancient ones nobody likes) will chew through verts happily. But it all depends on how good your shaders are.
     
  13. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Well, I find pixel shaders work well too, depending on how much you shovel need. in my case, with one of my mobile pixel shaders, the only possible bottleneck is a custom shadow map filter I applied to a shader I use for my game environments, but that's it otherwise.
     
  14. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It's simple: there's millions of pixels but only thousands of verts to process.
     
  15. BeautifulFish

    BeautifulFish

    Joined:
    Sep 25, 2014
    Posts:
    55
    FuzzyQuills thanks for the great reply!
    I had no idea that you could choose different shadings for different parts of the same object. That's really cool to know! Doing that I did manage to reduce a lot of the edge lines, so it could be a case now of my model not being high res enough

    I've attached the blender file for it anyway, if you get a chance if you could give me some possible pointers on it, whether it is too low polly or my normals are incorrect i'd really appreciate it but no worries if not!

    And hippocoder thanks as well for the information, some of it is over my head haha, but it's interesting to know more about how mobiles can process with/without complex shaders, and the way blender deals with splitting verts!
     

    Attached Files:

  16. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Well, lucky for you also that the laptop I'm typing this from has blender also!

    Will see what I can do. Might also sneak in a texture or two... :D
     
  17. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Oh, and technically, any rendering app would split the verts like that anyway, not sure if there is one that understands smooth groups properly! ;)
     
  18. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    My Verdict: For a start, AMAZING Mesh modelling skills! ;)

    The only thing I found that was a bit wrong, IMO: the door frame is missing a material. Something I prefer to do is to put a material on every object, that way, Unity doesn't confuse you when you find several "untitle or "no name" materials in a folder!

    Other than that, superb! :)

    EDIT: Another thing I will point out: your mesh UVs are outside the range Unity allows: all UV coordinate points must be inside the image for Unity to import them correctly!
     
    Last edited: Jan 25, 2015
  19. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Might as well show off the little scene I built in literally 20 mins with your door. (Note also: done in a Renderman Raytracer, not Unity!)
    Raytraced_Door_3Delight.png
     
  20. BeautifulFish

    BeautifulFish

    Joined:
    Sep 25, 2014
    Posts:
    55
    Thanks again for the replies and the kind words.
    I'll make sure to add materials to them now, all those empty unnamed materials are annoying haha. And i'll make sure to keep the uv's within the constraints from now on!

    You're render is exactly the kind of look i'm aiming for inside of unity, the edges look really good especially with shadows in there too.

    Thanks again man i've learned a lot from you! Really appreciate the time you put in to help me out
     
  21. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    You're welcome! let me know if you have any further issues. :)