shader中注意的问题
1大小写,例如:
#pragma
vertex vert
#pragma
fragment frag
2、subshader 中
pass不可或缺
SV_POSITION 顶点着色器输出的定点位置,裁剪空间中的坐标
SV_Target 描述片元着色器的输出颜色,输出的值将会存储到渲染目标
#pragma 指令告诉unity我们定义的定点着色器和片元着色器的名字
_World2Object 模型空间到世界空间的逆转矩阵
_LightColor0 unity提供的内置变量来处理光源的颜色和强度信息以及光源的方向
saturatge 把参数截取到0--1范围内
a2v 在unity中 常用的语义
POSITION float4类型
NORMAL float3类型
TANGENT float4类型
TEXCOORD0到TEXCOORDN float2或者float4类型
COLOR float4或者fixed4类型
v2f 在unity中常用的语义
SV_POSTION
COLOR0
COLOR1
TEXCOORD0--TEXCOORD7
Name | Type | Value |
UNITY_MATRIX_MVP | float4x4 | Current model * view * projection matrix.模型视图投影矩阵 |
UNITY_MATRIX_MV | float4x4 | Current model * view matrix.模型视图矩阵 |
UNITY_MATRIX_V | float4x4 | Current view matrix.视图矩阵 |
UNITY_MATRIX_P | float4x4 | Current projection matrix.投影矩阵 |
UNITY_MATRIX_VP | float4x4 | Current view * projection matrix.视图投影矩阵 |
UNITY_MATRIX_T_MV | float4x4 | Transpose of model * view matrix. |
UNITY_MATRIX_IT_MV | float4x4 | Inverse transpose of model * view matrix.模型视图矩阵逆转 |
UNITY_MATRIX_TEXTURE0 to UNITY_MATRIX_TEXTURE3 | float4x4 | Texture transformation matrices. |
_Object2World | float4x4 | Current model matrix. |
_World2Object | float4x4 | Inverse of current world matrix. |
_WorldSpaceCameraPos | float3 | World space position of the camera. |
unity_Scale | float4 | xyz components unused; w contains scale for uniformly scaled objects. |
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 |
_Light2World | float4x4 | Light to World space matrix |
_World2Light | float4x4 | World to Light space matrix |
_Object2Light | float4x4 | Object to Light space matrix |
Name |
Type | Value |
_Time | float4 | Time (t/20, t, t*2, t*3), use to animate things inside the shaders. |
_SinTime | float4 | Sine of time: (t/8, t/4, t/2, t). |
_CosTime | float4 | Cosine of time: (t/8, t/4, t/2, t). |
unity_DeltaTime | float4 | Delta time: (dt, 1/dt, smoothDt, 1/smoothDt). |
_ProjectionParams | float4 | x is 1.0 (or –1.0 if currently rendering with a flipped projection matrix), y is the camera’s near plane, z is the camera’s far plane and w is 1/FarPlane. |
_ScreenParams | float4 | x is the current render target width in pixels, y is the current render target height in pixels, z is 1.0 + 1.0/width and w is 1.0 + 1.0/height. |