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

WIP - Smooth Fade LOD

Discussion in 'Works In Progress - Archive' started by Haagndaaz, Oct 7, 2014.

  1. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    As wonderful as the Unity LOD system is, I have always desired the ability to be able to fade between LODs. This is what I am seeking to accomplish. Also, when its done, I want to release it for free!

    Goals:

    1. Imitate basic LOD functionality - DONE!

    2. Add option to fade between LODs - Mostly finished!

    3. Ability to choose the type of fade shader for each material present in LOD objects

    4. LOD Categories (more abstract distances and such for each category)

    5. Prettier looking inspector GUI and automatic setup functions (get objects with suffix '_LOD0', etc. to automate things as much as possible)

    How does the system work?

    Each object that will be doing LOD swapping has an 'actorLOD' script attached to it which sets up individual properties. Then the player object or camera has a 'controlLOD' script attached which does all of the distance computation and sends the results to the individual actors. For optimization sake, it is of course not running every frame for every actor in the scene, there is a variable called 'updateWait', this is how many seconds the script waits before running again. When it runs it first finds the objects that are within range, then only calculates distance for those objects and sends the result of that distance to the actor.

    Currently it gathers actors using physics.ColliderOverlapSphere which requires a collider component on every actor object, which is not ideal, so if anyone knows a way to gather objects in another way, I'd love to hear!

    Here is the github: https://github.com/haagndaaz/Coltron-LOD

    EDIT: fixed the link, demo actually runs!
    Proof of concept in a fairly eye pleasing environment: http://haagndaaz.x10host.com/UnityProjects/ColtronLOD/LOD Demos.html

    Post any comments or suggestions for improvement
     
    Last edited: Oct 9, 2014
  2. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,605
    I don't think you linked the correct link in the web player. You have it to download the player. Make it inside it's own folder(web player and html file).
     
  3. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    lol, thanks, never posted a demo before haha, fixed the link, I think
     
  4. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    Will it have LOD alpha fading in and out like Oblivion ? It was so subtule it's hard to notice it if you don't pay attention.
     
  5. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    That's the plan! Currently I am working out the normalized 0-1 distancing for whether it is the last LOD in the list or not, since they fade differently. Once I have a proper formula for the normalized distance then I can apply it to the alphas.

    Hoping to have a working (if not ugly interface) prototype to give out for testing by the end of the week if all goes well
     
  6. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    Huzzah! After spending so much time laying the framework, I finally get to enjoy the (albeit still a bit buggy) fruits of my labor!

    Image of it in action:

    Demo has also been updated, beware though, it has bugs, in order to initialise it properly, just run around for a bit and then it acts as it should, I'll fix this tomorrow and such, for now though it is bedtime:
    http://haagndaaz.x10host.com/UnityProjects/ColtronLOD/Test.html
     
    Last edited: Oct 8, 2014
    zenGarden likes this.
  7. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    Good :)
    I notice the dissolve shader should totally dissolve or show a model at distances limits, instead the effect begins and just stops showing a mid dissolved cube. In Guild Wars 2 the effects entirely dissolve progressively a model when you reach some distance, but it don't stop showing a mid dissolved one.
    I'll give a try at Skyrim that uses the alpha fading to see if the effect can stop at 0.5 alpha or goes from 0 to 1 each time ?
     
  8. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    Good point, and actually that would make it much simpler. I'll play around with it and see how it looks
     
    zenGarden likes this.
  9. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    (Somewhat) stable fading accomplished! I realised why the objects weren't initializing properly, because the distance was starting at zero and getting moved up to the proper number on startup, found that if I set the distance to automatically equal the maxDistance from the beginning then all objects 'distance' parameter are moving down, so no more random blips before fading in!

    Here is the new demo! http://haagndaaz.x10host.com/UnityProjects/ColtronLOD/LOD Demos.html

    And a screenshot of the new demo (reused the environment from an old project that never finished):
     
  10. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    The dissolve is to oslow , in Guild Wars 2 it is two times faster, harder to notice.
    I prefer Oblivion/skyrim method with the fade in and out full alpha object , it's lot more hard to notice, you don't see nothing until you really concentrate to look at the effect :)
    I find the the dissolve shader effect lot less effective as it catches your attention due to the effect and holes on the object compared to some progressive alpha fading with a smooth transition.
    Anyway good work.
     
  11. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    There is a variable called 'fadeDistance' whcih can be increased/decreased to make the fade slower/faster if you want, perhaps the next demo I will expose some of the variables so that they can be manipulated while running around and show some stats of what is going on in the background.
    Yea, now that I have fiddled around with this method a bit, I may change it over to just a full swap when the correct distance is tripped, it would probably be easier, finding that getting a correct initialisation is a bit difficult currently.
    The dissolve shader is just a standard cutout shader since with a solid object in unity the cutout shader is more accurate with its proper depth and such, but the system is built so you can choose either type of transparent material and it will work automatically!
    Any other features that you would like to see in a package like this?
     
  12. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    How many LODS are possible ? Does it supports animation ? It is compatible with any shaders ?
    Can we have different shaders on ach LOD stage ? This is usefull to have models some more distant using a less intensive shaders.
     
  13. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    it will be able to support any number of LODs, it is built with expandability in mind. Any type of shader that has a Color or Cutoff property will work automatically. You can use whatever shader on whatever LOD and it will work! Want this to be as flexible as possible :)

    Honestly though, come up against a bit of an impass wiht programming, I am still fairly new to programming in C# (6 months), so I'm hoping for another bit of programming revelation hahaha
     
  14. HunterAugust

    HunterAugust

    Joined:
    Jan 18, 2015
    Posts:
    2
    Has there been any progression made on this?
     
    Jaqal likes this.
  15. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    Not really, I have hit a bit of a wall, going to try some more things to get past it, hopefully can solve it
     
  16. PhiMue

    PhiMue

    Joined:
    Sep 21, 2013
    Posts:
    7
    I would really like to see what it looks like with actual LOD transitions, so that the objects do not just appear but change from a lower detail version to higher detail. It would be great to have a smoother transition between LOD levels.