Search Unity

Per-object LOD bias?

Discussion in 'Editor & General Support' started by electronic_fox, Dec 6, 2018.

  1. electronic_fox

    electronic_fox

    Joined:
    Apr 1, 2014
    Posts:
    24
    Pretty simple. I have an object which needs to switch to LOD1 pretty early (when its still very close to the camera), but I dont want to switch the global LOD bias value. Is there a method to achieve this?

    Thanks in advance

    Mike
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
  3. electronic_fox

    electronic_fox

    Joined:
    Apr 1, 2014
    Posts:
    24
    Even if I place LOD1 at 100%, it still does not activate as soon as I'd like. The model itself is quite large and LOD1 wont activate until its fairly far from the camera.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    What does your LOD scale look like?
     
  5. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Hi @karl_jones !

    I'd love to apply LOD scale only for a few objects (e.g. LOD0 should work when the object is basically overflowing outside the screen)

    I can't change the global LOD bias (the whole Art department would kill me) - I only need it for foliage to achieve some sort of see-through effect only on some objects.

    I was thinking to do this to do some LOD0 occlusion of the foliage when it's close to the camera.

    Is there some -even hackish- way to do this, without having to apply a component to each of such objects?

    What about applying it on all object within a radius (but, well, if I'm going to use a trigger system, probably I'm not going to get the LOD transition animated effect)
     
  6. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    After fighting with this for several days, I have found a way to get what you guys are looking for. Unfortunately this only works in the editor, whereas I was trying to implement it in runtime to let users turn up/down their LOD settings based on their hardware performance, so this doesn't work for my intended use, but there is a way to alter the LOD settings above 100%.

    If you switch the inspector to Debug mode, the editor will display and work with the native LOD[] that is otherwise inaccessible due to SetLODs() and GetLODs() being the only non-native interaction Unity provides us with, and the fact that SetLODs() will clamp any values above 1.0 back down to 1.0 =[ =[ =[

    You can however set them directly to 2.5, 1.5, etc., via the Debug Inspector, or even via a custom editor script if you get into the SerializedObject code as the LODGroup's Editor script does, for which C# references can be found online.

    It would be really nice if Unity didn't assume that there are no cases where an LOD group would be needed above 100% screen usage, as this absolutely does show up with large trees / large objects in general. Messing with a global bias is totally out of the question. Alternatively a group based bias, perhaps with LODGroups subscribing to a group index for example, would also work great for my runtime needs.
     
    TheVirtualMunk likes this.
  7. JLJac

    JLJac

    Joined:
    Feb 18, 2014
    Posts:
    36
    Why not just lower the "size" parameter? From how I understand it halving the size does the same thing as doubling the transition percentages, meaning you can effectively reach >100% that way
     
  8. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    Hmm, that's not mentioned in the manual, nor are any examples of it givin'. I would like to test out and see what that's used for though.
     
  9. JLJac

    JLJac

    Joined:
    Feb 18, 2014
    Posts:
    36
    Yeah it's not mentioned anywhere but it works. The LOD component calls it "size" making you think that it does some complicated calculations to get the on-screen area of the object, but as far as my testing has concluded it does nothing like that. It just goes by distance to the camera, probably dividing the distance by the "size" paramter.

    Say that you have a huge house but you set the "size" parameter as if it was just a little brick-sized object. You'd have to walk into the house and walk up to its origin point before it snapped into LOD0, at which point the actual house mesh will fill the screen many times over. That way you essentially get a LOD transition at 600% of screen size or something like that.

    Conversely you can set the "size" to something huge, and the object will snap into LOD0 while far away on the horizon, regardless of how big the actual mesh is :)
     
    paladim likes this.