Hi there I’m creating a Tri-planar shader with 13 textures in total , naturally I need texture arrays,
This works perfectly with just textures , however once i try using normal maps the shader breaks and the maps end up being incorrect .
Normal mapping works perfectly if I don’t use texture arrays , So my question is :
Is there some special way to create texture arrays if they contain normal maps?
Thanks so much for the help.
Heres the code example of how I make texture arrays
//format = texture format
//I tried every single Texture format as far as i know
Texture2DArray textureArrayN = new Texture2DArray(1024, 1024, numberOfTextures, format, true,false );
for (int i = 0; i < texturesNormal.Length; i++)
{
textureArray.SetPixels32(texturesNormal[i].GetPixels32(0), i, 0);
}
textureArrayN.Apply();
m_material.SetTexture("_MainTexNorm",textureArray);
The tri planar shader works fine with non textureArray textures,So I cant imagine thats the problem , unless there is some special way to get the texture from a normal map besides “UNITY_SAMPLE_TEX2DARRAY(_MainTex , uv.xyz);”
Again thanks so much Im completly stumped.
see attached file for example of normals not working
Normal maps textures need to be linear. Texture2DArray textureArrayN = [new](http://www.google.com/search?q=new+msdn.microsoft.com) Texture2DArray(1024, 1024, numberOfTextures, format, true, __*true*__ );
Ok I tried linear space , still the problem persists.
I think when unity does its getpixels it ignores the fact that it’s a normal map , but I already tried using a regular texture not marked as a normal map then doing SampleTex (text, uv)*2-1 , nothing works , I read somewhere that the texture format for the arrays if using normal maps should be ARGB32 but even that doesn’t work
GetPixels/SetPixels doesn’t care if the texture is linear or not. Those functions are getting and setting the raw data.
However you shouldn’t really be using those functions anyway. You should be using CopyTexture so you can use compressed formats.
When sampling a normal map in the shader, you’ll still want to use the UnpackNormal function, and other than using the texture array sampler it should be no different than a non-array texture.
Ok sorry for that turns out I was setting the normal maps to the regular textures in the array .
It was my mistake. thanks for your help though it led me to the correct answer
For anyone else coming here ,bgolus is right , you should use graphics.copyTexture,
Especially for normal maps otherwise they come out white and are unusable.
Even though I knew normal texture need to be in linear space, but often so I still stuck into issues led by this T_T
Just spent 3 hours to dig into space transforming, dot product and this post eventually rings a bell to me. sign…
Thanks!