gpt4 book ai didi

unity3d - 渲染完整的相机 View (16 :9) onto a texture in Unity3d

转载 作者:行者123 更新时间:2023-12-04 22:58:46 24 4
gpt4 key购买 nike

我在玩 Unity 的渲染纹理,您可以在其中将相机的 View 渲染到纹理上。但是,我注意到它并没有渲染整个相机的 View 。它只渲染相机 View 的方形切片。

enter image description here

我想要的是将相机的整个 View (16:9 纵横比)渲染到纹理(也是 16:9 纵横比)上。但现在它似乎只能在方形表面上投影出它的方形切片。有什么解决办法吗?

最佳答案

使用“RenderTexture”,您可以指定纹理大小:http://docs.unity3d.com/ScriptReference/RenderTexture.Create.html

它应该是这样的:

Camera camera = GameObject.Find("Main Camera");
int resWidth = Screen.width;
int resHeight = Screen.height;

RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
camera.targetTexture = rt; //Create new renderTexture and assign to camera
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false); //Create new texture

camera.Render();

RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0); //Apply pixels from camera onto Texture2D

camera.targetTexture = null;
RenderTexture.active = null; //Clean
Destroy(rt); //Free memory

关于unity3d - 渲染完整的相机 View (16 :9) onto a texture in Unity3d,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32996534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com