I wasn't sure if this should go into a graphics section or game programming, so a flip of a coin decided to put it into general.
I'm working on a top down shooter game, and i'm trying to get blood splatter to be drawn at the locations where monsters get killed. The blood should stay on the ground forever, essentially covering the ground entirely after enough time has passed and enough monsters died. The camera is focused on the character (camera is z=-50, game stuff is at z=0), and the map itself is slightly bigger than what the camera sees, so it scrolls a bit until it reaches the edge of the playable area where it stops following the character on that axis.
My idea was to draw all the blood that was spawned in the current frame to a texture, and then draw that texture with alpha blending enabled after the background image, so it would be like a transparent blood-filled layer over the background image.
I can draw all the blood so it looks as i want it if i keep all the blood splatter information (world pos and a sprite index) in a vector, and draw them after the background. Image here. However, this is not going to work in the long run, seeing i want to have the ground covered in blood after a while.
If i set the render target to be a texture, draw all the blood generated in the current frame onto the texture, then setting the render target back to the backbuffer and drawing the background and then the texture over it, i get a weird result where the blood doesn't get spawned at the location the monster was at (problem 1) and the new blood overwrites the previously drawn blood (problem 2). Image before monster death and image after, both issues can be seen.
I'm probably missunderstanding how the render to texture process really works, which is causing my issues.
First off, is this a good way to do blood at all? I've read about decals a bit today, and am not sure if that's the way i should be going for, or if i can get decent results with this.
If this approach might work, then any ideas on how to setup this flow to get good results?
Backbuffer is 1200x900, background image is 1200x900, drawn on a quad bigger than what the camera sees so the camera can scroll with the character, and i tried making the texture render target a wide array of values, with the results all being the same.
My transparency blend state is initialized with:
D3D11_BLEND_DESC blendDesc; ZeroMemory(&blendDesc, sizeof(D3D11_BLEND_DESC)); blendDesc.AlphaToCoverageEnable = false; D3D11_RENDER_TARGET_BLEND_DESC& rtbd = blendDesc.RenderTarget; rtbd.BlendEnable = true; rtbd.SrcBlend = D3D11_BLEND_SRC_ALPHA; rtbd.DestBlend = D3D11_BLEND_INV_SRC_ALPHA; rtbd.BlendOp = D3D11_BLEND_OP_ADD; rtbd.SrcBlendAlpha = D3D11_BLEND_ONE; rtbd.DestBlendAlpha = D3D11_BLEND_ZERO; rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD; rtbd.RenderTargetWriteMask = D3D10_COLOR_WRITE_ENABLE_ALL; HRESULT hr = m_dev->CreateBlendState(&blendDesc, &m_transparency);
I appreciate any help, suggestions and critique! Thanks.