首页 > 代码库 > Asm Shader Reference --- Shader Model 1 part
Asm Shader Reference --- Shader Model 1 part
ps部分
ps_1_1,ps_1_2,ps_1_3,ps_1_4
总览
Instruction Set | |||||||
版本 | 指令槽 | 1_1 | 1_2 | 1_3 | 1_4 | ||
ps | 版本号 | 0 | x | x | x | x | |
常数指令 | 1_1 | 1_2 | 1_3 | 1_4 | |||
def - ps | 定义常数 | 0 | x | x | x | x | |
相位指令 | 1_1 | 1_2 | 1_3 | 1_4 | |||
phase - ps | 在相位1与相位2之间转换 | 0 | x | ||||
算法指令 | 1_1 | 1_2 | 1_3 | 1_4 | |||
add - ps | 两个向量相加 | 1 | x | x | x | x | |
bem - ps | 使用一个假的 bump environment-map 变换 | 2 | x | ||||
cmp - ps | 以0为比较赋值 | 11 | x | x | x | ||
cnd - ps | 以0.5为比较赋值 | 1 | x | x | x | x | |
dp3 - ps | 三个分量点积 | 1 | x | x | x | x | |
dp4 - ps | 四个分量点积 | 11 | x | x | x | ||
lrp - ps | 线性插值 | 1 | x | x | x | x | |
mad - ps | 每个分量乘完了加 | 1 | x | x | x | x | |
mov - ps | 赋值 | 1 | x | x | x | x | |
mul - ps | 乘法 | 1 | x | x | x | x | |
nop - ps | 无运算 | 0 | x | x | x | x | |
sub - ps | 减法 | 1 | x | x | x | x | |
图片指令 | 1_1 | 1_2 | 1_3 | 1_4 | |||
tex - ps | 对图片采样 | 1 | x | x | x | ||
texbem - ps | 使用一个假的 bump environment-map 变换 | 1 | x | x | x | ||
texbeml - ps | 使用一个经过亮度校正的假的 bump environment-map 变换 | 1+12 | x | x | x | ||
texcoord - ps | 返回图片坐标为颜色 | 1 | x | x | x | ||
texcrd - ps | 复制图片坐标为颜色 | 1 | x | ||||
texdepth - ps | 计算深度值 | 1 | x | ||||
texdp3 - ps | 贴图数据与贴图坐标之间的三个分量的点积 | 1 | x | x | |||
texdp3tex - ps | 三个分量点积并且查找1D图片 | 1 | x | x | |||
texkill - ps | 基于一个比较来取消像素的渲染 | 1 | x | x | x | x | |
texld - ps_1_4 | 对图片采样 | 1 | x | ||||
texm3x2depth - ps | 逐像素计算深度值用于深度测试 | 1 | x | ||||
texm3x2pad - ps | First row matrix multiply of a two-row matrix multiply | 1 | x | x | x | ||
texm3x2tex - ps | 最后一行与一个二行矩阵进行矩阵乘法 | 1 | x | x | x | ||
texm3x3 - ps | 3x3矩阵相乘 | 1 | x | x | |||
texm3x3pad - ps | 第一行或者第二行与一个三行矩阵进行矩阵乘法,需要与 texm3x3 - ps, texm3x3spec - ps, texm3x3vspec - ps, 或 texm3x3tex - ps结合使用 | 1 | x | x | x | ||
texm3x3spec - ps | 最后一行与一个三行矩阵进行矩阵乘法使用计算结果进行图片查找,可以用于镜面反射与环境贴图 | 1 | x | x | x | ||
texm3x3tex - ps | 通过3x3 矩阵乘积的结果来查找图片 | 1 | x | x | x | ||
texm3x3vspec - ps | 用一个3x3矩阵乘法的计算结果作为法向量,与一个非常量的视线方向向量进行图片查找,可以用于镜面反射与环境贴图 | 1 | x | x | x | ||
texreg2ar - ps | 通过r和a通道作为uv来采样图片 | 1 | x | x | x | ||
texreg2gb - ps | 通过g和b通道作为uv来采样图片 | 1 | x | x | x | ||
texreg2rgb - ps | 通过r、g和b通道来采样图片 | 1 | x | x | |||
部分函数细节
bem
语法
bem dst.rg, src0, src1
算法
(Given n == dest register #)
dest.r = src0.r + D3DTSS_BUMPENVMAT00(stage n) * src1.r
+D3DTSS_BUMPENVMAT10(stage n) * src1.g
dest.g = src0.g + D3DTSS_BUMPENVMAT01(stage n) * src1.r
+D3DTSS_BUMPENVMAT11(stage n) * src1.g
cmp
语法
cmp dst, src0, src1, src2
如果src0>=0返回src1否则src2
算法
ps_1_4
def c0, -0.6, 0.6, 0, 0.6
def c1 0,0,0,0
def c2 1,1,1,1
mov r1, c1
mov r2, c2
cmp r0, c0, r1, r2 // r0 is assigned 1,0,0,0 based on the following:
// r0.x = c2.x because c0.x < 0
// r0.y = c1.y because c0.y >= 0
// r0.z = c1.z because c0.z >= 0
// r0.w = c1.w because c0.w >= 0
cnd
语法
cmp dst, src0, src1, src2
如果src0>0.5 返回src1否则src2
算法
在1_1到1_3版本,src0必须为r0.a(单通道)
// Version 1_1 to 1_3
if (r0.a > 0.5)
dest = src1
else
dest = src2
在1_4版本就可以每个通道分别比较值
for each component in src0
{
if (src0.component > 0.5)
dest.component = src1.component
else
dest.component = src2.component
}
示例
ps_1_4
def c0, -0.5, 0.5, 0, 0.6
def c1, 0,0,0,0
def c2, 1,1,1,1
cnd r1, c0, c1, c2 // r0 contains 1,1,1,0 because
// r1.x = c2.x because c0.x <= 0.5
// r1.y = c2.y because c0.y <= 0.5
// r1.z = c2.z because c0.z <= 0.5
// r1.w = c1.w because c0.w > 0.5
dp3
语法
dp3 dst, src0, src1
计算三个分量的点积
算法
dest.x = dest.y = dest.z = dest.w =
(src0.x * src1.x) + (src0.y * src1.y) + (src0.z * src1.z);
dp4
语法
dp4 dst, src0, src1
计算四个分量的点积
算法
dest.x = dest.y = dest.z = dest.w =
(src0.x * src1.x) + (src0.y * src1.y) +
(src0.z * src1.z) + (src0.w * src1.w);
lrp
语法
lrp dst, src0, src1, src2
基于src0对src1与src2做线性插值运算
算法
dest = src0 * src1 + (1-src0) * src2
// which is the same as
dest = src2 + src0 * (src1 - src2)
mad
语法
mad dst, src0, src1, src2
做(src0 * src1) + src2处理
算法
dest.x = src0.x * src1.x + src2.x;
dest.y = src0.y * src1.y + src2.y;
dest.z = src0.z * src1.z + src2.z;
dest.w = src0.w * src1.w + src2.w;
mov
语法
mov dst, src
转移值处理
mul
语法
mul dst, src0, src1
乘法
算法
dest.x = src0.x * src1.x;
dest.y = src0.y * src1.y;
dest.z = src0.z * src1.z;
dest.w = src0.w * src1.w;
nop
语法
nop
执行无运算
sub
语法
sub dst, src0, src1
减法运算
算法
dest = src0 - src1
vs部分
vs1
总览
Instruction Set | |||||||
Name | Description | Instruction slots | Setup | Arithmetic | New | ||
add - vs | 两个向量加法运算 | 1 | x | x | |||
dcl_usage input (sm1, sm2, sm3 - vs asm) | 声明输入向量寄存器 (see Registers - vs_1_1) | 0 | x | x | |||
def - vs | 定义常量 | 0 | x | x | |||
dp3 - vs | 三个分量的点积运算 | 1 | x | x | |||
dp4 - vs | 四个分量的点积运算 | 1 | x | x | |||
dst - vs | 计算距离向量 | 1 | x | x | |||
exp - vs | 全精度的2的x次方计算 | 10 | x | x | |||
exp - vs | 半精度的2的x次方计算 | 1 | x | x | |||
frc - vs | 小数部分 | 3 | x | x | |||
lit - vs | 局部光计算 | 1 | x | x | |||
log - vs | 全精度的 log?(x)计算 | 10 | x | x | |||
logp - vs | 半精度的 log?(x)计算 | 1 | x | x | |||
m3x2 - vs | 3x2 乘法 | 2 | x | x | |||
m3x3 - vs | 3x3 乘法 | 3 | x | x | |||
m3x4 - vs | 3x4 乘法 | 4 | x | x | |||
m4x3 - vs | 4x3 乘法 | 3 | x | x | |||
m4x4 - vs | 4x4 乘法 | 4 | x | x | |||
mad - vs | 每个分量乘完了加 | 1 | x | x | |||
max - vs | 求最大值 | 1 | x | x | |||
min - vs | 求最小值 | 1 | x | x | |||
mov - vs | 赋值 | 1 | x | x | |||
mul - vs | 乘法 | 1 | x | x | |||
nop - vs | 无运算 | 1 | x | x | |||
rcp - vs | 倒数 | 1 | x | x | |||
rsq - vs | 平方根之后的倒数 | 1 | x | x | |||
sge - vs | 大于或等于比较,返回1或0 | 1 | x | x | |||
slt - vs | 小于比较,返回1或0 | 1 | x | x | |||
sub - vs | 减法 | 1 | x | x | |||
vs | 版本 | 0 | x | x | |||
部分函数细节
dst
语法
dst dest, src0, src1
计算距离向量
src0为(ignored, d*d, d*d,ignored)
src1为(ignored, 1/d,ignored, 1/d)
最终得到的结果为(1, d, d*d, 1/d)
算法
dest.x = 1;
dest.y = src0.y * src1.y;
dest.z = src0.z;
dest.w = src1.w;
exp
语法
exp dst, src
算法
dest.x = dest.y = dest.z = dest.w = (float)pow(2, src.replicateSwizzleComponent);
frc
语法
frc dst, src
算法
dest.x = src.x - (float)floor(src.x);
dest.y = src.y - (float)floor(src.y);
dest.z = src.z - (float)floor(src.z);
dest.w = src.w - (float)floor(src.w);
lit
语法
lit dst, src
src的各部分为
src.x = N*L ; The dot product between normal and direction to light
src.y = N*H ; The dot product between normal and half vector
src.z = ignored ; This value is ignored
src.w = exponent ; The value must be between -128.0 and 128.0
算法
dest.x = 1;
dest.y = 0;
dest.z = 0;
dest.w = 1;
float power = src.w;
const float MAXPOWER = 127.9961f;
if (power < -MAXPOWER)
power = -MAXPOWER; // Fits into 8.8 fixed point format
else if (power > MAXPOWER)
power = MAXPOWER; // Fits into 8.8 fixed point format
if (src.x > 0)
{
dest.y = src.x;//diffuse
if (src.y > 0)
{
// Allowed approximation is EXP(power * LOG(src.y))
dest.z = (float)(pow(src.y, power));//specular
}
}
log
语法
log dst, src
算法
float v = abs(src);
if (v != 0)
{
dest.x = dest.y = dest.z = dest.w =
(float)(log(v)/log(2));
}
else
{
dest.x = dest.y = dest.z = dest.w = -FLT_MAX;
}
logp
语法
logp dst, src
算法
float f = abs(src);
if (f != 0)
dest.x = dest.y = dest.z = dest.w = (float)(log(f)/log(2));
else
dest.x = dest.y = dest.z = dest.w = -FLT_MAX;
m3x2
语法
m3x2 dst, src0, src1
算法
dest.x = (src0.x * src1.x) + (src0.x * src1.y) + (src0.x * src1.z);
dest.y = (src0.x * src2.x) + (src0.y * src2.y) + (src0.z * src2.z);
m3x3
语法
m3x3 dst,src0, src1
算法
dest.x = (src0.x * src1.x) + (src0.y * src1.y) + (src0.z * src1.z);
dest.y = (src0.x * src2.x) + (src0.y * src2.y) + (src0.z * src2.z);
dest.z = (src0.x * src3.x) + (src0.y * src3.y) + (src0.z * src3.z);
m3x4
语法
m3x4 dst, src0, src1
算法
dest.x = (src0.x * src1.x) + (src0.y * src1.y) + (src0.z * src1.z);
dest.y = (src0.x * src2.x) + (src0.y * src2.y) + (src0.z * src2.z);
dest.z = (src0.x * src3.x) + (src0.y * src3.y) + (src0.z * src3.z);
dest.w = (src0.x * src4.x) + (src0.y * src4.y) + (src0.z * src4.z);
m4x3
语法
m4x3dst, src0, src1
算法
dest.x = (src0.x * src1.x) + (src0.y * src1.y) + (src0.z * src1.z) + (src0.w * src1.w);
dest.y = (src0.x * src2.x) + (src0.y * src2.y) + (src0.z * src2.z) + (src0.w * src2.w);
dest.z = (src0.x * src3.x) + (src0.y * src3.y) + (src0.z * src3.z) + (src0.w * src3.w);
m4x4
语法
m4x4 dst, src0, src1
算法
dest.x = (src0.x * src1.x) + (src0.y * src1.y) + (src0.z * src1.z) +
(src0.w * src1.w);
dest.y = (src0.x * src2.x) + (src0.y * src2.y) + (src0.z * src2.z) +
(src0.w * src2.w);
dest.z = (src0.x * src3.x) + (src0.y * src3.y) + (src0.z * src3.z) +
(src0.w * src3.w);
dest.w = (src0.x * src4.x) + (src0.y * src4.y) + (src0.z * src4.z) +
(src0.w * src4.w);
max
语法
max dst, src0, src1
算法
dest.x=(src0.x >= src1.x) ? src0.x : src1.x;
dest.y=(src0.y >= src1.y) ? src0.y : src1.y;
dest.z=(src0.z >= src1.z) ? src0.z : src1.z;
dest.w=(src0.w >= src1.w) ? src0.w : src1.w;
min
语法
min dst, src0, src1
算法
dest.x=(src0.x < src1.x) ? src0.x : src1.x;
dest.y=(src0.y < src1.y) ? src0.y : src1.y;
dest.z=(src0.z < src1.z) ? src0.z : src1.z;
dest.w=(src0.w < src1.w) ? src0.w : src1.w;
rcp
语法
rcp dst, src
算法
float f = src0;
if(f == 0.0f)
{
f = FLT_MAX;
}
else
{
if(f != 1.0)
{
f = 1/f;
}
}
dest = f;
rsq
语法
rsq dst, src
算法
float f = abs(src0);
if (f == 0)
f = FLT_MAX
else
{
if (f != 1.0)
f = 1.0/(float)sqrt(f);
}
dest.z = dest.y = dest.z = dest.w = f;
sge
语法
sge dst, src0, src1
src0大于等于 src1返回1否则为0
算法
dest.x = (src0.x >= src1.x) ? 1.0f : 0.0f;
dest.y = (src0.y >= src1.y) ? 1.0f : 0.0f;
dest.z = (src0.z >= src1.z) ? 1.0f : 0.0f;
dest.w = (src0.w >= src1.w) ? 1.0f : 0.0f;
slt
语法
slt dst, src0, src1
src0小于 src1返回1否则为0
算法
dest.x = (src0.x < src1.x) ? 1.0f : 0.0f;
dest.y = (src0.y < src1.y) ? 1.0f : 0.0f;
dest.z = (src0.z < src1.z) ? 1.0f : 0.0f;
dest.w = (src0.w < src1.w) ? 1.0f : 0.0f;
库: https://msdn.microsoft.com/en-us/library/bb219840(v=vs.85).aspx
--wolf96 2017/1/1
Asm Shader Reference --- Shader Model 1 part