1

对于我正在处理的 HLSL 着色器(用于练习),如果纹理坐标(在模型上)高于相应大小的一半(即x > width / 2y > height / 2),我将尝试执行部分代码。我熟悉 C/C++ 并且了解 HLSL 的基础知识(非常基础)。如果没有其他解决方案,我将使用 XNA 手动设置纹理大小(事实上,我在其中使用着色器)。有更好的解决方案吗?如果可能,我会尽量保持在 Shader Model 2.0 中。

4

2 回答 2

2

默认纹理坐标空间被归一化为 0..1,所以x > width / 2应该只是texcoord.x > 0.5.

于 2013-11-11T20:42:14.767 回答
1

这里要小心。tex2d() 和其他纹理调用不应if()/else 子句中。所以如果你有一个像素着色器输入“IN.UV”并且你的目标是“OUT.color”,你需要这样做:

float4 aboveCol = tex2d(mySampler,some_texcoords);
float4 belowCol = tex2d(mySampler,some_other_texcoords);
if (UV.x >= 0.5) {
   OUT.color = /* some function of... */ aboveCol;
} else {
   OUT.color = /* some function of... */ belowCol;
}

而不是将 tex() 调用放在 if() 块中。

于 2013-11-12T14:02:51.157 回答