multi_compile
【multi_compile】
Used to compile the shader code multiple times with different preprocessor directives for each case.
#pragma multi_compile
#pragma shader_feature
At runtime, the appropriate shader variant is picked up from the Material keywords (Material.EnableKeyword and DisableKeyword) or global shader keywords (Shader.EnableKeyword and DisableKeyword).
1、How multi_compile works
#pragma multi_compile FANCY_STUFF_OFF FANCY_STUFF_ON
Will produce two shader variants, one with FANCY_STUFF_OFF defined, and another with FANCY_STUFF_ON. At runtime, one of them will be activated based on the Material or global shader keywords.
If neither of these two keywords are enabled then the first one (“off”) will be used.
Following will produce four shader variants:
#pragma multi_compile SIMPLE_SHADING BETTER_SHADING GOOD_SHADING BEST_SHADING
When any of the names are all underscores, then a shader variant will be produced, with no preprocessor macro defined.
Following directive below will produce two shader variants; first one with nothing defined, and second one with FOO_ON defined:

2、Difference between shader_feature and multi_compile
The only difference is that unused variants of shader_feature shaders will not be included into game build. So shader_feature makes most sense for keywords that will be set on the materials, while multi_compile for keywords that will be set from code globally.
Additionally, it has a shorthand notation with just one keyword,Which is just a shortcut for #pragma shader_feature _ FANCY_STUFF, i.e. it expands into two shader variants (first one without the define; second one with it).
#pragma shader_feature FANCY_STUFF
#pragma shader_feature _ FANCY_STUFF
3、Keyword limit
There is a limit of 256 keywords in Unity, and around 60 of them are used internally.
So be careful not to exceed the limit when multiple keywords are defined in several different Shaders.
4、Built-in multi_compile shortcuts
以下是一些“shortcut”,即意味着一个命令对应着多个 multi_compile。
multi_compile_fwdbasecompiles all variants needed byForwardBase(forward rendering base) pass type. The variants deal with different lightmap types and main directional light having shadows on or off.multi_compile_fwdaddcompiles variants forForwardAdd(forward rendering additive) pass type. This compiles variants to handle directional, spot or point light types, and their variants with cookie textures.multi_compile_fwdadd_fullshadows- same as above, but also includes ability for the lights to have realtime shadows.multi_compile_fogexpands to several variants to handle different fog types (off/linear/exp/exp2).
为了减少一些内置条件选项,可以用skip_variants:
#pragma multi_compile_fwdadd
// will make all variants containing
// "POINT" or "POINT_COOKIE" be skipped
#pragma skip_variants POINT POINT_COOKIE
参考:https://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html
multi_compile的更多相关文章
- [UnityShader基础]06.#pragma multi_compile
参考链接: https://blog.csdn.net/qq826364410/article/details/81774741 https://docs.unity3d.com/Manual/SL- ...
- 多版本Shader与multi_compile
多版本Shader与multi_compile https://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html #pragma ...
- Unity multi_compile
http://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html http://forum.unity3d.com/threads/tuto ...
- Shader实例:扭曲,漩涡
效果: 案例:新仙剑,王者之剑. 在切换场景的时候,就会有这样的全屏扭曲效果. 思路: 1.用GrabPass抓屏到一张纹理中. 2.进行扭曲,绘制到UGUI的Image上. 准备: 去官网下载Uni ...
- Shader预处理宏、内置状态变量、多版本编译等
预定义shader预处理宏: Target platform: SHADER_API_OPENGL - desktop OpenGL SHADER_API_D3D9 - Direct3D SHADER ...
- 水面shader 线性擦除
// Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position // Upgrade N ...
- Unity ShaderLab学习总结
http://www.jianshu.com/p/7b9498e58659 Unity ShaderLab学习总结 Why Bothers? 为什么已经有ShaderForge这种可视化Shader编 ...
- 给The Lab Renderer for Unity中地形添加阴影
The Lab Renderer for Unity是Valve针对VR在Unity的体验渲染器,提高VR的渲染效率,更多的大家可以查相应资料,在这,说个The Lab Renderer for Un ...
- Unity中Mesh分解与边缘高亮加上深度检测
一个比较简单的需求,不过遇到些坑,记录下. 房间有多个模型,每个模型可能多个SubMesh,点击后,需要能具体到是那个SubMesh,并且在这个SubMesh上显示边缘高光,以及能个性这单个SubMe ...
随机推荐
- glibc -The GNU C Library
1.使用库文件 1.1.头文件 C库实际包含两部分:头文件,实际的库文件.头文件定义类型.定义宏.声明变量.声明函数.头文件定义的内容实际在库文件中实现.需要使用到 C库 的某些功能时,程序源文件包含 ...
- [转]【ROLLUP】Oracle分组函数之ROLLUP魅力
原创:http://blog.itpub.net/519536/viewspace-610995 本文通过演示给出Oracle ROLLUP分组函数的用法,体验一下Oracle在统计查询领域中的函数魅 ...
- uva-10954-贪心
题意:俩个数相加,产生的和就是这次加法的代价,问,所有数都加起来,最小代价是多少 解题思路:贪心,每次都选取最小俩个数相加,如果只有一个数,计算完毕,注意,加法的和要再次入队列. #include & ...
- 以虎嗅网4W+文章的文本挖掘为例,展现数据分析的一整套流程
本文转自知乎 作者:苏格兰折耳喵 ----------------------------------------------------- 本文作者将结合自身经验,并以实际案例的形式进行呈现,涉及从 ...
- jquery小效果:新浪游戏右侧导航菜单 (页面效果)
偷盗:新浪游戏右侧导航菜单 http://games.sina.com.cn 效果: 随着页面的滚动,左侧页面的内容,和右侧的导航菜单的按钮文字对应: 点击右侧的导航按钮,左侧页面滚动到相应的内容 2 ...
- C++学习基础十五--sizeof的常见使用
sizeof的常见用法 1. 基本类型所占的内存大小 类型 32位系统(字节) 64位系统(字节) char 1 1 int 4 4 short 2 2 long 4 8 float 4 4 doub ...
- add_polygon_to_map
var poly = new esri.geometry.Polygon({ "rings": [ [[117.008726, 30.931672], [117.009635, 3 ...
- JQuery:聚焦清空输入框值,失焦恢复默认值
本来这个小玩意很简单,不用记录到博客里,但今天是娱乐日,要快落一天,为了减轻负罪感,假装自己又学了点新东西 <!DOCTYPE html> <html> <head> ...
- Swoole 结合TP5创建http服务
下载TP5框架,在项目根目录下创建server目录 http_service.php <?php //创建服务 $http = new swoole_http_server("0.0. ...
- ubuntu16.04搭建geodjango+postgresql+postgis的WebGIS框架(二))安装postgresql和postgis
卸载老版本sudo dpkg --purge postgis postgresql-9.3-postgis1.安装postgresql sudo apt-cache search postgresql ...