Unity Sentis built in function TextureConverter.RenderToTexture()
Fails when using OpenGL ES Graphics backend. See https://docs.unity3d.com/Packages/com.unity.sentis@1.0/api/Unity.Sentis.TextureConverter.html
Original Issue: Android build failed when using OpenGL ES3 Graphics API · Issue #1 · julienkay/com.doji.mobilesam · GitHub
Steps to reproduce - activate Graphics API OpenGL ES
Build for Android arm64 target
Texture is null even thought the Tensor contains the result.
I am using Sentis 2.1.1 - the same behavior is on 2.1.2. Editor Linux Valkan works as expected, on Android with OpenGL ES it fails (that is needed for ARCore I am using in my project)
I have made my own Tensor to Texture2D conversion function to prove it.
public static Texture2D TensorToTexture(Tensor<float> tensor) {
Debug.Log($"Tensor Shape: N={tensor.shape[0]}, C={tensor.shape[1]}, H={tensor.shape[2]}, W={tensor.shape[3]}");
int width = tensor.shape[3]; // W (Last Dimension)
int height = tensor.shape[2]; // H (Second Last Dimension)
int channels = tensor.shape[1]; // C (RGB should be 3)
// Create new Texture2D
Texture2D texture = new Texture2D(width, height, TextureFormat.RGB24, false);
// Read pixel data from tensor
Color[] pixels = new Color[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int index = (y * width + x) * channels;
float r = tensor[index];
//float g = tensor[index];//[index + 1];
//float b = tensor[index];//[index + 2];
pixels[y * width + x] = new Color(r, r, r, 1.0f); // Alpha = 1, in this case the Tensor is grayscale -it is a mask
}
}
// Apply pixel data to texture
texture.SetPixels(pixels);
texture.Apply();
return texture;
}