unity shader 内置变量

本文详细介绍了Unity中Shader使用的各种内置变量,包括变换矩阵、摄像机与屏幕相关变量、时间变量等,并涵盖了前向渲染、延迟渲染及顶点光照中涉及的关键光照变量。

一、变换矩阵

UNITY_MATRIX_MVP  从object space转到 projection space(投影)

UNITY_MATRIX_MV    从object space转到camera space

UNITY_MATRIX_V       从world space转到camera space

UNITY_MATRIX_P       从camera space转到projection space

UNITY_MATRIX_VP   从world space转到projection space

UNITY_MATRIX_T_MV   UNITY_MATRIX_MV 的转置矩阵

UNITY_MATRIX_IT_MV  UNITY_MATRIX_MV的逆转置矩阵,法线的矩阵转换需要用变换矩阵的逆转置矩阵.

_Object2World    从object space转到world space

_World2Object    _Object2World的逆矩阵,从world space 到object space

二、Camera and screen

 

Name

Type

Value

_WorldSpaceCameraPos

float3

World space position of the camera.

相机的世界坐标

_ProjectionParams

float4

Xis 1.0 (or –1.0 if currently rendering with aflipped projection matrix),yis the camera’s near plane,zis the camera’s far plane andwis 1/FarPlane.

x 值是1.0或-1.0(当为反转的投影矩阵时)

y 近截面,z远截面,w 1/远截面

_ScreenParams

float4

xis the camera’s render target width in pixels,yis the camera’s render target height in pixels,zis 1.0 + 1.0/width andwis 1.0 + 1.0/height.

屏幕尺寸x宽,y高,z 1+1.0/width,w 1+1.0/height

_ZBufferParams

float4

Used to linearize Z buffer values.xis (1-far/near),yis (far/near),zis (x/far) andwis (y/far).

用于线性化zbuffer

unity_OrthoParams

float4

xis orthographic camera’s width,yis orthographic camera’s height,zis unused andwis 1.0 when camera is orthographic, 0.0 when perspective.

正交摄像机的相关参数,w值1时是正交投影,0时是透视投影

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).

帧间隔时间

 

四、forward渲染的光照变量

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).

World space 光照位置,平行光的w值为0,其他光源的w值为1

_LightMatrix0(declared in AutoLight.cginc)

float4x4

World-to-light matrix. Used to sample cookie & attenuation textures.

World space转到light space矩阵

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.

 

五、延迟光照相关变量

Name

Type

Value

_LightColor

float4

Light color.光照颜色

_LightMatrix0

float4x4

World-to-light matrix. Used to sample cookie & attenuation textures.

World space转到light space矩阵

 

 

六、顶点光照相关变量

Name

Type

Value

unity_LightColor

half4[8]

Light colors. 光照颜色

unity_LightPosition

float4[8]

View-space light positions. (-direction,0) for directional lights; (position,1) for point/spot lights.

View space光照位置,平行光的w值为0,其他光源的w值为1

unity_LightAtten

half4[8]

Light attenuation factors.xis cos(spotAngle/2) or –1 for non-spot lights;yis 1/cos(spotAngle/4) or 1 for non-spot lights;zis quadratic attenuation;wis squared light range.

光照衰减值

unity_SpotDirection

float4[8]

View-space spot light positions; (0,0,1,0) for non-spot lights.

View space聚光灯位置

 

 

 

 

转载于:https://www.cnblogs.com/xhg986/p/7491077.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值