作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在玩 Unity 的渲染纹理,您可以在其中将相机的 View 渲染到纹理上。但是,我注意到它并没有渲染整个相机的 View 。它只渲染相机 View 的方形切片。
我想要的是将相机的整个 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/
我是一名优秀的程序员,十分优秀!