I need to initialize a rendertarget ('SurfaceFormat.Single' format) drawing sprites into it. I would like the alpha channel of the sprite to be written into the rendertarget, so that regardless of the sprite texture, i end up with sprites silhouettes in the rendertarget. But XNA doesn't support alpha blending when using SurfaceFormat.Single, and from the pixel shader in which i handle the rendertarget for further calculations, i have all 0 readings. I find documentation of this features to be sparse and partial, so, could anyone suggest some source where i can check the sanity of my code?
|
After some experimentation I wasn't able to directly use alpha when writing with spriteBatch to a SurfaceFormat.Single format RenderTarget. So I had to render
For first problem, it is not enough to specify an effect while calling spriteBatch.Begin(...), probably because using batch.Draw(...) isn't the same as drawing textured geometry; it is required to draw sprites to a rendertarget and then use that as a texture while drawing again to screen, applying the pixel shader, as suggested in Microsoft article http://msdn.microsoft.com/en-us/library/bb313868(v=xnagamestudio.31).aspx (outdated since it's referring to XNA 3.0 way of doing so, but the underlying theory still holds) For second problem, i still suspect there's a better way, but the only way i managed to use alpha while in context not supporting it was to do an additional pass before, writing alpha into some other channel (ok for me since for that technique i only cared about alpha) |
|||
|
|