directxhlsldirect3d

HLSL Compiler error?


float4x4 matInvViewProj;

float4 GetPointPosition(float2 Tex0)
{
    float4 PosImageSpace;
    PosImageSpace.xy = float2(Tex0*2-1);
    PosImageSpace.z = tex2D(DepthTextureSampler,Tex0).r;
    return mul(PosImageSpace,matInvViewProj);
}

That's a part of my pixelshader. Why is there a compiler error? I'm compiling it in ps_3_0. Without the mul() it compiles.


Solution

  • Ahh, I guess that makes sense. Since the w componenet is not initialized, the mul() function will fail.

    To avoid it you could initialize your vector as follows:

    float4 PosImageSpace = (float4)0;
    

    I will still recommend you to try compiling your shader using fxc in debug mode, as you can get much better error descriptions that way. You can even set up a custom build step that lets you right click the .fx file and compile it without having to compile the entire solution/project.

    To compile the shader using fxc in a debug configuration:

    fxc /Od /Zi /T fx_3_0 /Fo Directional_Lighting_Shader_Defaul.fxo Directional_Lighting_Shader_Defaul.fx
    

    You can find fxc in C:\Program Files\Microsoft DirectX SDK\Utilities\bin

    To set up a custom build step in Visual Studio check this sample from the DirectX SDK and also check this site

    Also check this article on msdn about using fxc.