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

⭐ 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转换为Texture2D
        Texture2D 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.kler.cn/a/153748.html

相关文章:

  • 代洋集团:太阳能充电宝,为您的未来充电
  • 统信UOS安装Virtualbox虚拟机和Windows10系统
  • Echarts大屏可视化_05 折线图的定制开发
  • Android Studio build.gradle获取项目绝对路径
  • LeetCode Hot100 287.寻找重复数
  • 剑指 Offer(第2版)题解(C++ Version)
  • Visual Studio Code之自动补全的设置
  • WPF不使用AllowsTransparency实现高性能透明背景异形窗体
  • MidJourney笔记(6)-Niji模式
  • 解决element ui tree组件不产生横向滚动条
  • JVM 类的加载
  • [Linux] 正则表达式及grep和awk
  • 微信小程序自定义tabBar简易实现
  • 二叉树的遍历及哈夫曼编码的代码思路及实现
  • Linux 系统是如何收发网络包的?(计算机网络)
  • 向量数据库,展望AGI时代
  • (二) Windows 下 Sublime Text 3 安装离线插件 Anaconda
  • 2312skia,13画布包入门
  • 自然语言处理 (NLP) 中的组合语义分析
  • MicroPython STM32F4 RTC功能使用介绍