summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/VRCSDK/Dependencies/VRChat/Scripts/Validation/ShaderValidation.cs
diff options
context:
space:
mode:
authortylermurphy534 <tylermurphy534@gmail.com>2022-11-06 15:12:42 -0500
committertylermurphy534 <tylermurphy534@gmail.com>2022-11-06 15:12:42 -0500
commiteb84bb298d2b95aec7b2ae12cbf25ac64f25379a (patch)
treeefd616a157df06ab661c6d56651853431ac6b08b /VRCSDK3AvatarsLegacy/Assets/VRCSDK/Dependencies/VRChat/Scripts/Validation/ShaderValidation.cs
downloadunityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.gz
unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.bz2
unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.zip
move to self host
Diffstat (limited to 'VRCSDK3AvatarsLegacy/Assets/VRCSDK/Dependencies/VRChat/Scripts/Validation/ShaderValidation.cs')
-rw-r--r--VRCSDK3AvatarsLegacy/Assets/VRCSDK/Dependencies/VRChat/Scripts/Validation/ShaderValidation.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/VRCSDK3AvatarsLegacy/Assets/VRCSDK/Dependencies/VRChat/Scripts/Validation/ShaderValidation.cs b/VRCSDK3AvatarsLegacy/Assets/VRCSDK/Dependencies/VRChat/Scripts/Validation/ShaderValidation.cs
new file mode 100644
index 00000000..0a69a1af
--- /dev/null
+++ b/VRCSDK3AvatarsLegacy/Assets/VRCSDK/Dependencies/VRChat/Scripts/Validation/ShaderValidation.cs
@@ -0,0 +1,86 @@
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEngine;
+
+namespace VRC.SDKBase.Validation
+{
+ public static class ShaderValidation
+ {
+ public static IEnumerable<Shader> FindIllegalShaders(GameObject target, string[] whitelist)
+ {
+ List<Shader> illegalShaders = new List<Shader>();
+ IEnumerator seeker = FindIllegalShadersEnumerator(target, whitelist, (c) => illegalShaders.Add(c));
+ while(seeker.MoveNext())
+ {
+ }
+
+ return illegalShaders;
+ }
+
+ private static IEnumerator FindIllegalShadersEnumerator(GameObject target, string[] whitelist, System.Action<Shader> onFound, bool useWatch = false)
+ {
+ System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
+ if(useWatch)
+ {
+ watch.Start();
+ }
+
+ List<Material> materialCache = new List<Material>();
+ Queue<GameObject> children = new Queue<GameObject>();
+ children.Enqueue(target.gameObject);
+ while(children.Count > 0)
+ {
+ GameObject child = children.Dequeue();
+ if(child == null)
+ {
+ continue;
+ }
+
+ for(int idx = 0; idx < child.transform.childCount; ++idx)
+ {
+ children.Enqueue(child.transform.GetChild(idx).gameObject);
+ }
+
+ foreach(Renderer childRenderers in child.transform.GetComponents<Renderer>())
+ {
+ if(childRenderers == null)
+ {
+ continue;
+ }
+
+ foreach(Material sharedMaterial in childRenderers.sharedMaterials)
+ {
+ if(materialCache.Any(cacheMtl => sharedMaterial == cacheMtl)) // did we already look at this one?
+ {
+ continue;
+ }
+
+ // Skip empty material slots, or materials without shaders.
+ // Both will end up using the magenta error shader.
+ if(sharedMaterial == null || sharedMaterial.shader == null)
+ {
+ continue;
+ }
+
+ if(whitelist.All(okayShaderName => sharedMaterial.shader.name != okayShaderName))
+ {
+ onFound(sharedMaterial.shader);
+ yield return null;
+ }
+
+ materialCache.Add(sharedMaterial);
+ }
+
+ if(!useWatch || watch.ElapsedMilliseconds <= 1)
+ {
+ continue;
+ }
+
+ yield return null;
+ watch.Reset();
+ }
+ }
+ }
+ }
+}