高级着色语言HLSL入门(7)
高级着色语言HLSL入门(7)
max (Direct3D 9 HLSL)
Selects the greater of x and y.
Syntax
ret max(x, y) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | scalar, vector, or matrix | float, int | any |
y | in | same as input x | float, int | same dimension(s) as input x |
ret | return type | same as input x | float, int | same dimension(s) as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_1_4 |
min (Direct3D 9 HLSL)
Selects the lesser of x and y.
Syntax
ret min(x, y) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | scalar, vector, or matrix | float, int | any |
y | in | same as input x | float, int | same dimension(s) as input x |
ret | return type | same as input x | float, int | same dimension(s) as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_1_4 |
mul (Direct3D 9 HLSL)
Performs matrix multiplication between x and y. If x is a vector, it treated as a row vector. If y is a vector, it is treated as a column vector. The inner dimension x-columns and y-rows must be equal. The result has the dimension x-rows x y-columns.
Syntax
ret mul(x, y) |
---|
There are 9 overloaded versions of this function, to handle the different cases for the types and sizes of the x and y input arguments. The following table lists these versions.
Version | Name | Purpose | Template Type | Component Type | Size |
---|---|---|---|---|---|
1 | |||||
x | in | scalar | float, int | 1 | |
y | in | scalar | same as input x | 1 | |
ret | out | scalar | same as input x | 1 | |
2 | |||||
x | in | scalar | float, int | 1 | |
y | in | vector | float, int | any | |
ret | out | vector | float, int | same dimension(s) as input y | |
3 | |||||
x | in | scalar | float, int | 1 | |
y | in | matrix | float, int | any | |
ret | out | matrix | same as input y | same dimension(s) as input y | |
4 | |||||
x | in | vector | float, int | any | |
y | in | scalar | float, int | 1 | |
ret | out | vector | float, int | same dimension(s) as input x | |
5 | |||||
x | in | vector | float, int | any | |
y | in | vector | float, int | same dimension(s) as input x | |
ret | out | scalar | float, int | 1 | |
6 | |||||
x | in | vector | float, int | any | |
y | in | matrix | float, int | rows = same dimension(s) as input x, columns = any | |
ret | out | vector | float, int | same dimension(s) as input y columns | |
7 | |||||
x | in | matrix | float, int | any | |
y | in | scalar | float, int | 1 | |
ret | out | matrix | float, int | same dimension(s) as input x | |
8 | |||||
x | in | matrix | float, int | any | |
y | in | vector | float, int | number of columns in input x | |
ret | out | vector | float, int | number of rows in input x | |
9 | |||||
x | in | matrix | float, int | any | |
y | in | matrix | float, int | rows = number of columns in input x | |
ret | out | matrix | float, int | rows = number of rows in input x, columns = number of columns in input y |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_1_1 |
normalize (Direct3D 9 HLSL)
Returns the normalized vector x / length(x). If the length of x is 0, the result is indefinite.
Syntax
ret normalize(x) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | vector | float | any |
ret | out | same as input x | float | same dimension(s) as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_2_0 |
pow (Direct3D 9 HLSL)
Returns xy.
Syntax
ret pow(x, y) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | scalar, vector, or matrix | float | any |
y | in | same as input x | float | same dimension(s) as input x |
ret | out | same as input x | float | same dimension(s) as input x |
Remarks
Special cases:
- If x = 0, then the result will always be 0.
- If x < 0, there will be a compile error.
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_2_0 |
radians (Direct3D 9 HLSL)
Converts x from degrees to radians.
Syntax
ret radians(x) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | scalar, vector, or matrix | float | any |
ret | out | same as input x | float | same dimension(s) as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_1_1 |
reflect (Direct3D 9 HLSL)
Returns the reflection vector v, given the entering ray direction i, and the surface normal n, as in:
v = i - 2 * dot(i, n) * n
Syntax
ret reflect(i, n) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
i | in | vector | float | any |
n | in | vector | float | same dimension(s) as input i |
ret | out | vector | float | same dimension(s) as input i |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_1_1 |
refract (Direct3D 9 HLSL)
Returns the refraction vector given the entering ray direction i, the surface normal n, and the refraction index ri. If the angle between i and n is too great for a given eta, refract returns (0,0,0).
Syntax
ret refract(i, n, ri) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
i | in | vector | float | any |
n | in | vector | float | same dimension(s) as input i |
ri | in | scalar | float | 1 |
refraction vector | out | vector | float | same dimension(s) as input i |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_2_0 |
rsqrt (Direct3D 9 HLSL)
Returns 1 / sqrt(x).
Syntax
ret rsqrt(x) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | scalar, vector, or matrix | float | any |
ret | out | same as input x | float | same dimension(s) as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_2_0 |
saturate (Direct3D 9 HLSL)
Clamps x to the range [0, 1].
Syntax
ret saturate(x) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | scalar, vector, or matrix | float | any |
ret | out | same as input x | float | same dimension(s) as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_1_1 |
sin (Direct3D 9 HLSL)
Returns the sine of x.
Syntax
ret sin(x) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | scalar, vector, or matrix | float | any |
ret | out | same as input x | float | same dimension(s) as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_2_0 |
sincos (Direct3D 9 HLSL)
Returns the sine and cosine of x. sin(x) is stored in the output parameter s. cos(x) is stored in the output parameter c.
Syntax
sincos(x, out s, out c) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | scalar, vector, or matrix | float | any |
s | out | same as input x | float | same dimension(s) as input x |
c | out | same as input x | float | same dimension(s) as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_2_0 |
sqrt (Direct3D 9 HLSL)
Square root (per component).
Syntax
ret sqrt(x) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | scalar, vector, or matrix | float | any |
ret | out | same as input x | float | same dimension(s) as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_2_0 |
tan (Direct3D 9 HLSL)
Returns the tangent of x.
Syntax
ret tan(x) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | scalar, vector, or matrix | float | any |
ret | out | same as input x | float | same dimension(s) as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_2_0 |
transpose (Direct3D 9 HLSL)
Returns the transpose of the input matrix x. If the dimensions of the source matrix is p-rows x q-columns, the resulting matrix is q-columns x p-rows.
Syntax
ret transpose(x) |
---|
Where:
Name | In/Out | Template Type | Component Type | Size |
---|---|---|---|---|
x | in | matrix | float, int, bool | any |
ret | out | matrix | float, int, bool | rows = same number of columns as input x, columns = same number of rows as input x |
Minimum Shader Version
This intrinsic function is supported in the following (or above) shader versions:
Vertex Shader | Pixel Shader |
---|---|
vs_1_1 | ps_1_1 |
大多数函数已经重载以使其可以对所有内建类型有意义。例如,abs对所有数值类型有意义,所以它为所有这些数值类型进行了重载。又例如,叉积的叉乘仅对3D向量有意义,所以它对所有类型的3D向量(比如:int,float,double的3D向量)进行了重载。另一方面,线性插值——lerp,对于数值、2D、3D和4D向量有意义,因此重载了这些类型。
注意:如果你传递进去一个非数值类型到一个(要求)数值类型的函数,也就是一个仅能对数值类型进行操作的函数(比如:cos(x)),那么这个函数会对传进去的每个分量进行操作。例如,你写:
floats v = float3 (0.0f, 0.0f, 0.0f); v = cos(v); |
那么函数将会对每个分量进行操作:v=(cos(x),cos(y),cos(z))。
下例展示了这些固有的函数可能被调用的方式:
float x = sin(1.0f); // sine of 1.0f radian. float y = sqrt(4.0f); // square root of 4. vector u = {1.0f, 2.0f, -3.0f, 0.0f}; vector v = {3.0f, -1.0f, 0.0f, 2.0f}; float s = dot(u, v); // compute dot product of u and v. float3 i = {1.0f, 0.0f, 0.0f}; float3 j = {0.0f, 1.0f, 0.0f}; float3 k = cross(i, j); // compute cross product of i and j. matrix<float, 2, 2> M = {1.0f, 2.0f, 3.0f, 4.0f}; matrix<float, 2, 2> T = transpose(M); // compute transpose |
高级着色语言HLSL入门(7)相关推荐
- 《高级着色语言HLSL入门》系列文章
此系列文章由 博客园 天行健 归纳整理,此处仅作收藏与共享之用! 如欲转载该系列文章,需按如下方式于文章起始位置显式标明文章作者以及原文出处,以示尊重!! 文章作者:天行健 君子当自强而不息 原文出处 ...
- 高级着色语言HLSL入门(6)
高级着色语言HLSL入门(6) 16.7内建函数 HLSL有一个丰富的内建函数的集合,它们对3D图形来说非常有用.下表是一个删减了的列表,注意:要得到更多的参考,可以参看DirectX文档中内建HLS ...
- 高级着色语言HLSL入门(5)
高级着色语言HLSL入门(5) 16.4关键字.语句和强制转换 16.4.1 关键字 为便于参考,这里给出一个HLSL定义的关键字列表: asm bool compile ...
- 高级着色语言HLSL入门(4)
高级着色语言HLSL入门(4) 16.3 变量类型 注意:除了下列各小节中描述的类型外,HLSL还有一些内建的对象类型(如:纹理对象). 16.3.1 数值类型 HLSL支持下列数值类型(scalar ...
- 高级着色语言HLSL入门(3)
高级着色语言HLSL入门(3) SetMatrixTranspose-Used to set a transposed 4 × 4 matrix. Sample call: D3DXMATRIX M( ...
- 高级着色语言HLSL入门(2)
高级着色语言HLSL入门(2) 16.2 编译HLSL 着色器 16.2.1 常量表 每个着色器有一个常量表,用来保存它的变量.D3DX库通过ID3DXConstantTable接口,提供给应用程序访 ...
- 高级着色语言HLSL入门(1)
高级着色语言HLSL入门(1) 在我们写的程序里顶点和像素是很小的对象,它们由GPU来执行,是固定功能管线的一部分.用我们自己写的着色器程序替换一部分固定功能管线,在绘制效果上我们获得很大的灵活性.我 ...
- 高级着色语言HLSL入门
http://www.bullock.cn/blogs/geeker/archives/68700.aspx 高级着色语言HLSL入门(1) 在我们写的程序里顶点和像素是很小的对象,它们由GPU来执行 ...
- DirectX 高级着色语言HLSL入门
为了编写着色器程序,我们需要一种高级着色器语言(High-Level Shading Language ,简称HLSL) . 在DirectX 8中,着色器是用低级着色器汇编语言编写的. Direct ...
最新文章
- linux c va_list 32位和64位的差异
- 【Android 事件分发】事件分发源码分析 ( ViewGroup 事件传递机制 七 )
- C#winform listbox多选的取值,采用DataRowView
- java 接口 实现和继承关系
- lesson from kong fu
- 函数式编程里的Materialization应该翻译成什么?
- 使用pdf.js来预览pdf文件_适用于Dynamics365与PowerApps的注释预览组件
- 专家:不仅人脸识别,信息验证、生物特征都不可靠
- 开源协议神图介绍 MIT 与 Apache 等
- 想学数学建模???先来看会这几个MATLAB题吧!!!(一)
- mac 安装 cocoapods
- QAbstractButton的clicked、pressed、released、toggled、triggered等信号区别
- freebsd上运行hpool
- 中国生物农药市场投资前景及“十四五”规划建议报告2022-2028年
- 本地组策略与安全策略的自动导入
- 硬盘快满了,怎么办?查找重复文件
- C#反射的实现原理及简单应用
- 推动人工智能教育发展,创新学校高质量发展模式
- 金仓数据库 KingbaseES 插件DBMS_OUTPUT
- Mac安装JDK详解
热门文章
- 力扣——搜索插入位置
- 线程Thread(Java)
- ubuntu之修改硬盘名称
- opencv之解决对加载图片大小限制的问题
- wordpress 资料管理系统_说一说库存管理系统。
- OpenCV adaptiveThreshold 自适应阈值
- linux系统命令学习系列8-文件相关操作touch,rm,mv,cat,head,tail命令
- 构建指定仓库_使用Travis CI自动构建和部署你的GitBook
- Android Studio 无法启动模拟器的一种可能是你装的是Ghost版的系统
- win64位下安装python的image支持