blend-state

My character uses animated and interchangeable body parts, so the full body comes in a few different sprites, that I combine in different ways…

I want to draw a simple offset shadow behind him… So I want to draw the body parts in all black, slightly transparant…

But as you can imagine, on this shadow I now have, the joints of his body, look darker than the rest, because there is some overlap of sprites…

Do I HAVE to draw the shadow to its own rendertarget using alpha=1, and then draw THAT rendertarget with the desired alpha?

Or is there a BLEND-STATE type of thing I can just “declare” that will prevent overlaps from looking darker?

ALSO, does anyone have a cheat-sheet for blend-state combinations? I always have trouble guessing the right combination of reverse subtracting this from that… source alpha, color source blend, alpha blend, destination-wide subtract, reverse pain subtract, upside-down-horizontal back-flip add, I’m so confuzed…

I don’t believe you can accomplish this with a BlendState. You could write a shader to do this, but I would probably just go the RenderTarget route. Is there a reason you don’t want to do that?

Thanks! well, I guess the reason I’d want to avoid that, is that I am already switching rendertargets, and begin/ending my spritebatch so much, I’m affraid it is becoming an issue.

Do you have a good rule of thumb for how many times I can interupt the spritebatch drawing to switch render targets and such?

Same as any other performance concern (ensure target FPS on target platforms/hardware and such). FWIW most of our 2D games use many RTs and generally run at hundreds of frames per second on pretty much anything it seems. Only time we ever had to deliberately make code/engine optimizations for the sake of performance was when we were trying to ensure that our 16-player split screen game would still run over 60fps on Xbox One when there were a couple hundred AIs on a huge map :stuck_out_tongue:

If you’re having bad performance because of RTs: are you generating these RTs mid-game-loop? If so, could you instead generate them at load time with your other assets/textures and re-use? RenderTarget2D is just a fancy Texture2D ref (more or less), so if you’re generating them on the fly you’ll see a hit for sure, not to mention a pretty wild memory alloc increase, I’d guess.

I’m not having issues, but things can escalate quickly, because each light has a render-targer, and each layer has a few, and there can be multiple lights on multiple layers… Plus there is water, uses one, etc…

But so drawing to like 20 or 50 different render-targets is not in itself a concern?