Hi!
I’m having some trouble with performance when I try to update a texture on every frame using Texture.Apply(). It runs smooth on a MacBook Pro and on an iPhone 6, but when I test it on older devices, I get around 2-5 fps.
I’m trying to create a scratch card thing, which loops over some brush pixels and applies them to a texture on given x and y coordinates. Check this video to get an idea of the effect I’m looking for: https://drive.google.com/file/d/0B0aaXCyLab3sd1hmZFpJcmFGR0U/view
The texture painting code looks like this:
for (int x = 0; x < brush.width; x++) {
for (int y = 0; y < brush.height; y++) {
Color sourceColor = brush.GetPixel(x, y);
Color maskColor = maskTexture.GetPixel(xPos + x, yPos + y);
if (sourceColor.a < 1 && maskColor.a > 0) {
maskTexture.SetPixel(xPos + x, yPos + y, sourceColor);
}
}
}
maskTexture.Apply();
Is it any alternative method I can use to achieve a similar effect? Doing this inside a shader would probably be much better performance, but I have very limited experience with shaders in Unity.
I have also looked at the RenderTexture class, but I’m not really sure how to use it for this particular task.