HLSL 循环/采样问题
我有一段 HLSL 代码,如下所示:
float4 GetIndirection(float2 TexCoord)
{
float4 indirection = tex2D(IndirectionSampler, TexCoord);
for (half mip = indirection.b * 255; mip > 1 && indirection.a < 128; mip--)
{
indirection = tex2Dlod(IndirectionSampler, float4(TexCoord, 0, mip));
}
return indirection;
}
我得到的结果与仅执行一次的循环一致。我检查了 PIX 中的着色器,事情变得更加奇怪,指示代码中位置的黄色箭头进入循环,遍历一次,然后跳回到开头,此时黄色箭头再也不会移动,但光标移动代码并返回结果(PIX 中的错误,或者我只是使用错误?)
我怀疑这可能是与纹理读取被编译器移出循环有关的问题,但是我认为由于我手动设置 LOD,所以 tex2Dlod 没有发生这种情况:/
所以:
1)有什么问题?
2)有什么建议的解决方案吗?
I have a piece of HLSL code which looks like this:
float4 GetIndirection(float2 TexCoord)
{
float4 indirection = tex2D(IndirectionSampler, TexCoord);
for (half mip = indirection.b * 255; mip > 1 && indirection.a < 128; mip--)
{
indirection = tex2Dlod(IndirectionSampler, float4(TexCoord, 0, mip));
}
return indirection;
}
The results I am getting are consistent with that loop only executing once. I checked the shader in PIX and things got even more weird, the yellow arrow indicating position in the code gets to the loop, goes through it once, and jumps back to the start, at that point the yellow arrow never moves again but the cursor moves through the code and returns a result (a bug in PIX, or am I just using it wrong?)
I have a suspicion this may be a problem to do with texture reads getting moved outside the loop by the compiler, however I thought that didn't happen with tex2Dlod since I'm setting the LOD manually :/
So:
1) What's the problem?
2) Any suggested solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题解决了,这是一个简单的编码错误,我需要在每次迭代中增加 mip 级别,而不是减少它。
Problem was solved, it was a simple coding mistake, I needed to increase mip level on each iteration, not decrease it.