VRMShaders.GetTextureParam

This commit is contained in:
ousttrue 2021-03-24 15:52:51 +09:00
parent 95ee01b41f
commit 7cf9895b02
18 changed files with 371 additions and 347 deletions

View File

@ -3,7 +3,8 @@
"references": [
"UniGLTF",
"MeshUtility",
"MeshUtility.Editor"
"MeshUtility.Editor",
"VRMShaders"
],
"optionalUnityReferences": [],
"includePlatforms": [

View File

@ -2,7 +2,8 @@
"name": "UniGLTF",
"references": [
"UniUnlit",
"ShaderProperty.Runtime"
"ShaderProperty.Runtime",
"VRMShaders"
],
"optionalUnityReferences": [],
"includePlatforms": [],

View File

@ -27,7 +27,7 @@ namespace UniGLTF
// emission
if (m.emissiveTexture != null)
{
yield return GetTextureParam.CreateSRGB(parser, m.emissiveTexture.index);
yield return TextureFactory.CreateSRGB(parser, m.emissiveTexture.index);
}
// normal

View File

@ -45,7 +45,7 @@ namespace UniGLTF
public static GetTextureParam BaseColorTexture(GltfParser parser, glTFMaterial src)
{
return GetTextureParam.CreateSRGB(parser, src.pbrMetallicRoughness.baseColorTexture.index);
return TextureFactory.CreateSRGB(parser, src.pbrMetallicRoughness.baseColorTexture.index);
}
public static GetTextureParam StandardTexture(GltfParser parser, glTFMaterial src)
@ -57,7 +57,7 @@ namespace UniGLTF
metallicFactor = src.pbrMetallicRoughness.metallicFactor;
roughnessFactor = src.pbrMetallicRoughness.roughnessFactor;
}
return GetTextureParam.CreateStandard(parser,
return TextureFactory.CreateStandard(parser,
src.pbrMetallicRoughness?.metallicRoughnessTexture?.index,
src.occlusionTexture?.index,
metallicFactor,
@ -66,7 +66,7 @@ namespace UniGLTF
public static GetTextureParam NormalTexture(GltfParser parser, glTFMaterial src)
{
return GetTextureParam.CreateNormal(parser, src.normalTexture.index);
return TextureFactory.CreateNormal(parser, src.normalTexture.index);
}
public static async Task<Material> CreateAsync(IAwaitCaller awaitCaller, GltfParser parser, int i, GetTextureAsyncFunc getTexture)
@ -168,7 +168,7 @@ namespace UniGLTF
if (src.emissiveTexture != null && src.emissiveTexture.index != -1)
{
var texture = await getTexture(awaitCaller, parser.GLTF, GetTextureParam.CreateSRGB(parser, src.emissiveTexture.index));
var texture = await getTexture(awaitCaller, parser.GLTF, TextureFactory.CreateSRGB(parser, src.emissiveTexture.index));
if (texture != null)
{
material.SetTexture("_EmissionMap", texture);

View File

@ -21,7 +21,7 @@ namespace UniGLTF
// texture
if (src.pbrMetallicRoughness.baseColorTexture != null)
{
material.mainTexture = await getTexture(awaitCaller, parser.GLTF, GetTextureParam.CreateSRGB(parser, src.pbrMetallicRoughness.baseColorTexture.index));
material.mainTexture = await getTexture(awaitCaller, parser.GLTF, TextureFactory.CreateSRGB(parser, src.pbrMetallicRoughness.baseColorTexture.index));
// Texture Offset and Scale
MaterialFactory.SetTextureOffsetAndScale(material, src.pbrMetallicRoughness.baseColorTexture, "_MainTex");

View File

@ -1,328 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
namespace UniGLTF
{
public delegate Task<ArraySegment<byte>> GetTextureBytesAsync();
/// <summary>
/// STANDARD(Pbr) texture = occlusion + metallic + smoothness
/// </summary>
public struct GetTextureParam
{
public const string NORMAL_PROP = "_BumpMap";
public const string NORMAL_SUFFIX = ".normal";
public const string METALLIC_GLOSS_PROP = "_MetallicGlossMap";
public const string OCCLUSION_PROP = "_OcclusionMap";
public const string STANDARD_SUFFIX = ".standard";
public enum TextureTypes
{
sRGB,
NormalMap,
// Occlusion + Metallic + Smoothness
StandardMap,
Linear,
}
public static string RemoveSuffix(string src)
{
if (src.EndsWith(NORMAL_SUFFIX))
{
return src.Substring(0, src.Length - NORMAL_SUFFIX.Length);
}
else if (src.EndsWith(STANDARD_SUFFIX))
{
return src.Substring(0, src.Length - STANDARD_SUFFIX.Length);
}
else
{
return src;
}
}
public struct NameExt
{
public readonly string GltfName;
public readonly string ConvertedName;
public readonly string Ext;
public string Uri;
public NameExt(string gltfName, string convertedName, string ext, string uri)
{
GltfName = gltfName;
ConvertedName = convertedName;
Ext = ext;
Uri = uri;
}
public string GltfFileName => $"{GltfName}{Ext}";
public string ConvertedFileName => $"{ConvertedName}.png";
public static NameExt Create(glTF gltf, int textureIndex, TextureTypes textureType)
{
if (textureIndex < 0 || textureIndex >= gltf.textures.Count)
{
throw new ArgumentOutOfRangeException();
}
var gltfTexture = gltf.textures[textureIndex];
if(gltfTexture.source < 0 || gltfTexture.source >=gltf.images.Count)
{
throw new ArgumentOutOfRangeException();
}
var gltfImage = gltf.images[gltfTexture.source];
return new NameExt(gltfTexture.name, Convert(gltfTexture.name, textureType), gltfImage.GetExt(), gltfImage.uri);
}
static string Convert(string name, TextureTypes textureType)
{
switch (textureType)
{
case TextureTypes.StandardMap: return $"{name}{STANDARD_SUFFIX}";
case TextureTypes.NormalMap: return $"{name}{NORMAL_SUFFIX}";
default: return name;
}
}
}
public readonly NameExt Name;
public string GltfName => Name.GltfName;
public string GltfFileName => Name.GltfFileName;
public string ConvertedName => Name.ConvertedName;
public string ConvertedFileName => Name.ConvertedFileName;
public string Uri => Name.Uri;
public struct TextureSamplerParam
{
public enum TextureWrapType
{
All,
U,
V,
W,
}
public (TextureWrapType, TextureWrapMode)[] WrapModes;
public FilterMode FilterMode;
public static TextureSamplerParam Create(glTF gltf, int index)
{
var gltfTexture = gltf.textures[index];
if(gltfTexture.sampler<0 || gltfTexture.sampler>= gltf.samplers.Count)
{
// default
return new TextureSamplerParam
{
FilterMode = FilterMode.Bilinear,
WrapModes = new (TextureWrapType, TextureWrapMode)[]{},
};
}
var gltfSampler = gltf.samplers[gltfTexture.sampler];
return new TextureSamplerParam
{
WrapModes = GetUnityWrapMode(gltfSampler).ToArray(),
FilterMode = ImportFilterMode(gltfSampler.minFilter),
};
}
public static IEnumerable<(TextureWrapType, TextureWrapMode)> GetUnityWrapMode(glTFTextureSampler sampler)
{
if (sampler.wrapS == sampler.wrapT)
{
switch (sampler.wrapS)
{
case glWrap.NONE: // default
yield return (TextureWrapType.All, TextureWrapMode.Repeat);
break;
case glWrap.CLAMP_TO_EDGE:
yield return (TextureWrapType.All, TextureWrapMode.Clamp);
break;
case glWrap.REPEAT:
yield return (TextureWrapType.All, TextureWrapMode.Repeat);
break;
case glWrap.MIRRORED_REPEAT:
yield return (TextureWrapType.All, TextureWrapMode.Mirror);
break;
default:
throw new NotImplementedException();
}
}
else
{
switch (sampler.wrapS)
{
case glWrap.NONE: // default
yield return (TextureWrapType.U, TextureWrapMode.Repeat);
break;
case glWrap.CLAMP_TO_EDGE:
yield return (TextureWrapType.U, TextureWrapMode.Clamp);
break;
case glWrap.REPEAT:
yield return (TextureWrapType.U, TextureWrapMode.Repeat);
break;
case glWrap.MIRRORED_REPEAT:
yield return (TextureWrapType.U, TextureWrapMode.Mirror);
break;
default:
throw new NotImplementedException();
}
switch (sampler.wrapT)
{
case glWrap.NONE: // default
yield return (TextureWrapType.V, TextureWrapMode.Repeat);
break;
case glWrap.CLAMP_TO_EDGE:
yield return (TextureWrapType.V, TextureWrapMode.Clamp);
break;
case glWrap.REPEAT:
yield return (TextureWrapType.V, TextureWrapMode.Repeat);
break;
case glWrap.MIRRORED_REPEAT:
yield return (TextureWrapType.V, TextureWrapMode.Mirror);
break;
default:
throw new NotImplementedException();
}
}
}
public static FilterMode ImportFilterMode(glFilter filterMode)
{
switch (filterMode)
{
case glFilter.NEAREST:
case glFilter.NEAREST_MIPMAP_LINEAR:
case glFilter.NEAREST_MIPMAP_NEAREST:
return FilterMode.Point;
case glFilter.NONE:
case glFilter.LINEAR:
case glFilter.LINEAR_MIPMAP_NEAREST:
return FilterMode.Bilinear;
case glFilter.LINEAR_MIPMAP_LINEAR:
return FilterMode.Trilinear;
default:
throw new NotImplementedException();
}
}
}
public TextureSamplerParam Sampler;
public readonly TextureTypes TextureType;
public readonly float MetallicFactor;
public readonly float RoughnessFactor;
public readonly GetTextureBytesAsync Index0;
public readonly GetTextureBytesAsync Index1;
public readonly GetTextureBytesAsync Index2;
public readonly GetTextureBytesAsync Index3;
public readonly GetTextureBytesAsync Index4;
public readonly GetTextureBytesAsync Index5;
/// <summary>
/// この種類は RGB チャンネルの組み換えが必用
/// </summary>
public bool ExtractConverted => TextureType == TextureTypes.StandardMap;
public GetTextureParam(NameExt name, TextureSamplerParam sampler, TextureTypes textureType, float metallicFactor, float roughnessFactor,
GetTextureBytesAsync i0,
GetTextureBytesAsync i1,
GetTextureBytesAsync i2,
GetTextureBytesAsync i3,
GetTextureBytesAsync i4,
GetTextureBytesAsync i5)
{
Name = name;
Sampler = sampler;
TextureType = textureType;
MetallicFactor = metallicFactor;
RoughnessFactor = roughnessFactor;
Index0 = i0;
Index1 = i1;
Index2 = i2;
Index3 = i3;
Index4 = i4;
Index5 = i5;
}
public static GetTextureParam CreateSRGB(GltfParser parser, int textureIndex)
{
var name = NameExt.Create(parser.GLTF, textureIndex, TextureTypes.sRGB);
var sampler = TextureSamplerParam.Create(parser.GLTF, textureIndex);
GetTextureBytesAsync getTextureBytesAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex);
return new GetTextureParam(name, sampler, TextureTypes.sRGB, default, default, getTextureBytesAsync, default, default, default, default, default);
}
public static GetTextureParam CreateNormal(GltfParser parser, int textureIndex)
{
var name = NameExt.Create(parser.GLTF, textureIndex, TextureTypes.NormalMap);
var sampler = TextureSamplerParam.Create(parser.GLTF, textureIndex);
GetTextureBytesAsync getTextureBytesAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex);
return new GetTextureParam(name, sampler, TextureTypes.NormalMap, default, default, getTextureBytesAsync, default, default, default, default, default);
}
public static GetTextureParam CreateStandard(GltfParser parser, int? metallicRoughnessTextureIndex, int? occlusionTextureIndex, float metallicFactor, float roughnessFactor)
{
NameExt name = default;
GetTextureBytesAsync getMetallicRoughnessAsync = default;
TextureSamplerParam sampler = default;
if (metallicRoughnessTextureIndex.HasValue)
{
name = NameExt.Create(parser.GLTF, metallicRoughnessTextureIndex.Value, TextureTypes.StandardMap);
sampler = TextureSamplerParam.Create(parser.GLTF, metallicRoughnessTextureIndex.Value);
getMetallicRoughnessAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, metallicRoughnessTextureIndex.Value);
}
GetTextureBytesAsync getOcclusionAsync = default;
if (occlusionTextureIndex.HasValue)
{
if(string.IsNullOrEmpty(name.GltfName)){
name = NameExt.Create(parser.GLTF, occlusionTextureIndex.Value, TextureTypes.StandardMap);
}
sampler = TextureSamplerParam.Create(parser.GLTF, occlusionTextureIndex.Value);
getOcclusionAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, occlusionTextureIndex.Value);
}
return new GetTextureParam(name, sampler, TextureTypes.StandardMap, metallicFactor, roughnessFactor, getMetallicRoughnessAsync, getOcclusionAsync, default, default, default, default);
}
public static GetTextureParam Create(GltfParser parser, int index, string prop, float metallicFactor, float roughnessFactor)
{
switch (prop)
{
case NORMAL_PROP:
return CreateNormal(parser, index);
case OCCLUSION_PROP:
case METALLIC_GLOSS_PROP:
return CreateStandard(parser, index, default, metallicFactor, roughnessFactor);
default:
return CreateSRGB(parser, index);
}
}
}
}

View File

@ -190,19 +190,19 @@ namespace UniGLTF
{
switch (key)
{
case GetTextureParam.TextureSamplerParam.TextureWrapType.All:
case GetTextureParam.TextureWrapType.All:
texture.wrapMode = value;
break;
case GetTextureParam.TextureSamplerParam.TextureWrapType.U:
case GetTextureParam.TextureWrapType.U:
texture.wrapModeU = value;
break;
case GetTextureParam.TextureSamplerParam.TextureWrapType.V:
case GetTextureParam.TextureWrapType.V:
texture.wrapModeV = value;
break;
case GetTextureParam.TextureSamplerParam.TextureWrapType.W:
case GetTextureParam.TextureWrapType.W:
texture.wrapModeW = value;
break;
@ -273,5 +273,196 @@ namespace UniGLTF
throw new NotImplementedException();
}
}
public static GetTextureParam CreateSRGB(GltfParser parser, int textureIndex)
{
var name = CreateNameExt(parser.GLTF, textureIndex, GetTextureParam.TextureTypes.sRGB);
var sampler = CreateSampler(parser.GLTF, textureIndex);
GetTextureBytesAsync getTextureBytesAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex);
return new GetTextureParam(name, sampler, GetTextureParam.TextureTypes.sRGB, default, default, getTextureBytesAsync, default, default, default, default, default);
}
public static GetTextureParam CreateNormal(GltfParser parser, int textureIndex)
{
var name = CreateNameExt(parser.GLTF, textureIndex, GetTextureParam.TextureTypes.NormalMap);
var sampler = CreateSampler(parser.GLTF, textureIndex);
GetTextureBytesAsync getTextureBytesAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex);
return new GetTextureParam(name, sampler, GetTextureParam.TextureTypes.NormalMap, default, default, getTextureBytesAsync, default, default, default, default, default);
}
public static GetTextureParam CreateStandard(GltfParser parser, int? metallicRoughnessTextureIndex, int? occlusionTextureIndex, float metallicFactor, float roughnessFactor)
{
GetTextureParam.NameExt name = default;
GetTextureBytesAsync getMetallicRoughnessAsync = default;
GetTextureParam.TextureSamplerParam sampler = default;
if (metallicRoughnessTextureIndex.HasValue)
{
name = CreateNameExt(parser.GLTF, metallicRoughnessTextureIndex.Value, GetTextureParam.TextureTypes.StandardMap);
sampler = CreateSampler(parser.GLTF, metallicRoughnessTextureIndex.Value);
getMetallicRoughnessAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, metallicRoughnessTextureIndex.Value);
}
GetTextureBytesAsync getOcclusionAsync = default;
if (occlusionTextureIndex.HasValue)
{
if(string.IsNullOrEmpty(name.GltfName)){
name = CreateNameExt(parser.GLTF, occlusionTextureIndex.Value, GetTextureParam.TextureTypes.StandardMap);
}
sampler = CreateSampler(parser.GLTF, occlusionTextureIndex.Value);
getOcclusionAsync = async () => parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, occlusionTextureIndex.Value);
}
return new GetTextureParam(name, sampler, GetTextureParam.TextureTypes.StandardMap, metallicFactor, roughnessFactor, getMetallicRoughnessAsync, getOcclusionAsync, default, default, default, default);
}
public static GetTextureParam Create(GltfParser parser, int index, string prop, float metallicFactor, float roughnessFactor)
{
switch (prop)
{
case GetTextureParam.NORMAL_PROP:
return CreateNormal(parser, index);
case GetTextureParam.OCCLUSION_PROP:
case GetTextureParam.METALLIC_GLOSS_PROP:
return CreateStandard(parser, index, default, metallicFactor, roughnessFactor);
default:
return CreateSRGB(parser, index);
}
}
public static GetTextureParam.NameExt CreateNameExt(glTF gltf, int textureIndex, GetTextureParam.TextureTypes textureType)
{
if (textureIndex < 0 || textureIndex >= gltf.textures.Count)
{
throw new ArgumentOutOfRangeException();
}
var gltfTexture = gltf.textures[textureIndex];
if (gltfTexture.source < 0 || gltfTexture.source >= gltf.images.Count)
{
throw new ArgumentOutOfRangeException();
}
var gltfImage = gltf.images[gltfTexture.source];
var convertedName = GetTextureParam.NameExt.Convert(gltfTexture.name, textureType);
return new GetTextureParam.NameExt(gltfTexture.name, convertedName, gltfImage.GetExt(), gltfImage.uri);
}
public static GetTextureParam.TextureSamplerParam CreateSampler(glTF gltf, int index)
{
var gltfTexture = gltf.textures[index];
if (gltfTexture.sampler < 0 || gltfTexture.sampler >= gltf.samplers.Count)
{
// default
return new GetTextureParam.TextureSamplerParam
{
FilterMode = FilterMode.Bilinear,
WrapModes = new (GetTextureParam.TextureWrapType, TextureWrapMode)[] { },
};
}
var gltfSampler = gltf.samplers[gltfTexture.sampler];
return new GetTextureParam.TextureSamplerParam
{
WrapModes = GetUnityWrapMode(gltfSampler).ToArray(),
FilterMode = ImportFilterMode(gltfSampler.minFilter),
};
}
public static IEnumerable<(GetTextureParam.TextureWrapType, TextureWrapMode)> GetUnityWrapMode(glTFTextureSampler sampler)
{
if (sampler.wrapS == sampler.wrapT)
{
switch (sampler.wrapS)
{
case glWrap.NONE: // default
yield return (GetTextureParam.TextureWrapType.All, TextureWrapMode.Repeat);
break;
case glWrap.CLAMP_TO_EDGE:
yield return (GetTextureParam.TextureWrapType.All, TextureWrapMode.Clamp);
break;
case glWrap.REPEAT:
yield return (GetTextureParam.TextureWrapType.All, TextureWrapMode.Repeat);
break;
case glWrap.MIRRORED_REPEAT:
yield return (GetTextureParam.TextureWrapType.All, TextureWrapMode.Mirror);
break;
default:
throw new NotImplementedException();
}
}
else
{
switch (sampler.wrapS)
{
case glWrap.NONE: // default
yield return (GetTextureParam.TextureWrapType.U, TextureWrapMode.Repeat);
break;
case glWrap.CLAMP_TO_EDGE:
yield return (GetTextureParam.TextureWrapType.U, TextureWrapMode.Clamp);
break;
case glWrap.REPEAT:
yield return (GetTextureParam.TextureWrapType.U, TextureWrapMode.Repeat);
break;
case glWrap.MIRRORED_REPEAT:
yield return (GetTextureParam.TextureWrapType.U, TextureWrapMode.Mirror);
break;
default:
throw new NotImplementedException();
}
switch (sampler.wrapT)
{
case glWrap.NONE: // default
yield return (GetTextureParam.TextureWrapType.V, TextureWrapMode.Repeat);
break;
case glWrap.CLAMP_TO_EDGE:
yield return (GetTextureParam.TextureWrapType.V, TextureWrapMode.Clamp);
break;
case glWrap.REPEAT:
yield return (GetTextureParam.TextureWrapType.V, TextureWrapMode.Repeat);
break;
case glWrap.MIRRORED_REPEAT:
yield return (GetTextureParam.TextureWrapType.V, TextureWrapMode.Mirror);
break;
default:
throw new NotImplementedException();
}
}
}
public static FilterMode ImportFilterMode(glFilter filterMode)
{
switch (filterMode)
{
case glFilter.NEAREST:
case glFilter.NEAREST_MIPMAP_LINEAR:
case glFilter.NEAREST_MIPMAP_NEAREST:
return FilterMode.Point;
case glFilter.NONE:
case glFilter.LINEAR:
case glFilter.LINEAR_MIPMAP_NEAREST:
return FilterMode.Bilinear;
case glFilter.LINEAR_MIPMAP_LINEAR:
return FilterMode.Trilinear;
default:
throw new NotImplementedException();
}
}
}
}

