Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

30fps performance with simple meshes in Unity?

Hi,

I'm getting terrible performance in Unity with a very simple (~12K triangles) mesh. I've tried everything I can think of but none of these have had any impact:

  1. HoloToolkit shaders (StandardFast, Vertex Lit, etc.)
  2. Disabling spatial perception (I use it only for occlusion and use the Unity component for now).
  3. Disable animators (I use a single one for the rotor animation).
  4. Disable all colliders (the object has a single box collider and I perform a raycast on each Update() to determine whether the user is looking at it).
  5. Disable the rendering in the post-rendering step (I draw 4 triangles using OnPostRender() to create a selection reticle around the object when it is in the user's gaze).
  6. I always compile in Release mode and run without a debugger attached.
  7. All performance settings are as recommended: Fastest quality setting, shadows disabled, blend probes disabled, motion vectors disabled, etc. Forward rendering is being used.

Regardless, the symptoms are the same:

  • When within view and near to the user (the object is ~2 feet long in real space and can occupy a considerable part of the display when viewed up close), the frame rate drops to 30 FPS.
  • Gazing away restores 60 FPS performance immediately.
  • Viewing at a distance (> 5m or so) improves performance as well.

I've used the Unity profiler but couldn't find anything interesting (see attached).

Any ideas? Is this just a Unity-specific problem? I have yet to try Direct3D directly (would prefer not to code up an entire engine for such a simple project). Looking at the performance of other, published apps, I don't see this issue (always get a reliable 60FPS) but I'm not sure whether they use Unity or not.

Project available here: http://www.github.com/trzy/hololens.

Thanks,

Bart



Best Answers

Answers

  • sptspt ✭✭

    I notice that you are calling coroutines from within your Update code. I don't know if it explains the symptoms you are seeing, but using coroutines like this could have a terrible impact on performance.

  • trzytrzy ✭✭✭

    @spt said:
    I notice that you are calling coroutines from within your Update code. I don't know if it explains the symptoms you are seeing, but using coroutines like this could have a terrible impact on performance.

    Why is that? I thought coroutines should be fairly lightweight. I have two coroutines, one for animation and one to drive the helicopter inputs as it follows waypoints. I'm a beginner when it comes to C# and coroutines were presented as an effective way to do animation and timing-dependent tasks in the Unity documentation.

    Nevertheless, the coroutines aren't causing the problem -- I disabled the animation coroutine and examined the helicopter before starting the waypoint coroutine. The results were the same.

    I think it's something to do with the mesh but I just can't figure out what. Unity's renderer is almost a black box from my perspective but I've tried to take care not to do anything obviously weird (and the weird stuff I do do, like drawing the reticles, is performing just fine :)).

  • trzytrzy ✭✭✭

    Today I tried displaying my mesh with Direct3D (using the spinning cube template project). Runs without a hitch. Obviously, this is a vastly lighter-weight rendering process with very simple shaders, but given that I'm rendering only that single model in Unity, the complexity should not be too different.

    No one else has experienced this issue in Unity? :(

  • The coroutines shouldn't have anything to do with it, they are a fixed cost and nothing to do with looking away or being closer.

    I had pretty much exactly the same issue. Single mesh, 100's of polys (not 1000s or whatever), StandardFast shader, but when viewing full-screen the frame rate dropped to 30 fps and stayed there.

    In the end I fixed it by baking the objects lighting and using an unlit shader (its fairly static). I haven't dug too deep into it, but unity's surface shading seems awfully suspect here.

  • trzytrzy ✭✭✭

    @MrSteveT said:
    The coroutines shouldn't have anything to do with it, they are a fixed cost and nothing to do with looking away or being closer.

    I had pretty much exactly the same issue. Single mesh, 100's of polys (not 1000s or whatever), StandardFast shader, but when viewing full-screen the frame rate dropped to 30 fps and stayed there.

    In the end I fixed it by baking the objects lighting and using an unlit shader (its fairly static). I haven't dug too deep into it, but unity's surface shading seems awfully suspect here.

    You're right. But I was able to get decent performance from the Vertex Lit shaders, too. In my app, there are actually two different things (possibly three) causing performance issues:

    1. HoloToolkit/StandardFast perform horribly. Doesn't matter what "Baking" is set to on the Directional Light component. I just leave it as Realtime now. Interestingly, however, the performance especially degrades after the helicopter starts moving, but since the helicopter follows waypoints which are represented by small 3D objects, I actually think what's happening is some sort of interaction between the objects and the helicopter. I don't have any sort of emissive lighting enabled but I wonder whether there is a bug causing Unity's renderer to perform multi-pass rendering anyway?

    2. The Spatial Mapping Renderer (attached to my Main Camera) also degrades performance. I'm still not 100% sure how to use this component so I may post another question about this. My understand was that there should only be a single instance per scene, so I attached it to the main camera. I've also heard that one should be attached per drawable object, which seems suspect to me.

    It seems to me that [1] and [2] alone will cause performance degradation (e.g., even with unlit shaders, if the Spatial Mapping Renderer component is active, the frame rate drops to 30 FPS quickly.) What's unusual is that the frame rate drop does not occur initially, when the game starts and the helicopter is hovering in place. I have to either move very close or place a waypoint and cause the helicopter to move (which is accomplished with a coroutine).

    I also thought that the animator controller at one point was causing issues. But I re-tested again and couldn't reproduce. To animate the rotor, I use an animator plus a coroutine to set a parameter (essentially the rotation angle of the rotor).

  • which project?

    ===
    This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.

    (Daddy, what does 'now formatting drive C:' mean?)

  • I'm going to assume Demo-Helicopter

    ===
    This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.

    (Daddy, what does 'now formatting drive C:' mean?)

  • The project didn't have spatial perception enabled so spatial mapping wasn't running. I'm looking some more.

    ===
    This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.

    (Daddy, what does 'now formatting drive C:' mean?)

  • trzytrzy ✭✭✭

    Hey Patrick,

    Sorry for the delayed reply. Thank you for taking a look at the project. I think the latest git version does indeed have spatial mapping disabled. I also did not check in the exported app, hence why you had to configure the quality settings manually, but I've always made sure to deploy to HoloLens with quality set to Fastest.

    It ran at 60 FPS for you? Even after moving the helicopter? That's most interesting. I typically get very choppy motion as the helicopter moves and the profiler confirms it is dropping to 30 FPS. But, as I said, with spatial mapping disabled and the Vertex Lit shaders, it seems to maintain close to 60 FPS for the most part.

    I'll be using the HoloToolkit\Vertex Lit-Configurable shaders from now on. Oddly enough, though, I can't seem to use the HoloToolkit's Occlusion shader. I see where it's located in the directory structure but it's not selectable for me in Unity when I try to change the spatial mapping component's shader. I can try to pull the latest HoloToolkit again and rebuild the package, or maybe I'm just being dumb and missing an obvious way to select it.

    I'll also try to pre-map the room and then disable mesh updates before starting the game, as per MrSteveT (and others') suggestion.

    Bart

  • trzytrzy ✭✭✭

    Oh boy, I am an idiot. You were right -- I wasn't building with Fastest quality. For some reason, I thought the gray bar indicated the selection. Indeed, now it runs at a consistent 60 fps! There is some jerkiness up close, perhaps related to stabilization plane? I tried experimenting with this function call by crudely forcing it to stabilize on the helicopter but maybe it's not necessary.

    Also, re: the HoloToolkit occlusion material, I figured it out. Set "Custom Render Setting" -> "Custom Material", and then one of the selectable materials is indeed "Occlusion" from HoloToolkit (as opposed to Unity's "SpatialMappingOcclusion").

    Thanks a lot, guys!

  • When close I still drop under 60fps. You might experiment with the 'Graphics Jobs' and 'Single Pass Stereo Rendering'. These settings are where you enable Virtual Reality Supported in the player settings. These helped my personal project get 60fps more often.

    The stabilization plane can help, but picking the right depth can be tricky. I've had the best results when I put the stabilization plane at either 2m or at the contact point of the collider hit by the gaze ray. If you put it 'on an object' there are good odds that the origin of the object isn't actually where the user is looking and you'll get some really jittery Holograms. (This will actually be a nice way to make a cheap special effect, come to think of it. )

    ===
    This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.

    (Daddy, what does 'now formatting drive C:' mean?)

Sign In or Register to comment.