Testing multiple MipMap/TexelDensity solutions

This commit is contained in:
max
2021-04-20 03:52:32 +02:00
parent 4debab5567
commit 0ce4962c05
30 changed files with 1632 additions and 3 deletions

View File

@ -0,0 +1,117 @@
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text.RegularExpressions;
public class CustomMipMapImporter : AssetPostprocessor
{
bool m_isReadable;
bool m_importing;
bool ShouldImportAsset(string path)
{
string pattern = GetMipmapFilenamePattern(path);
string mip1Path = string.Format(pattern, 1);
return File.Exists(mip1Path);
}
string GetMipmapFilenamePattern(string path)
{
var filename = Path.GetFileName(path);
var filenameWithoutExtention = Path.GetFileNameWithoutExtension(path);
var extension = Path.GetExtension(path);
var directoryName = Path.GetDirectoryName(path);
return Path.Combine(directoryName, filenameWithoutExtention + ".mip{0}" + extension);
}
void OnPreprocessTexture()
{
string extension = Path.GetExtension(assetPath);
string filenameWithoutExtention = Path.GetFileNameWithoutExtension(assetPath);
var match = Regex.Match(filenameWithoutExtention, @".mip(\d)+$");
if (match.Success)
{
string filenameWithoutMip = filenameWithoutExtention.Substring(0, match.Index);
string directoryName = Path.GetDirectoryName(assetPath);
string mip0Path = Path.Combine(directoryName, filenameWithoutMip + extension);
TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(mip0Path);
if (importer != null)
{
importer.SaveAndReimport();
}
}
if (ShouldImportAsset(assetPath))
{
m_importing = true;
string pattern = GetMipmapFilenamePattern(assetPath);
int m = 1;
bool reimport = false;
while (true)
{
string mipPath = string.Format(pattern, m);
m++;
TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(mipPath);
if (importer != null)
{
if (!importer.mipmapEnabled || !importer.isReadable)
{
importer.mipmapEnabled = true;
importer.isReadable = true;
importer.SaveAndReimport();
reimport = true;
}
continue;
}
else
{
break;
}
}
if (reimport)
{
m_importing = false;
return;
}
TextureImporter textureImporter = (TextureImporter)assetImporter;
m_isReadable = textureImporter.isReadable;
textureImporter.isReadable = true;
}
}
void OnPostprocessTexture(Texture2D texture)
{
if (m_importing)
{
string pattern = GetMipmapFilenamePattern(assetPath);
for (int m = 0; m < texture.mipmapCount; m++)
{
var mipmapTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(string.Format(pattern, m));
if (mipmapTexture != null)
{
Color[] c = mipmapTexture.GetPixels(0);
texture.SetPixels(c, m);
}
}
texture.Apply(false, !m_isReadable);
TextureImporter textureImporter = (TextureImporter)assetImporter;
textureImporter.isReadable = m_isReadable;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1b3c6a9a745cf994c924b3a44a3309db
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,144 @@
fileFormatVersion: 2
guid: e613356da75e6764ea82a89a5ce3c6bc
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 2
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 32
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 32
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: iPhone
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Windows Store Apps
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,97 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1aa272ccd1306c545b68254a527f8025, type: 3}
m_Name: MipMaps
m_EditorClassIdentifier:
content:
icon: {fileID: 2800000, guid: e613356da75e6764ea82a89a5ce3c6bc, type: 3}
tooltip:
sortingOrder: 30
compact:
m_Text:
m_Image: {fileID: 2800000, guid: e613356da75e6764ea82a89a5ce3c6bc, type: 3}
m_Tooltip:
normal:
m_Text: ' MipMaps'
m_Image: {fileID: 2800000, guid: e613356da75e6764ea82a89a5ce3c6bc, type: 3}
m_Tooltip:
shader: {fileID: 4800000, guid: 19d63524eb012af4e8e086121f546128, type: 3}
replacementTag:
parameters:
- m_name: _Max
m_parameterType: 7
m_texture: {fileID: 0}
m_vector: {x: 0, y: 0, z: 0, w: 0}
m_vectorArray: []
m_color: {r: 0, g: 0, b: 0, a: 0}
m_colorArray:
- {r: 0, g: 0.4, b: 1, a: 1}
- {r: 0, g: 1, b: 1, a: 1}
- {r: 0, g: 1, b: 0.4, a: 1}
- {r: 0.2, g: 1, b: 0, a: 1}
- {r: 0.8, g: 1, b: 0, a: 1}
- {r: 1, g: 0.6, b: 0, a: 1}
m_float: 0
m_floatArray: []
m_int: 6
m_matrix:
e00: 0
e01: 0
e02: 0
e03: 0
e10: 0
e11: 0
e12: 0
e13: 0
e20: 0
e21: 0
e22: 0
e23: 0
e30: 0
e31: 0
e32: 0
e33: 0
m_matrixArray: []
- m_name: _MipMapColors
m_parameterType: 4
m_texture: {fileID: 0}
m_vector: {x: 0, y: 0, z: 0, w: 0}
m_vectorArray: []
m_color: {r: 0, g: 0, b: 0, a: 0}
m_colorArray:
- {r: 0, g: 0.4, b: 1, a: 1}
- {r: 0, g: 1, b: 1, a: 1}
- {r: 0, g: 1, b: 0.4, a: 1}
- {r: 0.2, g: 1, b: 0, a: 1}
- {r: 0.8, g: 1, b: 0, a: 1}
- {r: 1, g: 0.6, b: 0, a: 1}
m_float: 0
m_floatArray: []
m_int: 0
m_matrix:
e00: 0
e01: 0
e02: 0
e03: 0
e10: 0
e11: 0
e12: 0
e13: 0
e20: 0
e21: 0
e22: 0
e23: 0
e30: 0
e31: 0
e32: 0
e33: 0
m_matrixArray: []

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ce4e894416ac8004fa4d80eddd059296
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,95 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1aa272ccd1306c545b68254a527f8025, type: 3}
m_Name: TexelDensityChecker
m_EditorClassIdentifier:
content:
icon: {fileID: 2800000, guid: e613356da75e6764ea82a89a5ce3c6bc, type: 3}
tooltip:
sortingOrder: 31
compact:
m_Text:
m_Image: {fileID: 2800000, guid: e613356da75e6764ea82a89a5ce3c6bc, type: 3}
m_Tooltip:
normal:
m_Text: ' TexelDensityChecker'
m_Image: {fileID: 2800000, guid: e613356da75e6764ea82a89a5ce3c6bc, type: 3}
m_Tooltip:
shader: {fileID: 4800000, guid: 83a3ee0da908c7542be7a089c047d28f, type: 3}
replacementTag:
parameters:
- m_name: _RS_Texture
m_parameterType: 0
m_texture: {fileID: 0}
m_vector: {x: 0, y: 0, z: 0, w: 0}
m_vectorArray:
- {x: 0, y: 0, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
m_color: {r: 1, g: 0, b: 0, a: 0.14901961}
m_colorArray: []
m_float: 0
m_floatArray:
- 0
- 0
- 0
m_int: 0
m_matrix:
e00: 0
e01: 0
e02: 0
e03: 0
e10: 0
e11: 0
e12: 0
e13: 0
e20: 0
e21: 0
e22: 0
e23: 0
e30: 0
e31: 0
e32: 0
e33: 0
m_matrixArray:
- e00: 0
e01: 0
e02: 0
e03: 0
e10: 0
e11: 0
e12: 0
e13: 0
e20: 0
e21: 0
e22: 0
e23: 0
e30: 0
e31: 0
e32: 0
e33: 0
- e00: 0
e01: 0
e02: 0
e03: 0
e10: 0
e11: 0
e12: 0
e13: 0
e20: 0
e21: 0
e22: 0
e23: 0
e30: 0
e31: 0
e32: 0
e33: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6ce604b84317ba14f823bc107e0f895a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant: