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

Unity中,可以使用一些内置的方法来设置Unity Shader变量。 这些方法包括: 1. SetColor:用于设置颜色值。 2. SetColorArray:用于设置颜色数组属性。 3. SetFloat:用于设置指定浮点值。 4. SetFloatArray:用于设置浮点数组属性。 5. SetInt:用于设置指定的整数值。 6. SetMatrix:用于设置指定的四维矩阵。 7. SetMatrixArray:用于设置指定的四维矩阵数组属性。 8. SetOverrideTag:用于设置材质上的覆盖标签/值。 9. SetPass:用于激活给定的通道进行渲染。 10. SetShaderPassEnabled:用于在每个材质级别上启用或禁用着色器传递。 11. SetTexture:用于设置一个图片纹理。 12. SetTextureOffset:用于设置图片纹理的位置偏移量。 13. SetTextureScale:用于设置图片纹理的放置比例。 14. SetVector:用于设置四维向量。 15. SetVectorArray:用于设置四维向量数组属性。 这些方法可以根据需要设置Unity Shader中的不同类型的变量,如颜色、浮点数、矩阵、纹理和向量等。 使用这些方法可以方便地操作Unity Shader中的变量,而不需要手动计算一些值。 <span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Unity Shader入门精要第四章:Unity Shader内置变量(数学篇)](https://blog.csdn.net/aoxuestudy/article/details/123976015)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [关于unity 调用Shader变量的方式](https://blog.csdn.net/dxs1990/article/details/124045419)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值