Skip to content

Commit

Permalink
Merge pull request #1328 from anatawa12/fix-basic-mesh-not-considered…
Browse files Browse the repository at this point in the history
…-optimize-texture

fix: basic Mesh Renderers are not considered in Optimize Texture
  • Loading branch information
anatawa12 authored Nov 4, 2024
2 parents dd45e45 + 4da7b04 commit 331d56e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- basic Mesh Renderers are not considered in Optimize Texture `#1328`

### Security

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The format is based on [Keep a Changelog].
- We may relax some restriction in the future.
- Because we have to check for each condition if we use AnyState but we can check for only one (in best case) with entry/exit, this generally reduces cost for checking an parameter in a state.
- Combined with Entry / Exit to 1D BlendTree optimization, which is implemented in previous release, your AnyState layer may be optimized to 1D BlendTree.
- Optimize Texture in Trace nad Optimize `#1181` `#1184` `#1193` `#1215` `#1225` `#1235` `#1268` `#1278` `#1313`
- Optimize Texture in Trace nad Optimize `#1181` `#1184` `#1193` `#1215` `#1225` `#1235` `#1268` `#1278` `#1313` `#1328`
- Avatar Optimizer will pack texture and tries to reduce the VRAM usage.
- Currently liltoon is only supported.
- `Copy Enablement Animation` to Merge Skinned Mesh `#1173`
Expand Down
5 changes: 5 additions & 0 deletions Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,12 @@ public static void DoMerge(BuildContext context,
target.ClearMeshData();
target.SubMeshes.Capacity = Math.Max(target.SubMeshes.Capacity, materials.Count);
foreach (var material in materials)
{
target.SubMeshes.Add(new SubMesh(material.material, material.topology));
if (material.material != null
&& context.GetMaterialInformation(material.material) is { } information)
information.UserRenderers.Add(target.SourceRenderer);
}

TexCoordStatus TexCoordStatusMax(TexCoordStatus x, TexCoordStatus y) =>
(TexCoordStatus)Math.Max((int)x, (int)y);
Expand Down
8 changes: 8 additions & 0 deletions Editor/Processors/TraceAndOptimize/OptimizeTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ internal class MaterialNode : UnionFindNodeBase
{
// If we cannot collect textures from shader information (if null), unable to merge
public List<TextureUsageInformation>? TextureUsageInformations { get; set; }
public List<Renderer>? UserRenderersOnAvatar { get; set; }

// The list of submeshes that use this material
public List<SubMeshNode> Users { get; } = new();
Expand Down Expand Up @@ -229,6 +230,7 @@ BuildContext context
if (materialInformation?.TextureUsageInformationList is { } informations)
{
materialNode.TextureUsageInformations = informations.ToList();
materialNode.UserRenderersOnAvatar = materialInformation.UserRenderers.Where(x => x != null).ToList();

textures = informations.Select(x =>
((Texture2D?)material.GetTexture(x.MaterialPropertyName), (TextureUsageInformation?)x));
Expand Down Expand Up @@ -293,6 +295,12 @@ BuildContext context
if (info.Materials.Any(mat => mat.TextureUsageInformations == null))
return Array.Empty<(EqualsHashSet<UVID>, AtlasResult)>();

// the material should not be used by other renderers.
// we're ignoring basic Mesh Renderers so we have to check if the material is not used by basic Mesh Renderers.
var renderers = info.SubMeshes.Select(x => x.SubMeshId.MeshInfo2.SourceRenderer).ToHashSet();
if (info.Materials.Any(mat => mat.UserRenderersOnAvatar == null || !renderers.SetEquals(mat.UserRenderersOnAvatar)))
return Array.Empty<(EqualsHashSet<UVID>, AtlasResult)>();

var textureByUvId = new Dictionary<UVID, List<TextureNode>>();
var uvidByTexture = new Dictionary<TextureNode, List<UVID>>();

Expand Down

0 comments on commit 331d56e

Please sign in to comment.