但是 pow(0, 2.0) 给出 0
似乎任何浮点指数都给出 1,而整数指数给出 0。
我正在使用 DirectX 9 和 hlsl 编译器“D3DCompiler_43.dll”。在 Nvidia 和 Ati 卡上确认了这一点。
我很困惑!这是某种已知的行为或错误吗?
为了说明效果,请尝试以下简单的测试着色器:
// Test shader demonstrating strange pow behaviour
// when brightness becomes 0 resulting color will jump to white
float4x4 WorldViewProjXf : WorldViewProjection < string UIWidget="None";>;
float Brightness
<
string UIName = "Brightness";
float UIMin = 0;
float UIMax = 1;
> = 0;
struct VS_Input
{
float4 position : POSITION0;
};
struct VS_Output
{
float4 position : POSITION0;
};
VS_Output Vertex_Func( VS_Input in_data )
{
VS_Output outData;
outData.position = mul(in_data.position, WorldViewProjXf);
return outData;
}
float4 Fragment_Func( VS_Output in_data ) : COLOR
{
return pow(Brightness, 2.2);
}
technique Main
{
pass p0
{
VertexShader = compile vs_3_0 Vertex_Func();
PixelShader = compile ps_3_0 Fragment_Func();
}
}