Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for editor import: convert normal maps to dxt5nm when its enabled in …
…project settings
- Loading branch information
pfcDorn
committed
Jan 12, 2024
1 parent
c9e4592
commit dae24c7
Showing
4 changed files
with
104 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
Runtime/Scripts/SceneImporter/NormalMapEncodingConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Threading.Tasks; | ||
using UnityEngine; | ||
|
||
namespace UnityGLTF | ||
{ | ||
public static class NormalMapEncodingConverter | ||
{ | ||
public static Texture2D ConvertToDxt5nm(Texture2D source) | ||
{ | ||
var dest = new Texture2D(source.width, source.height, TextureFormat.DXT5, false); | ||
var pixels = source.GetPixels(); | ||
for (var i = 0; i < pixels.Length; i++) | ||
{ | ||
var c = pixels[i]; | ||
pixels[i] = new Color(1, c.g, 1, c.r); | ||
} | ||
|
||
dest.SetPixels(pixels); | ||
return dest; | ||
} | ||
|
||
public static void ConvertToDxt5nm(Texture2D source, Texture2D dest) | ||
{ | ||
var pixels = source.GetPixels(); | ||
for (var i = 0; i < pixels.Length; i++) | ||
{ | ||
var c = pixels[i]; | ||
pixels[i] = new Color(1, c.g, 1, c.r); | ||
} | ||
|
||
dest.SetPixels(pixels); | ||
} | ||
|
||
public static async Task ConvertToDxt5nmAsync(Texture2D texture) | ||
{ | ||
var pixels = texture.GetPixels(); | ||
await Task.Run(() => | ||
{ | ||
for (var i = 0; i < pixels.Length; i++) | ||
{ | ||
var c = pixels[i]; | ||
pixels[i] = new Color(1, c.g, 1, c.r); | ||
} | ||
}); | ||
|
||
texture.SetPixels(pixels); | ||
} | ||
|
||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Runtime/Scripts/SceneImporter/NormalMapEncodingConverter.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.