View File

@ -2,7 +2,8 @@
"name": "UniGLTF.Tests",
"references": [
"UniGLTF",
"UniGLTF.Editor"
"UniGLTF.Editor",
"VRMShaders"
],
"optionalUnityReferences": [
"TestAssemblies"

View File

@ -7,7 +7,8 @@
"MeshUtility.Editor",
"UniUnlit",
"UniGLTF",
"UniGLTF.Editor"
"UniGLTF.Editor",
"VRMShaders"
],
"optionalUnityReferences": [],
"includePlatforms": [

View File

@ -297,7 +297,7 @@ namespace VRM
meta.Title = gltfMeta.title;
if (gltfMeta.texture >= 0)
{
meta.Thumbnail = await TextureFactory.GetTextureAsync(awaitCaller, GLTF, GetTextureParam.CreateSRGB(Parser, gltfMeta.texture));
meta.Thumbnail = await TextureFactory.GetTextureAsync(awaitCaller, GLTF, TextureFactory.CreateSRGB(Parser, gltfMeta.texture));
}
meta.AllowedUser = gltfMeta.allowedUser;
meta.ViolentUssage = gltfMeta.violentUssage;

View File

@ -73,7 +73,7 @@ namespace VRM
}
foreach (var kv in item.textureProperties)
{
var param = GetTextureParam.Create(parser, kv.Value, kv.Key, 1, 1);
var param = TextureFactory.Create(parser, kv.Value, kv.Key, 1, 1);
var texture = await getTexture(awaitCaller, parser.GLTF, param);
if (texture != null)
{

View File

@ -22,7 +22,7 @@ namespace VRM
foreach (var kv in vrmMaterial.textureProperties)
{
// SRGB color or normalmap
yield return GetTextureParam.Create(parser, kv.Value, kv.Key, default, default);
yield return TextureFactory.Create(parser, kv.Value, kv.Key, default, default);
}
}
else
@ -38,7 +38,7 @@ namespace VRM
// thumbnail
if (m_vrm.meta != null && m_vrm.meta.texture != -1)
{
yield return GetTextureParam.CreateSRGB(parser, m_vrm.meta.texture);
yield return TextureFactory.CreateSRGB(parser, m_vrm.meta.texture);
}
}
}

