unity shader 学习一

来源:互联网 发布:人工智能的中医郎中 编辑:程序博客网 时间:2024/04/30 07:06
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






 NameTypeValueUNITY_MATRIX_MVPfloat4x4Current model * view * projection matrix.模型视图投影矩阵UNITY_MATRIX_MVfloat4x4Current model * view matrix.模型视图矩阵UNITY_MATRIX_Vfloat4x4Current view matrix.视图矩阵UNITY_MATRIX_Pfloat4x4Current projection matrix.投影矩阵UNITY_MATRIX_VPfloat4x4Current view * projection matrix.视图投影矩阵UNITY_MATRIX_T_MVfloat4x4Transpose of model * view matrix.UNITY_MATRIX_IT_MVfloat4x4Inverse transpose of model * view matrix.模型视图矩阵逆转UNITY_MATRIX_TEXTURE0 to UNITY_MATRIX_TEXTURE3float4x4Texture transformation matrices._Object2Worldfloat4x4Current model matrix._World2Objectfloat4x4Inverse of current world matrix._WorldSpaceCameraPosfloat3World space position of the camera.unity_Scalefloat4xyz components unused; w contains scale for uniformly scaled objects.


NameTypeValue_ModelLightColorfloat4Material’s Main * Light color_SpecularLightColorfloat4Material’s Specular * Light color_ObjectSpaceLightPosfloat4Light’s position in object space. w component is 0 for directional lights, 1 for other lights_Light2Worldfloat4x4Light to World space matrix_World2Lightfloat4x4World to Light space matrix_Object2Lightfloat4x4Object to Light space matrix


Name
TypeValue_Timefloat4Time (t/20, t, t*2, t*3), use to animate things inside the shaders._SinTimefloat4Sine of time: (t/8, t/4, t/2, t)._CosTimefloat4Cosine of time: (t/8, t/4, t/2, t).unity_DeltaTimefloat4Delta time: (dt, 1/dt, smoothDt, 1/smoothDt)._ProjectionParamsfloat4x 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._ScreenParamsfloat4x 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.
0 0