1. 程式人生 > >Unity Shader 內建函式

Unity Shader 內建函式

這個是MSDN上的,DirectX Documentation裡也有,其實也就是HLSL的內建函式

Intrinsic Functions (DirectX HLSL)

The following table lists the intrinsic functions available in HLSL. Each function has a brief description, and a link to a reference page that has more detail about the input argument and return type.

Name Syntax Description
abs abs(x) Absolute value (per component).
acos acos(x) Returns the arccosine of each component of x.
all all(x) Test if all components of x are nonzero.
any any(x) Test if any component of x is nonzero.
asfloat(x) Convert the input type to a float.
asin asin(x) Returns the arcsine of each component of x.
asint asint(x) Convert the input type to an integer.
asuint(x) Convert the input type to an unsigned integer.
atan atan(x) Returns the arctangent of x.
atan2 atan2(y, x) Returns the arctangent of of two values (x,y).
ceil ceil(x) Returns the smallest integer which is greater than or equal to x.
clamp clamp(x, min, max) Clamps x to the range [min, max].
clip clip(x) Discards the current pixel, if any component of x is less than zero.
cos cos(x) Returns the cosine of x.
cosh cosh(x) Returns the hyperbolic cosine of x.
cross cross(x, y) Returns the cross product of two 3D vectors.
D3DCOLORtoUBYTE4(x) Swizzles and scales components of the 4D vector x to compensate for the lack of UBYTE4 support in some hardware.
ddx ddx(x) Returns the partial derivative of x with respect to the screen-space x-coordinate.
ddy ddy(x) Returns the partial derivative of x with respect to the screen-space y-coordinate.
degrees(x) Converts x from radians to degrees.
determinant(m) Returns the determinant of the square matrix m.
distance(x, y) Returns the distance between two points.
dot dot(x, y) Returns the dot product of two vectors.
exp exp(x) Returns the base-e exponent.
exp2 exp2(x) Base 2 exponent (per component).
faceforward(n, i, ng) Returns -n * sign(•(i, ng)).
floor floor(x) Returns the greatest integer which is less than or equal to x.
fmod fmod(x, y) Returns the floating point remainder of x/y.
frac frac(x) Returns the fractional part of x.
frexp frexp(x, exp) Returns the mantissa and exponent of x.
fwidth(x) Returns abs(ddx(x)) + abs(ddy(x))
GetRenderTargetSampleCount() Returns the number of render-target samples.
GetRenderTargetSamplePosition(x) Returns a sample position (x,y) for a given sample index.
isfinite(x) Returns true if x is finite, false otherwise.
isinf isinf(x) Returns true if x is +INF or -INF, false otherwise.
isnan isnan(x) Returns true if x is NAN or QNAN, false otherwise.
ldexp ldexp(x, exp) Returns x * 2exp
length(v) Returns the length of the vector v.
lerp lerp(x, y, s) Returns x + s(y - x).
lit lit(n • l, n • h, m) Returns a lighting vector (ambient, diffuse, specular, 1)
log log(x) Returns the base-e logarithm of x.
log10 log10(x) Returns the base-10 logarithm of x.
log2 log2(x) Returns the base-2 logarithm of x.
max max(x, y) Selects the greater of x and y.
min min(x, y) Selects the lesser of x and y.
modf modf(x, out ip) Splits the value x into fractional and integer parts.
mul mul(x, y) Performs matrix multiplication using x and y.
noise noise(x) Generates a random value using the Perlin-noise algorithm.
normalize(x) Returns a normalized vector.
pow pow(x, y) Returns xy.
radians(x) Converts x from degrees to radians.
reflect(i, n) Returns a reflection vector.
refract(i, n, R) Returns the refraction vector.
round round(x) Rounds x to the nearest integer
rsqrt rsqrt(x) Returns 1 / sqrt(x)
saturate(x) Clamps x to the range [0, 1]
sign sign(x) Computes the sign of x.
sin sin(x) Returns the sine of x
sincos(x, out s, out c) Returns the sine and cosine of x.
sinh sinh(x) Returns the hyperbolic sine of x
smoothstep(min, max, x) Returns a smooth Hermite interpolation between 0 and 1.
sqrt sqrt(x) Square root (per component)
step step(a, x) Returns (x >= a) ? 1 : 0
tan tan(x) Returns the tangent of x
tanh tanh(x) Returns the hyperbolic tangent of x
tex1D tex1D(s, t) 1D texture lookup.
tex1Dbias(s, t) 1D texture lookup with bias.
tex1Dgrad(s, t, ddx, ddy) 1D texture lookup with a gradient.
tex1Dlod(s, t) 1D texture lookup with LOD.
tex1Dproj(s, t) 1D texture lookup with projective divide.
tex2D tex2D(s, t) 2D texture lookup.
tex2Dbias(s, t) 2D texture lookup with bias.
tex2Dgrad(s, t, ddx, ddy) 2D texture lookup with a gradient.
tex2Dlod(s, t) 2D texture lookup with LOD.
tex2Dproj(s, t) 2D texture lookup with projective divide.
tex3D tex3D(s, t) 3D texture lookup.
tex3Dbias(s, t) 3D texture lookup with bias.
tex3Dgrad(s, t, ddx, ddy) 3D texture lookup with a gradient.
tex3Dlod(s, t) 3D texture lookup with LOD.
tex3Dproj(s, t) 3D texture lookup with projective divide.
texCUBE(s, t) Cube texture lookup.
texCUBEbias(s, t) Cube texture lookup with bias.
texCUBEgrad(s, t, ddx, ddy) Cube texture lookup with a gradient.
tex3Dlod(s, t) Cube texture lookup with LOD.
texCUBEproj(s, t) Cube texture lookup with projective divide.
transpose(m) Returns the transpose of the matrix m.
trunc trunc(x) Truncates floating-point value(s) to integer value(s)


