From 69ff1c7fa9240c6555bae40603a9154fc6654771 Mon Sep 17 00:00:00 2001 From: yutopp Date: Wed, 23 Jan 2019 22:27:34 +0900 Subject: [PATCH 1/4] Switch logics in the shader instead of C# Co-authored-by: Masataka SUMI Co-authored-by: junichi_hirose --- .../VRM/UniGLTF/Resources/Shaders/NormalMapEncoder.shader | 7 +++++++ Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs | 6 ++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Assets/VRM/UniGLTF/Resources/Shaders/NormalMapEncoder.shader b/Assets/VRM/UniGLTF/Resources/Shaders/NormalMapEncoder.shader index 02096bc54..ca61ed3aa 100644 --- a/Assets/VRM/UniGLTF/Resources/Shaders/NormalMapEncoder.shader +++ b/Assets/VRM/UniGLTF/Resources/Shaders/NormalMapEncoder.shader @@ -41,7 +41,14 @@ fixed4 frag(v2f i) : SV_Target { + half4 col = tex2D(_MainTex, i.uv); + +#if defined(UNITY_NO_DXT5nm) + // This is a trick from UnpackNormal in UnityCG.cginc !!!! + return col; +#endif + half4 normal; normal.x = 1.0; normal.y = col.y; diff --git a/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs b/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs index 94d2d95b1..74041ef28 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs @@ -113,9 +113,6 @@ namespace UniGLTF public Texture2D GetImportTexture(Texture2D texture) { -#if UNITY_WEBGL && !UNITY_EDITOR - return texture; -#endif var mat = GetEncoder(); var converted = TextureConverter.Convert(texture, glTFTextureTypes.Normal, null, mat); TextureConverter.AppendTextureExtension(converted, m_extension); @@ -124,6 +121,7 @@ namespace UniGLTF public Texture2D GetExportTexture(Texture2D texture) { + #if UNITY_WEBGL && !UNITY_EDITOR return texture; #endif @@ -174,4 +172,4 @@ namespace UniGLTF }; } } -} \ No newline at end of file +} From f5ae88c07177e9281414be179eac8d7d0ceb46ca Mon Sep 17 00:00:00 2001 From: yutopp Date: Wed, 23 Jan 2019 22:33:54 +0900 Subject: [PATCH 2/4] Use tabs instead of spaces. Remove new lines --- Assets/VRM/UniGLTF/Resources/Shaders/NormalMapEncoder.shader | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Assets/VRM/UniGLTF/Resources/Shaders/NormalMapEncoder.shader b/Assets/VRM/UniGLTF/Resources/Shaders/NormalMapEncoder.shader index ca61ed3aa..c4d5fc6a5 100644 --- a/Assets/VRM/UniGLTF/Resources/Shaders/NormalMapEncoder.shader +++ b/Assets/VRM/UniGLTF/Resources/Shaders/NormalMapEncoder.shader @@ -41,12 +41,11 @@ fixed4 frag(v2f i) : SV_Target { - half4 col = tex2D(_MainTex, i.uv); #if defined(UNITY_NO_DXT5nm) - // This is a trick from UnpackNormal in UnityCG.cginc !!!! - return col; + // This is a trick from UnpackNormal in UnityCG.cginc !!!! + return col; #endif half4 normal; From 21dad1497ec539eb1cd128fd06ec035fabc8cbf6 Mon Sep 17 00:00:00 2001 From: yutopp Date: Wed, 23 Jan 2019 23:51:25 +0900 Subject: [PATCH 3/4] Remove conditions for WEBGL when exporting normal map textures --- Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs b/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs index 74041ef28..eedf9ca9d 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs @@ -121,10 +121,6 @@ namespace UniGLTF public Texture2D GetExportTexture(Texture2D texture) { - -#if UNITY_WEBGL && !UNITY_EDITOR - return texture; -#endif var mat = GetDecoder(); var converted = TextureConverter.Convert(texture, glTFTextureTypes.Normal, null, mat); TextureConverter.RemoveTextureExtension(converted, m_extension); From 885823748a77493c77b68082926473ba1f1f784b Mon Sep 17 00:00:00 2001 From: yutopp Date: Wed, 23 Jan 2019 23:59:02 +0900 Subject: [PATCH 4/4] Add comments --- Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs b/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs index eedf9ca9d..b10e27682 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/TextureConverter.cs @@ -111,6 +111,8 @@ namespace UniGLTF return m_encoder; } + // GLTF data to Unity texture + // ConvertToNormalValueFromRawColorWhenCompressionIsRequired public Texture2D GetImportTexture(Texture2D texture) { var mat = GetEncoder(); @@ -119,6 +121,8 @@ namespace UniGLTF return converted; } + // Unity texture to GLTF data + // ConvertToRawColorWhenNormalValueIsCompressed public Texture2D GetExportTexture(Texture2D texture) { var mat = GetDecoder();