-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into feature/text-tool
- Loading branch information
Showing
283 changed files
with
12,907 additions
and
1,394 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
using System.IO; | ||
using Unity.Collections; | ||
|
||
public static class ConvertNormalMaps | ||
{ | ||
[MenuItem("Open Brush/Toolkit/Convert Bump Maps to Normal Maps")] | ||
static void Convert() | ||
{ | ||
foreach (Object obj in Selection.objects) | ||
{ | ||
if (obj is Material) | ||
{ | ||
Material material = (Material)obj; | ||
Shader shader = material.shader; | ||
int propertiesCount = ShaderUtil.GetPropertyCount(shader); | ||
|
||
for (int j = 0; j < propertiesCount; j++) | ||
{ | ||
if (ShaderUtil.GetPropertyType(shader, j) == ShaderUtil.ShaderPropertyType.TexEnv) | ||
{ | ||
string propertyName = ShaderUtil.GetPropertyName(shader, j); | ||
Texture texture = material.GetTexture(propertyName); | ||
|
||
if (texture is Texture2D normalMap) | ||
{ | ||
string texturePath = AssetDatabase.GetAssetPath(normalMap); | ||
bool isNormal = ReimportTexture(texturePath, true); | ||
if (!isNormal) continue; | ||
Texture2D remappedTexture = new Texture2D(normalMap.width, normalMap.height); | ||
|
||
// Get the pixels from the source texture | ||
NativeArray<Color32> pixels = normalMap.GetPixelData<Color32>(0); | ||
|
||
for (int i = 0; i < pixels.Length; i++) | ||
{ | ||
byte red = pixels[i].a; | ||
byte green = pixels[i].g; | ||
byte blue = 255; // pixels[i].b; | ||
byte alpha = 255; // pixels[i].r; | ||
pixels[i] = new Color32(red, green, blue, alpha); | ||
} | ||
remappedTexture.SetPixels32(pixels.ToArray()); | ||
|
||
// Apply changes | ||
remappedTexture.Apply(); | ||
|
||
File.WriteAllBytes(texturePath, remappedTexture.EncodeToPNG()); | ||
Debug.Log("Exported Normal Map: " + texturePath); | ||
RemoveConversion(texturePath); | ||
} | ||
else | ||
{ | ||
Debug.LogWarning("No normal map found in material: " + material.name); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
AssetDatabase.Refresh(); | ||
} | ||
|
||
private static bool ReimportTexture(string assetPath, bool isReadable) | ||
{ | ||
TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; | ||
if (textureImporter != null) | ||
{ | ||
if (textureImporter.textureType != TextureImporterType.NormalMap) | ||
{ | ||
return false; | ||
} | ||
textureImporter.isReadable = isReadable; | ||
textureImporter.textureCompression = TextureImporterCompression.Uncompressed; | ||
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); | ||
} | ||
return true; | ||
} | ||
|
||
private static bool RemoveConversion(string assetPath) | ||
{ | ||
TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; | ||
if (textureImporter != null) | ||
{ | ||
if (textureImporter.textureType != TextureImporterType.NormalMap) | ||
{ | ||
return false; | ||
} | ||
textureImporter.convertToNormalmap = false; | ||
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); | ||
} | ||
return true; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,89 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!21 &2100000 | ||
Material: | ||
serializedVersion: 8 | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_Name: 360 Panorama Sphere | ||
m_Shader: {fileID: 4800000, guid: 2acb44a1aabdeb44ca27f9dd497c779a, type: 3} | ||
m_ValidKeywords: [] | ||
m_InvalidKeywords: | ||
- _STEREOSCOPIC_ON | ||
m_LightmapFlags: 4 | ||
m_EnableInstancingVariants: 0 | ||
m_DoubleSidedGI: 0 | ||
m_CustomRenderQueue: -1 | ||
stringTagMap: {} | ||
disabledShaderPasses: [] | ||
m_SavedProperties: | ||
serializedVersion: 3 | ||
m_TexEnvs: | ||
- _BumpMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailAlbedoMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailMask: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailNormalMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _EmissionMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _MainTex: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _MetallicGlossMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _OcclusionMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _ParallaxMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
m_Ints: [] | ||
m_Floats: | ||
- _BumpScale: 1 | ||
- _Cutoff: 0.5 | ||
- _DetailNormalMapScale: 1 | ||
- _DstBlend: 0 | ||
- _GlossMapScale: 1 | ||
- _Glossiness: 0.5 | ||
- _GlossyReflections: 1 | ||
- _H: 360 | ||
- _Metallic: 0 | ||
- _Mode: 0 | ||
- _OcclusionStrength: 1 | ||
- _Parallax: 0.02 | ||
- _Shininess: 20 | ||
- _SmoothnessTextureChannel: 0 | ||
- _SpecularHighlights: 1 | ||
- _SrcBlend: 1 | ||
- _Stereoscopic: 1 | ||
- _UVSec: 0 | ||
- _V: 180 | ||
- _WarpEnd: 1 | ||
- _WarpStart: 6 | ||
- _ZWrite: 1 | ||
m_Colors: | ||
- _Color: {r: 1, g: 1, b: 1, a: 1} | ||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} | ||
- _SpecularColor: {r: 1, g: 1, b: 1, a: 1} | ||
- _WarpParams: {r: 6, g: 0.5, b: 0.3, a: 0.1} | ||
m_BuildTextureStacks: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.