Hello, I’m developing a game for smartphones where you can “erase” a texture of a 2d plane by touching the screen; that is, making it invisible in the area the finger touched. My concern with this is performance, so the game can run on most devices.
[ Note that the game won’t be just a paint app, it will be a full 2D game with its playable character, enemies and stuff, so the performance of the “texture eraser” is a secondary mechanic, that’s why it should not have an important impact of performance ]
So, what’s the most efficient technique to accomplish that?
Should I use the standard Texture2D.SetPixel()?
Or would it be better a shader that modifies the alfa of certain pixels on its fragment shader?
Maybe something regarding RenderToTexture?
Any other idea other than these, that would be better?
I’m hearding your comments, and thanks for the help, graphics gurus!
I’d use Vectrosity with a separate camera and a depth mask shader for the line, demonstrated here. (That’s a minor modification of the line drawing demo, which uses 1) a depth-only camera to draw the black rectangle, 2) a depth mask shader for the line material, and 3) the drawing script is slightly modified to use Draw3D with world-space coords using ScreenToWorldPoint.) I think that’s about as fast as you can get; much faster than SetPixel and uploading textures.
Hi Eric, thanks for your answer, it does seems like a powerful tool. Just have some questions:
Using vectrosity, could I replace that black rectangle with another image texture, so erasing this one would reveal the background?
And also, does it has support for modifying alpha more softly? I mean, without those hard borders, smoothing the alpha from the edges to the center of the line
Can it work in some other ways than lines? For example, erasing the texture in a circle where touched
Hi Emak-Bakia, thanks for your answer.
I don’t quite understand the 2nd step. What do you mean by draw from A to B?
Also, does Graphics.Blit has good performance on mobile platforms?
Thank you for your time!
where material has your drawing shader.
As for performance issues, I haven’t ecnountered any, but I was targeting middle-to-high-end devices, so I’m afraid you’ll have to check performance yourself.