第1种
static void Test() { Texture2D srcTex = null; var srcTempRT = RenderTexture.GetTemporary(512, 512, 0, RenderTextureFormat.Default); Graphics.Blit(srcTex, srcTempRT); var oldActiveRT = RenderTexture.active; RenderTexture.active = srcTempRT; //业务代码 RenderTexture.active = oldActiveRT; RenderTexture.ReleaseTemporary(srcTempRT); }
第2种
static void Test2() { Texture2D srcTex = null; var srcTempRT = RenderTexture.GetTemporary(512, 512, 0, RenderTextureFormat.Default); Graphics.SetRenderTarget(srcTempRT); Graphics.Blit(srcTex, srcTempRT); //业务代码 Graphics.SetRenderTarget(null); RenderTexture.ReleaseTemporary(srcTempRT); }
SetRenderTarget(RenderTexture rt)和 RenderTexture.active = rt作用一样,都是把渲染的结果存到rt中,如果为null则输出到屏幕,
如果只是想要某个camera的渲染结果,用Camera.targetTexture=rt代替。
【参考】
几个Graphics函数 - Tearix - 博客园 (cnblogs.com)
标签:rt,RenderTexture,渲染,srcTex,Graphics,null,写法,srcTempRT From: https://www.cnblogs.com/sailJs/p/16866054.html