ShaderLab
【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] [CommonState] Passdef [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 Value1, TagName2 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的更多相关文章
- Unity ShaderLab学习总结
http://www.jianshu.com/p/7b9498e58659 Unity ShaderLab学习总结 Why Bothers? 为什么已经有ShaderForge这种可视化Shader编 ...
- Unity3D ShaderLab 修改渲染队列进行深度排序
Unity3D ShaderLab 修改渲染队列进行深度排序 为了更深刻的理解透明度,我们还需要学习一下深度排序,简单来说就是物体被渲染的先后顺序. Unity允许我们通过代码来控制某个特定物体渲染到 ...
- Unity3D ShaderLab 透明裁剪着色器
Unity3D ShaderLab 透明裁剪着色器 上一篇,我们介绍了使用Alpha实现透明的手法,其实Unity为我们的#pragma提供了另一种参数,是我们能做出更高效 简单的透明效果,也就是裁剪 ...
- Unity3D ShaderLab 使用alpha参数创建透明效果
Unity3D ShaderLab 使用alpha参数创建透明效果 其实Unity为了方便我们的工作,为我们内置了很多参数.比如马上用到的透明功能. 准备场景新建Shader Material ,一张 ...
- Unity3D ShaderLab 布料着色器
Unity3D ShaderLab布料着色器 布料着色器是我们在虚拟现实中经常使用的着色器.本篇就来完成一个较为简单的布料着色器. 新建Shader,Material,InteractiveCloth ...
- Unity3D ShaderLab 漫反射卷积光照模型
Unity3D ShaderLab 漫反射卷积光照模型 漫反射卷积[Diffuse convolution]是一个模糊立方体的过程,它保留了立方图的整体光照强度,只模糊了细节. 这种效果在我们要活得一 ...
- Unity3D ShaderLab 静态贴图光照模型
Unity3D ShaderLab 静态贴图光照模型 其实在unity的光照模型中,我们可以把光照讯息烘培进入一个2D贴图,来实现着色器的光照效果. 下面是在unity中关闭灯光和打开灯光的对比效果. ...
- Unity3D ShaderLab 立方体图的菲涅尔反射
Unity3D ShaderLab 立方体图的菲涅尔反射 菲涅尔反射是反射类型中比较常见的一种类型,当我们的视线正对物体表面,那么反射量会明显增加, 我们几乎可以在任何支持反射类型的物体表面看到这种情 ...
- Unity3D ShaderLab立方体图的法线渲染
Unity3D ShaderLab立方体图的法线渲染 某些情况下,我们希望立方体图的材质球上产生法线效果,来更多的表现细节,比如菱形花纹的玻璃,冰块的表面. 在帧数的协调下,我们可以通过input结构 ...
- Unity3D ShaderLab 立方体图的反射遮罩
Unity3D ShaderLab 立方体图的反射遮罩 上一篇,简单的介绍了立方体图的反射,那么我们能不能使用一张纹理对其进行指定遮罩呢?这样美工可以更好的控制图像的效果. 我们接着使用上一篇的sha ...
随机推荐
- [Aizu2784]Similarity of Subtrees
vjudge Description 给一棵\(n\)个节点的有根树,定义两棵树同构当且仅当他们每个深度的节点个数相同.问这个树上有多少对子树满足同构.\(n\le100000\). sol 树\(h ...
- Linux安装vsftpd总结
我使用的是CentOS6安装的vsftpd,转载请注明出处,以下是我的记录: #查看是否已经安装了vsfptd vsftpd -v #安装 yum -y install vsftpd #创建:chro ...
- 关于simulink hdlcoder的优化问题
HDL Block Properties中包含有多个优化选项. 1,delay balance 当其他分支优化过后,可能会引入一个或几个周期的delay,这时候需要在与其并行的几条信号路径上也加上de ...
- lapis 基本开发
1. 生成项目代码 // 支持lua 以及 moonscript, 默认是moonscript 通过--lua 可以生成lua 的代码 lapis new --lua ├── app.lua ├── ...
- saas 系统租户个性化域名&&租户绑定自己域名的解决方案
实际的需求就类似github 的自定义page 1. 个性化域名 github 实现原理就是用户个性化域名使用泛域名解析,这个比较简单,大部分域名提供商都可以解决 具体操作不用赘述 ...
- 【转】Ubuntu中Vmware Tools的安装与卸载
原文网址:http://blog.csdn.net/huanghe423/article/details/7005611 Vmware Tools是VMware提供的一套非常人性化的程序,可以用来解决 ...
- 在Qt中如何使用QtDesigner创建的UI文件(一) (转)
使用Qt有一些时间了,一直在IDE环境(qtcreator和VS2003+集成器)中使用,自然少了很多麻烦的步骤.但是在享受这种便利的同时,我们也失去了理解更多知识背后的点滴.在IDE中,如果我们要开 ...
- 2、ambari搭建HDP集群
一.平台环境 操作系统:CentOS release 6.5 (Final) Java版本:jdk1.8.0_60 Ambari版本:2.2.1.0 HDP版本:2.4.0 MySQL版本:MySQL ...
- OPCClient和OPCServer在Windows上运行方式的恩怨
http://www.diangon.com/wenku/PLC/201504/00021970.html 近段时间,遇到不少人都被OPCClient与OPCServer之间的通讯搞得头大,通过几次远 ...
- 了解IHttpModule接口事件执行顺便 获取Session
本文转载自:http://www.cnblogs.com/eflylab/archive/2008/05/29/1209767.html 最近公司一个项目让人SQL注入了-为了临时先解决这个问题,使攻 ...