Global textures works in Editor but not in Build (URP, Shader Graph)
I have a procedural mesh of hexagons and I'm using several lookup textures to assign different colors and values to each hexagon, each represented by a pixel of the texture. The texture is generated at runtime and everything works as expected in the editor but not in my builds where they don't do anything.
After some research on similar issues, I have tried the following things to no avail:
Adding all my shaders to "Always Include" in graphic settings. - Shader Graph shaders throws an error when trying to build when added there so no help.
My shaders are working other than receiving data from the lookup textures so I assumed the texture was simply not included in the build. So instead of generating the texture at runtime, I created one manually so it can be referenced in my scene and then just update that one. Texture updates successfully but still doesn't appear in build.
Tried moving it to "Resources" and using both references and Resources.Load(), still nothing. I can even see the texture clearly being included in Editor.log.
Any ideas why it's not working? Am I missing something? Could it be a shader graph specific? I'm on URP 2020.2.2f1.
Here is a basic version of code i'm using:
Texture2D testTexture;
public void Initialize(int width, int height, Color32[] data)
{
// testTexture = TextureAttempt1(x, height, "_HexTestData", testTexture);
Texture2D test = Resources.Load("Lookup/TestData") as Texture2D;
testTexture = TextureAttempt2(width, height, "_HexTestData", test);
UpdateTexture(testTexture, data);//calling this many times throughout running the game
}
Texture2D TextureAttempt1(int width, int height, string reference, Texture2D texture)
{
if (texture)
texture.Resize(width, height);
else
{
texture = new Texture2D(width, height, TextureFormat.RGBA32, false, true);
texture.filterMode = FilterMode.Point;
texture.wrapModeU = TextureWrapMode.Repeat;
texture.wrapModeV = TextureWrapMode.Clamp;
Shader.SetGlobalTexture(reference, texture);
}
return texture;
}
Texture2D TextureAttempt2(int width, int height, string reference, Texture2D texture)
{
texture.Resize(width, height);
texture.filterMode = FilterMode.Point;
texture.wrapModeU = TextureWrapMode.Repeat;
texture.wrapModeV = TextureWrapMode.Clamp;
Shader.SetGlobalTexture(reference, texture);
return texture;
}
public void UpdateTexture(Texture2D texture, Color32[] data)
{
texture.SetPixels32(data);
texture.Apply();
}