mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-28 05:44:48 -05:00
mv and separate
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d2d27884d6c4780b08c745e5cc5c5b5
|
||||
timeCreated: 1537261040
|
||||
8
Assets/UniGLTF/Runtime/UniGLTF/IO/TextureConverter.meta
Normal file
8
Assets/UniGLTF/Runtime/UniGLTF/IO/TextureConverter.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79721770f23ba6748abc1720cd99ad74
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public interface ITextureConverter
|
||||
{
|
||||
Texture2D GetImportTexture(Texture2D texture);
|
||||
Texture2D GetExportTexture(Texture2D texture);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55c6531d46a98a845b19cbe1f938eab1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class MetallicRoughnessConverter : ITextureConverter
|
||||
{
|
||||
private float _smoothnessOrRoughness;
|
||||
|
||||
public MetallicRoughnessConverter(float smoothnessOrRoughness)
|
||||
{
|
||||
_smoothnessOrRoughness = smoothnessOrRoughness;
|
||||
}
|
||||
|
||||
public Texture2D GetImportTexture(Texture2D texture)
|
||||
{
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Metallic, Import, null);
|
||||
return converted;
|
||||
}
|
||||
|
||||
public Texture2D GetExportTexture(Texture2D texture)
|
||||
{
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Metallic, Export, null);
|
||||
return converted;
|
||||
}
|
||||
|
||||
public Color32 Import(Color32 src)
|
||||
{
|
||||
// Roughness(glTF): dst.g -> Smoothness(Unity): src.a (with conversion)
|
||||
// Metallic(glTF) : dst.b -> Metallic(Unity) : src.r
|
||||
|
||||
var pixelRoughnessFactor = (src.g * _smoothnessOrRoughness) / 255.0f; // roughness
|
||||
var pixelSmoothness = 1.0f - Mathf.Sqrt(pixelRoughnessFactor);
|
||||
|
||||
return new Color32
|
||||
{
|
||||
r = src.b,
|
||||
g = 0,
|
||||
b = 0,
|
||||
// Bake roughness values into a texture.
|
||||
// See: https://github.com/dwango/UniVRM/issues/212.
|
||||
a = (byte)Mathf.Clamp(pixelSmoothness * 255, 0, 255),
|
||||
};
|
||||
}
|
||||
|
||||
public Color32 Export(Color32 src)
|
||||
{
|
||||
// Smoothness(Unity): src.a -> Roughness(glTF): dst.g (with conversion)
|
||||
// Metallic(Unity) : src.r -> Metallic(glTF) : dst.b
|
||||
|
||||
var pixelSmoothness = (src.a * _smoothnessOrRoughness) / 255.0f; // smoothness
|
||||
// https://blogs.unity3d.com/jp/2016/01/25/ggx-in-unity-5-3/
|
||||
var pixelRoughnessFactorSqrt = (1.0f - pixelSmoothness);
|
||||
var pixelRoughnessFactor = pixelRoughnessFactorSqrt * pixelRoughnessFactorSqrt;
|
||||
|
||||
return new Color32
|
||||
{
|
||||
r = 0,
|
||||
// Bake smoothness values into a texture.
|
||||
// See: https://github.com/dwango/UniVRM/issues/212.
|
||||
g = (byte)Mathf.Clamp(pixelRoughnessFactor * 255, 0, 255),
|
||||
b = src.r,
|
||||
a = 255,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae1f69c4441f3a74292499f75467c057
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class NormalConverter : ITextureConverter
|
||||
{
|
||||
private Material m_decoder;
|
||||
private Material GetDecoder()
|
||||
{
|
||||
if (m_decoder == null)
|
||||
{
|
||||
m_decoder = new Material(Shader.Find("UniGLTF/NormalMapDecoder"));
|
||||
}
|
||||
return m_decoder;
|
||||
}
|
||||
|
||||
private Material m_encoder;
|
||||
private Material GetEncoder()
|
||||
{
|
||||
if (m_encoder == null)
|
||||
{
|
||||
m_encoder = new Material(Shader.Find("UniGLTF/NormalMapEncoder"));
|
||||
}
|
||||
return m_encoder;
|
||||
}
|
||||
|
||||
// GLTF data to Unity texture
|
||||
// ConvertToNormalValueFromRawColorWhenCompressionIsRequired
|
||||
public Texture2D GetImportTexture(Texture2D texture)
|
||||
{
|
||||
var mat = GetEncoder();
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Normal, null, mat);
|
||||
return converted;
|
||||
}
|
||||
|
||||
// Unity texture to GLTF data
|
||||
// ConvertToRawColorWhenNormalValueIsCompressed
|
||||
public Texture2D GetExportTexture(Texture2D texture)
|
||||
{
|
||||
var mat = GetDecoder();
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Normal, null, mat);
|
||||
return converted;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c6170d9d89ac7f43b6860805e5e6214
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class OcclusionConverter : ITextureConverter
|
||||
{
|
||||
|
||||
public Texture2D GetImportTexture(Texture2D texture)
|
||||
{
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Occlusion, Import, null);
|
||||
return converted;
|
||||
}
|
||||
|
||||
public Texture2D GetExportTexture(Texture2D texture)
|
||||
{
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Occlusion, Export, null);
|
||||
return converted;
|
||||
}
|
||||
|
||||
public Color32 Import(Color32 src)
|
||||
{
|
||||
return new Color32
|
||||
{
|
||||
r = 0,
|
||||
g = src.r,
|
||||
b = 0,
|
||||
a = 255,
|
||||
};
|
||||
}
|
||||
|
||||
public Color32 Export(Color32 src)
|
||||
{
|
||||
return new Color32
|
||||
{
|
||||
r = src.g,
|
||||
g = 0,
|
||||
b = 0,
|
||||
a = 255,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 268e807d3ea7f0f45882d20bf318cf8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -9,11 +9,6 @@ using UnityEditor;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public interface ITextureConverter
|
||||
{
|
||||
Texture2D GetImportTexture(Texture2D texture);
|
||||
Texture2D GetExportTexture(Texture2D texture);
|
||||
}
|
||||
|
||||
public static class TextureConverter
|
||||
{
|
||||
@@ -176,144 +171,6 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
public class MetallicRoughnessConverter : ITextureConverter
|
||||
{
|
||||
private float _smoothnessOrRoughness;
|
||||
|
||||
public MetallicRoughnessConverter(float smoothnessOrRoughness)
|
||||
{
|
||||
_smoothnessOrRoughness = smoothnessOrRoughness;
|
||||
}
|
||||
|
||||
public Texture2D GetImportTexture(Texture2D texture)
|
||||
{
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Metallic, Import, null);
|
||||
return converted;
|
||||
}
|
||||
|
||||
public Texture2D GetExportTexture(Texture2D texture)
|
||||
{
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Metallic, Export, null);
|
||||
return converted;
|
||||
}
|
||||
|
||||
public Color32 Import(Color32 src)
|
||||
{
|
||||
// Roughness(glTF): dst.g -> Smoothness(Unity): src.a (with conversion)
|
||||
// Metallic(glTF) : dst.b -> Metallic(Unity) : src.r
|
||||
|
||||
var pixelRoughnessFactor = (src.g * _smoothnessOrRoughness) / 255.0f; // roughness
|
||||
var pixelSmoothness = 1.0f - Mathf.Sqrt(pixelRoughnessFactor);
|
||||
|
||||
return new Color32
|
||||
{
|
||||
r = src.b,
|
||||
g = 0,
|
||||
b = 0,
|
||||
// Bake roughness values into a texture.
|
||||
// See: https://github.com/dwango/UniVRM/issues/212.
|
||||
a = (byte)Mathf.Clamp(pixelSmoothness * 255, 0, 255),
|
||||
};
|
||||
}
|
||||
|
||||
public Color32 Export(Color32 src)
|
||||
{
|
||||
// Smoothness(Unity): src.a -> Roughness(glTF): dst.g (with conversion)
|
||||
// Metallic(Unity) : src.r -> Metallic(glTF) : dst.b
|
||||
|
||||
var pixelSmoothness = (src.a * _smoothnessOrRoughness) / 255.0f; // smoothness
|
||||
// https://blogs.unity3d.com/jp/2016/01/25/ggx-in-unity-5-3/
|
||||
var pixelRoughnessFactorSqrt = (1.0f - pixelSmoothness);
|
||||
var pixelRoughnessFactor = pixelRoughnessFactorSqrt * pixelRoughnessFactorSqrt;
|
||||
|
||||
return new Color32
|
||||
{
|
||||
r = 0,
|
||||
// Bake smoothness values into a texture.
|
||||
// See: https://github.com/dwango/UniVRM/issues/212.
|
||||
g = (byte)Mathf.Clamp(pixelRoughnessFactor * 255, 0, 255),
|
||||
b = src.r,
|
||||
a = 255,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class NormalConverter : ITextureConverter
|
||||
{
|
||||
private Material m_decoder;
|
||||
private Material GetDecoder()
|
||||
{
|
||||
if (m_decoder == null)
|
||||
{
|
||||
m_decoder = new Material(Shader.Find("UniGLTF/NormalMapDecoder"));
|
||||
}
|
||||
return m_decoder;
|
||||
}
|
||||
|
||||
private Material m_encoder;
|
||||
private Material GetEncoder()
|
||||
{
|
||||
if (m_encoder == null)
|
||||
{
|
||||
m_encoder = new Material(Shader.Find("UniGLTF/NormalMapEncoder"));
|
||||
}
|
||||
return m_encoder;
|
||||
}
|
||||
|
||||
// GLTF data to Unity texture
|
||||
// ConvertToNormalValueFromRawColorWhenCompressionIsRequired
|
||||
public Texture2D GetImportTexture(Texture2D texture)
|
||||
{
|
||||
var mat = GetEncoder();
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Normal, null, mat);
|
||||
return converted;
|
||||
}
|
||||
|
||||
// Unity texture to GLTF data
|
||||
// ConvertToRawColorWhenNormalValueIsCompressed
|
||||
public Texture2D GetExportTexture(Texture2D texture)
|
||||
{
|
||||
var mat = GetDecoder();
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Normal, null, mat);
|
||||
return converted;
|
||||
}
|
||||
}
|
||||
|
||||
public class OcclusionConverter : ITextureConverter
|
||||
{
|
||||
|
||||
public Texture2D GetImportTexture(Texture2D texture)
|
||||
{
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Occlusion, Import, null);
|
||||
return converted;
|
||||
}
|
||||
|
||||
public Texture2D GetExportTexture(Texture2D texture)
|
||||
{
|
||||
var converted = TextureConverter.Convert(texture, glTFTextureTypes.Occlusion, Export, null);
|
||||
return converted;
|
||||
}
|
||||
|
||||
public Color32 Import(Color32 src)
|
||||
{
|
||||
return new Color32
|
||||
{
|
||||
r = 0,
|
||||
g = src.r,
|
||||
b = 0,
|
||||
a = 255,
|
||||
};
|
||||
}
|
||||
|
||||
public Color32 Export(Color32 src)
|
||||
{
|
||||
return new Color32
|
||||
{
|
||||
r = src.g,
|
||||
g = 0,
|
||||
b = 0,
|
||||
a = 255,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0342907cb8901f44b8792016ac152fcd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user