Built-in shader variables

Transformations

All these matrices are float4x4 type.

   
Name Value
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.

Camera and screen

Name Type Value
_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.

Time

     
Name Type Value
_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).

Lighting

Name Type Value
_LightColor0 (declared in Lighting.cginc) fixed4 Light color.
_WorldSpaceLightPos0 float4 Directional lights: (world space direction, 0). Other lights: (world space position, 1).
_LightMatrix0 (declared in AutoLight.cginc) float4x4 World-to-light matrix. Used to sample cookie & attenuation textures.
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0 float4 (ForwardBase pass only) world space positions of first four non-important point lights.
unity_4LightAtten0 float4 (ForwardBase pass only) attenuation factors of first four non-important point lights.
unity_LightColor half4[4] (ForwardBase pass only) colors of of first four non-important point lights.

Deferred shading and deferred lighting, used in the lighting pass shader (all declared in UnityDeferredLibrary.cginc):

     
Name Type Value
_LightColor float4 Light color.
_LightMatrix0 float4x4 World-to-light matrix. Used to sample cookie & attenuation textures.

Fog and Ambient

     
Name Type Value
UNITY_LIGHTMODEL_AMBIENT fixed4 Ambient lighting color (Equator ambient in three-color lighting case).
unity_AmbientSky fixed4 Sky ambient lighting color in three-color lighting case.
unity_AmbientGround fixed4 Ground ambient lighting color in three-color lighting case.
unity_FogColor fixed4 Fog color.
unity_FogParams float4 Parameters for fog calculation: (density / sqrt(ln(2)), density / ln(2), –1/(end-start), end/(end-start)). x is useful for Exp2 fog mode, y for Exp mode, z and w for Linear mode.










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值