microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Border Light Issues on Mixed Reality Toolkit/Standard materials when building onto Android with Dynamic Batching #11098

Closed septianrazi closed 9 months ago

septianrazi commented 2 years ago

Describe the bug

Mixed Reality Toolkit/Standard Materials with Border Lights will have it's Border Light Width seemingly increase when multiple of the same Materials need to be rendered. If only one instance is rendered, material border width is displayed normally.

May have something to do with Mesh Draw Call Batching as disabling Dynamic Batching in the Player settings for the project eliminates the issue

To reproduce

Steps to reproduce the behavior:

  1. Add multiple GameObjects into a scene with the same Mixed Reality Toolkit/Standard material that includes Border width (many of the default gameObjects from the MRTK toolbox can be used)
  2. Ensure Dynamic Batching is checked in Player settings
  3. Target build for Android
  4. Build for Android
  5. Open the app in an Oculus device, and ensure multiple gameObjects are within view

Expected behavior

Material border width should say consistent even when multiple materials of the same instance need to be rendered with Dynamic Batching

Screenshots

This is what it looks like in an Oculus Quest 2 Android build:

au csiro ie LabTrainDev-20220709-113328

These are the default Slates and Tooltips in MRTK Toolbox, yet border width is different compared to in Editor which would be the expected behaviour:

OculusScreenshot1665546773

Your setup

Target platform

Additional context

Issue only occurred after upgrading from Unity 2020.3.30f1 to 2021.3.11f1

Zee2 commented 2 years ago

Assigning @Cameron-Micka .

Cameron-Micka commented 2 years ago

Thank you for reporting this @septianrazi. I think your hypothesis is correct:

May have something to do with Mesh Draw Call Batching as disabling Dynamic Batching in the Player settings for the project eliminates the issue

If a MRTK/Standard shader material is batched and uses a feature requiring object scale, then you will see artifacts like this.

To avoid this issue, we automatically enable GPU instancing on the material which also has the side effect of disabling batching: image

My guess is Unity 2021.3.11f1 Unity no longer respects that flag and performs batching anyway.

But, there may be a better solution. As a test could you change this line in MixedRealityStandard.shader: Tags{ "RenderType" = "Opaque" "LightMode" = "ForwardBase" "DisableBatching" = "False"}

image

And add this line to MixedRealityStandardShaderGUI.cs: material.SetOverrideTag("DisableBatching", ScaleRequired() ? "True" : "False");

image

If this fixed the issue you are observing, then we can make this change in the toolkit. 😊

IssueSyncBot commented 9 months ago

We appreciate your feedback and thank you for reporting this issue.

Microsoft Mixed Reality Toolkit version 2 (MRTK2) is currently in limited support. This means that Microsoft is only fixing high priority security issues. Unfortunately, this issue does not meet the necessary priority and will be closed. If you strongly feel that this issue deserves more attention, please open a new issue and explain why it is important.

Microsoft recommends that all new HoloLens 2 Unity applications use MRTK3 instead of MRTK2.

Please note that MRTK3 was released in August 2023. It features an all new architecture for developing rich mixed reality experiences and has a minimum requirement of Unity 2021.3 LTS. For more information about MRTK3, please visithttps://www.mixedrealitytoolkit.org.

Thank you for your continued support of the Mixed Reality Toolkit!