Но вот делаю что-то не так и после упаковки нормал смотрится совсем по-другому.
Проект-пример в аттаче.
До:
После:
Обращаюсь за помощью в сообщество!
Кто что думает?
Сам код работы с нормалмапой вот:
Синтаксис:
Используется csharp
Texture2D normal_packedTexture = (Texture2D)Instantiate(shaderToMaterial[key][0].GetTexture(normal_tex_name));
//new Texture2D(packedTexture.width, packedTexture.height);
if (normal_packedTexture.Resize(packedTexture.width, packedTexture.height))
{
Debug.Log("resized");
}
else
{
Debug.Log("not resized");
}
normal_packedTexture.Apply();
Texture2D[] normal_texs = new Texture2D[texs.Length];
for (int i = 0; i < texs.Length; i++)
{
if (shaderToMaterial[key][i].HasProperty(normal_tex_name))
{
normal_texs[i] = shaderToMaterial[key][i].GetTexture(normal_tex_name) as Texture2D;
if (normal_texs[i] == null)
{
Debug.Log("normal null!");
}
//setpixels32, make no longer readable
float x = (int)(uvs[i].x * packedTexture.width);
float y = (int)(uvs[i].y * packedTexture.height);
float width = (int)(uvs[i].width * packedTexture.width);
float height = (int)(uvs[i].height * packedTexture.height);
Debug.Log(string.Format("pack normal: {0},{1},{2},{3} ", x, y, width, height));
Color[] colz = normal_texs[i].GetPixels();
normal_packedTexture.SetPixels((int)x, (int)y, (int)width, (int)height, colz);
}
else
{
Debug.Log("doesn't have property");
}
}
normal_packedTexture.Apply(true, false);
//new Texture2D(packedTexture.width, packedTexture.height);
if (normal_packedTexture.Resize(packedTexture.width, packedTexture.height))
{
Debug.Log("resized");
}
else
{
Debug.Log("not resized");
}
normal_packedTexture.Apply();
Texture2D[] normal_texs = new Texture2D[texs.Length];
for (int i = 0; i < texs.Length; i++)
{
if (shaderToMaterial[key][i].HasProperty(normal_tex_name))
{
normal_texs[i] = shaderToMaterial[key][i].GetTexture(normal_tex_name) as Texture2D;
if (normal_texs[i] == null)
{
Debug.Log("normal null!");
}
//setpixels32, make no longer readable
float x = (int)(uvs[i].x * packedTexture.width);
float y = (int)(uvs[i].y * packedTexture.height);
float width = (int)(uvs[i].width * packedTexture.width);
float height = (int)(uvs[i].height * packedTexture.height);
Debug.Log(string.Format("pack normal: {0},{1},{2},{3} ", x, y, width, height));
Color[] colz = normal_texs[i].GetPixels();
normal_packedTexture.SetPixels((int)x, (int)y, (int)width, (int)height, colz);
}
else
{
Debug.Log("doesn't have property");
}
}
normal_packedTexture.Apply(true, false);