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_fwdbase compiles all variants needed by ForwardBase (forward rendering base) pass type. The variants deal with different lightmap types and main directional light having shadows on or off.
  • multi_compile_fwdadd compiles variants for ForwardAdd (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_fog expands 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的更多相关文章

  1. [UnityShader基础]06.#pragma multi_compile

    参考链接: https://blog.csdn.net/qq826364410/article/details/81774741 https://docs.unity3d.com/Manual/SL- ...

  2. 多版本Shader与multi_compile

    多版本Shader与multi_compile   https://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html   #pragma ...

  3. Unity multi_compile

    http://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html http://forum.unity3d.com/threads/tuto ...

  4. Shader实例:扭曲,漩涡

    效果: 案例:新仙剑,王者之剑. 在切换场景的时候,就会有这样的全屏扭曲效果. 思路: 1.用GrabPass抓屏到一张纹理中. 2.进行扭曲,绘制到UGUI的Image上. 准备: 去官网下载Uni ...

  5. Shader预处理宏、内置状态变量、多版本编译等

    预定义shader预处理宏: Target platform: SHADER_API_OPENGL - desktop OpenGL SHADER_API_D3D9 - Direct3D SHADER ...

  6. 水面shader 线性擦除

    // Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position // Upgrade N ...

  7. Unity ShaderLab学习总结

    http://www.jianshu.com/p/7b9498e58659 Unity ShaderLab学习总结 Why Bothers? 为什么已经有ShaderForge这种可视化Shader编 ...

  8. 给The Lab Renderer for Unity中地形添加阴影

    The Lab Renderer for Unity是Valve针对VR在Unity的体验渲染器,提高VR的渲染效率,更多的大家可以查相应资料,在这,说个The Lab Renderer for Un ...

  9. Unity中Mesh分解与边缘高亮加上深度检测

    一个比较简单的需求,不过遇到些坑,记录下. 房间有多个模型,每个模型可能多个SubMesh,点击后,需要能具体到是那个SubMesh,并且在这个SubMesh上显示边缘高光,以及能个性这单个SubMe ...

随机推荐

  1. vue生命周期理解图

    ............................... 它可以总共分为8个阶段: beforeCreate(创建前), created(创建后), beforeMount(载入前), moun ...

  2. 《汇编语言 基于x86处理器》第十一章 MS-DOS 编程部分的代码 part 2

    ▶ 书中第十一章的程序,主要讲了 Windows 接口,在小黑框中进行程序交互 ● 在屏幕指定位置输出带自定义属性的文字 INCLUDE Irvine32.inc .data outHandle HA ...

  3. Linux文件浏览命令

    1.cat 命令 快快捷查看当前文件的内容.cat适合查看少量信息的文件 cat file 2.more 命令 分页显示文件内容 more file 操作: enter                 ...

  4. [转] Android中的设计模式-备忘录模式

    转自Android中的设计模式-备忘录模式 定义 备忘录设计模式的定义就是把对象的状态记录和管理委托给外界处理,用以维持自己的封闭性. 比较官方的定义 备忘录模式(Memento Pattern)又叫 ...

  5. asp.net excel模板下载

    string filePath = Server.MapPath("~/model/模板.xls");//路径 FileInfo fileInfo = new FileInfo(f ...

  6. new date() 计算本周周一日期

    new date() 计算本周周一日期 需求:计算某天的那一周周一的日期 1.new Date() date.getDay(); //获取周几 0-6 date.getTime();//获取时间戳 1 ...

  7. 图片 base64转byte[]

    /// <summary> /// 保存base64图片,返回阿里云地址 /// </summary> /// <param name="imgCode&quo ...

  8. enum使用方法

    DK1.5引入了新的类型——枚举.在 Java 中它虽然算个“小”功能,却给我的开发带来了“大”方便. 用法一:常量 在JDK1.5 之前,我们定义常量都是: publicstaticfianl... ...

  9. oracle 内连接(inner join)、外连接(outer join)、全连接(full join)

    转自:https://premier9527.iteye.com/blog/1659689 建表语句: create table EMPLOYEE(EID NUMBER,DEPTID NUMBER,E ...

  10. Nginx代理webSocket经常中断的解决方案, 如何保持长连接

    背景 这天气够热的,要处理的事情也够多的.... 1 2 想看解决的,直接 ctrl+f搜索关键字‘配置点’ 开始前交代(想看原因的看这个,个人观点,不代表正确) 解说:今天用nginx反代通讯项目, ...