当前位置: 首页 > news >正文

⭐ Unity 开发bug —— 打包后shader失效或者bug (我这里用Shader做两张图片的合并发现了问题)

1.这里我代码没啥问题~~~编辑器里也没毛病

 void Start(){// 加载底图和上层图片string backgroundImagePath = Application.streamingAssetsPath + "/background.jpg";Texture2D backgroundTexture = new Texture2D(2, 2);byte[] backgroundImageData = System.IO.File.ReadAllBytes(backgroundImagePath);backgroundTexture.LoadImage(backgroundImageData);string overlayImagePath = Application.streamingAssetsPath + "/1.png";Texture2D overlayTexture = new Texture2D(2, 2);byte[] overlayImageData = System.IO.File.ReadAllBytes(overlayImagePath);overlayTexture.LoadImage(overlayImageData);// 创建合成材质Material imageProcessingMaterial = new Material(Shader.Find("Custom/ImageProcessingShader"));imageProcessingMaterial.SetTexture("_MainTex", backgroundTexture);imageProcessingMaterial.SetTexture("_OverlayTex", overlayTexture);// 创建RenderTexture,并渲染到其中RenderTexture renderTexture = new RenderTexture(backgroundTexture.width, backgroundTexture.height, 0);Graphics.Blit(null, renderTexture, imageProcessingMaterial);// 将RenderTexture转换为Texture2DTexture2D outputTexture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGBA32, false);RenderTexture.active = renderTexture;outputTexture.ReadPixels(new UnityEngine.Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);outputTexture.Apply();RenderTexture.active = null;// 显示处理后的图像raw.texture = outputTexture;}

2.但是打包完之后,原本要合并的图片却没有反应

3.解决方法如下:

选择Edit->ProjectSettings->Graphics:

在ProjectSettings里面的Graphics,Always Included Shaders数组更改size,并将所需用到的Shader拖入其中

http://www.lryc.cn/news/250428.html

相关文章:

  • document
  • NodeJS(二):npm包管理工具、yarn、npx、pnpm工具等
  • day3 移出链表中值为x的节点
  • 浅谈 Guava 中的 ImmutableMap.of 方法的坑
  • Symbol()和迭代器生成器
  • USB Type-C的基本原理
  • HarmonyOS开发(八):动画及网络
  • Pinctrl子系统和GPIO子系统
  • Unittest单元测试框架之unittest构建测试套件
  • Django回顾4
  • Apache APISIX 体验指南
  • Promise的resolve和reject方法(手写题)
  • 关于wiki的Unlink攻击理解--附例题BUUCTF-hitcontraining_bamboobox1
  • 【linux】日志有哪些
  • Redis主从复制实现RCE
  • Flutter应用程序的加固原理
  • Centos7部署NFS
  • 我已经开了一个融资融券的账户了,还可以再在别的券商开两融(信用账户)吗?
  • Spring Cloud 版本升级记:OpenFeignClient与Gateway的爱恨交织
  • 华为OD机试 - 最多购买宝石数目(Java JS Python C)
  • 【LeetCode】挑战100天 Day17(热题+面试经典150题)
  • 正则表达式的基本语法
  • 使用visual Studio MFC 平台实现对灰度图添加椒盐噪声,并进行均值滤波与中值滤波
  • Django HMAC 请求签名校验与 Vue.js 实现安全通信
  • 深度学习之循环神经网络
  • 与原有视频会议系统对接
  • C# Serilog--可记录异常完整路径
  • 鉴源实验室 | 汽车网络安全攻击实例解析(三)
  • php 中生成订单号
  • Jmeter工具+ant+jenkins实现持续集成