关闭

Unity Shader 基础2---编程基础

443人阅读 评论(0) 收藏 举报
分类:

(1)Shader文件定义

Shader 文件是通过 Shader 这个关键字开始,引用名与文件路径格式相似,对于文件名和引用名,没有必须相同的限制。
例如:

  • 文件名 Shader_Mine1
  • 定义 Shader “Custom/LearnShader_1”

(2)Shader标签(ShaderLab)

  • Properties 用于定义 Shader 的各种属性
  • SubShader 用于实现 Shader 的各种渲染
  • Fallback 用于当所有定义的 SubShader 对设备都无效时的最后备用的 Shader 的定义
  • CustomEditor 用于使用自定义的 Shader Editor 编辑栏
  • Other commands 用于对 SubShader 的特殊处理

(3)变换参数

参数名 数值表示
UNITY_MATRIX_MVP Current model * view * projection matrix
UNITY_MATRIX_MV Current model * view matrix
UNITY_MATRIX_V Current view matrix
UNITY_MATRIX_P Current projection matrix
UNITY_MATRIX_VP Current view * projection matrix
UNITY_MATRIX_T_MV Transpose of model * view matrix
UNITY_MATRIX_IT_MV Inverse transpose of model * view matrix
_Object2World Current model matrix
_World2Object Inverse of current world matrix


(4)摄像机和屏幕参数

参数名 参数类型 数值表示
_WorldSpaceCameraPos float3 World space position of the camera
_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 camera’s render target width in pixels, y is the camera’s render target height in pixels, z is 1.0 + 1.0/width and w is 1.0 + 1.0/height.
_ZBufferParams float4 Used to linearize Z buffer values. x is (1-far/near), y is (far/near), z is (x/far) and w is (y/far).
unity_OrthoParams float4 x is orthographic camera’s width, y is orthographic camera’s height, z is unused and w is 1.0 when camera is orthographic, 0.0 when perspective.
unity_CameraProjection float4x4 Camera’s projection matrix.
unity_CameraInvProjection float4x4 Inverse of camera’s projection matrix.
unity_CameraWorldClipPlanes[6] float4 Camera frustum plane world space equations, in this order: left, right, bottom, top, near, far.


(5)时间参数

参数名 参数类型 数值表示
_Time float4 Time since level load (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).


(6)纹理参数

参数名 参数类型 数值表示
UNITY_MATRIX_TEXTURE0 float4x4
UNITY_MATRIX_TEXTURE1 float4x4
UNITY_MATRIX_TEXTURE2 float4x4
UNITY_MATRIX_TEXTURE3 float4x4
UNITY_LIGHTMODEL_AMBIENT float4 当前环境的颜色
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3490次
    • 积分:153
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档