Unity Shader built-in variables

transformation matrix

variable name describe
UNITY_MATRIX_MVP The current model-view-projection matrix used to transform vertex/orientation vectors from model space to clip space
UNITY_MATRIX_MV  The current model-view matrix used to transform the vertex/orientation vectors from model space to view space
UNITY_MATRIX_V  Current view matrix, used to transform vertex/orientation vectors from world space to view space
UNITY_MATRIX_P  The current projection matrix used to transform the vertex/orientation vectors from view space to clip space
UNITY_MATRIX_VP The current view-projection matrix used to transform vertex/orientation vectors from world space to clip space
UNITY_MATRIX_T_MV Transpose matrix of UNITY_MATRIX_T_MV
UNITY_MATRIX_IT_MV The inverse transposition matrix of UNITY_MATRIX_T_MV, used to transform the normal from the model space to the observation space, can also be used to get the inverse matrix of UNITY_MATRIX_T_MV
_Object2World The current magic heart matrix used to transform the vertex/orientation vector from model space to world space
_World2Object The inverse matrix of _Object2World, used to transform the fixed point/orientation vector from world space to model space

Camera and Screen Parameters

variable name type describe
_WorldSpaceCameraPos float3 The position of this camera in world space
_ProjectionParams float4  x=1.0 (or -1.0, if you are using an inverted projection matrix for rendering), y=Near, z=Far, w=1.0+1.0/Far, where Near and Far are divided into near clipping plane and far clipping plane distance from camera
_ScreenParams float4  x=width, y=height, z=1.0+1.0/width, w=1.0+1.0/height, where width and height are the pixel width and height of the rendering target of the camera respectively
_ZBufferParams float4  x=1-Far/Near, y=Far/Near, z=x/Far, w=y/Far, this variable is used to linearize the depth value in the Z buffer
unity_OrthoParams float4  x=width, y=height, z is not defined, w=1.0 (the camera is an orthographic camera) or w=0.0 (the camera is a perspective camera), where width and height are the width and height of the orthographic projection camera
unity_CameraProjection float4x4 The projection matrix for this camera
unity_CameraIveProjection float4x4 the inverse of the camera's projection matrix
unity_CameraWorldClipPlanes[6] float4 The lighting of the camera's 6 clipping planes in world space, in the following order: left, right, bottom, top, near, and far clipping planes

time

variable name type describe
_Time float4 Time calculated from scene loading (t/20,t,t*2,t*3), used for animation in shader
_SinTime float4 Sine value of time (t/8,t/4,t/2,t)
_CosTime float4 Cosine value of time (t/8,t/4,t/2,t)
unity_DeltaTime float4 Interframe time (dt, 1/dt, smoothDt, 1/smoothDt).

Lighting variables for forward rendering

variable name type describe

_LightColor0(declared in Lighting.cginc)

fixed4

light color

_WorldSpaceLightPos0

float4

The position of the light source in the world space, w=0 represents the direction of the parallel light, and w=1 represents the position of other light sources

_LightMatrix0(declared in AutoLight.cginc)

float4x4

Transform vertices from world space to light space

unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0

float4

 (ForwardBase channel only) The world space coordinates of the first four unimportant point lights

unity_4LightAtten0

float4

 (ForwardBase channel only) Attenuation coefficients for the first four unimportant point lights

unity_LightColor

half4[4]

 (Only ForwardBase passes) The color array of the first four unimportant point light sources, used to calculate the vertex light source

 

Delayed lighting related variables

variable name type describe

_LightColor

float4

light color

_LightMatrix0

float4x4

把顶点从世界空间变换到光源空间

顶点光照相关变量

变量名 类型 描述

unity_LightColor

half4[8]

光线颜色

unity_LightPosition

float4[8]

 视图空间光源的位置。方向光源的坐标是(-方向,0);(位置,1)用于点/点指示灯,点光源,聚光灯的坐标是(位置,1)

unity_LightAtten

half4[8]

光源衰减系数。x=cos(spotAngle/2)或非聚光灯为-1;y=1/cos(spotangle/4)或非聚光灯为-1;z是衰减的二次方;w是正方形光源的范围

unity_SpotDirection

float4[8]

如果光源是聚光灯的话,值为视图空间的聚光灯的位置,如果是其他类型的光源,值为(0,0,1,0)。

Guess you like

Origin blog.csdn.net/ttod/article/details/122323126