mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-07 19:38:13 -05:00
VRMShaders にテスト移動。IsReadable=false のときにコピーしないとエラーになるテスト
This commit is contained in:
@@ -13,7 +13,7 @@ namespace UniGLTF
|
||||
/// <param name="bytes"></param>
|
||||
/// <param name="texture"></param>
|
||||
/// <returns></returns>
|
||||
static (byte[] bytes, string mine) GetBytesWithMime(Texture2D texture)
|
||||
public static (byte[] bytes, string mine) GetBytesWithMime(Texture2D texture)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var path = UnityPath.FromAsset(texture);
|
||||
|
||||
8
Assets/UniGLTF/Tests/Resources.meta
Normal file
8
Assets/UniGLTF/Tests/Resources.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee977e7fc2164bd408c27953f01dd8f1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/UniGLTF/Tests/Resources/4x4.png
Normal file
BIN
Assets/UniGLTF/Tests/Resources/4x4.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 560 B |
88
Assets/UniGLTF/Tests/Resources/4x4.png.meta
Normal file
88
Assets/UniGLTF/Tests/Resources/4x4.png.meta
Normal file
@@ -0,0 +1,88 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db15802c623d98042a8cf5f03959818c
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 9
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
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
|
||||
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: -1
|
||||
nPOTScale: 1
|
||||
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: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 2
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/UniGLTF/Tests/UniGLTF/Resources.meta
Normal file
8
Assets/UniGLTF/Tests/UniGLTF/Resources.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ff3cfe62633ecc40a4ee5b12d3e680f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/UniGLTF/Tests/UniGLTF/Resources/4x4.png
Normal file
BIN
Assets/UniGLTF/Tests/UniGLTF/Resources/4x4.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 560 B |
88
Assets/UniGLTF/Tests/UniGLTF/Resources/4x4.png.meta
Normal file
88
Assets/UniGLTF/Tests/UniGLTF/Resources/4x4.png.meta
Normal file
@@ -0,0 +1,88 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82e462ede66d6d0488b5be50747cbad9
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 9
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
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
|
||||
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: -1
|
||||
nPOTScale: 1
|
||||
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: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 2
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/UniGLTF/Tests/UniGLTF/Resources/4x4compressed.DDS
Normal file
BIN
Assets/UniGLTF/Tests/UniGLTF/Resources/4x4compressed.DDS
Normal file
Binary file not shown.
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1e26504b87027940bfbd21ea1327ff6
|
||||
IHVImageFormatImporter:
|
||||
externalObjects: {}
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 0
|
||||
wrapV: 0
|
||||
wrapW: 0
|
||||
isReadable: 0
|
||||
sRGBTexture: 1
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -31,93 +31,24 @@ namespace UniGLTF
|
||||
Assert.AreEqual(glFilter.LINEAR_MIPMAP_LINEAR, sampler.minFilter);
|
||||
Assert.AreEqual(glFilter.LINEAR_MIPMAP_LINEAR, sampler.magFilter);
|
||||
}
|
||||
}
|
||||
|
||||
public class MetallicRoughnessConverterTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void ExportingColorTest()
|
||||
public void NotReadable()
|
||||
{
|
||||
{
|
||||
var smoothness = 1.0f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ExportPixel(new Color32(255, 255, 255, 255), smoothness, default),
|
||||
// r <- 0 : (Unused)
|
||||
// g <- 0 : ((1 - src.a(as float) * smoothness) ^ 2)(as uint8)
|
||||
// b <- 255 : Same metallic (src.r)
|
||||
// a <- 255 : (Unused)
|
||||
Is.EqualTo(new Color32(0, 0, 255, 255)));
|
||||
}
|
||||
|
||||
{
|
||||
var smoothness = 0.5f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ExportPixel(new Color32(255, 255, 255, 255), smoothness, default),
|
||||
// r <- 0 : (Unused)
|
||||
// g <- 63 : ((1 - src.a(as float) * smoothness) ^ 2)(as uint8)
|
||||
// b <- 255 : Same metallic (src.r)
|
||||
// a <- 255 : (Unused)
|
||||
Is.EqualTo(new Color32(0, 127, 255, 255)));
|
||||
}
|
||||
|
||||
{
|
||||
var smoothness = 0.0f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ExportPixel(new Color32(255, 255, 255, 255), smoothness, default),
|
||||
// r <- 0 : (Unused)
|
||||
// g <- 255 : ((1 - src.a(as float) * smoothness) ^ 2)(as uint8)
|
||||
// b <- 255 : Same metallic (src.r)
|
||||
// a <- 255 : (Unused)
|
||||
Is.EqualTo(new Color32(0, 255, 255, 255)));
|
||||
}
|
||||
var readonlyTexture = Resources.Load<Texture2D>("4x4");
|
||||
Assert.False(readonlyTexture.isReadable);
|
||||
var (bytes, mime) = GltfTextureExporter.GetBytesWithMime(readonlyTexture);
|
||||
Assert.NotNull(bytes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ImportingColorTest()
|
||||
public void Compressed()
|
||||
{
|
||||
{
|
||||
var roughnessFactor = 1.0f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ImportPixel(new Color32(255, 255, 255, 255), 1.0f, roughnessFactor, default),
|
||||
// r <- 255 : Same metallic (src.r)
|
||||
// g <- 0 : (Unused)
|
||||
// b <- 0 : (Unused)
|
||||
// a <- 0 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
|
||||
Is.EqualTo(new Color32(255, 0, 0, 0)));
|
||||
}
|
||||
|
||||
{
|
||||
var roughnessFactor = 1.0f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ImportPixel(new Color32(255, 128, 255, 255), 1.0f, roughnessFactor, default),
|
||||
// r <- 255 : Same metallic (src.r)
|
||||
// g <- 0 : (Unused)
|
||||
// b <- 0 : (Unused)
|
||||
// a <- 128 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
|
||||
Is.EqualTo(new Color32(255, 0, 0, 127))); // smoothness 0.5 * src.a 1.0
|
||||
}
|
||||
|
||||
{
|
||||
var roughnessFactor = 0.5f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ImportPixel(new Color32(255, 255, 255, 255), 1.0f, roughnessFactor, default),
|
||||
// r <- 255 : Same metallic (src.r)
|
||||
// g <- 0 : (Unused)
|
||||
// b <- 0 : (Unused)
|
||||
// a <- 74 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
|
||||
Is.EqualTo(new Color32(255, 0, 0, 127)));
|
||||
}
|
||||
|
||||
{
|
||||
var roughnessFactor = 0.0f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ImportPixel(new Color32(255, 255, 255, 255), 1.0f, roughnessFactor, default),
|
||||
// r <- 255 : Same metallic (src.r)
|
||||
// g <- 0 : (Unused)
|
||||
// b <- 0 : (Unused)
|
||||
// a <- 255 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
|
||||
Is.EqualTo(new Color32(255, 0, 0, 255)));
|
||||
}
|
||||
var readonlyTexture = Resources.Load<Texture2D>("4x4compressed");
|
||||
Assert.False(readonlyTexture.isReadable);
|
||||
var (bytes, mime) = GltfTextureExporter.GetBytesWithMime(readonlyTexture);
|
||||
Assert.NotNull(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
Assets/VRMShaders/Tests.meta
Normal file
8
Assets/VRMShaders/Tests.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b9c0681fd83aa3439d3221de54fdacf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
93
Assets/VRMShaders/Tests/MetallicRoughnessConverterTests.cs
Normal file
93
Assets/VRMShaders/Tests/MetallicRoughnessConverterTests.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRMShaders
|
||||
{
|
||||
public class MetallicRoughnessConverterTests
|
||||
{
|
||||
[Test]
|
||||
public void ExportingColorTest()
|
||||
{
|
||||
{
|
||||
var smoothness = 1.0f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ExportPixel(new Color32(255, 255, 255, 255), smoothness, default),
|
||||
// r <- 0 : (Unused)
|
||||
// g <- 0 : ((1 - src.a(as float) * smoothness) ^ 2)(as uint8)
|
||||
// b <- 255 : Same metallic (src.r)
|
||||
// a <- 255 : (Unused)
|
||||
Is.EqualTo(new Color32(0, 0, 255, 255)));
|
||||
}
|
||||
|
||||
{
|
||||
var smoothness = 0.5f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ExportPixel(new Color32(255, 255, 255, 255), smoothness, default),
|
||||
// r <- 0 : (Unused)
|
||||
// g <- 63 : ((1 - src.a(as float) * smoothness) ^ 2)(as uint8)
|
||||
// b <- 255 : Same metallic (src.r)
|
||||
// a <- 255 : (Unused)
|
||||
Is.EqualTo(new Color32(0, 127, 255, 255)));
|
||||
}
|
||||
|
||||
{
|
||||
var smoothness = 0.0f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ExportPixel(new Color32(255, 255, 255, 255), smoothness, default),
|
||||
// r <- 0 : (Unused)
|
||||
// g <- 255 : ((1 - src.a(as float) * smoothness) ^ 2)(as uint8)
|
||||
// b <- 255 : Same metallic (src.r)
|
||||
// a <- 255 : (Unused)
|
||||
Is.EqualTo(new Color32(0, 255, 255, 255)));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ImportingColorTest()
|
||||
{
|
||||
{
|
||||
var roughnessFactor = 1.0f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ImportPixel(new Color32(255, 255, 255, 255), 1.0f, roughnessFactor, default),
|
||||
// r <- 255 : Same metallic (src.r)
|
||||
// g <- 0 : (Unused)
|
||||
// b <- 0 : (Unused)
|
||||
// a <- 0 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
|
||||
Is.EqualTo(new Color32(255, 0, 0, 0)));
|
||||
}
|
||||
|
||||
{
|
||||
var roughnessFactor = 1.0f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ImportPixel(new Color32(255, 128, 255, 255), 1.0f, roughnessFactor, default),
|
||||
// r <- 255 : Same metallic (src.r)
|
||||
// g <- 0 : (Unused)
|
||||
// b <- 0 : (Unused)
|
||||
// a <- 128 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
|
||||
Is.EqualTo(new Color32(255, 0, 0, 127))); // smoothness 0.5 * src.a 1.0
|
||||
}
|
||||
|
||||
{
|
||||
var roughnessFactor = 0.5f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ImportPixel(new Color32(255, 255, 255, 255), 1.0f, roughnessFactor, default),
|
||||
// r <- 255 : Same metallic (src.r)
|
||||
// g <- 0 : (Unused)
|
||||
// b <- 0 : (Unused)
|
||||
// a <- 74 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
|
||||
Is.EqualTo(new Color32(255, 0, 0, 127)));
|
||||
}
|
||||
|
||||
{
|
||||
var roughnessFactor = 0.0f;
|
||||
Assert.That(
|
||||
OcclusionMetallicRoughnessConverter.ImportPixel(new Color32(255, 255, 255, 255), 1.0f, roughnessFactor, default),
|
||||
// r <- 255 : Same metallic (src.r)
|
||||
// g <- 0 : (Unused)
|
||||
// b <- 0 : (Unused)
|
||||
// a <- 255 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
|
||||
Is.EqualTo(new Color32(255, 0, 0, 255)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98670a2a3852f3f40a7f9cbd5791e506
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/VRMShaders/Tests/VRMShaders.Tests.asmdef
Normal file
18
Assets/VRMShaders/Tests/VRMShaders.Tests.asmdef
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "VRMShaders.Tests",
|
||||
"references": [
|
||||
"VRMShaders"
|
||||
],
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": []
|
||||
}
|
||||
7
Assets/VRMShaders/Tests/VRMShaders.Tests.asmdef.meta
Normal file
7
Assets/VRMShaders/Tests/VRMShaders.Tests.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e517ae7a2a124241a6da9588530ce79
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user