diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader b/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader deleted file mode 100644 index 8c77bb20b..000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader +++ /dev/null @@ -1,68 +0,0 @@ -Shader "UniGLTF/NormalMapEncoder" -{ - Properties - { - _MainTex("Texture", 2D) = "white" {} - } - SubShader - { - // No culling or depth - Cull Off ZWrite Off ZTest Always - - Pass - { - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - - #include "UnityCG.cginc" - - struct appdata - { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - }; - - struct v2f - { - float2 uv : TEXCOORD0; - float4 vertex : SV_POSITION; - }; - - v2f vert(appdata v) - { - v2f o; - o.vertex = UnityObjectToClipPos(v.vertex); - o.uv = v.uv; - return o; - } - - sampler2D _MainTex; - - fixed4 frag(v2f i) : SV_Target - { - half4 col = tex2D(_MainTex, i.uv); - - half4 packedNormal; - packedNormal.x = col.x; - packedNormal.y = col.y; - packedNormal.z = col.z; - packedNormal.w = 1.0; - - // normalize as normal vector - float3 normal; - normal.xy = packedNormal.xy * 2 - 1; - if (dot(normal.xy, normal.xy) > 1) - { - normal.xy = normalize(normal.xy); - } - normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); - - packedNormal.xyz = normal.xyz * 0.5 + 0.5; - return packedNormal; - } - ENDCG - } - } -} - diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader.meta b/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader.meta deleted file mode 100644 index d0ef10022..000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 3e39586253f31b34f87fa7e133449b1e -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs b/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs index 88180aa2a..bd9ea9bf6 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs @@ -17,28 +17,13 @@ namespace VRMShaders } } - private static Material m_encoder; - private static Material Encoder - { - get - { - if (m_encoder == null) - { - m_encoder = new Material(Shader.Find("UniGLTF/NormalMapEncoder")); - } - return m_encoder; - } - } - // GLTF data to Unity texture - // ConvertToNormalValueFromRawColorWhenCompressionIsRequired public static Texture2D Import(Texture2D texture) { - return TextureConverter.CopyTexture(texture, ColorSpace.Linear, false, Encoder); + return texture; } // Unity texture to GLTF data - // ConvertToRawColorWhenNormalValueIsCompressed public static Texture2D Export(Texture texture) { return TextureConverter.CopyTexture(texture, ColorSpace.Linear, false, Decoder); diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs b/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs index bf2f34425..d3bc48f0c 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs @@ -61,13 +61,9 @@ namespace VRMShaders } /// - /// テクスチャーをロード、必要であれば変換して返す。 - /// 同じものはキャッシュを返す + /// テクスチャ生成情報を基に、テクスチャ生成を行う。 + /// SubAssetKey が同じ場合はキャッシュを返す。 /// - /// 変換の有無を判断する: METALLIC_GLOSS_PROP - /// METALLIC_GLOSS_PROPの追加パラメーター - /// gltf の texture index - /// public async Task GetTextureAsync(TextureDescriptor texDesc) { var subAssetKey = texDesc.SubAssetKey; @@ -86,15 +82,16 @@ namespace VRMShaders { case TextureImportTypes.NormalMap: { - // Runtime/SubAsset 用に変換する + // no conversion. Unity's normal map is same with glTF's. + // + // > contrary to Unity’s usual convention of using Y as “up” + // https://docs.unity3d.com/2018.4/Documentation/Manual/StandardShaderMaterialParameterNormalMap.html var data0 = await texDesc.Index0(); var rawTexture = await _textureDeserializer.LoadTextureAsync(data0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); - var convertedTexture = NormalConverter.Import(rawTexture); - convertedTexture.name = subAssetKey.Name; - convertedTexture.SetSampler(texDesc.Sampler); - _textureCache.Add(subAssetKey, convertedTexture); - DestroyResource(rawTexture); - return convertedTexture; + rawTexture.name = subAssetKey.Name; + rawTexture.SetSampler(texDesc.Sampler); + _textureCache.Add(subAssetKey, rawTexture); + return rawTexture; } case TextureImportTypes.StandardMap: