Render a texture to a specific location in RenderTexture
Hello Unity Folks,
My goal is to build a blood splatter system for a 2d game im working on. I have used stencil buffers to highlight areas that should clip or show blood splatters. Initially I was spawning sprites that I would display on screen, but after a while this led to poor performance as I want the splatter to last nearly indefinitely.
So i thought I would render the sprite texture to a RenderTexture with an additive blend. I create a RenderTexture that is the same size as my screen:
RenderTexture paintTexture = new RenderTexture(Screen.width, Screen.height,24)// enable the stencil buffer.
My question is, how do I draw my 24x24 pixel blood texture on to the RenderTexture?
I tried doing:
Graphics.SetRenderTarget (paintTexture);
//GL.Clear (true, true, Color.black); //i need the stencil so dont clear
//GL.PushMatrix ();
//GL.LoadPixelMatrix();
Vector3 sp = Camera.main.WorldToScreenPoint(transform.position);
Graphics.DrawTexture(new Rect(0,0,Screen.width,Screen.height),this.sprites[4].texture);
//GL.PopMatrix ();
RenderTexture.active = null;
but I have no luck, the sprite is not in the correct location and the size is totally off. I would prefer doing this in a shader as well, but how would I scale the blood texture to ensure to get the correct position and ensure the UV's dont scale the entire size of the RenderTexture?
I would use Graphics.Blit(paintTexture,longTermPaintTexture,transferToLongTermMaterial) to additively blend the 2 renderTextures after.
Any help would be greatly appreciated.