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

Remove Runtime Uses of EnableKeyword/DisableKeyword for shader_feature Keywords #7582

Closed Cameron-Micka closed 9 months ago

Cameron-Micka commented 4 years ago

Describe the bug

A handful of issues have been reported around shader features working in editor but not working within a built player. This is due to a few MRTK scripts using the EnableKeyword and DisableKeyword methods at runtime for keywords which utilize the shader_feature pragma. For more information as to why this is an issue please see "Special requirements for Scripting with the Standard Shader."

To reproduce

For example, if you look at ConstructGltf.CreateMRTKShaderMaterial() you can see code which does the following:

material.EnableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");

This is perfectly valid within editor scripts, but not at runtime.

Expected behavior

Runtime calls to EnableKeyword/DisableKeyword should be removed and replaced with explicit material references. Please see this thread for more information.

Target platform

mtaulty commented 4 years ago

Like @FreakTheMighty, I've come across this issue when trying to load glTF models dynamically as per #7543.

I'm on a slightly old toolkit and so in order to temporarily get around the problem with directional light, I've switched the _DIRECTIONAL_LIGHT in the MRTK standard shader to be marked with the pragma multi_compile rather than shader_feature - I'm assuming that I'll take a hit for this and it doesn't solve the potential issues with the other uses of Enable/DisableKeyword in the glTF code but for my needs it seemed to make things a lot better (i.e. I got some light on my models on device).

Cameron-Micka commented 4 years ago

@mtaulty that should be a totally fine workaround for your scenario. You will notice slightly longer build times as more shader variants will get included in the build. But, I wouldn't expect you experience any significant runtime costs.

stale[bot] commented 2 years ago

This issue has been marked as stale by an automated process because it has not had any recent activity. It will be automatically closed in 30 days if no further activity occurs. If this is still an issue please add a new comment with more recent details and repro steps.

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!