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 ...
随机推荐
- Python-requests设置请求的超时时间
使用timeout 参数可以设定等待连接的秒数,如果等待超时,Requests会抛出异常 >>> requests.get('http://github.com', timeout= ...
- c++ map 官方样例
#include <iostream> #include <string> #include <iomanip> #include <map> temp ...
- idea 关闭代码自动折叠,形参提示,行数栏图标,启动不默认打开上次的项目
1,代码自动折叠 1.1,File > setting > Editor > General > Code Folding 1.2,勾选右侧不想要折叠的代码部分 2,形参提示 ...
- Set和Map数据
es6新的数据结构 1.Set:构造函数 const s = new Set ([1,2,3]); console.log(s)//Set(3){1,2,3};[...s];//[1,2,3]cons ...
- php实现SSO单点登录实例
1.点击登录跳转到SSO登录页面并带上当前应用的callback地址2.登录成功后生成COOKIE并将COOKIE传给callback地址3.callback地址接收SSO的COOKIE并设置在当前域 ...
- 【转】Django 图表制作(By Highcharts)
马克,待不时之需 Django 图表制作(By Highcharts):https://blog.csdn.net/Temanm/article/details/54141759 免费而优秀的图表JS ...
- win10 死机 无响应
win10 死机 无响应 用着用着无响应,结束任务出不来,ctrl+alt+delete 无效. 点 窗口的关闭关闭不了. 鼠标键盘无响应. 写的代码变成乱码,影响太严重了,损失惨重. 紧急启动 c ...
- hive案例
数据倾斜: 操作• Join on a.id=b.id• Group by• Count Distinct count(groupby)• 原因• key分布不均导致的• 人为的建表疏忽• 业务数据特 ...
- 把网卡中断绑定到CPU,最大化网卡的吞吐量(转)
先来看一下问题, 我们通过 ifconfig 查看接口的名称 为 p15p1, 一般机器为 eth0 再通过命令 ➜ ~ cat /proc/interrupts | head -n 1 && ...
- 服务发现 - consul 的介绍、部署和使用(转)
什么是服务发现 相关源码: spring cloud demo 微服务的框架体系中,服务发现是不能不提的一个模块.我相信了解或者熟悉微服务的童鞋应该都知道它的重要性.这里我只是简单的提一下,毕竟这不是 ...