ShaderLab

  Shader is the root command of a shader file. Each file must define one (and only one) Shader. It specifies how any objects whose material uses this shader are rendered.

1、Syntax

  Shader "name{ [Properties] Subshaders [Fallback] } Defines a shader. It will appear in the material inspector listed under name. Shaders optionally can define a list of properties that show up as material settings. After this comes a list of SubShaders, and optionally a fallback.

2、Properties

  Shaders can have a list of properties. Any properties declared in a shader are shown in the material inspector inside Unity. Typical properties are the object color, textures, or just arbitrary values to be used by the shader.

3、SubShaders & Fallback

  Each shader is comprised of a list of sub-shaders. You must have at least one. When loading a shader, Unity will go through the list of subshaders, and pick the first one that is supported by the end user's machine. If no subshaders are supported, Unity will try to use fallback shader.

// colored vertex lighting
Shader "Simple colored lighting" {
// a single color property
Properties {
_Color ("Main Color", Color) = (,.,.,)
}
// define one subshader
SubShader {
Pass {
Material {
Diffuse [_Color]
}
Lighting On
}
}
}

Properties

 Syntax

 Properties { Property [Property ...] }
    Defines the property block. Inside braces multiple properties are defined as follows.

 

  Each property a default value is given after equals sign: 

  

Properties {
// properties for water shader
_WaveScale ("Wave scale", Range (0.02,0.15)) = 0.07 // sliders
_ReflDistort ("Reflection distort", Range (,1.5)) = 0.5
_RefrDistort ("Refraction distort", Range (,1.5)) = 0.4
_RefrColor ("Refraction color", Color) = (., ., ., ) // color
_ReflectionTex ("Environment Reflection", 2D) = "" {} // textures
_RefractionTex ("Environment Refraction", 2D) = "" {}
_Fresnel ("Fresnel (A) ", 2D) = "" {}
_BumpMap ("Bumpmap (RGB) ", 2D) = "" {}
}

  

  Later on in the shader’s fixed function parts, property values can be accessed using property name in square brackets:[name]. For example, you could make blending mode be driven by a material property by declaring two integer properties (say “SrcBlend“ and ”DstBlend”), and later on make Blend Command use them: Blend [_SrcBlend] [_DstBlend].

  In front of any property, optional attributes in square brackets can be specified.

  • [HideInInspector] - does not show the property value in the material inspector.
  • [NoScaleOffset] - material inspector will not show texture tiling/offset fields for texture properties with this attribute.
  • [Normal] - indicates that a texture property expects a normal-map.
  • [HDR] - indicates that a texture property expects a high-dynamic range (HDR) texture.
  • [Gamma] - indicates that a float/vector property is specified as sRGB value in the UI (just like colors are), and possibly needs conversion according to color space used. See Properties in Shader Programs.

Fallback

  After all Subshaders a Fallback can be defined. It basically says "if none of subshaders can run on this hardware, try using the ones from another shader".

  Syntax

  Fallback "name"

    Fallback to shader with a given name.

  Fallback Off
    Explicitly state that there is no fallback and no warning should be printed, even if no subshaders can run on this hardware.
Shader "example" {
// properties and subshaders here...
Fallback "otherexample"
}

