Unity RenderTexture 当作为 Camera.targetTexture 时,在某些安卓手机或模拟器无法显示或出现错乱


using UnityEngine;
using UnityEngine.UI;

public class Test:MonoBehaviour{
	
	public RawImage rawImage;
	public Camera cam;

	private RenderTexture m_renderTexture;
	
	private void Start(){
		m_renderTexture=new RenderTexture(512,512,16,RenderTextureFormat.ARGB32);

		rawImage.texture=m_renderTexture;
		cam.targetTexture=m_renderTexture;
		//必须为 CameraClearFlags.SolidColor或CameraClearFlags.Depth,CameraClearFlags.Nothing 时会不显示
		cam.clearFlags=CameraClearFlags.SolidColor;
		
		//CameraClearFlags.SolidColor时会有背景色,需要设置背景色透明
		Color color=cam.backgroundColor;
		color.a=0f;
		cam.backgroundColor=color;
	}
}
  • 注意:Camera.clearFlags 必须为 CameraClearFlags.SolidColor或CameraClearFlags.Depth,CameraClearFlags.Nothing 时会不显示
    CameraClearFlags.SolidColor:会有背景色,需要设置Camera背景色为透明
    CameraClearFlags.Depth:不会清除上一次渲染的内容,会出现重叠花屏
  • 使用以上方法将粒子系统制作的特效显示在 UI 时,需要注意粒子系统 Renderer 栏下的 Material、TrailMaterial 使用的 Shader ,在 Unity2019.4.28f1c1 使用 Legacy Shaders/Particels/Additive 的粒子特效无法实现背景透明,改成 Moblile/Particels/Additive

原文地址:https://www.cnblogs.com/kingBook/p/14160483.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM