Hey Guys,
I am currently working on a system that allows users to edit and paint on to multiple custom built texture layers that will then be blended together to a render texture and applied to a material. The current issue that I am having is a problem with the Graphics.Blit() function.
When I pass in my source texture and my own RenderTexture and include a material containing a shader (any shader, even “Diffuse”) my output is black as if nothing was copied to the RenderTexture.
Graphics.Blit(src, dest, ms_TextureBlendMaterial); //<-- output is black.
If I use the same parameters but set the destination RenderTexture to null, then everything works and the output is displayed to the screen RECT.
Graphics.Blit(src, null, ms_TextureBlendMaterial); //<-- correct output but is of course rendered to the screen Rect.
If I use my own RenderTexture but remove the material parameter so that I am simply copying my source texture to the RenderTexture that also works.
Graphics.Blit(src, dest); //<-- works
I looked at compositor effects as a reference as they basically achieve what I am trying to do. I have seen that many examples first link the RenderTexture to a camera and then call Blit() within the OnRenderImage() call. Must the RenderTexture be linked to a camera when attemping to pass a shader through the blit function? I’m sure I am making some stupid little mistake or missing some concept here but any information would be appreciated.
This is a snippet of my TextureModification class:
public class TextureManipulation
{
static bool ms_bLoaded = false;
static Material ms_TextureBlendMaterial;
static void Init()
{
if (ms_bLoaded)
return;
ms_TextureBlendMaterial = new Material(Shader.Find("LayerBlend"));
ms_bLoaded = true;
}
//This gets called every frame
public static void BlendTextures(Texture src, Texture blendTex, ref RenderTexture dest)
{
Init();
ms_TextureBlendMaterial.SetTexture("_BlendTex", blendTex);
Graphics.Blit(src, dest, ms_TextureBlendMaterial);
RenderTexture.active = null;
}
...
}
Cheers.