Skip to content

Commit

Permalink
v1.2.2
Browse files Browse the repository at this point in the history
- normal maps were suggest to change to DXT1, they cant use that
  • Loading branch information
YP committed Mar 19, 2023
1 parent d0bb7ce commit 465724d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Editor/AvatarEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace Thry.AvatarHelpers {
public class AvatarEvaluator : EditorWindow
{
public const string VERSION = "1.2.1";
public const string VERSION = "1.2.2";

[MenuItem("Thry/Avatar/Evaluator")]
static void Init()
Expand Down
24 changes: 11 additions & 13 deletions Editor/VRAM Check/TextureVRAM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ struct TextureInfo
public long size;
public bool isActive;
public int BPP;
public int minBPP;
public string format;
public bool hasAlpha;
}
Expand Down Expand Up @@ -375,13 +376,14 @@ private void OnGUI()
EditorGUILayout.ObjectField(texInfo.texture, typeof(Texture), false);
EditorGUILayout.LabelField(texInfo.print, GUILayout.Width(100));
EditorGUILayout.LabelField($"({texInfo.format})", GUILayout.Width(100));
if(texInfo.texture is Texture2D && texInfo.hasAlpha ? texInfo.BPP > 8 : texInfo.BPP > 4)
if(texInfo.texture is Texture2D && texInfo.BPP > texInfo.minBPP)
{
TextureImporterFormat newFormat = texInfo.hasAlpha ? TextureImporterFormat.BC7 : TextureImporterFormat.DXT1;
TextureImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texInfo.texture)) as TextureImporter;
TextureImporterFormat newFormat = texInfo.hasAlpha || importer.textureType == TextureImporterType.NormalMap ?
TextureImporterFormat.BC7 : TextureImporterFormat.DXT1;
string savedSize = AvatarEvaluator.ToMebiByteString(texInfo.size - TextureToBytesUsingBPP(texInfo.texture, BPP[newFormat]));
if(GUILayout.Button($"{newFormat} => Save {savedSize}", GUILayout.Width(200)))
{
TextureImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texInfo.texture)) as TextureImporter;
importer.SetPlatformTextureSettings(new TextureImporterPlatformSettings()
{
name = "PC",
Expand Down Expand Up @@ -425,13 +427,6 @@ private void OnGUI()
}
}

public static void GUI_Small_VRAM_Evaluation(long size, GameObject avatar)
{
// TODO
// if (size > VRAM_EXCESSIVE_THRESHOLD) EditorGUILayout.HelpBox("Your avatar uses a lot of video memory. Please reduce the texture sizes or change the compression to prevent bottlenecking yourself and others.", MessageType.Error);
// else if (size > VRAM_WARNING_THRESHOLD) EditorGUILayout.HelpBox("Your avatar is still ok. Try not to add too many more big textures.", MessageType.Warning);
}

static Dictionary<Texture, bool> GetTextures(GameObject avatar)
{
IEnumerable<Material>[] materials = AvatarEvaluator.GetMaterials(avatar);
Expand Down Expand Up @@ -484,13 +479,14 @@ public long Calc(GameObject avatar)
_sizeAllMeshes = 0;
foreach (KeyValuePair<Texture, bool> t in textures)
{
(long size, string format, int BPP, bool hasAlpha) textureInfo = CalculateTextureSize(t.Key, t.Value);
(long size, string format, int BPP, int minBPP, bool hasAlpha) textureInfo = CalculateTextureSize(t.Key, t.Value);
TextureInfo texInfo = new TextureInfo();
texInfo.texture = t.Key;
texInfo.size = textureInfo.size;
texInfo.print = AvatarEvaluator.ToMebiByteString(textureInfo.size);
texInfo.format = textureInfo.format;
texInfo.BPP = textureInfo.BPP;
texInfo.minBPP = textureInfo.minBPP;
texInfo.hasAlpha = textureInfo.hasAlpha;
texInfo.isActive = t.Value;
_texturesList.Add(texInfo);
Expand Down Expand Up @@ -620,10 +616,11 @@ static long CalculateMeshSize(Mesh mesh)
return bytes;
}

static (long size, string format, int BPP, bool hasAlpha) CalculateTextureSize(Texture t, bool addToList)
static (long size, string format, int BPP, int minBPP, bool hasAlpha) CalculateTextureSize(Texture t, bool addToList)
{
string format = "";
int bpp = 0;
int minBPP = 8;
bool hasAlpha = false;
long size = 0;

Expand All @@ -640,6 +637,7 @@ static long CalculateMeshSize(Mesh mesh)
#pragma warning restore CS0618

hasAlpha = textureImporter.DoesSourceTextureHaveAlpha();
minBPP = (hasAlpha || textureImporter.textureType == TextureImporterType.NormalMap) ? 8 : 4;

if (BPP.ContainsKey(textureFormat))
{
Expand Down Expand Up @@ -671,7 +669,7 @@ static long CalculateMeshSize(Mesh mesh)
size = Profiler.GetRuntimeMemorySizeLong(t);
}

return (size,format, bpp, hasAlpha);
return (size,format, bpp, minBPP, hasAlpha);
}

static long TextureToBytesUsingBPP(Texture t, int bpp)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "de.thryrallo.vrc.avatar-performance-tools",
"displayName": "Thry's Avatar Performance Tools",
"version": "1.2.1",
"version": "1.2.2",
"description": "Calculated and evaluates some avatar metric not currently taking into account by vrchats ranking system.\r\n\nMost prominently gives a breakdown over VRAM usage of different parts of the avatar.",
"gitDependencies": {},
"vpmDependencies": {},
Expand Down

0 comments on commit 465724d

Please # to comment.