Unity provides a handful of builtin values for your shaders: things like current object's transformation matrices, time etc.

Unity为你在编写shader是提供了少量的内置变量:类似 当前物体的变换矩阵,时间等。

You just use them in ShaderLab like you'd use any other property, the only difference is that you don't have to declare it somewhere - they are "built in".

你只能在ShaderLab中使用它们,就像你使用其他属性一样,唯一不同的是你不能声明内置的变量。

Using them in programmable shaders requires including UnityCG.cginc file.

要用到这些内置变量你必须在你的shader程序中包含UnityCG.cginc file文件。

Transformations 变换

float4x4 UNITY_MATRIX_MVP
Current model*view*projection matrix 
当前物体*视*投影矩阵。(注:物体矩阵为 本地->世界)
float4x4 UNITY_MATRIX_MV
Current model*view matrix 
当前物体*视矩阵
float4x4 UNITY_MATRIX_P
Current projection matrix 
当前物体*投影矩阵
float4x4 UNITY_MATRIX_T_MV
Transpose of model*view matrix 
转置物体*视矩阵
float4x4 UNITY_MATRIX_IT_MV 
Inverse transpose of model*view matrix 
逆转置物体*视矩阵
float4x4 UNITY_MATRIX_TEXTURE0 to UNITY_MATRIX_TEXTURE3
Texture transformation matrices 
贴图变换矩阵
float4x4 _Object2World
Current model matrix 
当前物体矩阵
float4x4 _World2Object
Inverse of current world matrix 
物体矩阵的逆矩阵
float3 _WorldSpaceCameraPos
World space position of the camera 
世界坐标空间中的摄像机位置
float4 unity_Scale
xyz components unused; .w contains scale for uniformly scaled objects. 
不适用xyz分量,而是通过w分量包含的缩放值等比缩放物体。

Lighting 光照

In plain ShaderLab, you access the following properties by appending zero at the end: e.g. the light's model*light color is _ModelLightColor0. In Cg shaders, they are exposed as arrays with a single element, so the same in Cg is _ModelLightColor[0].

在纯粹的ShaderLab中,你可以利用下面这些属性,只要在末尾增加一个零数:例如 灯光的物体*灯光颜色是_ModelLightColor0.在Cgshader中这些变量更像是一个包含单一元素的数组。所以在Cg中他们是这样的_ModelLightColor[0];

Name Type Value
_ModelLightColor float4 Material's Main * Light color 材质的主颜色*灯光颜色
_SpecularLightColor float4 Material's Specular * Light color 材质的镜面反射(高光)*灯光颜色。
_ObjectSpaceLightPos float4 Light's position in object space. w component is 0 for directional lights, 1 for other lights 
物体空间中的灯光为,平行光w分量为零其灯光为1;
_Light2World float4x4 Light to World space matrix 灯光转世界空间矩阵
_World2Light float4x4 World to Light space matrix 世界转灯光空间矩阵
_Object2Light float4x4 Object to Light space matrix 物体转灯光空间矩阵

Various 变量

  • float4 _Time : Time (t/20, t, t*2, t*3), use to animate things inside the shaders 
    时间: 用于Shasder中可动画的地方。
  • float4 _SinTime : Sine of time: (t/8, t/4, t/2, t) 
    时间的正弦值。
  • float4 _CosTime : Cosine of time: (t/8, t/4, t/2, t) 
    时间的余弦值
  • float4 _ProjectionParams : 投影参数
    x is 1.0 or -1.0, negative if currently rendering with a flipped projection matrix 
    x为1.0 或者-1.0如果当前渲染使用的是一个反转的投影矩阵那么为负。 
    y is camera's near plane y是摄像机的近剪裁平面
    z is camera's far plane z是摄像机远剪裁平面
    w is 1/FarPlane. w是1/远剪裁平面
  • float4 _ScreenParams : 屏幕参数
    x is current render target width in pixels x是当前渲染目标在像素值中宽度
    y is current render target height in pixels y是当前渲染目标在像素值中的高度
    z is 1.0 + 1.0/width z是1.0+1.0/宽度
    w is 1.0 + 1.0/height w是1.0+1.0/高度