Subshaders

  Syntax,实际上是Pass的容器,组合多个Pass。

  Subshader { [Tags] [CommonStatePassdef [Passdef ...}

  Defines the subshader as optional tags, common state and a list of pass definitions.

  Each pass definition can be a regular Pass, a Use Pass or a Grab Pass.

  Any statements that are allowed in a Pass definition can also appear in Subshader block. This will make all passes use this "shared" state.  

// ...
SubShader {
Pass {
Lighting Off
SetTexture [_MainTex] {}
}
}
// ...

Subshader Tags

  Subshaders use tags to tell how and when they expect to be rendered to the rendering engine.

  Syntax

  Tags { "TagName1" = "Value1" "TagName2" = "Value2}
  Specifies TagName1 to have Value1TagName2 to have Value2. You can have as many tags as you like.

  In addition to built-in tags recognized by Unity, you can use your own tags and query them using Material.GetTag function.   

  You can determine in which order your objects are drawn using the Queue tag.   

Shader "Transparent Queue Example" {
SubShader {
Tags {"Queue" = "Transparent" }
Pass {
// rest of the shader body...
}
}
}

  For special uses in-between queues can be used. Internally each queue is represented by integer index; Background is 1000,Geometry is 2000, AlphaTest is 2450, Transparent is 3000 and Overlay is 4000. If a shader uses a queue like this:

ShaderLab的更多相关文章

  1. Unity ShaderLab学习总结

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

  2. Unity3D ShaderLab 修改渲染队列进行深度排序

    Unity3D ShaderLab 修改渲染队列进行深度排序 为了更深刻的理解透明度,我们还需要学习一下深度排序,简单来说就是物体被渲染的先后顺序. Unity允许我们通过代码来控制某个特定物体渲染到 ...

  3. Unity3D ShaderLab 透明裁剪着色器

    Unity3D ShaderLab 透明裁剪着色器 上一篇,我们介绍了使用Alpha实现透明的手法,其实Unity为我们的#pragma提供了另一种参数,是我们能做出更高效 简单的透明效果,也就是裁剪 ...

  4. Unity3D ShaderLab 使用alpha参数创建透明效果

    Unity3D ShaderLab 使用alpha参数创建透明效果 其实Unity为了方便我们的工作,为我们内置了很多参数.比如马上用到的透明功能. 准备场景新建Shader Material ,一张 ...

  5. Unity3D ShaderLab 布料着色器

    Unity3D ShaderLab布料着色器 布料着色器是我们在虚拟现实中经常使用的着色器.本篇就来完成一个较为简单的布料着色器. 新建Shader,Material,InteractiveCloth ...

  6. Unity3D ShaderLab 漫反射卷积光照模型

    Unity3D ShaderLab 漫反射卷积光照模型 漫反射卷积[Diffuse convolution]是一个模糊立方体的过程,它保留了立方图的整体光照强度,只模糊了细节. 这种效果在我们要活得一 ...

  7. Unity3D ShaderLab 静态贴图光照模型

    Unity3D ShaderLab 静态贴图光照模型 其实在unity的光照模型中,我们可以把光照讯息烘培进入一个2D贴图,来实现着色器的光照效果. 下面是在unity中关闭灯光和打开灯光的对比效果. ...

  8. Unity3D ShaderLab 立方体图的菲涅尔反射

    Unity3D ShaderLab 立方体图的菲涅尔反射 菲涅尔反射是反射类型中比较常见的一种类型,当我们的视线正对物体表面,那么反射量会明显增加, 我们几乎可以在任何支持反射类型的物体表面看到这种情 ...

  9. Unity3D ShaderLab立方体图的法线渲染

    Unity3D ShaderLab立方体图的法线渲染 某些情况下,我们希望立方体图的材质球上产生法线效果,来更多的表现细节,比如菱形花纹的玻璃,冰块的表面. 在帧数的协调下,我们可以通过input结构 ...

  10. Unity3D ShaderLab 立方体图的反射遮罩

    Unity3D ShaderLab 立方体图的反射遮罩 上一篇,简单的介绍了立方体图的反射,那么我们能不能使用一张纹理对其进行指定遮罩呢?这样美工可以更好的控制图像的效果. 我们接着使用上一篇的sha ...

随机推荐

  1. python模块--如何相互调用自己写的模块

    一.模块相互调用同级目录调用时的两种方法 import module print(module.add(3,8)) from module import add print(add(2,4)) 同级目 ...

  2. grpc xservice 使用

    1. 安装(此处比较简单) dep 包管理 配置环境变量 GOPATH/bin GO/bin protoc 下载并配置环境变量 2. xservice 安装 a. 预备(一些需要的依赖) mkdir ...

  3. C语言控制台窗体图形界面编程(八):鼠标事件

           上次讲的是键盘事件,这次我们介绍鼠标事件. 以下先介绍下鼠标事件的结构体以及相关信息. typedef struct _MOUSE_EVENT_RECORD //鼠标事件结构体 { CO ...

  4. rundll32命令大全

    rundll32命令大全 命令列:rundll32.exe user.exe,restartwindows 功能: 系统重启 命令列:rundll32.exe user.exe,exitwindows ...

  5. FastAdmin env.sample 的用法

    FastAdmin env.sample 的用法 在 FastAdmin 的 1.0.0.20180513 中我提交了一个 PR,增加 env.sample 内容如下: [app] debug = f ...

  6. 解决EditPlus的默认编码方式有关问题(转)

    http://blog.csdn.net/hzhsan/article/details/7911660 最近在使用英文版的Editplus写代码的时候,发现中文字符在调试过程中都变成了乱码, 发现是E ...

  7. elasticsearch 6.0.0及之后移除了一个索引允许映射多个类型的操作(Removal of mapping types)

    分给线一下内容为理解错误内容,实际允许建立父子分档,只是类型改成来 join 官方demo: join datatypeedit The join datatype is a special fiel ...

  8. CentOS部署NetCore - 3. 部署站点

    一. CentOS 安装FTP linux 安装 ftp第一步 使用如下命令#rpm -qa |grep vsftpd可以检测出是否安装了vsftpd软件, 如果没有安装,使用YUM命令进行安装. y ...

  9. 手动封装OpenCV1.0的IplImage读取保存功能遇到的小问题

    最近准备重新学习图像处理的知识,主要目的是自己实现一遍图像处理的算法,所以除了读取.保存图像外的操作都自己写,没想到直接封装OpenCV的读取.保存功能的第一步就出错.关键代码如下 void MyIm ...

  10. JVM内存管理之GC算法精解(五分钟让你彻底明白标记/清除算法)

    相信不少猿友看到标题就认为LZ是标题党了,不过既然您已经被LZ忽悠进来了,那就好好的享受一顿算法大餐吧.不过LZ丑话说前面哦,这篇文章应该能让各位彻底理解标记/清除算法,不过倘若各位猿友不能在五分钟内 ...