Unity_调用Shader使YUV420p贴到Materials
来源:互联网 发布:php单页面源码 编辑:程序博客网 时间:2024/06/04 01:18
Shader下载地址http://download.csdn.net/download/le_sam/9980147
相关Inspector如下:
public class Player : MonoBehaviour { public Renderer mRenderer; private Texture2D texY, texU, texV; private void Awake() { mRenderer.material = new Material(Shader.Find("Unlit/Transparent AvatarPi D3D")); shareMemRead(); } private void shareMemRead() { Application.targetFrameRate = 30; StartCoroutine(readFrames()); } private IEnumerator readFrames() { yield return new WaitForSeconds(3); bool isRead = true; //float lastTiem = Time.deltaTime; while (isRead) { yield return new WaitForEndOfFrame(); byte[] data = new byte[Width * Height * 3 / 2]; //从dll里获取YUV420__byte[] Sharemem.pisoft_share_mem_read(ref isVideo, ref len, data, Sharemem.hLib); Debug.LogFormat("单帧接收_Byte[]:{0}", len); if (len > 0) { byte[] dataY = new byte[Width * Height]; byte[] dataU = new byte[Width * Height / 4]; byte[] dataV = new byte[Width * Height / 4]; Buffer.BlockCopy(data, 0, dataY, 0, Width * Height); Buffer.BlockCopy(data, Width * Height, dataU, 0, Width * Height / 4); Buffer.BlockCopy(data, Width * Height * 5 / 4, dataV, 0, Width * Height / 4); CreateTexture(Width, Height, dataY, dataU, dataV); } } } private void CreateTexture(int width, int height, byte[] dataY, byte[] dataU, byte[] dataV) { //if (width == mLastWidth && height == mLastHeight) //{ // return; //} //if (width == 0 || height == 0) //{ // return; //} //mLastWidth = width; //mLastHeight = height; //Color32[] grayColors = new Color32[width * height]; //for (int i = 0; i < grayColors.Length; ++i) //{ // grayColors[i].a = 0; //} //Y if (texY) { Destroy(texY); } texY = new Texture2D(width, height, TextureFormat.Alpha8, false); //texY.filterMode = FilterMode.Bilinear; //texY.wrapMode = TextureWrapMode.Clamp; //texY.SetPixels32(grayColors); texY.LoadRawTextureData(dataY); texY.Apply(); //grayColors = new Color32[(width / 2) * (height / 2)]; //for (int i = 0; i < grayColors.Length; ++i) //{ // grayColors[i].a = 128; //} //U if (texU) { Destroy(texU); } texU = new Texture2D(width / 2, height / 2, TextureFormat.Alpha8, false); //texU.filterMode = FilterMode.Point; //texU.wrapMode = TextureWrapMode.Clamp; //texU.SetPixels32(grayColors); texU.LoadRawTextureData(dataU); texU.Apply(); //V if (texV) { Destroy(texV); } texV = new Texture2D(width / 2, height / 2, TextureFormat.Alpha8, false); //texV.filterMode = FilterMode.Point; //texV.wrapMode = TextureWrapMode.Clamp; //texV.SetPixels32(grayColors); texV.LoadRawTextureData(dataV); texV.Apply(); Material mMaterial = mRenderer.sharedMaterial; mMaterial.mainTexture = texY; mMaterial.SetTexture("_MainTexU", texU); mMaterial.SetTexture("_MainTexV", texV); } }
阅读全文
0 0
- Unity_调用Shader使YUV420p贴到Materials
- Materials
- Materials
- yuv420p
- YUV420P
- ffmpeg 转换其他格式到YUV420P
- 图片格式转换--从bmp到yuv420p
- Unity Shader 学习笔记(17) 程序纹理(Procedural Texture)、程序材质(Procedural Materials)
- 最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)
- 最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)
- 最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)
- 最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)
- 最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)
- 使用ffmpeg将YUV420P图像压缩到jpg图片
- 切换到shader模式
- 传递数组到 Shader
- aroma materials
- opencv materials
- Easyui笔记
- [markdown]欢迎使用CSDN-markdown编辑器
- MyBatis学习总结(22)——Mybatis自增长ID获取
- c专家编程
- java基本语法(socket数据互转、传)
- Unity_调用Shader使YUV420p贴到Materials
- Host 'XXX' is not allowed to connect to this MySQL server 解决方案/如何开启MySQL的远程帐号
- 栈的压入、弹出序列
- 使用docker在阿里云搭建wordpress个人博客
- [javascript高手之路]最通俗易懂的javascript变量提升
- 前端常见跨域解决方案
- Android Studio逆向分析APK(Analyse APK)
- eclipse集成weblogic开发环境的搭建
- .NET中的特性、属性以及两者的区别