表 3-1 HLSL內建函式

函式名            用法

abs                         計算輸入值的絕對值。

acos                        返回輸入值反餘弦值。

all                           測試非0值。

any                         測試輸入值中的任何非零值。

asin                         返回輸入值的反正弦值。

atan                        返回輸入值的反正切值。

atan2                       返回y/x的反正切值。

ceil                         返回大於或等於輸入值的最小整數。

clamp                      把輸入值限制在[min, max]範圍內。

clip                         如果輸入向量中的任何元素小於0,則丟棄當前畫素。

cos                         返回輸入值的餘弦。

cosh                       返回輸入值的雙曲餘弦。

cross                      返回兩個3D向量的叉積。

ddx                         返回關於螢幕座標x軸的偏導數。

ddy                         返回關於螢幕座標y軸的偏導數。

degrees                   弧度到角度的轉換

determinant              返回輸入矩陣的值。

distance                   返回兩個輸入點間的距離。

dot                          返回兩個向量的點積。

exp                         返回以e為底數,輸入值為指數的指數函式值。

exp2                       返回以2為底數,輸入值為指數的指數函式值。

faceforward             檢測多邊形是否位於正面。

floor                       返回小於等於x的最大整數。

fmod                       返回a / b的浮點餘數。

frac                        返回輸入值的小數部分。

frexp                       返回輸入值的尾數和指數

fwidth                     返回 abs ( ddx (x) + abs ( ddy(x))。

isfinite                     如果輸入值為有限值則返回true,否則返回false。

isinf                        如何輸入值為無限的則返回true。

isnan                       如果輸入值為NAN或QNAN則返回true。

ldexp                       frexp的逆運算,返回 x * 2 ^ exp。

len / lenth                返回輸入向量的長度。

lerp                         對輸入值進行插值計算。

lit                            返回光照向量(環境光,漫反射光,鏡面高光,1)。

log                          返回以e為底的對數。

log10                      返回以10為底的對數。

log2                        返回以2為底的對數。

max                        返回兩個輸入值中較大的一個。

min                         返回兩個輸入值中較小的一個。

modf                       把輸入值分解為整數和小數部分。

mul                         返回輸入矩陣相乘的積。

normalize                 返回規範化的向量,定義為 x / length(x)。

pow                        返回輸入值的指定次冪。

radians                    角度到弧度的轉換。

reflect                     返回入射光線i對錶面法線n的反射光線。

refract                     返回在入射光線i,表面法線n,折射率為eta下的折射光線v。

round                      返回最接近於輸入值的整數。

rsqrt                       返回輸入值平方根的倒數。

saturate                   把輸入值限制到[0, 1]之間。

sign                        計算輸入值的符號。

sin                          計算輸入值的正弦值。

sincos                     返回輸入值的正弦和餘弦值。

sinh                        返回x的雙曲正弦。

smoothstep              返回一個在輸入值之間平穩變化的插值。

sqrt                         返回輸入值的平方根。

step                        返回(x >= a)? 1 : 0。

tan                          返回輸入值的正切值。

fanh                        返回輸入值的雙曲線切線。

transpose                 返回輸入矩陣的轉置。

tex1D*                    1D紋理查詢。

tex2D*                    2D紋理查詢。

tex3D*                    3D紋理查詢。

texCUBE*                立方紋理查詢。

Intrinsic Functions (DirectX HLSL)

The following table lists the intrinsic functions available in HLSL. Each function has a brief description, and a link to a reference page that has more detail about the input argument and return type.

Name Description Minimum shader model
abs Absolute value (per component). 11
acos Returns the arccosine of each component of x. 11
all Test if all components of x are nonzero. 11
Blocks execution of all threads in a group until all memory accesses have been completed. 5
Blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call. 5
any Test if any component of x is nonzero. 11
Reinterprets a cast value into a double. 5
Convert the input type to a float. 4
asin Returns the arcsine of each component of x. 11
asint Convert the input type to an integer. 4
Reinterprets the bit pattern of a 64-bit type to a uint. 5
Convert the input type to an unsigned integer. 4
atan Returns the arctangent of x. 11
atan2 Returns the arctangent of of two values (x,y). 11
ceil Returns the smallest integer which is greater than or equal to x. 11
clamp Clamps x to the range [min, max]. 11
clip Discards the current pixel, if any component of x is less than zero. 11
cos Returns the cosine of x. 11
cosh Returns the hyperbolic cosine of x. 11
Counts the number of bits (per component) in the input integer. 5
cross Returns the cross product of two 3D vectors. 11
Swizzles and scales components of the 4D vector xto compensate for the lack of UBYTE4 support in some hardware. 11
ddx Returns the partial derivative of x with respect to the screen-space x-coordinate. 21
Computes a low precision partial derivative with respect to the screen-space x-coordinate. 5
Computes a high precision partial derivative with respect to the screen-space x-coordinate. 5
ddy Returns the partial derivative of x with respect to the screen-space y-coordinate. 21
Computes a low precision partial derivative with respect to the screen-space y-coordinate. 5
Computes a high precision partial derivative with respect to the screen-space y-coordinate. 5
Converts x from radians to degrees. 11
Returns the determinant of the square matrix m.

相關推薦

Unity Shader函式

內建shader輔助函式定義在UnityCG.cginc檔案中 頂點轉換函式: Function: Description: float4 UnityObjectToClipPos(float3 pos)

Unity Shader 函式

這個是MSDN上的,DirectX Documentation裡也有,其實也就是HLSL的內建函式 Intrinsic Functions (DirectX HLSL) The following table lists the intrinsic functions available in HLS

Shader函式(方便自己看)

一、內建包含檔案   Unity中有類似於C++的包含檔案.cginc,在編寫Shader時我們可以使用#include指令把這些檔案包含進來 這樣我們就可以使用Unity為我們提供的一些非常好用的函式、巨集和變數。 例如:#include"UnityCG.cginc" 包含檔案的位置:

Unity Shader入門精要筆記(七):Unity Shader檔案、變數和語義

本系列文章由Aimar_Johnny編寫,歡迎轉載,轉載請標明出處,謝謝。 http://blog.csdn.net/lzhq1982/article/details/74279052 1、Unity提供的內建檔案和變數 上一篇我們學了一個簡單的頂點/片元著色器。複雜的著

GLSL:Shader變數與函式

shader內建變數:    gl_Position: 用於vertex shader, 寫頂點位置;被圖元收集、裁剪等固定操作功能所使用;其內部宣告是:highp vec4 gl_Position;    gl_PointSize: 用於vertex shader, 寫光柵

unity shader 置變量

htm ant texture lds line position 頂點光照 ble tdi 一、變換矩陣 UNITY_MATRIX_MVP  從object space轉到 projection space(投影) UNITY_MATRIX_MV    從object

Unity Shader 置函數

lam roo component sig atan -c cef range clip Intrinsic Functions (DirectX HLSL) The following table lists the intrinsic functions availab

函式和常用模組【day04】:函式(十)

一、36-40 36、isinstance(object, classinfo) 功能:用於判斷,物件是否是某個類的例項 # s = "alex" # 物件,"alex" => str s = [11,11,11] # 用於判斷,物件是否是某個類的例項 r = isinsta

python之路-day3-函式

一、 昨日內容回顧   1、生成器     本質就是迭代器     特點:       1、省記憶體       2、惰性機制       3、只能向前  不能反覆   2、生成器函式     函式中的yield 。yield表示返回和return,分段執行一段程式碼     def fun

python D13 函式

# 1、內建函式# 什麼是內建函式? 就是python給你提供的. 拿來直接⽤的函式, 比如print., input等等. 截⽌# 到python版本3.6.2 python⼀共提供了68個內建函式. 他們就是python直接提供給我們的. 有# ⼀些我們已經⽤過了. 有⼀些還沒有⽤過. 還有⼀些需

day12-2018-11-2 函式

lst = ["唐伯虎", "小娟", "張鶴倫", "燒餅"] # it = lst.__iter__() # print(it.__next__()) # print(it.__next__()) # print(it.__next__()) # print(it.__next__())

python學習day15 day16 函式、匿名函式

https://www.processon.com/view/link/5bdc4fe3e4b09ed8b0c75e81 例子: print(locals()) #返回本地作用域中的所有名字 print(globals()) #返回全域性作用域中的所有名字 global 變數 nonlocal

Python全棧學習筆記day 15:函式

全部內建函式列表:     Built-in Functions     abs() dict() help() min()

Python函式map

簡介 map()是 Python 內建的高階函式,它接收一個函式 func 和一個 list,並通過把函式 func依次作用在 list 的每個元素上,得到一個新的 list 並返回。 一、當list只有一個時 當list只有一個時,將函式func作用於這個list的每個元素上

day013函式

一、內建函式一 [內建函式思維導圖連結] (https://www.processon.com/view/link/5bdc5328e4b0844e0bc6c846) 內建函式就是python提供的,拿來直接用的,如print,input等等 1.作用域相關的 locals

day_12 函式

    1. 內建函式 1.雙下劃線方法的使用 1.原來it=lst.__iter__() print(it__next__()) 2.現在it=iter(list) print(next(it)) 2.id() hash()

【轉】Python 函式 locals() 和globals()

Python 內建函式 locals() 和globals() 轉自: https://blog.csdn.net/sxingming/article/details/52061630

MySQL 常用函式與所有函式

MySQL 常用內建函式 【數值函式】 Abs(X) //絕對值abs(-10.9) = 10 Format(X,D) //格式化千分位數值format(1234567.456, 2) =1,234,567.46 Ceil(X) //向上取整ceil(10.1) = 11 Floor(X) //

常用函式

dir:檢視當前物件的可呼叫的函式。 help:檢視當前函式的幫助文件 字串: lower():所有的大寫字母轉換成小寫 upper():所有的小寫字母轉換成大寫 swapcase():大寫變小寫,小寫變大寫 title()

9 幾個函式

一、 bytes()  s = "你好" bs = s.encode("UTF-8") print(bs) s1 = bs.decode("UTF-8") print(s1) bs = bytes(s, encoding="utf-8") # 把字串串編碼成UTF-8 print(b