View File

@ -6,7 +6,8 @@
"UniHumanoid",
"ShaderProperty.Runtime",
"MeshUtility",
"UniGLTF"
"UniGLTF",
"VRMShaders"
],
"optionalUnityReferences": [],
"includePlatforms": [],

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fcad5106da772b9478acad653777c2c8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,138 @@
using System;
using System.Threading.Tasks;
using UnityEngine;
namespace UniGLTF
{
public delegate Task<ArraySegment<byte>> GetTextureBytesAsync();
/// <summary>
/// STANDARD(Pbr) texture = occlusion + metallic + smoothness
/// </summary>
public struct GetTextureParam
{
public const string NORMAL_PROP = "_BumpMap";
public const string NORMAL_SUFFIX = ".normal";
public const string METALLIC_GLOSS_PROP = "_MetallicGlossMap";
public const string OCCLUSION_PROP = "_OcclusionMap";
public const string STANDARD_SUFFIX = ".standard";
public enum TextureTypes
{
sRGB,
NormalMap,
// Occlusion + Metallic + Smoothness
StandardMap,
Linear,
}
public static string RemoveSuffix(string src)
{
if (src.EndsWith(NORMAL_SUFFIX))
{
return src.Substring(0, src.Length - NORMAL_SUFFIX.Length);
}
else if (src.EndsWith(STANDARD_SUFFIX))
{
return src.Substring(0, src.Length - STANDARD_SUFFIX.Length);
}
else
{
return src;
}
}
public struct NameExt
{
public readonly string GltfName;
public readonly string ConvertedName;
public readonly string Ext;
public string Uri;
public NameExt(string gltfName, string convertedName, string ext, string uri)
{
GltfName = gltfName;
ConvertedName = convertedName;
Ext = ext;
Uri = uri;
}
public string GltfFileName => $"{GltfName}{Ext}";
public string ConvertedFileName => $"{ConvertedName}.png";
public static string Convert(string name, TextureTypes textureType)
{
switch (textureType)
{
case TextureTypes.StandardMap: return $"{name}{STANDARD_SUFFIX}";
case TextureTypes.NormalMap: return $"{name}{NORMAL_SUFFIX}";
default: return name;
}
}
}
public readonly NameExt Name;
public string GltfName => Name.GltfName;
public string GltfFileName => Name.GltfFileName;
public string ConvertedName => Name.ConvertedName;
public string ConvertedFileName => Name.ConvertedFileName;
public string Uri => Name.Uri;
public enum TextureWrapType
{
All,
U,
V,
W,
}
public struct TextureSamplerParam
{
public (TextureWrapType, TextureWrapMode)[] WrapModes;
public FilterMode FilterMode;
}
public TextureSamplerParam Sampler;
public readonly TextureTypes TextureType;
public readonly float MetallicFactor;
public readonly float RoughnessFactor;
public readonly GetTextureBytesAsync Index0;
public readonly GetTextureBytesAsync Index1;
public readonly GetTextureBytesAsync Index2;
public readonly GetTextureBytesAsync Index3;
public readonly GetTextureBytesAsync Index4;
public readonly GetTextureBytesAsync Index5;
/// <summary>
/// この種類は RGB チャンネルの組み換えが必用
/// </summary>
public bool ExtractConverted => TextureType == TextureTypes.StandardMap;
public GetTextureParam(NameExt name, TextureSamplerParam sampler, TextureTypes textureType, float metallicFactor, float roughnessFactor,
GetTextureBytesAsync i0,
GetTextureBytesAsync i1,
GetTextureBytesAsync i2,
GetTextureBytesAsync i3,
GetTextureBytesAsync i4,
GetTextureBytesAsync i5)
{
Name = name;
Sampler = sampler;
TextureType = textureType;
MetallicFactor = metallicFactor;
RoughnessFactor = roughnessFactor;
Index0 = i0;
Index1 = i1;
Index2 = i2;
Index3 = i3;
Index4 = i4;
Index5 = i5;
}
}
}

View File

@ -0,0 +1,3 @@
{
"name": "VRMShaders"
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: da3e51d19d51a544fa14d43fee843098
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: