ARB fragment INSTRUCTIONS
- CMP dest, src0, src1, src2
Choose src1 if src0 >= 0. Otherwise, choose src2. The comparison is done per channel.
dest = ((src0 >= 0) ? 1.0 : 0.0) * (src1 - src2) + src2
- LRP dest, src0, src1, src2
Interpolates linearly between the second and third source registers by a proportion specified in the first source register.
dest = src0 * src1 + (1-src0) * src2
// which is the same as
dest = src2 + src0 * (src1 - src2)
The above explain is different from ARB fragment, is equal to
ADD result src0, -src2
MAD result, result, src1, src2
dest = (src0 - src2) * src1 + src2 // proportion specified in src1
- .xyzw 后缀与默认后缀
r0.zw = tex2D(_MainTex, i.tex0);
// tex2D的返回内容为float4, 把它内容传递给 r0.zw 时,默认下会取 .xy 也即:r0.zw = tex2D(_MainTex, i.tex0).xy;
// 若该指令是从一条汇编指令直译过来,其正确写法为:r0.zw = tex2D(_MainTex, i.tex0).zw;
r0.z = max(r0, r1.w);
// max()函数中的 r0 默认后缀为 .x,上面等价于 r0.z = max(r0.x, r1.w);
// 实际上该式子应该为: r0.z = max(r0.z, r1.w);
// 结论:根据目标寄存器所采用的xyzw分量的数目,会自动选择源寄存器中对应的分量组合:.x .xy .xyz .xyzw
// 若要有意选择 .y .z .w .yz .zw 等分量,则需要明确填写
-
Unity 查看Shader生成的代码
-
Reference: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/cmp---ps