pow(0,2.2)在hlsl像素着色器中给出1?

Ole*_*ann 9 math shader hlsl pixel-shader

但是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();
    }
}
Run Code Online (Sandbox Code Playgroud)

Nat*_*ead 7

查看HLSL文档,pow(x, y)似乎直接实现为exp(y * log(x)).既然x=0在你的问题中,再次查看文档log(x) == -INF.y只要它是积极的并且大于零,似乎在那一点上的价值无关紧要.

您可能会意外地pow(0.0, 2.0) == 0.0与之比较pow(0.0, 0.0) == 1.0.这是我对发生的事情的最好猜测.

log(0)=-INF 参考

pow = exp(y * log(x)) 参考