我正在使用Nvidia CG
和Direct3D9
并且有关于下面的代码的问题。C++着色器问题
它会编译,但不会“加载”(使用cgLoadProgram
包装),并将产生的故障简单描述为D3D failure happened
。
它的Shader Model编译像素着色器的一部分设定为3.0
什么可能是有趣的是,这种着色器加载在下列情况下罚款:
1)手动展开while语句(对许多if { }
语句)。
2)删除循环中tex2D
函数的行。
3)切换到着色器模型2_X
并手动展开循环。着色器代码的
问题的一部分:
float2 tex = float2(1, 1);
float2 dtex = float2(0.01, 0.01);
float h = 1.0 - tex2D(height_texture1, tex);
float height = 1.00;
while (h < height)
{
height -= 0.1;
tex += dtex;
// Remove the next line and it works (not as expected,
// of course)
h = tex2D(height_texture1, tex);
}
如果有人知道为什么会发生这种情况或会在非CG环境中测试similiar代码或能帮助我在一些其他的方式,我在等你;)
谢谢。