日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于Unity中Shader的内置值

發布時間:2024/9/21 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于Unity中Shader的内置值 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Unity provides a handful of builtin values for your shaders: things like current object's transformation matrices, time etc.

Unity為你在編寫shader是提供了少量的內置變量:類似 當前物體的變換矩陣,時間等。

You just use them in ShaderLab like you'd use any other property, the only difference is that you don't have to declare it somewhere - they are "built in".

你只能在ShaderLab中使用它們,就像你使用其他屬性一樣,唯一不同的是你不能聲明內置的變量。

Using them in?programmable shaders?requires including?UnityCG.cginc file.

要用到這些內置變量你必須在你的shader程序中包含UnityCG.cginc file文件。

Transformations 變換

float4x4 UNITY_MATRIX_MVP
Current model*view*projection matrix?
當前物體*視*投影矩陣。(注:物體矩陣為 本地->世界)
float4x4 UNITY_MATRIX_MV
Current model*view matrix?
當前物體*視矩陣
float4x4 UNITY_MATRIX_P
Current projection matrix?
當前物體*投影矩陣
float4x4 UNITY_MATRIX_T_MV
Transpose of model*view matrix?
轉置物體*視矩陣
float4x4 UNITY_MATRIX_IT_MV?
Inverse transpose of model*view matrix?
逆轉置物體*視矩陣
float4x4 UNITY_MATRIX_TEXTURE0 to UNITY_MATRIX_TEXTURE3
Texture transformation matrices?
貼圖變換矩陣
float4x4 _Object2World
Current model matrix?
當前物體矩陣
float4x4 _World2Object
Inverse of current world matrix?
物體矩陣的逆矩陣
float3 _WorldSpaceCameraPos
World space position of the camera?
世界坐標空間中的攝像機位置
float4 unity_Scale
xyz components unused; .w contains scale for uniformly scaled objects.?
不適用xyz分量,而是通過w分量包含的縮放值等比縮放物體。

Lighting 光照

In plain ShaderLab, you access the following properties by appending zero at the end: e.g. the light's model*light color is?_ModelLightColor0. In Cg shaders, they are exposed as arrays with a single element, so the same in Cg is?_ModelLightColor[0].

在純粹的ShaderLab中,你可以利用下面這些屬性,只要在末尾增加一個零數:例如 燈光的物體*燈光顏色是_ModelLightColor0.在Cgshader中這些變量更像是一個包含單一元素的數組。所以在Cg中他們是這樣的_ModelLightColor[0];

NameTypeValue
_ModelLightColorfloat4Material's Main * Light color?材質的主顏色*燈光顏色
_SpecularLightColorfloat4Material's Specular * Light color?材質的鏡面反射(高光)*燈光顏色。
_ObjectSpaceLightPosfloat4Light's position in object space.?w?component is 0 for directional lights, 1 for other lights?
物體空間中的燈光為,平行光w分量為零其燈光為1;
_Light2Worldfloat4x4Light to World space matrix?燈光轉世界空間矩陣
_World2Lightfloat4x4World to Light space matrix?世界轉燈光空間矩陣
_Object2Lightfloat4x4Object to Light space matrix?物體轉燈光空間矩陣

Various 變量

  • float4 _Time?: Time (t/20, t, t*2, t*3), use to animate things inside the shaders?
    時間: 用于Shasder中可動畫的地方。
  • float4 _SinTime?: Sine of time: (t/8, t/4, t/2, t)?
    時間的正弦值。
  • float4 _CosTime?: Cosine of time: (t/8, t/4, t/2, t)?
    時間的余弦值
  • float4 _ProjectionParams : 投影參數
    x is 1.0 or -1.0, negative if currently rendering with a flipped projection matrix?
    x為1.0 或者-1.0如果當前渲染使用的是一個反轉的投影矩陣那么為負。?
    y is camera's near plane?y是攝像機的近剪裁平面
    z is camera's far plane?z是攝像機遠剪裁平面
    w is 1/FarPlane.?w是1/遠剪裁平面
  • float4 _ScreenParams : 屏幕參數
    x is current render target width in pixels?x是當前渲染目標在像素值中寬度
    y is current render target height in pixels?y是當前渲染目標在像素值中的高度
    z is 1.0 + 1.0/width?z是1.0+1.0/寬度
    w is 1.0 + 1.0/height?w是1.0+1.0/高度

轉載于:https://www.cnblogs.com/lancidie/p/6964590.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的关于Unity中Shader的内置值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。