So I’m trying to use Graphics.Blit as cross-platform alternative to using Compute Shaders, specifically to merge a bunch of different images together and store them into a Texture2D. I’ve set up a shader that does this successfully, and a utility function as follows:
public void LayerMerge(Texture2D destination, Texture2D over, Texture2D region = null, int regionIndex = 0, Texture2D under = null)
{
avatarLayerMergeMaterial.SetTexture("_MainTex", destination);
avatarLayerMergeMaterial.SetTexture("_Over", over);
avatarLayerMergeMaterial.SetTexture("_Region",region);
avatarLayerMergeMaterial.SetInt("_RegionIndex",regionIndex);
avatarLayerMergeMaterial.SetTexture("_Under", under == null ? nullTexture : under);
Graphics.Blit(destination,avatarLayerMergeRenderTexture,avatarLayerMergeMaterial,-1);
Graphics.CopyTexture(avatarLayerMergeRenderTexture,destination);
}
The region/region index stuff is unimportant, and for now under is as well. My function call looks like this, using only the first two parameters:
foreach (AvatarLayer layer in layers)
{
textureUtility.LayerMerge(displayTexture,layer.Texture);
}
The problem is that the render texture is completely empty and seems to be completely unaffected by the Blit call. I’m able to look at the actual material instance (avatarLayerMergeMaterial) and it’s got a little preview window in the inspector at runtime that displays the correct results. For some reason it’s simply not being copied over into the render texture.
Thanks.