assetbundle 对自定义shader的打包
http://docs.unity3d.com/Manual/managingassetdependencies.html
Managing asset dependencies
Any given asset in a bundle may depend on other assets. For example, a model may incorporate materials which in turn make use of textures and shaders. It is possible to include all an asset’s dependencies along with it in its bundle. However, several assets from different bundles may all depend on a common set of other assets (eg, several different models of buildings may use the same brick texture). If a separate copy of a shared dependency is included in each bundle that has objects using it, then redundant instances of the assets will be created when the bundles are loaded. This will result in wasted memory.
To avoid such wastage, it is possible to separate shared dependencies out into a separate bundle and simply reference them from any bundles with assets that need them. First, the referencing feature needs to be enabled with a call toBuildPipeline.PushAssetDependencies. Then, the bundle containing the referenced dependencies needs to be built. Next, another call to PushAssetDependencies should be made before building the bundles that reference the assets from the first bundle. Additional levels of dependency can be introduced using further calls to PushAssetDependencies. The levels of reference are stored on a stack, so it is possible to go back a level using the corresponding BuildPipeline.PopAssetDependencies function. The push and pop calls need to be balanced including the initial push that happens before building.
At runtime, you need to load a bundle containing dependencies before any other bundle that references them. For example, you would need to load a bundle of shared textures before loading a separate bundle of materials that reference those textures.
Asset IDs
If you anticipate needing to rebuild asset bundles that are part of a dependency chain then you should build them with theBuildAssetBundleOptions.DeterministicAssetBundle option enabled. This guarantees that the internal ID values used to identify assets will be the same each time the bundle is rebuilt.
When building the asset bundle with this method, the objects in it are assigned a 32 bit hash code that is calculated using the name of the asset bundle file, the GUID of the asset and the local id of the object in the asset. For that reason make sure to use the same file name when rebuilding. Also note that having a lot of objects might cause hash collisions preventing Unity from building the asset bundle.
Shaders dependencies
Whenever shaders are directly referenced as parameters in BuildPipeline.BuildAssetBundle, or indirectly with the optionBuildAssetBundleOptions.CollectDependencies the shader’s code is included with the asset bundle(这里的shader指定是在工程中有代码的自定义的shader,unity中内置的shader是不会被打包的). This could cause a problem if you use BuildAssetBundle alone to create several asset bundles, since referenced shaders will be included in every generated bundle. There could be conflicts, i.e. when you mix different versions of a shader, so you will have to rebuild all your bundles after modifying the shaders. The shader’s code will also increase the size of bundles. To avoid these problems you can useBuildPipeline.PushAssetDependencies to separate shaders in a single bundle, and that will allow you to update the shader bundle only. As an example of how to achieve this workflow, you can create a prefab that includes references to the required shaders:
C
using UnityEngine;
public class ShadersList : MonoBehaviour {
public Shader[] list;
}
Create an empty object, assign the script, add the shaders to the list and create the prefab, i.e. “ShadersList”. Then you can create an exporter that generates all the bundles and updates the bundle of shaders:
C
using UnityEngine;
using UnityEditor;
public class Exporter : MonoBehaviour {
[MenuItem("Assets/Export all asset bundles")]
static void Export() {
BuildAssetBundleOptions options =
BuildAssetBundleOptions.CollectDependencies |
BuildAssetBundleOptions.CompleteAssets |
BuildAssetBundleOptions.DeterministicAssetBundle;
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/ShadersList.prefab"), null, "WebPlayer/ShadersList.unity3d", options);
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Scene1.prefab"), null, "WebPlayer/Scene1.unity3d", options);
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Scene2.prefab"), null, "WebPlayer/Scene2.unity3d", options);
BuildPipeline.PopAssetDependencies();
BuildPipeline.PopAssetDependencies();
}
[MenuItem("Assets/Update shader bundle")]
static void ExportShaders() {
BuildAssetBundleOptions options =
BuildAssetBundleOptions.CollectDependencies |
BuildAssetBundleOptions.CompleteAssets |
BuildAssetBundleOptions.DeterministicAssetBundle;
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/ShadersList.prefab"), null, "WebPlayer/ShadersList.unity3d", options);
BuildPipeline.PopAssetDependencies();
}
}
Bear in mind that you must load the shader bundle first. One drawback of this method is that the optionBuildAssetBundleOptions.DeterministicAssetBundle can produce conflicts due to colliding hashes when the amount of objects is too large. In this case the build will fail, and it won’t be possible to update the shader bundle alone. In this case you will have to remove that option and rebuild all the asset bundles.
assetbundle 对自定义shader的打包的更多相关文章
- bgfx入门练习3——编译自定义Shader
马个鸡,总算编译过了自定义Shader,在此感谢自己,感谢自己,以及感谢自己.没有自己的努力,我是不可能解决这个问题的,自己真是太叼了.妈的智障!!! 管方那屎一样的make工具根本没用,反正我是折腾 ...
- unity中使用自定义shader进行光照贴图烘培无法出现透明度的坑爹问题
最近开发中在对场景进行光照贴图烘焙时发现一个坑爹问题,在使用自定义shader的时候,shader命名中必须包含Transparent路径,否则烘焙的时候不对alpha通道进行计算,烘焙出来都是狗皮膏 ...
- Cocos2d-x项目移植到WP8系列之九:使用自定义shader
本文原链接:http://www.cnblogs.com/zouzf/p/3995132.html 有时候想得到一些例如灰度图等特殊的渲染效果,就得用到自定义shader,关于shader的一些背景知 ...
- Shader Variants 打包遇到的问题
1. 遇到的问题 最常见的是打包到手机后效果与PC上不一致,具体情况比如: 光照贴图失效 雾失效 透明或者cutoff失效 以上首先需要检查的地方是Shader变体的编译设置 2. 超级着色器编译成N ...
- AssetBundle系列——场景资源之打包(一)
本篇讲解的是3D游戏的场景资源打包方式,首先简单的分析一下场景中所包含的资源的类型. 场景资源一般包含:地表模型(或者是Unity Terrain),非实例化物体(摄像机.空气墙.光源.各种逻辑物体之 ...
- 自定义Vue组件打包、发布到npm以及使用
本文将帮助:将自己写的Vue组件打包到npm进行代码托管,以及正常发布之后如何使用自己的组件. 本文讲述的仅仅是最基础的实现,其他复杂的操作需要非常熟悉webpack的相关知识,作者将继续学习. 先附 ...
- U3D 自定义shader创建Editor扩展
“工欲善其事,必先利其器”Shader学习工具篇 最近一直忙于录制关于Shader入门的视频教程,其中一个反复的机械动作就是右键创建所需要的新Shader.悲剧的是每次打开的都是Unity3D默认的S ...
- three.js后期之自定义shader通道实现扫光效果
如果你还不知道如何在three.js中添加后期渲染通道,请先看一下官方的一个最简单的demo : github. 正如demo中所示的那样,我们的扫光效果,也是一个自定义的ShaderPass. 所以 ...
- Python 自定义模块的打包和发布
写了一个Python模块,要求打包发布,供同事们使用,好吧,查了一下,网上大部分教程没有一个能把话说明白,不过最后还是解决了,特此记录一下, 以免下次遇到同样问题,也帮助其他有缘人,哈哈. 首先看一下 ...
随机推荐
- CentOS 7搭建OpenVPN-Admin
安装注意要点: 1.用户及目录权限 2.openvpn配置文件/etc/openvpn/server.conf,可以设置不同的转发模式等等 3.全程使用apache,不要用其它的如nginx这些,不然 ...
- USBDM BDM Interface for Freescale Microcontroller -- Hardware
USBDM BDM Interface for Freescale Microcontroller -- Hardware Adapter_4_0_0 - Adapter for Coldfire - ...
- android adb命令 unable to connect to 192.168.1.155:5555
如果使用有线网络无法用adb connect命令连接设备的话,可以选择使用无线wifi来连接. 首先在android设备上装一个叫做Adb Wireless的软件,打开wifi,然后打开adb wir ...
- wifidog交叉编译
本文主要记录在linux平台下.交叉编译wifidog并在openwrt平台上执行的过程.主要是针对wifidog源代码被改动后. 不得不亲自进行交叉编译移植的时候,所碰到的一些问题. (1)下载源代 ...
- IEnumerable是集合,IEnumerator是集合的迭代器
我们常用IEnumerable,却忽视IEnumerator.简单来说,IEnumerable是可以被循环遍历的集合,IEnumerator实施循环遍历. 接口分别是: public interfac ...
- finger-guessing game:1场景搭建
场景搭建 //初始化legend组件 init(50, "div_caiquan", 800, 400, main); //定义游戏层 //游戏背景层,结果显示层,点击层 var ...
- ios成长之每日一遍(day 4)
今天, 主要讲四种常见的问题, 废话不多说了, 直接开始. 自动布局:这个我发现有一篇文章写得非常好, 直接表明出地http://www.cocoachina.com/applenews/devnew ...
- C#零基础入门07:打老鼠之面向对象重构
一:前言 有了上面两节的知识,尤其是第六节之后,现在我们回过头看我们的打老鼠游戏,我们是不是会发现:这个程序也太不面向对象了.我们所有的代码逻辑都分布在Code-Hide中(UI的后台代码,称之为Co ...
- 深入理解多线程(五)—— Java虚拟机的锁优化技术
本文是<深入理解多线程>的第五篇文章,前面几篇文章中我们从synchronized的实现原理开始,一直介绍到了Monitor的实现原理. 前情提要 通过前面几篇文章,我们已经知道: 1.同 ...
- npm速度过慢的解决方案
因为npm连接的数据源网站太慢,可以使用淘宝提供的npm数据源, npm config set registry https://registry.npm.taobao.org 使用NPM(Node. ...