关于Unity中Shader的内置值的更多相关文章

  1. Unity3D -- shader语法内置函数

    该篇是Unity Shader中HLSL的内置函数,主要是一些数学方面的计算函数.在写Shader的时候可以直接使用. abs //计算输入值的绝对值. acos //返回输入值反余弦值. all / ...

  2. OE中admin的内置帐号

    在OE中admin的内置帐号为SUPERUSER_ID,可以用来直接做判断登录用户是否admin from openerp import SUPERUSER_ID if uid == SUPERUSE ...

  3. JS中的日期内置函数

    用JS中的日期内置函数实现在页面显示:“今天是:2013年9月26日14:32:45”. var date=new Date(Date.parse('9/26/2013 14:32:45'));   ...

  4. Javascript 内置值、typeof运算符、true/false判断

    一.内置值       true       false         null         undefined       NaN       Infinity   二.typeof运算结果 ...

  5. 在IDEA中使用JSP中的out内置对象,out.println()——println红色解决方法

    今天在学习JSP的时候,在jsp中使用out内置对象,开发工具用的是IDEA,结果如下图所示 郁闷了半天找度娘,可能关键字输的不准确,乱七八糟的方法一大堆,什么加依赖啊啥的,反正都不管用,最后找到一篇 ...

  6. 学习笔记:GLSL Core Tutorial – Vertex Shader(内置变量说明)

    1.每个Vertex Shader都有用户定义的输入属性,例如:位置,法线向量和纹理坐标等.Vertex Shaders也接收一致变量(uniform variables). uniform vari ...

  7. Unity中Shader和AssetBundle结合使用的注意事项

    之前遇到了一件事情就是打包安卓的ab后,unity在editor启动下,加载出来的abshader丢失,其实发布安卓后运行是正常的,当时还纠结了半天,还写了个重新赋值的脚本 下面是unity开发的一些 ...

  8. 在jsp中常用的内置对象(5个)小总结和两种页面跳转方式(服务器端调转、客户端跳转)的区别

    jsp中常用的几个内置对象: 一.request对象 主要作用:  (1)获取请求页面的信息   比如:request.getParameter("参数名");  (2)获取客户端 ...

  9. Perl中的特殊内置变量详解

    #!/usr/bin/perl -w @array = qw(a b c d); foreach (@array) { print $_," "; } 例子的作用就是定义一个数组并 ...

随机推荐

  1. Ionic实战五:ionic图表源码基于highcharts

    ionic图表demo基于Highcharts,highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是web应用程序添加有交互性的图表.HighCha ...

  2. Hadoop整理三(Hadoop分布式计算框架MapReduce)

    一.概念 MapReduce是一种编程模型,用于大规模数据集(大于1TB)的并行运算.概念"Map(映射)"和"Reduce(归约)",是它们的主要思想.它极大 ...

  3. PHP验证时有用的几段代码

    1.htmlspecialchars() htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体.预定义的字符是: & (和号) 成为 & " ( ...

  4. ssm框架常见问题

    搭建SSM框架时,总是遇到这样那样的问题,有的一眼就能看出来,有的需要经验的积累.现将自己搭建SSM框架时遇到的典型问题总结如下: 一.Struts2框架下的action中无法使用@Autowired ...

  5. [leetcode DP]72. Edit Distance

    计算最少用多少不把word1变为word2, 思路:建立一个dp表,行为word1的长度,宽为word2的长度 1.边界条件,dp[i][0] = i,dp[0][j]=j 2.最优子问题,考虑已经知 ...

  6. Xamarin 2017.10.9更新

     Xamarin 2017.10.9更新 本次更新主要解决了一些bug.Visual Studio 2017升级到15.4获得新功能.Visual Studio 2015需要工具-选项-Xamarin ...

  7. string rune byte 的关系

    在Go当中 string底层是用byte数组存的,并且是不可以改变的. 例如 s:="Go编程" fmt.Println(len(s)) 输出结果应该是8因为中文字符是用3个字节存 ...

  8. 「HNOI2018」转盘

    「HNOI2018」转盘 现场推出了大部分结论但是只写了 \(40\) 分暴力,被贺指导踩爆,现在还有点怀念 HNOI2018 贺指导对着镜子荒野行动的日子,那几天他云球迷瞎**指点篮球,被送上指导称 ...

  9. OI刷题记录(Updating)

    [Counter] [AGC]:0/96 [ARC]:0/70 [2016年省选]:0/69 [2017年省选]:22/75 [2018年省选]:0/63 [ZROI2018]:0/30 [ZROI2 ...

  10. Kali2.0通过xrdp实现windows远程链接Linux

    标题:Kali2.0通过xrdp实现windows远程链接Linux apt-get install xrdp 首先需要安装xrdp 接下来安装xfce4 apt-get install xfce4 ...