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. (转)SVN搭建(附下载地址)

    原文地址:http://blog.csdn.net/jiminull/article/details/7763795 一.SVN服务端 1.VisualSVN Server下载: http://dow ...

  2. 自写UiAutomator 调试类

    package sms_test; import java.lang.*; import java.util.ArrayList; import java.util.Collection; impor ...

  3. spring mvc 异常处理

    一般实现业务的时候避免不了会抛一些自定义异常 抛给controller进行最终处理.如果业务上比较复杂.频繁的在try catch操作. 时间一长,代码维护性,可读性自然而然就上来了. 然后,spri ...

  4. java.lang.ClassNotFoundException: org.thymeleaf.spring5.view.ThymeleafViewRe。。。。。。。。。。。

    直接上代码问题: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoc ...

  5. mybatis foreach 循环 list(map)

    直接上代码: 整体需求就是: 1.分页对象里面有map map里面又有数组对象 2.分页对象里面有list list里面有map map里面有数组对象. public class Page { pri ...

  6. openx

    1openx 插件开发——终端用 2openx _金额 3openx ————带整理 4openx url 5Openx 2.8.x 在php5.4.x下数据统计不能正常显示解决方案 6openx改造 ...

  7. cookie、localStorage、sessionStorage和会话控制机制

    简介 cookie cookie的内容主要包括:名字Name.值Value.域Domain.路径Path.过期时间Expires/Max-Age.大小Size.HTTP.Secure.SameSite ...

  8. spring data jpa update

    一:在controller  加上: @Controller @RequestMapping("/user") public class UserController { @Aut ...

  9. PHP 服务 php-fpm 的一些常见配置

    < 操作系统 Centos7,PHP版本7.2.7 > 已下所有配置涉及到时间单位均使用 => 秒(s) 分 (m) 时 (h) 天(d) [ 以下为全局配置 ] 01,关于,进程文 ...

  10. 使用cuteFTP与虚拟机交互文件---安装ftp服务

    安装ftp服务,以便在Windows中使用cuteFTP与虚拟机交互文件,使用sudo apt-get install vsftpd 安装完后,打开/etc/vsftpd.conf文件,去掉local ...