Search Unity

[RELEASED] Impostors - Runtime Optimization

Discussion in 'Assets and Asset Store' started by MUGIK, Oct 11, 2019.

?

What dependencies you are ok with using in your project?

  1. Unity 2019.4+

    77 vote(s)
    84.6%
  2. Jobs (+ Collection and Mathematics)

    78 vote(s)
    85.7%
  3. Burst (+ Mathematics)

    79 vote(s)
    86.8%
Multiple votes are allowed.
  1. arczi79

    arczi79

    Joined:
    May 10, 2021
    Posts:
    45
    I see in the description of the Impostors asset this information:
    "- For now, Impostors work only with no moving objects."
    Does it mean that it is not possible to move objects with ImpostorLODGroup to any new position? The periodical updates of player (and the whole world) to position (0,0,0) should happen very rarely so it would be nice to have exposed any function to reevaluate positions of all impostors (on demand, when it is needed).
     
  2. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Currently, there are no such plans just because you are the first and the only one requesting this integration. I don't want to sound rude but that's not enough to spend development time on this while there are other more important improvements. Also, ECS is still an experimental package.

    The core of the Impostors package is the DOTS part of the code where all calculation and mesh generation occurs. MonoBehaviour part is only a wrapper to conveniently configure and transfer required data to the system. If you are willing to I could help you with some tips for writing your own adaptation of the Impostors package that fits your needs.

    One more thing to consider, Impostors work in conjunction with unity's LODGroup component and I don't know if there is a replacement for that functionality in ECS. LODGroup is responsible for rendering and culling objects before they turn into impostors, so maybe you will also need to implement this part.

    I don't know your full situation, there might be some other gotchas. If you are interested we could discuss this further in PM.
     
  3. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Ahh sorry, that's outdated statement in the documentation.
    On ImpostorLODGroup there is a setting called IsStatic. If you turn this off then system will update the position every frame. Try this first to verify that it works with World Streamer 2
     
  4. arczi79

    arczi79

    Joined:
    May 10, 2021
    Posts:
    45
    It works.... I am only a little confused with that part: "system will update the position every frame". Is there any better way to handle that? Probably I will need to update position every few minutes (in a worse scenario, at best maybe only a few times in the scene/level) so the update every frame sounds like big overkill for my "scenario".
     
  5. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Got you.
    You could try to call ImpostorLODGroup.UpdateSettings() on all active impostors. But this could be quite expensive if you have more than 1000 objects.

    I will look for a more optimal way of doing this.
     
  6. olivecrow

    olivecrow

    Joined:
    Jul 15, 2017
    Posts:
    24
    hello.
    I am using Imposters v1.0.5 and Unity 2021.3.6 URP.

    Imposters not working when
    Code (CSharp):
    1. ImposterRenderingType == Scheduled
    in UniversalRenderPipelineProxy.cs

    MainCameraImposter.jpg

    But when I set
    Code (CSharp):
    1. ImposterRenderingType == Immediately
    it works fine.

    Can only Immediately be used in URP?
     
  7. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Hi
    Scheduled should work fine in URP.
    Make sure that you use UpdateImpostorsTexturesFeature from the appropriate Renderer Data
     
    MaxEden likes this.
  8. ysundawa

    ysundawa

    Joined:
    Mar 2, 2020
    Posts:
    33
    Hello,

    I got some compiling error with 2020.3.34f1.
    please let me know where to start digging to fix this error?

    Thanks...

    upload_2022-7-23_6-33-52.png
     
  9. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Hello
    Let me guess, you updated Impostors to the latest version? If so, then this is what caused the compilation error because of legacy scripts that should be deleted. You can delete these scripts.

    Or, you can reinstall the Impostors package completely. To do so just delete Impostors folder from the project view. You will get a lot of compilation errors, but that's ok. Then just import the latest version of Impostors package. All references to scripts should remain and after this step your project should function properly.
    Strongly recommend backup your project before this process, just in case something went wrong.
     
  10. AnotherWorldCo

    AnotherWorldCo

    Joined:
    May 31, 2018
    Posts:
    2
    Hi. Can i apply anti-aliasing to an impostor? (URP, MSAA, Oculus Quest 2)
     
  11. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    What do you mean by that? MSAA applies globally to everything rendered by the camera, including impostors.
     
  12. AnotherWorldCo

    AnotherWorldCo

    Joined:
    May 31, 2018
    Posts:
    2
    But the impostor edges and inside the texture is very aliased compared to 3d object. Is it expected behavior? upload_2022-8-4_21-25-9.png upload_2022-8-4_21-26-25.png
     
  13. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Yes. Impostors are meant to be used at a distance, where such details won't be noticeable.
     
  14. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    I recently updated Impostors and now there's a notice about Graphics Jobs enabled makes a bug in impostors. I was wondering what bug is this?

    Also, I am finding that the Metal bug that I posted about a long time ago maybe has something to do with the system incorrectly rendering impostors swapped with each other.

    For example, I have two impostors: Streetlamp and Car.

    Sometimes, I will see the Car impostor flicker where the Streetlamp would be. This leads me to think the flickering is due to using multiple impostors and the system incorrectly assigning the positions for rendering.
     
  15. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    For some reason enabled Graphics Jobs setting messes up shader variables related to lightning and impostors are rendered without lightning in the build. This does not happen in the editor.

    I read again our previous conversation, and I realize that the problem might be with the impostor shader. It does a lot in the vertex shader where this flickering might occur due to floating precision or platform-specific data conversion.
    I would highly appreciate some video of the flickering when camera doesn't change position and only rotates. You can send it in DM if you wish to.
     
    sameng likes this.
  16. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    Dear MUGIK,

    Absolutely love the impostor system. Great fun to use and incredible performance gains.

    However I'm struggling a bit with Android builds. We target both PC and Android. On PC and in Editor all looks great and crisp. In Android builds the impostors get really blurry for some reason. Do you have any clue or tips?

    Using Unity 2020.3.36. LTS. Default render pipeline. Target: Neo Pico3 VR headset. Running on OpenGLES 3.

    Here is a Screenshot made from within the Neo Pico3 VR Headset.

    On the Impostor LOD Groups Manager I use a Cutout of 0.5. On The Camera Impostors Manager, Atlas res is set to 2048 x 2048 with a Texture size scale of 4. Setting it lower will result in more blurry impostors. This only happens in the Android Build.

    I did have it on higher quality before on Android. But I cant find the cause. If you know of anything that might help, please let me know.
     

    Attached Files:

  17. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Looks like it's due to mipmaps. Try to disable mipmaps on the ImpostorLODGropsManager.
    Also, TextureResolution setting in Quality Settings could affect this
     
  18. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    Thanks for the quick response! Ive tried disabling the Mipmaps bool on the ImpostorLODGropsManager to off. I'm getting the same result. The Texture Quality is set to full res.

    Il fiddle around with the settings see if i can find it. If you have any other lead that might save time please let me know.
     
  19. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Are you sure this quality setting is also used on the device? Maybe lower QS could take place?

    You can try to decrease atlas resolution and see if it has any effect.

    Also, on the ImpostorLODGroup component, there is a "min resolution" setting. You could try to increase it to 256 just to better understand what is going on when running on the device.
     
  20. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    Setting the Min Resolution on the ImposterLodGroup(s) fixes it! I'm sure about the Quality settings.

    I written a small tool so I can easily adjust the Min Res setting. Will try to reduce the atlas quality temporary to see it is has a effect. I prefer to keep the atlas quality because it reduces the quality of the textures substantially.

    I'm really glad the Min Texture Quality fixes it! Thanks for the help.

    One last question, not a big deal. But the impostors are a little brighter than the actual geometry. Is there a way to make the impostors a little darker?
     
  21. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Ok, so it looks like there is some hardware thing that lowers sampling resolution.
    Increasing Min Resolution is not a solution because it drastically increases GPU memory usage. On mobile devices this is not GPU memory but RAM.

    Atlas resolution should not affect impostor quality. It just determines what "container" size to use for impostors textures. So for example 512x512 atlas is able to store 16 impostors with texture size 128 px. And 1024x1024 atlas is able to store 16*4=64 impostors with texture size 128 px. But it should not change impostors' appearance.
    If you are sure that the atlas resolution is affecting impostors let me know how it looks.

    Overall, this looks like a hardware-related issue.

    To understand what is going I need more info.
    If you could somehow obtain the 'name' field of all chunks using some scripting and modifying plugin code, that would help a lot.
    Here is a path to get chunk's name:
    CameraImpostorsManager._chunkPool._chunks[i].name
     
  22. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    Changing the Atlas resolutions didn't have any effect.

    I added the debugging to the end of each teleport.

    I'm always getting:
    • Chunk#3 64
    • Chunk#4 128
    • Chunk#5 32
    Also the same when I lowered the atlas resolutions. I hope this helps. Let me know if you need extra info, or to check some other stuff for you.
     
  23. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Interesting. Maybe graphics API returns incorrect screen height in pixels, or camera's field of view is so big that it breaks calculation.

    As a workaround, you can manually set CameraImpostorsManager.textureSizeScale through code to some value that best fits your visuals exclusively when running on a device. In the inspector textureSizeScale is clamped between 0.5 and 4, but this is just for general use cases.

    Btw, what is QualitySettings.lodBias in your case?
     
  24. AlanHero

    AlanHero

    Joined:
    Feb 7, 2021
    Posts:
    4
    Hello MUGIK,
    Thanky you for your great asset!
    I ran into a problem when referencing camera that instantiated on the level with impostors. I used the Zenject attribute for this, replacing it in your scripts where the camera is required, but then the impostors stop working!
     
  25. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    Thanks MUGIK! Il test it out.

    We are using 1.3 currently as LOD Bias on the Android Quality setting. Il debug the Screen.height as well and let you know.
     
  26. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    I got some debugging results. Looks like the Screen.height is only 103. which is weird indeed. Il do some more research.

    textureSizeMultiplier: 316.9231 textureSizeScale: 4 Screen.height: 103 lodBias: 1.3
     
    MUGIK likes this.
  27. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Most likely you need to assign camera in two places. In the CameraImpostorsManager and on the same object there is RenderPipelineProxy component where you also need to specify camera but only if you are using scheduled mode. This Proxy could be BuiltIn or URP based on the render pipeline of your project.
     
  28. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Yeah, so that's the root of the problem. You could fix this by manually settings textureSizeScale to something like $real_screen_height$ / Screen.height * 1.5
     
  29. JMeer

    JMeer

    Joined:
    Mar 3, 2017
    Posts:
    29
    I've found the culprit. If in Player settings under "Resolution and Presentation" the Resolution Scaling Mode is set to Fixed DPI. The Target DPI causes the lower Screen.height. However a Low Target DPI increases performance a lot in our build for some reason. We use a separate app for control and interface.

    I replaced Screen.height with mainCamera.scaledPixelHeight to work around this. Its working great.

    Really appreciate the help! Thanks a lot!
     
    MUGIK likes this.
  30. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Great solution!
    I also will adjust the plugin's code to use mainCamera.scaledPixelHeight. Thanks!
     
    hopeful likes this.
  31. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    340
    Hi,

    My game scene doesn't have a camera because like any multiplayer game the main camera will be spawned later. Therefore, I cannot setup my scene and cannot use your asset at all.
    I have multiple prefabs containing cameras and they just switch between each other during runtime. I can't have static setup like your documentation suggests.

    if there is no option for that, I would like to ask for a refund.

    Thank you.
     
  32. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Hi!

    That's not quite true. For example, using cinemachine you can set up only one camera for the whole game that is marked as DontDestroyOnLoad. And virtual cameras will take control over this camera during play.

    There should be only one single instance of ImpostorLODGroupsManager in the scene.
    But CameraImpostorsManager could be placed inside prefab and spawned later at runtime. This component is responsible for camera management inside impostor system.

    I don't know your full situation, but rapidly changing to a new camera will cause a micro lag because impostors should be recalculated for a new camera position. This could be fixed though but requires writing some logic.

    As far as I know, Asset Store is now responsible for refunds.
     
    hopeful likes this.
  33. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    340
    Thank you, appreciated.

    Yeah didn't think of the cinemachine way. I'm unfortunately (for now because of resources) unable to switch all my systems to that technique :(
     
  34. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    340
    I just realised how rude I may have looked like in my previous message, I'm sorry.

    I suppose I will then need to manually (through code) add the directional light of my game scene (kind of a host scene where other scenes are loaded and unloaded dynamically)?

    Cheers
     
  35. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Also, you can directly assign directional light through code into
    CameraImpostorsManager.directionalLight


    My biggest concern though is the camera switching.
     
  36. deshowiz

    deshowiz

    Joined:
    Mar 28, 2015
    Posts:
    22
    Hi,

    @MUGIK

    I wanted to ask a few questions before purchasing this asset. I've tried the Amplify Impostors asset and it has a couple of major problems so I'm looking to switch to this one if it doesn't also have the same issues.

    Issue #1: Assets that use Alpha cards (trees, bushes) have issues correctly drawing the overlapping alpha in the alpha maps (in the example image, I highlighted the edges of one of the leaves to show how there is black around the leaves for a cutout/alpha card). The trunk can be ignored in this picture.


    This causes the following effect because leaves drawn over each other overwrite previously white values with empty/black values:


    I can't tell if the trees in the example images cover this alpha card issue.

    Issue #2: Impostors aren't drawn to the depth pre-pass, causing them to not interact correctly with depth values. Namely fog. Fog breaks impostors that aren't drawn to the depth pre-pass in Amplify Impostors, as seen here:

    LOD0 with fog:


    Impostor with fog (I get that it is closer to the camera than impostors normally would be but that is just for clarity):


    Impostor without fog:


    Depth shows that the impostor isn't included:


    Changing the draw order of the impostor and fog shaders does not help unless I draw it after transparent objects, which isn't a good solution because it would mean the fog stops affecting them and they don't get drawn correctly relative to geometry. It's an issue caused by impostors not being written to depth at all.

    Sorry for all of the photos, I've already wasted some money on other assets and waited months for my support tickets with example projects I gave to give me some insight. I want to make sure these things aren't an issue before I purchase this asset. I can't believe the AI's asset has these MAJOR issues that anybody making an open world game with vegetation would expect to come across.

    I'd like to know if these are issues I would have to worry about, thanks.
     
  37. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Hi
    First of all, thanks for the detailed questions

    My impostors solution also suffers from this alpha issue. From what I know fixing the tree shader should help. Most likely the problem is with alpha blending mode. Or the shader should be cutout(alphatest)


    That's strange. As far as I know, Amplify Impostors shouldn't have problems with depth.
    My Impostors package writes to depth, but only as a flat plane. So impostors will be affected by fog slightly differently than original objects. However, at far distances, this difference is negligible.
     
    deshowiz likes this.
  38. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    Hi, first of all thank you so much for this well made asset, it works impressively well even in standalone VR.
    Currently I'm trying to optimize a project for Quest 2 and I have couple of questions

    1. We have multiple profiles for standalone and wired builds therefore we have multiple URP Universal render data assets which are selected depending on quality tier for build platform. Is it possible to make URP proxy to hook up Update Impostors feature from currently active Universal render data from currently active quality tier?

    2. It seems I can't get a grasp on how resolution of impostors is calculated. It looks like it somehow depends on Render Scale and MSAA settings but I'm still not sure (maybe LODGroup?), I often get either too blurry or too sharp textures.

    3. Is it possible to progressively collapse impostors based on some threshold? For example, I have a pile of small props, I would like to see this pile from a distance but I would also like not to waste texture atlas on rendering each of them individually.

    4. Is it possible to render impostors with some kind of antialiasing or maybe render them twice the size and then scale them down when packing to atlas? The issue is in VR the resolution often is pretty low but at the same time the picture is heavily antialiased, so it's okay to have blurry low res impostors, but it's pretty visible that they are pixelated
     
  39. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Hi

    Unfortunately, I can't see a universal solution to this problem as every project has its own architecture and dependencies resolving. I can suggest you two solutions:
    - create your own implementation of the Proxy that takes into account your project setup.
    - if you are not going to switch quality tiers at runtime you can postprocess scene at build time and assign the correct reference to Update Impostors Feature.

    Let me know if you have better solutions or suggestions.

    Most likely this is due to using
    Screen.height
    instead of
    Camera.pixelHeight
    (or scaledPixelHeigh) at lines ~354 and ~628 CameraImpostorsManager.cs.
    Also, there is TextureSizeScale on CameraImpostorsManager that you can change in the inspector. By default, it is set to 2. This value should be finetuned.

    You can combine them under one LODGroup, if I understand your question correctly.

    Increasing TextureSizeScale may help with this issue.
    Also, on ImpostorsLODGroupManager there is MipMapBias, try to lower it to -0.5 or less. The mipMap technique is a black box, it could be hardware-depended.

    Make sure impostors are far enough from the camera.
     
    MaxEden likes this.
  40. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    82
    Thank you for your quick reply!

    As part of context, currently I'm working on pretty extreme case of open space location where polycount is high and impostors are pretty close to camera, but everything works well enough thanks to your asset.

    What I had in mind is a situation where props are rendered as individual impostors when you are close to them when parallax is noticeable and when you are far enough and parallax is not that visible all the props are rendered to a single impostor
     
  41. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Glad to hear :)

    Got you, hierarchical LODGroups.
    Hierarchical LODGroups require custom culling implementation which is quite a hard task on its own, but also it should support Frustum and Occlusion culling, GPU instancing, and other non-trivial stuff that engine makes silently.
    This is why impostors package uses Unity's LODGroups to let the native culling/rendering pipeline work as fast as possible.
    This leads to conclusion that it's just impossible to implement hierarchical LODGroups without Unity implementing them first.
     
    MaxEden and sirleto like this.
  42. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    Hello Mugik,

    i purchased your system Impostors - Runtime Optimization. now i have some questions:
    maybe this was already asked or explained in documentation, then please just link me there :)

    my problem is that i want far away trees to be impostor'ed. i am drawing them with the usual unity terrain (tree) system (which also allows Unity LOD Group).

    can your impostor system be used here? or only on normal (static?) objects?

    what about prefabs, can your impostor system detect the reuse of identical objects and reuse impostors?

    thanks in advance,
    Daniel from switzerland
     
  43. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Hi

    Unfortunately, unity's terrain system doesn't allow custom components on trees.

    Yes, you can. Here is a sample script that shows you how to convert terrain trees into game objects.
    https://gist.github.com/STARasGAMES/01d7211cdbaebecbfb6064bb2436fab2

    Yes, Impostors package requires ImpostorLODGroup component on GOs to function properly. But they do not have to be static.

    No, it doesn't. System is designed to support as many scenarios as possible, so it assumes that every object is unique by its rotation, scale, and light direction.
     
    sirleto likes this.
  44. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    Thanks a lot!

    Does your last point mean 10k trees (from 10 prefabs) are rendered into one atlas with 100*100 impostor tiles? So 4096² means 40 pixels per impostor?

    How do you update these, a few render to texture each frame? How do I control how many, how fast, etc?

    Can you perhaps point to your documentation, e.g. page XY
     
  45. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Impostor texture can have resolutions of 32x32, 64x64, 128x128, 256x256, or 512x512 pixels based on object's size on the screen. This texture(snapshot of object) is packed into one of the atlases. Atlas possible resolutions: 512x512, 1024x1024, 2048x2048.
    For example, a 2048x2048 atlas for 32x32 impostors can contain up to (2048 / 32)² = 64² = 4096 unique impostor textures. When atlas is full system creates a new one.

    Under CameraImpostorsManager component there is SortingMethod component where you can set these values.
     
    sirleto likes this.
  46. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    128
    package looks awesome - any thoughts about supporting HDRP?
     
  47. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    For now, there are no plans for HDRP support, unfortunately.
     
  48. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    serious question: can i use your impostors on a terrain?

    i am running tests with 36 (6x6) / 144 (12x12) terrains to get a scene with far away terrain (but visitable by player) and i would love to have it only on a quad.
     
  49. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    No, unity does not provide a way to render terrain inside rendering CommandBuffer.
    Anyways, it should be quite cheap to render distant terrains as BaseMap
     
  50. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    Yes, terrain is not that expensive (basemap + instanced), and the perspective makes it super unpractical to use impostors on terrain ... i just want to run a few quick tests and would be very beneficial if your impostors would have been able to. nevermind :)