Is there any fast way (without using GetData/SetData) that I can any pixel where the alpha is non-zero with a solid color?
For example:
to:
I will need to be doing this to many small (32 x 32) textures, filling the entire screen.
I wrote a shader to do this, but it still seems too slow (drops to 15~20 fps).
Or, even better, if there is some way to determine if the mouse is over any opaque portion of a texture that has been drawn to the screen (while ignoring textures underneath it)?
Can you show your shader’s code. It should not be so slow.
I use a similar technique with thousands of 3d models to render them in a rendertarget with solid color and it runs blazing fast.
Another question is do you apply the shader to each drawn sprite or draw them in a rendertaget, and then apply it on the latter (if they have all the same solid color ?
Hi.
Your shader code looks fine, except that you’re missing the blue-channel of the new_color (color = new_color; color.a = 0).
Like alkher said that should be blazingly fast.
Be sure that you use SpriteBatch and batch all your sprites you need to draw using that effect into one draw call (don’t use SpriteSortMode.Immediate). The draw call will actually happen when you call SpriteBatch.End() and the effect will be applied once then.
So that would batch your sprites effectively, but you’d only be able to use a single replacement-color (since there will be only a single draw call).
Ok. Obviously you have some draw-order issues here.
The only way to speed things up is to batch at least some of the draw calls, since the number of draw calls by using SpriteSortMode.Immediate seems to be the limiting factor here.
But you may only batch sprites that would result in the same output color since you can only pass a single color to your shader for a single draw call.