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. Dismiss Notice

Texture on a single plane: How to deal with back-face culling?

Discussion in 'Editor & General Support' started by freerun, Sep 14, 2014.

  1. freerun

    freerun

    Joined:
    Dec 16, 2013
    Posts:
    29
    I'm made a very simple plant with just textures on simple planes, so I can save on performance. But back-face culling kinda ruins it. How to I counter this?



    error1.png error2.png
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You could use a shader which doesn't use backface culling, but that's not always a good solution. I think it's more common to copy the model in your modelling software and simply flip the directions. This way you'd have more polygons in your scene, but it's most-likely the better solution as far as i know as only one of both sides can be visible at once anyways.
     
  3. freerun

    freerun

    Joined:
    Dec 16, 2013
    Posts:
    29
    Are you talking about flipping the normals?
    --------------EDIT--------------
    Nevermind, found a way.
     
    Last edited: Sep 14, 2014
  4. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Yes, the normals.

    Any other way that you found out?
     
  5. freerun

    freerun

    Joined:
    Dec 16, 2013
    Posts:
    29
    Flipping the normals would still keep a single normal. Extruding the vertices creates two normals, at the expense of a couple of tris.
     
  6. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Extruding also adds polygons between both sides, which are most-likely pretty small in your case and cannot be seen by the user, but they're still there for the engine.

    What i meant is duplicating your leaves, keep one as it was before and flip the other one. This way you don't have the extra polygons connecting both sides with each other. That should work, i've already used that method in blender and exported everything to Unity.
     
  7. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Extruding slightly is the way I would go... simply flipping and keeping the two models at the same location may cause z-fighting issues as you'll have two polys at the same location... although if they're backface culled it may not. Only way to know is to try it. The other benefit you get of extrusion is when viewing from a grazing angle or a distance from an angle it would probably look more accurate.
     
  8. EreRune

    EreRune

    Joined:
    Sep 14, 2014
    Posts:
    4
    Back face culling is a rendering optimization. If you don't want it, just turn it off by adding two words; "Cull Off" to your shader.

    Making duplicate polygons with reversed vertex normals is a waste of processing power for unnecessary culling calculations and waste of memory and disk space to store unnecessarily doubled mesh data.
     
  9. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    That's true. However, if i'm not mistaken there's still the problem with incorrect lighting then. It rather depends on the situation.
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Correct, using "cull off" results in incorrect lighting on the opposite side. While occasionally this can actually be what you want, in most cases you should just duplicate and flip normals (don't offset, there's no z-fighting since you can only ever see one side or the other)...it's not like GPUs have difficulty rendering polygons.

    That won't necessarily save on performance; there's a reason Unity Pro has the option to have tight-fit mesh sprites rather than quads. If you have large empty areas, the GPU still has to render all those transparent pixels, so having more complex meshes that better fit the texture can be faster even though there are more polygons.

    --Eric
     
  11. EreRune

    EreRune

    Joined:
    Sep 14, 2014
    Posts:
    4
    If lighting is a consideration then you are right. Actually lighting problem can be solved with a two-pass shader, but having a second pass most probably makes things less efficient then having duplicate faces.
     
  12. freerun

    freerun

    Joined:
    Dec 16, 2013
    Posts:
    29
    I see, but wouldn't occlusion culling fix that problem?