博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于Unity中Shader的内置值
阅读量:6994 次
发布时间:2019-06-27

本文共 2853 字,大约阅读时间需要 9 分钟。

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  requires including .

要用到这些内置变量你必须在你的中包含文件。

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/高度

转载于:https://www.cnblogs.com/lancidie/p/6964590.html

你可能感兴趣的文章
EBS_DBA_问题:关于不小心drop了表,进行恢复
查看>>
MongoDB数据库
查看>>
HDU-1875-畅通工程再续(最小生成树)
查看>>
POJ-1182-食物链(并查集种类)
查看>>
POJ1288 Sly Number(高斯消元 dfs枚举)
查看>>
Toping Kagglers:Bestfitting,目前世界排名第一
查看>>
Missing key(s) in state_dict: Unexpected key(s) in state_dict
查看>>
sqlconnection,sqlcommand,sqldataadapter,sqldatareader,dataset都是做什么用的?
查看>>
mysql字符集说明
查看>>
linux 动态库 静态库 函数覆盖
查看>>
nginx代理天地图做缓存解决跨域问题
查看>>
SQL MAP 注入测试
查看>>
Android开机自启动程序
查看>>
php弱类型
查看>>
vim
查看>>
【转载】MapReduce编程 Intellij Idea配置MapReduce编程环境
查看>>
安装配置管理 之 Fedora 6.0 蓝牙bluebooth传送文件的问题解决方法
查看>>
C 结构
查看>>
spring 加载不了jdbc.properties文件的数据问题
查看>>
JQuery Plugin 2 - Passing Options into Your Plugin
查看>>